:root {
  --primary: #1976D2; --primary-dark: #0D47A1; --primary-soft: #E3F2FD;
  --bg: #F5F9FF; --card: #fff; --text: #1b2733; --muted: #607080; --line: #dde6ef;
  --danger: #c62828; --ok: #2e7d32;
  --nav-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; overscroll-behavior-y: contain; }
#app { min-height: 100%; display: flex; flex-direction: column; }

/* horní lišta */
.top { background: var(--primary); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 12px; display: flex; align-items: center; gap: 10px; }
.top .titles { flex: 1; min-width: 0; }
.top h1 { margin: 0; font-size: 22px; font-weight: 700; }
.top .sub { font-size: 14px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { font-size: 12px; background: rgba(255,255,255,.2); border-radius: 12px; padding: 4px 10px; white-space: nowrap; }

main { flex: 1; padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); max-width: 640px; width: 100%; margin: 0 auto; }
h2 { font-size: 18px; margin: 18px 0 8px; }
.card { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(20,60,100,.08); }

/* velká tlačítka */
.big-row { display: flex; gap: 10px; margin-bottom: 12px; }
.big { flex: 1; min-width: 0; border: 0; border-radius: 16px; background: var(--primary); color: #fff; padding: 18px 4px; font-size: 16px; font-weight: 600; white-space: nowrap; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.big .ico { font-size: 28px; line-height: 1; }
.big:active { background: var(--primary-dark); transform: scale(.98); }
.big.alt { background: #00897B; }
.big.warm { background: #EF6C00; }
.wide { width: 100%; flex-direction: row; justify-content: center; padding: 14px; margin-bottom: 12px; }

/* dávka */
.dose { display: flex; align-items: center; gap: 12px; }
.dose .txt { flex: 1; }
.dose .big-num { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.muted { color: var(--muted); font-size: 14px; }

/* historie */
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 4px 4px; }
.day-head b { font-size: 16px; }
.day-sum { font-size: 13px; color: var(--muted); margin: 0 4px 6px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px 6px 10px 12px; margin-bottom: 6px; }
.row .time { font-weight: 700; min-width: 46px; color: var(--primary-dark); }
.row .what { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .what small { display: block; color: var(--muted); }
.kebab { border: 0; background: none; font-size: 22px; padding: 6px 12px; color: var(--muted); cursor: pointer; border-radius: 8px; }
.kebab:active { background: var(--primary-soft); }

/* spodní navigace */
nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 10; }
nav button { flex: 1; min-width: 0; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; cursor: pointer; }
nav button .ico { font-size: 22px; line-height: 1; }
nav button.on { color: var(--primary); font-weight: 700; }

/* formuláře */
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 11px 12px; border: 1px solid #c5d3e2; border-radius: 10px; background: #fff; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--text); font-size: 16px; }
.check input { width: 22px; height: 22px; }
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer; background: var(--primary); color: #fff; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; margin-top: 14px; }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* dialogy */
.overlay { position: fixed; inset: 0; background: rgba(10,30,50,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.dialog { background: #fff; width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 600px) { .overlay { align-items: center; } .dialog { border-radius: 20px; } }
.dialog h3 { margin: 0 0 6px; font-size: 20px; }
.dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.choices { display: flex; gap: 10px; margin-top: 12px; }
.choices .big { padding: 22px 4px; }
.menu { position: fixed; z-index: 60; background: #fff; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 6px 0; min-width: 160px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 18px; font: inherit; cursor: pointer; }
.menu button:active { background: var(--primary-soft); }
.menu .del { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { border: 1px solid #c5d3e2; background: #fff; border-radius: 20px; padding: 8px 14px; font: inherit; cursor: pointer; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* přihlášení / první spuštění */
.center { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; width: 100%; margin: 0 auto; }
.center .logo { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 14px; display: block; }
.center h1 { text-align: center; margin: 0 0 18px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1b2733; color: #fff; padding: 10px 18px; border-radius: 22px; z-index: 100; font-size: 14px; max-width: 90%; }

/* fáze 3 */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.big.wrap { white-space: normal; padding: 14px 4px; font-size: 14px; background: #546E7A; }
.link { display: block; padding: 10px 0; color: var(--primary); text-decoration: none; border-bottom: 1px solid var(--line); }
.link:last-child { border-bottom: 0; }

/* tisk / PDF */
#printview { display: none; }
@media print {
  body > *:not(#printview) { display: none !important; }
  body { background: #fff; }
  #printview { display: block; font: 12px/1.4 system-ui, sans-serif; color: #000; }
  #printview h1 { font-size: 20px; margin: 0 0 4px; }
  #printview h2 { font-size: 14px; margin: 16px 0 4px; border-bottom: 1px solid #999; padding-bottom: 2px; }
  #printview table { width: 100%; border-collapse: collapse; }
  #printview th, #printview td { text-align: left; padding: 3px 6px; border-bottom: 1px solid #ddd; }
  #printview thead { display: table-header-group; }
  #printview tr { break-inside: avoid; }
  #printview .none { color: #666; margin: 2px 0; }
}

/* fáze 4: tmavý režim (hvězdná noc) */
[data-mode="dark"] {
  --card: #1a2342; --text: #eaf0ff; --muted: #9fb0cc; --line: #2c3a63; --primary-dark: #90CAF9; --primary-soft: #26335c;
}
[data-mode="dark"] nav, [data-mode="dark"] .dialog, [data-mode="dark"] .menu, [data-mode="dark"] .chip,
[data-mode="dark"] input, [data-mode="dark"] select { background: var(--card); color: var(--text); border-color: var(--line); }
[data-mode="dark"] .chip.on { background: var(--primary); color: #fff; }
[data-mode="dark"] .kebab { color: var(--muted); }
body.stars {
  background-color: var(--bg);
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, #fff, transparent), radial-gradient(1px 1px at 90px 120px, #dfe9ff, transparent),
    radial-gradient(1.5px 1.5px at 150px 60px, #fff, transparent), radial-gradient(1px 1px at 60px 170px, #fff, transparent),
    radial-gradient(2px 2px at 180px 150px, #ffe9a8, transparent), radial-gradient(1px 1px at 120px 20px, #fff, transparent);
  background-size: 200px 200px; background-attachment: fixed;
}
.big.wrap.playing { background: var(--primary); box-shadow: 0 0 0 3px #90CAF9; }
input[type=range] { padding: 0; accent-color: var(--primary); }

.iconbtn { flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255,255,255,.2); font-size: 18px; line-height: 1; cursor: pointer; }
.iconbtn:active { background: rgba(255,255,255,.4); }

/* termíny */
.appt-next { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.appt-next .what small { display: block; color: var(--muted); }
.row.past { opacity: .75; }
/* průvodce příkrmy */
.guide h3 { font-size: 16px; margin: 14px 0 4px; }
.guide p, .guide li { line-height: 1.45; }
.guide ul { padding-left: 20px; margin: 6px 0; }
.guide table { width: 100%; border-collapse: collapse; font-size: 14px; }
.guide th, .guide td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.src { font-size: 12px; color: var(--muted); }
.warn { background: #FFF3E0; color: #5d4300; border-radius: 12px; padding: 10px 12px; font-size: 14px; }

/* v1.6 */
.card.last { padding: 10px 14px; }
.last-row { display: grid; grid-template-columns: 28px 70px 1fr; align-items: baseline; column-gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.last-row:last-of-type { border-bottom: 0; }
.last-row .li { font-size: 18px; }
.last-row b { color: var(--primary-dark); }
.last-row small { grid-column: 3; color: var(--muted); font-size: 12px; }
.sleep-btn { width: 100%; margin-top: 8px; }
.card.meds > b:first-child { display: block; margin-bottom: 6px; }
.medchk { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 10px 12px; margin-top: 6px; font: inherit; cursor: pointer; }
.medchk.done { background: var(--primary-soft); }
.medchk .what small { display: block; color: var(--muted); }
.row.ms { width: 100%; border: 0; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.preview { max-width: 100%; max-height: 220px; border-radius: 12px; display: block; margin-bottom: 8px; }
.card.supply.low { box-shadow: 0 0 0 2px #EF6C00; }
.row.warnrow { box-shadow: inset 4px 0 0 #EF6C00; }
