:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f4f0df;
  --panel: #fffaf0;
  --panel2: #f8f4e6;
  --text: #213328;
  --muted: #6f7d61;
  --line: #d9d6b9;
  --button: #2f6b45;
  --soft: #edf3dc;
  --accent: #d9962f;
  --bad: #b6362d;
  --ok: #0f7a4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 18px;
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 216, 132, .28), transparent 28%),
    linear-gradient(145deg, #f8f1d7 0%, #ecf5df 48%, #dcebd9 100%);
  color: var(--text);
}

body.auth {
  display: grid;
  place-items: center;
}

body.account {
  padding: 20px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 216, 132, .28), transparent 30%),
    linear-gradient(145deg, #f8f1d7 0%, #ecf5df 52%, #dcebd9 100%);
}

body.portal {
  padding: 18px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 216, 132, .24), transparent 30%),
    linear-gradient(145deg, #f8f1d7 0%, #ecf5df 52%, #dcebd9 100%);
}

main.auth-shell {
  width: min(520px, 100%);
}

main.account-shell {
  width: min(1040px, 100%);
  margin: 0 auto;
}

main.portal-shell {
  width: min(920px, 100%);
  margin: 0 auto;
}

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

.panel {
  background: color-mix(in srgb, var(--panel) 94%, white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 18px 52px rgba(63, 91, 57, .12);
}

.auth .panel {
  background: var(--panel);
  box-shadow: 0 18px 52px rgba(63, 91, 57, .16);
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

.auth h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: rgba(255, 255, 255, .54);
  color: var(--text);
}

.auth input {
  background: transparent;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: rgba(255, 255, 255, .54);
  color: var(--text);
}

button,
a.button {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--button);
  color: white;
  text-decoration: none;
  font: inherit;
  font-weight: 750;
}

button:disabled {
  cursor: wait;
  opacity: .62;
}

.auth button,
.auth a.button {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
}

button.secondary,
a.button.secondary {
  background: var(--soft);
  color: var(--button);
  border: 1px solid var(--line);
}

button.danger {
  background: #b84435;
}

.hidden {
  display: none;
}

.status {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.auth .status {
  margin-top: 14px;
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
}

.status.ok {
  color: var(--ok);
  background: #e7f5ee;
  border: 1px solid #b9dfcc;
}

.status.bad {
  color: var(--bad);
}

.eyebrow {
  color: var(--muted);
  font-weight: 750;
  margin: 0 0 8px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr);
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
}

.hero-card {
  background: linear-gradient(135deg, #fffaf0 0%, #edf5dd 100%);
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.stat {
  border: 1px solid rgba(47, 107, 69, .18);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, .48);
}

.stat-value {
  display: block;
  color: var(--button);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.next-step-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin-bottom: 4px;
}

.section-subtitle {
  margin: 0;
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid rgba(47, 107, 69, .2);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--soft);
  color: var(--button);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.badge.ok {
  border-color: #b9dfcc;
  background: #e7f5ee;
  color: var(--ok);
}

.badge.warn {
  border-color: #ead2a7;
  background: #fff4d8;
  color: #8a5a0a;
}

.badge.bad {
  border-color: #e3b7b0;
  background: #fff0ec;
  color: var(--bad);
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, .42);
}

.linkbox {
  display: block;
  color: var(--text);
  text-decoration: none;
}

.linkbox:hover {
  border-color: #a7bd88;
  background: rgba(255, 255, 255, .72);
}

.family-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.family-dashboard-card {
  align-items: flex-start;
}

.family-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.family-actions .button {
  min-width: 92px;
}

.card-action {
  color: var(--button);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.family-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.download-card {
  border-color: rgba(47, 107, 69, .34);
  background: #edf3dc;
}

.child-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.child-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(47, 107, 69, .2);
  border-radius: 8px;
  background: var(--soft);
  color: var(--button);
  font-weight: 900;
}

.child-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  margin-top: 6px;
}

.danger-zone {
  border-color: #e3b7b0;
  background: rgba(255, 250, 240, .72);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
}

.onboarding-empty {
  grid-column: 1 / -1;
  color: var(--text);
  background: rgba(255, 255, 255, .36);
}

.onboarding-empty ol {
  margin: 10px 0 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.5;
}

.panel-note {
  margin: 14px 0 0;
}

.ok-text {
  color: var(--ok);
  font-weight: 800;
}

.account form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 14px;
}

.portal form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
}

.child-profile-form {
  grid-template-columns: minmax(0, 1fr) minmax(140px, 180px) auto;
}

.tracking-form {
  grid-template-columns: minmax(0, 1fr) minmax(140px, 180px) auto;
}

.telegram-form {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.stack {
  display: grid;
  gap: 14px;
}

@media (max-width: 760px) {
  body.account {
    padding: 14px;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .quick-stats {
    grid-template-columns: 1fr;
  }

  .family-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .family-actions {
    width: 100%;
    justify-content: stretch;
  }

  .family-actions .button {
    flex: 1 1 120px;
  }

  .child-card {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .child-card .card-action {
    grid-column: 2;
  }

  .section-head {
    flex-direction: column;
  }

  .section-head > .button {
    width: 100%;
  }

  .account form,
  .portal form,
  .child-profile-form,
  .tracking-form,
  .telegram-form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .portal-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.portal-header h1 {
  font-size: 28px;
}

.portal h2 {
  margin: 22px 0 12px;
}

.portal .panel + .panel {
  margin-top: 14px;
}

.portal .section-head h2 {
  margin-top: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.status-card,
.metric-card {
  min-height: 112px;
  border: 1px solid rgba(47, 107, 69, .18);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, .42);
}

.status-card strong,
.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.command-status {
  position: relative;
  border-color: rgba(47, 107, 69, .16);
}

.command-status::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(74, 86, 70, .32);
}

.command-status.ok::after {
  background: var(--ok);
}

.command-status.pending::after {
  background: #c69025;
}

.command-status.warn::after {
  background: var(--danger);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.field-label {
  display: grid;
  gap: 6px;
  align-content: start;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.field-label input,
.field-label select {
  width: 100%;
}

.field-hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.form-actions button {
  width: min(360px, 100%);
}

.code-card {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(47, 107, 69, .22);
  border-radius: 8px;
  padding: 14px;
  background: #edf3dc;
}

.code-card code {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.event-list {
  display: grid;
  gap: 8px;
}

.event-card {
  display: grid;
  grid-template-columns: minmax(120px, .5fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .38);
}

.event-card time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.child-profile-form {
  align-items: end;
}

.portal form.tracking-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 12px;
}

.tracking-form .field-label {
  min-height: 184px;
  border: 1px solid rgba(47, 107, 69, .16);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, .34);
}

.tracking-form button {
  width: 100%;
  min-height: 56px;
  min-width: 120px;
}

.tracking-form .form-actions {
  grid-column: auto;
  align-self: end;
  align-items: flex-end;
  min-height: 0;
}

@media (max-width: 760px) {
  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .button,
  .section-head > .button,
  .section-head > button {
    width: 100%;
  }

  .portal form.tracking-form {
    grid-template-columns: 1fr;
  }

  .tracking-form .field-label {
    min-height: auto;
  }

  .form-actions {
    justify-content: stretch;
  }

  .tracking-form button {
    min-height: 56px;
  }

  .event-card {
    grid-template-columns: 1fr;
  }

  .event-card time {
    white-space: normal;
  }
}
