:root {
  --bg: #f7f5fb;
  --panel: #ffffff;
  --primary: #6d3c8f;
  --primary-dark: #532d72;
  --secondary: #f0e7f8;
  --text: #1e1d2f;
  --muted: #6b6b7c;
  --success: #3ca56b;
  --warning: #d2a819;
  --danger: #d95757;
  --shadow: 0 12px 24px rgba(39, 22, 59, 0.08);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  display: flex;
  justify-content: center;
  padding: 0 0 calc(84px + var(--safe-bottom));
}

button, input {
  font: inherit;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  background: linear-gradient(180deg, #f7f3fb 0%, #f2f6ff 100%);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 12px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--primary) 0%, #a957c2 100%);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1, h2, h3, p {
  margin: 0;
}

.topbar h1 {
  font-size: 1.1rem;
  color: var(--text);
}

.ghost-button {
  border: 0;
  background: #f2ebf9;
  color: var(--primary-dark);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.hidden { display: none !important; }

.app-view {
  padding: 0 18px 12px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.auth-card,
.card,
.summary-card,
.list-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card {
  padding: 22px 18px 18px;
  margin-top: 12px;
}

.logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.logo-wrap .brand-badge {
  width: 68px;
  height: 68px;
  font-size: 1.7rem;
}

.auth-card h2 {
  text-align: center;
  margin-bottom: 6px;
}

.auth-card p {
  text-align: center;
  color: var(--muted);
  margin-bottom: 18px;
}

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

input {
  width: 100%;
  border: 1px solid #e6dff0;
  background: #faf9fd;
  color: var(--text);
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(109, 60, 143, 0.1);
}

.primary-button {
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, #8e5eb2 100%);
  color: white;
  font-weight: 700;
  padding: 15px 16px;
  box-shadow: 0 8px 18px rgba(109, 60, 143, 0.22);
}

.secondary-link {
  text-align: center;
  color: var(--primary-dark);
  font-size: 0.8rem;
  margin-top: 14px;
}

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  display: none;
}

.alert.error { background: #faecec; color: #8f2f2f; display: block; }
.alert.success { background: #eaf8f1; color: #1e7a4f; display: block; }

.dashboard-header,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0 14px;
}

.dashboard-header h2,
.section-header h3 {
  font-size: 1.2rem;
}

.muted {
  color: var(--muted);
  font-size: 0.72rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  padding: 14px 12px;
}

.summary-card .label {
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 8px;
}

.summary-card .value {
  font-size: 0.96rem;
  line-height: 1.2;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.summary-card .trend {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.68rem;
  color: var(--success);
  background: rgba(60, 165, 107, 0.1);
  border-radius: 999px;
  padding: 4px 7px;
}

.card {
  padding: 18px 16px;
  margin-bottom: 14px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.action-item {
  background: #f6f0fb;
  border: 0;
  border-radius: 16px;
  padding: 12px 10px;
  color: var(--primary-dark);
  font-weight: 700;
  min-height: 78px;
}

.action-item span {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.list-card {
  padding: 18px 16px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #f0edf5;
}

.list-item:last-child { border-bottom: 0; }

.item-copy strong {
  display: block;
  margin-bottom: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
}

.badge.ok {
  background: rgba(60, 165, 107, 0.1);
  color: var(--success);
}

.badge.warn {
  background: rgba(210, 168, 25, 0.12);
  color: var(--warning);
}

.badge.info {
  background: rgba(109, 60, 143, 0.1);
  color: var(--primary-dark);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(8px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(100% - 18px, 460px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(109, 60, 143, 0.08);
  box-shadow: 0 -8px 22px rgba(18, 18, 28, 0.08);
  border-radius: 18px;
  padding: 8px 8px 10px;
  backdrop-filter: blur(10px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px 6px;
  border-radius: 12px;
  font-weight: 700;
}

.nav-item.active {
  background: var(--secondary);
  color: var(--primary-dark);
}

.nav-item span { font-size: 1.2rem; }
.nav-item small { font-size: 0.64rem; }

@media (min-width: 640px) {
  body {
    padding: 18px 0 100px;
  }

  .app-shell {
    border-radius: 28px;
    overflow: hidden;
    margin: 0 auto 24px;
    min-height: calc(100vh - 24px);
    box-shadow: 0 18px 40px rgba(35, 26, 55, 0.09);
  }
}
