:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --line: #e2ddd4;
  --text: #1d211f;
  --muted: #6b706c;
  --accent: #2f6b5e;
  --accent-soft: #dcebe6;
  --accent-text: #ffffff;
  --warn: #b26a12;
  --warn-soft: #fbecd6;
  --danger: #b3382c;
  --danger-soft: #f8dfdb;
  --ok: #2f7a45;
  --ok-soft: #dcefe1;
  --bubble-in: #ffffff;
  --bubble-out: #dcebe6;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 2px 8px rgba(30, 30, 20, .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151816; --surface: #1d211f; --surface-2: #252a27; --line: #303632; --text: #ecefed; --muted: #9aa29d;
    --accent: #6fbfa9; --accent-soft: #23362f; --accent-text: #0f1a16; --warn: #e3a556; --warn-soft: #3a2c19;
    --danger: #ec8478; --danger-soft: #3d2320; --ok: #7fcb94; --ok-soft: #1f3325; --bubble-in: #252a27; --bubble-out: #23362f;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151816; --surface: #1d211f; --surface-2: #252a27; --line: #303632; --text: #ecefed; --muted: #9aa29d;
  --accent: #6fbfa9; --accent-soft: #23362f; --accent-text: #0f1a16; --warn: #e3a556; --warn-soft: #3a2c19;
  --danger: #ec8478; --danger-soft: #3d2320; --ok: #7fcb94; --ok-soft: #1f3325; --bubble-in: #252a27; --bubble-out: #23362f;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 Figtree, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* layout */
.shell { max-width: 980px; margin: 0 auto; padding: 0 16px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 980px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand svg { width: 26px; height: 26px; }
.topbar nav { margin-left: auto; display: flex; gap: 4px; }
.navlink { padding: 7px 11px; border-radius: 999px; color: var(--muted); font-weight: 550; position: relative; }
.navlink.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dot-count { display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px; font-weight: 700; }

.page-head { display: flex; align-items: center; gap: 12px; margin: 20px 0 14px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 550; margin-top: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 720px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.section-title { display: flex; align-items: baseline; gap: 8px; margin: 22px 0 10px; }
.section-title h2 { flex: 1; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); outline: none; min-height: 40px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 90px; resize: vertical; font-size: 14px; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 24px; border-radius: 12px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; padding-top: 2px; }
.setting .text { flex: 1; min-width: 0; }

/* chips & pills */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 6px -16px 16px; padding: 0 16px; scrollbar-width: none; }
.tabs a { padding: 10px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* avatar */
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px; flex: none; }
.avatar.lg { width: 54px; height: 54px; font-size: 22px; }

/* kid card */
.kid { display: block; color: inherit; }
.kid .meter { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 12px 0 6px; }
.kid .meter > div { height: 100%; background: var(--accent); border-radius: 5px; }
.kid .meter.over > div { background: var(--danger); }
.kid .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.quick { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.list .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.list a.item { display: flex; gap: 12px; align-items: center; color: inherit; width: 100%; }
.icon-dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-2); font-size: 15px; }
.icon-dot.danger { background: var(--danger-soft); color: var(--danger); }
.icon-dot.warn { background: var(--warn-soft); color: var(--warn); }
.icon-dot.accent { background: var(--accent-soft); color: var(--accent); }
.unread-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; margin-top: 8px; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .col { width: 100%; max-width: 34px; border-radius: 6px 6px 3px 3px; background: var(--accent); min-height: 2px; position: relative; }
.bars .col.over { background: var(--danger); }
.bars .col.today { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
.bars .lbl { font-size: 11px; color: var(--muted); }
.bars .val { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hbar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.hbar > div { height: 100%; background: var(--accent); border-radius: 3px; }
.hbar.over > div { background: var(--danger); }

/* messages */
.chat-layout { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.chat-layout > * { min-width: 0; }
@media (min-width: 820px) { .chat-layout { grid-template-columns: 320px minmax(0, 1fr); align-items: start; } }
.thread { display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 8px 11px; border-radius: 14px; background: var(--bubble-in); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; }
.bubble.flagged { border: 2px solid var(--danger); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble .who { font-size: 12px; font-weight: 650; color: var(--accent); }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 2px 10px; border-radius: 999px; margin: 8px 0; }
mark { background: var(--warn-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.photo { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-src { position: absolute; bottom: 4px; right: 4px; font-size: 12px; line-height: 1; background: rgba(0,0,0,.45); border-radius: 6px; padding: 2px 3px; }
.modal-bg img { box-shadow: 0 12px 40px rgba(0,0,0,.4); }

.code { font-size: 40px; letter-spacing: .18em; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; padding: 10px; background: var(--surface-2); border-radius: 12px; }
ol.steps { padding-left: 20px; margin: 8px 0 0; }
ol.steps li { margin: 6px 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.banner { padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--text); display: flex; gap: 10px; align-items: flex-start; }
.banner.danger { background: var(--danger-soft); }
.banner.accent { background: var(--accent-soft); }
.perm-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 24px; }
.auth .brand { justify-content: center; margin-bottom: 6px; font-size: 22px; }
.auth .brand svg { width: 34px; height: 34px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; font-weight: 550; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; }

@media (max-width: 560px) {
  .topbar nav .label { display: none; }
  .hide-sm { display: none; }
  .code { font-size: 32px; }
}
