/* Дневник Егора. Ночной режим по умолчанию тёплый и тусклый: меньше синего света. */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #efe9de;
  --line: #ddd4c5;
  --text: #221d16;
  --muted: #6f6556;
  --accent: #9a5b17;
  --accent-ink: #fffaf2;
  --left: #8d4f63;
  --left-bg: #f4e5ea;
  --right: #2f6b67;
  --right-bg: #e1efed;
  --sleep: #4d5a8a;
  --sleep-bg: #e6e8f3;
  --diaper: #7a6420;
  --diaper-bg: #f3ecd5;
  --danger: #b3261e;
  --danger-bg: #fbe3e0;
  --danger-ink: #ffffff;
  --banner: #b3261e;
  --warn: #8a5a00;
  --warn-bg: #fbefd2;
  --ok: #2e6b3a;
  --info-bg: #ebe6dc;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08);
  --radius: 16px;
  --tap: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f;
    --surface: #211d18;
    --surface-2: #2b261f;
    --line: #3a332a;
    --text: #ece3d5;
    --muted: #a59a88;
    --accent: #d99a4e;
    --accent-ink: #1b140b;
    --left: #e2a3b6;
    --left-bg: #34232a;
    --right: #8fcfc8;
    --right-bg: #1d2f2d;
    --sleep: #aab4e0;
    --sleep-bg: #252838;
    --diaper: #dcc27a;
    --diaper-bg: #302a19;
    --danger: #ff7b72;
    --danger-bg: #4a1714;
    --danger-ink: #2a0806;
    --banner: #8c1d17;
    --warn: #f0be5c;
    --warn-bg: #3a2c10;
    --ok: #8fcf97;
    --info-bg: #2a251e;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f;
  --surface: #211d18;
  --surface-2: #2b261f;
  --line: #3a332a;
  --text: #ece3d5;
  --muted: #a59a88;
  --accent: #d99a4e;
  --accent-ink: #1b140b;
  --left: #e2a3b6;
  --left-bg: #34232a;
  --right: #8fcfc8;
  --right-bg: #1d2f2d;
  --sleep: #aab4e0;
  --sleep-bg: #252838;
  --diaper: #dcc27a;
  --diaper-bg: #302a19;
  --danger: #ff7b72;
  --danger-bg: #4a1714;
  --danger-ink: #2a0806;
  --banner: #8c1d17;
  --warn: #f0be5c;
  --warn-bg: #3a2c10;
  --ok: #8fcf97;
  --info-bg: #2a251e;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

/* шапка */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 0 12px;
}
.top h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.top .sub { color: var(--muted); font-size: 14px; }
.top .grow { flex: 1; min-width: 0; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; stroke: var(--text); fill: none; stroke-width: 1.8; }

/* баннеры */
.alerts { display: grid; gap: 8px; margin-bottom: 12px; }
.alert { border-radius: var(--radius); padding: 12px 14px; background: var(--info-bg); }
.alert.danger { background: var(--banner); color: #fff; }
.alert.warn { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn); }
.alert .a-title { font-weight: 700; font-size: 18px; }
.alert .a-row { display: flex; gap: 10px; align-items: center; }
.alert .a-row .grow { flex: 1; }
.alert .a-more { margin-top: 6px; font-size: 15px; }
.alert .a-more .ref { opacity: .85; font-size: 14px; margin-top: 4px; }
.alert.danger a:not(.call) { color: inherit; }
.alert .why { background: none; border: 0; padding: 4px 0; text-decoration: underline; font-size: 14px; color: inherit; opacity: .85; }
.call {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border-radius: 12px; background: #fff; color: #9b1c15; font-weight: 800; text-decoration: none;
  font-size: 18px; white-space: nowrap;
}

/* таймеры */
.running {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  margin-bottom: 10px; border: 2px solid currentColor;
}
.running.feed-L { color: var(--left); background: var(--left-bg); }
.running.feed-R { color: var(--right); background: var(--right-bg); }
.running.sleep { color: var(--sleep); background: var(--sleep-bg); }
.running .r-label { font-size: 15px; color: var(--text); }
.running .r-time { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
.running .grow { flex: 1; }
.running .r-actions { display: flex; flex-direction: column; gap: 8px; }
.btn-stop {
  min-height: 52px; min-width: 104px; border-radius: 12px; border: 0; background: currentColor; font-weight: 700;
}
.btn-stop span { color: var(--bg); }
.btn-ghost {
  min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 0 12px; font-size: 15px;
}

/* большие кнопки */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.one { grid-template-columns: 1fr; }
.section {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin: 16px 2px 6px; font-size: 13px;
}
.section:first-of-type { margin-top: 4px; }
.section .s-title { color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.section .s-hint { color: var(--muted); opacity: .85; text-align: right; }
.btn-manual {
  width: 100%; min-height: 48px; margin: 14px 0 4px; border-radius: 14px; border: 1px dashed var(--line);
  background: transparent; color: var(--muted); font-size: 16px; font-weight: 600;
}
.big {
  min-height: 84px; border-radius: var(--radius); border: 0; padding: 10px 12px; text-align: left;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; box-shadow: var(--shadow);
  background: var(--surface); position: relative;
}
.big .b-title { font-size: 20px; font-weight: 700; line-height: 1.15; }
.big .b-sub { font-size: 13px; color: var(--muted); }
.big.feed-L { background: var(--left-bg); }
.big.feed-L .b-title { color: var(--left); }
.big.feed-R { background: var(--right-bg); }
.big.feed-R .b-title { color: var(--right); }
.big.sleep { background: var(--sleep-bg); min-height: 64px; }
.big.sleep .b-title { color: var(--sleep); }
.big.diaper { background: var(--diaper-bg); min-height: 72px; text-align: center; align-items: center; padding: 8px 4px; }
.big.diaper .b-title { color: var(--diaper); font-size: 18px; }
.big.small { min-height: 60px; text-align: center; align-items: center; padding: 8px; }
.big.small .b-title { font-size: 17px; font-weight: 600; }
.big.small .b-sub { font-size: 12px; }
.big.milk { background: var(--surface-2); }
.big.done .b-title { color: var(--ok); }
.big .tag {
  position: absolute; top: 8px; right: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.big.active { outline: 3px solid currentColor; }
.big:active, .btn:active, .choice:active { transform: scale(.98); }

.link-row { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 18px; }
.text-btn { background: none; border: 0; color: var(--accent); padding: 10px 0; font-size: 16px; font-weight: 600; }

/* сводка */
h2 { font-size: 18px; margin: 22px 0 10px; }
h2 .h-sub { font-weight: 400; color: var(--muted); font-size: 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--surface); border-radius: 14px; padding: 10px 12px; border: 1px solid var(--line); }
.tile .t-label { font-size: 13px; color: var(--muted); }
.tile .t-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .t-norm { font-size: 13px; color: var(--muted); }
.tile.warn { border-color: var(--warn); background: var(--warn-bg); }
.tile.warn .t-value { color: var(--warn); }
.tile.danger { border-color: var(--danger); background: var(--danger-bg); }
.tile.danger .t-value { color: var(--danger); }
.tile.ok .t-value { color: var(--ok); }
.note-muted { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* список записей */
.list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line);
  width: 100%; background: none; text-align: left; min-height: 56px;
}
.row:last-child { border-bottom: 0; }
.row .r-time { font-variant-numeric: tabular-nums; font-weight: 600; width: 52px; flex: none; }
.row .r-main { flex: 1; min-width: 0; }
.row .r-what { font-weight: 600; }
.row .r-detail { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.row .r-by { color: var(--muted); font-size: 12px; flex: none; text-align: right; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.feed-L { background: var(--left); }
.dot.feed-R { background: var(--right); }
.dot.sleep { background: var(--sleep); }
.dot.diaper { background: var(--diaper); }
.dot.temp, .dot.weight { background: var(--accent); }
.dot.pump, .dot.bottle { background: var(--right); }
.dot.flag { background: var(--danger); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 2px 8px; gap: 8px; }
.day-head .d-title { font-weight: 700; }
.day-head .d-stats { color: var(--muted); font-size: 13px; text-align: right; }
.empty { padding: 18px 14px; color: var(--muted); }

/* таблица по дням */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
table.days { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 15px; }
table.days th, table.days td { padding: 9px 4px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.days th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.days td:first-child, table.days th:first-child { padding-left: 10px; }
table.days td:last-child, table.days th:last-child { padding-right: 10px; }
table.days tbody tr { cursor: pointer; }
table.days td:first-child, table.days th:first-child { text-align: left; }
table.days tr:last-child td { border-bottom: 0; }
table.days td.warn { background: var(--warn-bg); color: var(--warn); font-weight: 700; }
table.days td.danger { background: var(--danger-bg); color: var(--danger); font-weight: 700; }
table.days .n { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.day-alerts { margin-top: 10px; display: grid; gap: 6px; }

/* график веса */
.chart { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); padding: 8px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .birth { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .mark { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .line { stroke: var(--text); stroke-width: 2.5; fill: none; }
.chart .who-outer { fill: var(--right); opacity: .10; }
.chart .who-inner { fill: var(--right); opacity: .16; }
.chart .who-median { stroke: var(--right); stroke-width: 1.5; stroke-dasharray: 4 3; fill: none; opacity: .8; }
.chart text.who-label { fill: var(--right); font-size: 9px; }
.chart .pt { fill: var(--text); }
.chart .pt.birth-pt { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }
.chart text.val { fill: var(--text); font-size: 12px; font-weight: 700; }

/* формы и шторки */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 14px; font-size: 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 12px; font-size: 18px;
}
textarea.input { min-height: 96px; resize: vertical; }
.input.huge { font-size: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choices.three { grid-template-columns: 1fr 1fr 1fr; }
.choice {
  min-height: 56px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  padding: 8px 10px; text-align: left; display: flex; align-items: center; gap: 10px; font-weight: 600;
}
.choice.on { border-color: var(--accent); background: var(--surface-2); }
.swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 1px solid var(--muted); }
.sw-meconium { background: #1f2a14; }
.sw-yellow { background: #d7a928; }
.sw-green { background: #5d8a2e; }
.sw-pale { background: #ece6cf; }
.sw-blood { background: #a3261f; }
.btn {
  min-height: 56px; border-radius: 14px; border: 0; padding: 0 18px; font-weight: 700; font-size: 18px;
  background: var(--accent); color: var(--accent-ink); width: 100%;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.meta { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.err { color: var(--danger); font-weight: 600; margin: 6px 0; min-height: 1.2em; }
.keybox { background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 8px 0 12px; display: grid; gap: 8px; }
.keybox code { font-size: 14px; overflow-wrap: anywhere; user-select: all; }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin-bottom: 6px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.pains { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; }
.pain { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; padding: 0; }
.pain.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger-label { color: var(--danger) !important; font-weight: 700; }
.queue { background: var(--warn-bg); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.queue .q-title { font-weight: 700; }
.queue ul { margin: 6px 0; padding-left: 18px; font-size: 14px; }
.queue .btn-ghost { margin: 4px 6px 0 0; }
#queue-bar { max-width: 640px; margin: 0 auto; padding: 0 16px; }
#queue-bar .queue { margin-top: calc(10px + env(safe-area-inset-top)); }
.switches { display: grid; gap: 8px; margin-bottom: 8px; }
.choice.switch { justify-content: space-between; width: 100%; }
.choice.switch .sw-text { display: flex; flex-direction: column; gap: 2px; font-weight: 400; }
.choice.switch .sw-state { font-weight: 700; color: var(--muted); min-width: 44px; text-align: right; }
.choice.switch.on .sw-state { color: var(--ok); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick button { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; }

/* нижняя навигация */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav .inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 58px;
  color: var(--muted); text-decoration: none; font-size: 12px; gap: 2px;
}
.nav a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.nav a.on { color: var(--accent); font-weight: 700; }

/* тост */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; max-width: 600px; width: 100%; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast .grow { flex: 1; }
.toast button { background: none; border: 0; color: var(--bg); font-weight: 700; text-decoration: underline; min-height: 40px; padding: 0 8px; }
.toast.error { background: var(--banner); color: #fff; }

/* вход */
.login { padding-top: 14vh; }
.login h1 { font-size: 28px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.hidden { display: none !important; }

/* настройки, нормы */
.list + .card, .list + .alert { margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.card p { margin: 6px 0; }
.small { font-size: 14px; color: var(--muted); }

/* отчёт */
.report-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.report { background: var(--surface); color: var(--text); border-radius: var(--radius); padding: 16px; margin-top: 14px; border: 1px solid var(--line); }
.report h1 { font-size: 20px; margin: 0 0 4px; }
.report h4 { margin: 16px 0 6px; font-size: 16px; }
.report .table-scroll { overflow-x: auto; }
.report table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.report th, .report td { border: 1px solid var(--line); padding: 4px 5px; text-align: center; }
.report th { font-weight: 600; }
.report td.l, .report th.l { text-align: left; }
.report td.flag { font-weight: 700; text-decoration: underline; }
.report ul { margin: 4px 0; padding-left: 18px; }
.report .foot { margin-top: 14px; font-size: 12px; color: var(--muted); }

@media (max-width: 360px) {
  .big .b-title { font-size: 18px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] { --text: #000; --muted: #333; --line: #999; --surface: #fff; --bg: #fff; }
  body { background: #fff; color: #000; font-size: 12px; }
  .nav, .top, .no-print, #toast-root, #sheet-root { display: none !important; }
  #app { padding: 0; max-width: none; }
  .report { border: 0; padding: 0; margin: 0; }
  .report .table-scroll { overflow-x: auto; }
.report table { font-size: 11px; }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
