/* ───────────────────────────────────────────────
   Rhythm — тема дня и ночи.
   Ночь: тёплый графит + янтарь, без синего свечения (в 3:00 глаза скажут спасибо).
   День: кремовая бумага, спокойный контраст.
   Переключение: [data-theme="light" | "dark"] на <html>.
   ─────────────────────────────────────────────── */

:root {
  --amber:   #C4791E;
  --sleep:   #2F7F6A;
  --feed:    #C4791E;
  --diaper:  #3F7FA6;
  --measure: #6B5FA8;
  --med:     #B24C63;
  --danger:  #C0442F;
  --ok:      #2F7F6A;

  --radius: 14px;
  --radius-lg: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --shadow: 0 1px 2px rgba(40, 30, 20, .04), 0 8px 24px rgba(40, 30, 20, .05);
}

/* ── ДЕНЬ ── */
[data-theme="light"] {
  --bg:        #FAF7F2;
  --surface:   #FFFFFF;
  --surface-2: #F3EDE4;
  --line:      #E7DFD3;
  --line-soft: #F0EAE0;
  --txt:       #241F1B;
  --txt-dim:   #7C7167;
  --txt-mute:  #A79C90;
  --accent:    #C4791E;
  --accent-on: #FFFFFF;
  --tint:      #FBF1E1;
  --scrim:     rgba(36, 31, 27, .38);
}

/* ── НОЧЬ ── */
[data-theme="dark"] {
  --bg:        #151119;
  --surface:   #1E1922;
  --surface-2: #26202C;
  --line:      #332B3A;
  --line-soft: #241E2A;
  --txt:       #F3E6D3;
  --txt-dim:   #9C8D80;
  --txt-mute:  #6E6259;
  --accent:    #E8A33D;
  --accent-on: #2A1B06;
  --tint:      #2A2116;
  --scrim:     rgba(5, 3, 8, .6);

  --amber:   #E8A33D;
  --sleep:   #7FB8A8;
  --feed:    #E8A33D;
  --diaper:  #7FA8C9;
  --measure: #A79BE0;
  --med:     #E08496;
  --danger:  #E0715F;
  --ok:      #7FB8A8;
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  transition: background .35s ease, color .35s ease;
}
.hidden { display: none !important; }
.ico { flex: none; vertical-align: -.15em; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 16px; color: var(--txt);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label {
  display: block; font-size: 11px; color: var(--txt-dim);
  margin: 0 0 6px 2px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600;
}

/* ── загрузка ── */
.boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg);
}
.boot .ico { color: var(--accent); }
.boot-text { color: var(--txt-mute); letter-spacing: .32em; text-transform: uppercase; font-size: 11px; }

/* ── каркас ── */
.app { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 14px) 18px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
}
.topbar-title { font-size: 24px; font-weight: 700; letter-spacing: -.025em; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; color: var(--txt-dim);
  background: var(--surface); border: 1px solid var(--line-soft);
}
.icon-btn:active { transform: scale(.94); }

.screen { flex: 1; padding: 4px 14px calc(104px + var(--safe-b)); max-width: 760px; width: 100%; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line-soft);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; border-radius: 12px; font-size: 10px; font-weight: 600;
  color: var(--txt-mute); transition: color .2s;
}
.tab.active { color: var(--accent); }

/* ── карточки ── */
.card {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-t { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.muted { color: var(--txt-dim); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.divider { height: 1px; background: var(--line-soft); margin: 12px 0; }
.num { font-variant-numeric: tabular-nums; }

/* ── дети: 1 / 2 / 3+ — одна и та же сетка ── */
.kids { display: grid; gap: 10px; margin-bottom: 12px; }
.kids.n1 { grid-template-columns: 1fr; }
.kids.n2, .kids.n3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kids.n3 .kid:last-child:nth-child(odd) { grid-column: 1 / -1; }

.kid {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg); padding: 14px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kid::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c);
}
.kid-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.dot-lg { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.kid-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.kid-age { font-size: 11px; color: var(--txt-mute); }

.kid-state { display: flex; align-items: baseline; gap: 7px; margin-bottom: 2px; }
.kid-timer { font-size: 30px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kid-label { font-size: 12px; color: var(--txt-dim); }
.kid-sub { font-size: 11px; color: var(--txt-mute); min-height: 14px; }
.kid.asleep .kid-timer { color: var(--sleep); }
.kid.over .kid-timer { color: var(--danger); }

.ww-bar { height: 5px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 10px 0 6px; }
.ww-fill { height: 100%; border-radius: 5px; background: var(--c); transition: width .5s ease; }
.ww-fill.over { background: var(--danger); }

/* одна строка «сегодня» внутри карточки ребёнка */
.kid-facts { display: flex; gap: 12px; margin: 10px 0 12px; }
.fact { flex: 1; min-width: 0; }
.fact-v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fact-l { font-size: 10px; color: var(--txt-mute); text-transform: uppercase; letter-spacing: .05em; }

.kid-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kids.n1 .kid-actions { gap: 8px; }
.act {
  height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--txt-dim); transition: transform .08s;
}
.act:active { transform: scale(.92); }
.act.primary { background: var(--accent); color: var(--accent-on); }
.act.stop { background: var(--sleep); color: var(--accent-on); }
[data-theme="light"] .act.stop { color: #fff; }

/* ── синхронизация ── */
.sync { background: var(--tint); border-color: transparent; }
.sync-t {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--accent); font-weight: 700; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.sync-m { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.sync-m:last-child { margin-bottom: 0; }
.sync-m b { font-weight: 700; }
.queue { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.q-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.q-num { width: 18px; font-size: 11px; color: var(--txt-mute); font-weight: 700; }
.q-name { font-weight: 600; flex: 1; }
.q-when { font-variant-numeric: tabular-nums; font-weight: 700; }
.q-when.now { color: var(--danger); }
.q-when.soon { color: var(--accent); }

/* ── лента ── */
.tl { display: flex; flex-direction: column; }
.tl-i { display: flex; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.tl-i:first-child { border-top: 0; }
.tl-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; min-width: 40px; color: var(--txt-dim); }
.tl-ico { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-size: 14px; }
.tl-sub { font-size: 11px; color: var(--txt-mute); }
.tl-del { color: var(--txt-mute); padding: 4px; display: grid; place-items: center; }

/* ── графики ── */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--txt-dim); margin-bottom: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 0; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }

/* сравнение N детей */
.cmp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cmp-table th {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--txt-mute);
  font-weight: 600; text-align: right; padding: 6px 0 8px;
}
.cmp-table th:first-child { text-align: left; }
.cmp-table td { padding: 8px 0; border-top: 1px solid var(--line-soft); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cmp-table td:first-child { text-align: left; font-weight: 400; color: var(--txt-dim); }
.cmp-table td.best { color: var(--ok); }

/* ── заметки ── */
.note { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.note-m { font-size: 11px; color: var(--txt-mute); margin-top: 10px; display: flex; justify-content: space-between; align-items: center; }

/* ── гайд ── */
.acc { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; box-shadow: var(--shadow); }
.acc-h { padding: 14px; display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.acc-h .chev { margin-left: auto; color: var(--txt-mute); transition: transform .2s; }
.acc.open .chev { transform: rotate(90deg); }
.acc-b { padding: 0 14px 14px; font-size: 14px; color: var(--txt-dim); display: none; }
.acc.open .acc-b { display: block; }
.acc-b ul { padding-left: 18px; margin: 8px 0; }
.acc-b li { margin-bottom: 7px; }
.acc-b b { color: var(--txt); }
.src { font-size: 11px; color: var(--txt-mute); margin-top: 12px; line-height: 1.5; }
.flag { border-left: 3px solid var(--danger); padding: 10px 12px; background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: 0 10px 10px 0; }

/* ── кнопки ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; font-weight: 600; width: 100%;
}
.btn.primary { background: var(--accent); color: var(--accent-on); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--txt-dim); }
.btn.danger { color: var(--danger); }
.btn:active { transform: scale(.985); }
.btn.sm { padding: 9px 14px; font-size: 13px; width: auto; border-radius: 11px; }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 13px; }
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 10px; font-size: 13px; font-weight: 600;
  color: var(--txt-dim); display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button.on { background: var(--surface); color: var(--txt); box-shadow: var(--shadow); }
[data-theme="dark"] .seg button.on { background: var(--line); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 9px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: transparent; font-size: 13px; font-weight: 600; color: var(--txt-dim);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }

/* ── шторка ── */
.sheet-bg { position: fixed; inset: 0; background: var(--scrim); z-index: 50; animation: fade .18s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(22px + var(--safe-b));
  max-height: 92dvh; overflow-y: auto; max-width: 760px; margin: 0 auto;
  animation: up .26s cubic-bezier(.2, .9, .3, 1);
}
.grip { width: 36px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 16px; }
.sheet-t { font-weight: 700; font-size: 20px; margin-bottom: 16px; letter-spacing: -.02em; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ── вход ── */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 26px; max-width: 420px; margin: 0 auto; gap: 14px; }
.auth-logo { display: grid; place-items: center; color: var(--accent); margin-bottom: 4px; }
.auth-h { font-size: 30px; font-weight: 700; text-align: center; letter-spacing: -.03em; }
.auth-s { text-align: center; color: var(--txt-dim); font-size: 14px; margin-bottom: 8px; line-height: 1.5; }
.err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }
.code-box {
  font-size: 30px; font-weight: 700; letter-spacing: .3em; text-align: center;
  background: var(--tint); border-radius: 16px; padding: 18px; color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.toast-root { position: fixed; left: 0; right: 0; bottom: calc(90px + var(--safe-b)); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--txt); color: var(--bg); font-weight: 600; font-size: 13px;
  padding: 10px 18px; border-radius: 20px; animation: fade .16s;
}

.empty { text-align: center; color: var(--txt-mute); padding: 30px 12px; font-size: 14px; line-height: 1.6; }
.badge { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 7px; background: var(--surface-2); color: var(--txt-dim); }
.pct-bar { height: 6px; border-radius: 6px; background: var(--surface-2); position: relative; margin: 10px 0 6px; }
.pct-mark { position: absolute; top: -3px; width: 3px; height: 12px; border-radius: 2px; background: var(--c); }
