:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f3ece2;
  --text: #2c2235;
  --muted: #776880;
  --accent: #7fb287;
  --accent-2: #5e9270;
  --warn: #d9985a;
  --danger: #c96969;
  --link: #6b5fa0;
  --night-bg: #0e0a18;
  --night-surface: #1c1530;
  --night-surface-2: #2a1f3f;
  --night-text: #ece4f5;
  --night-muted: #a094b3;
  --night-accent: #8db698;
  --night-warn: #e3a76a;
  --pad: 16px;
  --radius: 14px;
  --tap: 44px;
}

body.night {
  --bg: var(--night-bg);
  --surface: var(--night-surface);
  --surface-2: var(--night-surface-2);
  --text: var(--night-text);
  --muted: var(--night-muted);
  --accent: var(--night-accent);
  --warn: var(--night-warn);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; font-size: 17px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
#app { min-height: 100vh; padding-bottom: 80px; }
h1 { font-size: 28px; margin: 16px 0 8px; }
h2 { font-size: 22px; margin: 16px 0 12px; font-weight: 600; }
h3 { font-size: 18px; margin: 24px 0 12px; }
h4 { font-size: 16px; margin: 0 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 14px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 20px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 16px; font-weight: 500; transition: background .15s; }
.btn.primary { background: var(--accent); color: #fff; }
body.night .btn.primary { background: var(--accent); color: #0e0a18; font-weight: 600; }
.btn.ghost { background: transparent; border: 1px solid var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.big { width: 100%; min-height: 56px; font-size: 17px; margin: 8px 0; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
button { font-family: inherit; }
input, textarea { font-family: inherit; font-size: 16px; color: inherit; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bg); position: sticky; top: 0; z-index: 10; }
.topbar-title { flex: 1; text-align: center; font-weight: 600; }
.topbar-btn { background: transparent; border: 0; padding: 10px; min-height: var(--tap); min-width: var(--tap); border-radius: 10px; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.topbar-btn:active { background: var(--surface-2); }
.topbar-child { display: flex; align-items: center; gap: 10px; flex: 1; }
.child-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; }
body.night .child-avatar { color: #0e0a18; }
.child-meta { line-height: 1.2; }
.child-name { font-weight: 600; font-size: 15px; }
.child-age { font-size: 13px; color: var(--muted); }
.child-corr { font-size: 11px; color: var(--warn); }
.child-name.big { font-size: 16px; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin: 8px 16px; }
body.night .card { border: 1px solid rgba(255,255,255,0.04); }
.card h3, .card h4 { margin-top: 0; }

/* Sections */
.section-h { padding: 16px 16px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Window card */
.window-card { padding: 8px 4px; }
.window-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.window-label { font-size: 14px; color: var(--muted); font-weight: 500; }
.window-awake { font-size: 38px; font-weight: 600; letter-spacing: -0.02em; }
.window-hint { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.window-empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 15px; }
.shift-badge { background: rgba(217,152,90,0.18); color: var(--warn); padding: 2px 8px; border-radius: 6px; font-size: 12px; }

/* Scale */
.scale { height: 16px; position: relative; border-radius: 8px; background: var(--surface-2); overflow: hidden; margin: 16px 0 30px; }
.scale-band { position: absolute; top: 0; bottom: 0; background: rgba(127,178,135,0.18); border-radius: 8px; }
.scale-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 8px; transition: width .3s; }
.scale-marker { position: absolute; top: 100%; transform: translateX(-50%); margin-top: 4px; font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Big button */
.big-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; width: calc(100% - 32px); margin: 8px 16px 16px; min-height: 140px; border-radius: 28px; border: 0; background: var(--accent); color: #fff; font-size: 22px; font-weight: 600; cursor: pointer; box-shadow: 0 6px 24px rgba(127,178,135,0.32); transition: transform .15s; }
body.night .big-button { color: #0e0a18; box-shadow: 0 6px 24px rgba(127,178,135,0.16); }
.big-button:active { transform: scale(0.98); }
.big-button.awake { background: #d9985a; box-shadow: 0 6px 24px rgba(217,152,90,0.32); }
body.night .big-button.awake { color: #0e0a18; }
.big-button-icon { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.18); border-radius: 50%; }
.big-button-label { letter-spacing: -0.01em; }

/* Sleep list */
.sleep-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.sleep-card { padding: 12px; }
.sleep-time { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.sleep-when { font-weight: 600; font-size: 16px; }
.sleep-dur { color: var(--muted); font-size: 14px; }
.sleep-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.sleep-tags-row { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.sleep-comment { font-size: 13px; color: var(--muted); margin-top: 6px; }
.sleep-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* Pills */
.pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--text); }
.pill.night { background: rgba(127,178,135,0.18); color: var(--accent-2); }
body.night .pill.night { color: var(--night-accent); }
.pill.day { background: rgba(170,179,214,0.18); color: #5d6680; }
body.night .pill.day { color: #c5cae8; }
.mini-tag { font-size: 11px; background: var(--surface-2); color: var(--muted); padding: 2px 8px; border-radius: 6px; }

.pill-btn { background: var(--surface-2); border: 0; border-radius: 999px; padding: 8px 14px; font-size: 13px; color: var(--text); cursor: pointer; min-height: 36px; }
.pill-btn.active { background: var(--accent); color: #fff; }
body.night .pill-btn.active { color: #0e0a18; }
.pill-btn.warn { background: rgba(201,105,105,0.15); color: var(--danger); }

/* Editor */
.editor { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--surface-2); }
.editor-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.editor-label { font-size: 13px; color: var(--muted); min-width: 100px; }
.editor-count { min-width: 24px; text-align: center; font-weight: 600; }
.editor-actions { display: flex; gap: 8px; justify-content: flex-end; }

.input { width: 100%; padding: 12px; border: 1px solid var(--surface-2); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 16px; min-height: var(--tap); }
.input.big { font-size: 18px; padding: 16px; }
textarea.input { resize: vertical; min-height: 80px; }

.tags-wrap, .row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }

.chip { background: var(--surface-2); border: 0; border-radius: 999px; padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--text); min-height: 36px; }
.chip.active { background: var(--accent); color: #fff; }
body.night .chip.active { color: #0e0a18; }

.choice { background: var(--surface-2); border: 0; border-radius: var(--radius); padding: 20px; font-size: 16px; cursor: pointer; color: var(--text); min-height: 80px; }
.choice.active { background: var(--accent); color: #fff; }
body.night .choice.active { color: #0e0a18; }

.checkbox { display: flex; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer; }
.checkbox input { width: 22px; height: 22px; }

/* Bottom nav */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--surface-2); display: flex; padding: 8px 0 max(8px, env(safe-area-inset-bottom)); z-index: 10; }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; background: transparent; border: 0; padding: 6px; color: var(--muted); cursor: pointer; }
.nav-btn span { font-size: 11px; }
.nav-btn.active { color: var(--accent); }

/* Onboarding */
.onb { max-width: 480px; margin: 0 auto; padding: 24px 20px 80px; }
.onb-hero { text-align: center; padding: 32px 0; }
.onb-mark { display: inline-flex; align-items: center; justify-content: center; width: 80px; height: 80px; border-radius: 50%; background: var(--surface); margin-bottom: 16px; }
.onb-sub { color: var(--muted); font-size: 16px; margin-top: 12px; }

/* Recommendations */
.rec { display: flex; gap: 12px; align-items: flex-start; }
.rec-icon { font-size: 28px; flex-shrink: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: rgba(127,178,135,0.12); border-radius: 12px; }
.rec-body { flex: 1; }
.rec-title { font-weight: 600; margin-bottom: 4px; }
.rec-text { font-size: 15px; color: var(--text); margin-bottom: 8px; }
.rec-details summary { font-size: 13px; color: var(--muted); cursor: pointer; padding: 4px 0; }
.rec-details p { font-size: 13px; color: var(--muted); margin-top: 6px; padding: 8px 0; }

.disclaimer { padding: 12px 16px 24px; font-size: 12px; color: var(--muted); font-style: italic; }

/* Metrics */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 16px; }
.metric { background: var(--surface); border-radius: var(--radius); padding: 12px; }
.metric-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.metric-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.metric-dot.warn { background: var(--warn); }
.metric-dot.low { background: var(--warn); }
.metric-norm { font-size: 11px; color: var(--muted); }

/* Segment */
.segment { display: flex; gap: 4px; padding: 4px; margin: 8px 16px; background: var(--surface); border-radius: 12px; }
.seg { flex: 1; padding: 10px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg.active { background: var(--accent); color: #fff; font-weight: 600; }
body.night .seg.active { color: #0e0a18; }

/* KV */
.kv { display: flex; flex-direction: column; gap: 4px; padding: 8px 0; }
.kv .big-num { font-size: 24px; font-weight: 700; }
.kv .delta.up { color: var(--accent-2); }
.kv .delta.down { color: var(--warn); }
.kv .muted { margin-top: 4px; }

/* Summary */
.summary, .advice { margin: 0; padding-left: 20px; }
.summary li, .advice li { margin: 6px 0; font-size: 14px; }
.summary li.ok { color: var(--text); }
.summary li.warn { color: var(--warn); }

/* History */
.history-day { display: flex; flex-direction: column; gap: 8px; }
.history-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--surface-2); }
.history-row:last-child { border-bottom: 0; }
.history-actions { display: flex; gap: 4px; }

/* Child row */
.child-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.child-row .row { margin-left: auto; }

/* Undo toast — мягкая плашка, без яркой вспышки */
.undo-bar { position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom, 0px) + 8px); background: var(--surface-2); color: var(--text); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); z-index: 50; font-size: 14px; animation: undo-in .25s ease-out; }
body.night .undo-bar { box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
@keyframes undo-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.undo-bar .undo-text { flex: 1; }
.undo-bar button { background: transparent; border: 0; color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; min-height: 36px; padding: 0 8px; }
.undo-bar .undo-dismiss { color: var(--muted); font-weight: 500; }

/* Modal — мягкое подтверждение, не выскакивает поверх всего */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; z-index: 100; animation: fade-in .2s ease-out; }
body.night .modal-back { background: rgba(0,0,0,0.75); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0; padding: 20px 20px max(20px, env(safe-area-inset-bottom)); width: 100%; max-width: 520px; box-shadow: 0 -8px 32px rgba(0,0,0,0.25); animation: modal-up .25s ease-out; }
body.night .modal { border-top: 1px solid rgba(255,255,255,0.06); }
@keyframes modal-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { margin-top: 0; font-size: 18px; }
.modal p { color: var(--muted); font-size: 15px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-actions .btn { flex: 1; min-height: 52px; font-size: 16px; }
.modal .time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.modal .time-grid label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.modal .time-grid input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--surface-2); background: var(--bg); color: var(--text); font-size: 18px; min-height: var(--tap); }

/* Manual add row */
.manual-add-btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); margin: 8px 16px 16px; padding: 0 16px; border-radius: 12px; border: 1px dashed var(--muted); background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; }
.manual-add-btn:active { background: var(--surface-2); }
