/* bp – blood-pressure log, phone first (designed at 375 px), laptop = same layout, centred and wider. */
:root {
  --bg: #f4f4f4; --card: #ffffff; --ink: #111111; --ink2: #4a4a4a; --muted: #8a8a8a; --line: #dddddd;
  --accent: #a50f1e; --accent-ink: #ffffff; --accent-soft: #f6e1e3; --sel: #a50f1e; --sel-soft: #fbeef0;
  --sys: #2a78d6; --dia: #eb6834; --pulse: #1baf7a;
  --c-opt: #1f8a4c; --c-norm: #4a9a2f; --c-hn: #b98900; --c-g1: #d46a12; --c-g2: #c7362b; --c-g3: #8e1b3b;
  --key: #ffffff; --key-press: #e9e4df;
  --radius: 14px; --gut: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #141414; --ink: #ffffff; --ink2: #bdbdbd; --muted: #808080; --line: #333333;
    --accent: #d42a3c; --accent-ink: #ffffff; --accent-soft: #3a1418; --sel: #e8394b; --sel-soft: #2a0f13;
    --sys: #3987e5; --dia: #d95926; --pulse: #199e70;
    --c-opt: #3fb36e; --c-norm: #72b552; --c-hn: #d9a91f; --c-g1: #e98a3a; --c-g2: #ec5f55; --c-g3: #d65a80;
    --key: #1c1c1c; --key-press: #333333;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #141414; --ink: #ffffff; --ink2: #bdbdbd; --muted: #808080; --line: #333333;
  --accent: #d42a3c; --accent-ink: #ffffff; --accent-soft: #3a1418; --sel: #e8394b; --sel-soft: #2a0f13;
  --sys: #3987e5; --dia: #d95926; --pulse: #199e70;
  --c-opt: #3fb36e; --c-norm: #72b552; --c-hn: #d9a91f; --c-g1: #e98a3a; --c-g2: #ec5f55; --c-g3: #d65a80;
  --key: #1c1c1c; --key-press: #333333;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#app { max-width: 560px; margin: 0 auto; padding: 0 var(--gut) calc(24px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 18px; height: 18px; }
[hidden] { display: none !important; }

/* ---------- top: tabs + sticky action area ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); margin: 0 calc(-1 * var(--gut)); padding: calc(6px + env(safe-area-inset-top)) var(--gut) 8px; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tab { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--ink2); font-weight: 600; cursor: pointer; }
.tab.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--c-g2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }

/* ---------- entry: mode switch, display, save ---------- */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin-top: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.mode { min-height: 38px; border: 0; background: transparent; border-radius: 9px; font-weight: 600; color: var(--ink2); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; }
.mode.on { background: var(--accent-soft); color: var(--accent); }
.editing { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--sel-soft); color: var(--sel); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.disp { display: grid; grid-template-columns: 1fr 1fr .8fr; gap: 8px; margin-top: 8px; }
.cell { position: relative; background: var(--card); border: 3px solid var(--line); border-radius: var(--radius); padding: 6px 4px 8px; text-align: center; cursor: pointer; min-height: 104px; }
.cell .lab { font-size: 16px; font-weight: 700; letter-spacing: .02em; color: var(--ink2); display: flex; align-items: center; justify-content: center; gap: 5px; }
.cell .lab i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.cell .val { font-size: 54px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; min-height: 60px; letter-spacing: -.02em; }
.cell .val.ph { color: var(--muted); font-weight: 400; }
.cell .unit { font-size: 14px; color: var(--muted); }
.cell.on { border-color: var(--sel); background: var(--sel-soft); }
.cell.on .val::after { content: ""; display: inline-block; width: 2px; height: 46px; background: var(--sel); margin-left: 2px; vertical-align: -4px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cell.bad { border-color: var(--c-g2); }
.saverow { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.save { min-height: 64px; font-size: 24px; }
.save .hint { font-weight: 600; font-size: 17px; opacity: .95; padding: 2px 8px; border-radius: 8px; background: rgba(255,255,255,.18); }
.catline { margin-top: 6px; min-height: 26px; font-size: 17px; color: var(--ink2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- number pad ---------- */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; user-select: none; }
.key { min-height: 66px; border: 1px solid var(--line); border-radius: 14px; background: var(--key); font-size: 34px; font-weight: 700; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center; }
.key:active, .key.press { background: var(--key-press); }
.key.fn { font-size: 18px; color: var(--ink2); }

/* ---------- rows below the pad ---------- */
.row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.row > .lbl { width: 64px; flex: none; font-size: 16px; color: var(--ink2); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--sel-soft); border-color: var(--sel); color: var(--sel); }
.chip.grow { flex: 1; justify-content: center; }
.timechip { flex: 1; justify-content: space-between; }
.sitbox { margin-top: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.sitlbl { font-size: 16px; font-weight: 600; color: var(--ink2); margin-bottom: 6px; }
.sitday { margin-top: 8px; }
.sitday > span { display: block; font-size: 15px; color: var(--ink2); margin-bottom: 4px; }
.sitbox .chip { justify-content: center; padding: 0 8px; position: relative; white-space: nowrap; min-height: 50px; font-size: 17px; }
.autotag { position: absolute; top: -8px; right: 6px; font-size: 10px; line-height: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 5px; border-radius: 6px; background: var(--sel); color: var(--accent-ink); }
.sitline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timechip.set { background: var(--sel-soft); border-color: var(--sel); color: var(--sel); }

.note { margin-top: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.note textarea { width: 100%; min-height: 48px; border: 0; background: transparent; color: var(--ink); font: inherit; resize: vertical; outline: none; }
.note .tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.note .tools .btn { min-height: 48px; }
.rec-on { background: var(--c-g2) !important; border-color: var(--c-g2) !important; color: #fff !important; }
.audios { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.audio { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink2); }
.audio audio { flex: 1; height: 36px; min-width: 0; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; color: var(--ink2); }
.medlist { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.medpick { text-align: left; justify-content: flex-start; font-weight: 400; min-height: 44px; }
.curmed { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); font-size: 15px; }
.curmed b { display: block; font-size: 13px; color: var(--ink2); }

/* ---------- category pill (always colour + text) ---------- */
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; padding: 2px 9px 2px 7px; border-radius: 20px; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--ink); white-space: nowrap; }
.cat::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }

/* ---------- history ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 12px; }
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--ink2); }
.periods { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.viewchips { margin-top: 8px; }
.viewchips { gap: 5px; }
.hmodes { display: grid; grid-template-columns: 1fr 1fr; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.htable { width: 100%; border-collapse: collapse; font-size: 17px; }
.htable th { text-align: left; font-size: 14px; color: var(--ink2); padding: 6px 4px; border-bottom: 2px solid var(--ink2); }
.htable td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: top; cursor: pointer; }
.htable .tv { text-align: right; font-variant-numeric: tabular-nums; }
.htable td.tv { font-size: 20px; font-weight: 700; }
.htable .tsit { font-size: 12px; color: var(--muted); white-space: nowrap; }
.htable td:nth-child(1), .htable td:nth-child(2) { white-space: nowrap; }
.htable tr.tev td:nth-child(3), .htable tr.tnote td { white-space: normal; }
.htable tr.hasnote td { border-bottom: 0; }
.htable tr.tnote td { font-size: 14px; color: var(--ink2); padding-top: 0; }
.htable tr.tev td { background: var(--accent-soft); font-size: 15px; }
.hiddenbar { display: block; width: 100%; margin-top: 10px; min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent); font: inherit; font-weight: 700; font-size: 16px; text-align: left; cursor: pointer; }
.viewchips .chip { min-height: 40px; padding: 0 10px; font-size: 15px; }
.charthead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.charthead h3 { margin: 0; }
.zoombar { display: grid; grid-template-columns: 52px 52px 1fr; gap: 6px; margin: 8px 0 4px; }
.zoombar .btn { font-size: 20px; }
.zoombar #zReset { font-size: 15px; }
.zoomable { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.legend i.dash { background: none; border-top: 2px dashed var(--muted); height: 0; }
.mmgrid { display: grid; grid-template-columns: auto 1fr 1fr 1fr; gap: 2px 10px; margin-top: 8px; font-size: 15px; font-variant-numeric: tabular-nums; }
.mmgrid b { font-size: 13px; color: var(--ink2); }
.periods .chip { justify-content: center; padding: 0; font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--ink2); }
.small { font-size: 13px; color: var(--ink2); }
.medper { border-top: 1px solid var(--line); padding: 8px 0 0; margin-top: 8px; font-size: 14px; }
.medper:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.chart { width: 100%; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink2); margin-top: 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 13px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; z-index: 5; }
.chartwrap { position: relative; }

.day { margin-top: 14px; font-size: 13px; font-weight: 700; color: var(--ink2); text-transform: uppercase; letter-spacing: .03em; }
.entry { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 6px; cursor: pointer; }
.entry .t { font-variant-numeric: tabular-nums; color: var(--ink2); width: 44px; flex: none; padding-top: 3px; }
.entry .m { flex: 1; min-width: 0; }
.entry .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.entry .v small { font-size: 14px; font-weight: 500; color: var(--ink2); }
.entry .n { font-size: 14px; color: var(--ink2); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.entry.ev .v, .entry.med .v { font-size: 16px; font-weight: 600; }
.entry .kind { display: inline-flex; align-items: center; gap: 5px; color: var(--ink2); font-size: 13px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- more / settings ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.field label { font-size: 14px; font-weight: 600; color: var(--ink2); }
.field input, .field select, .field textarea { min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; width: 100%; }
.field textarea { min-height: 140px; font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
.ok { color: var(--c-opt); } .err { color: var(--c-g2); }
.help h4 { margin: 14px 0 4px; } .help p { margin: 4px 0; font-size: 15px; }
.disclaimer { font-size: 13px; color: var(--ink2); margin-top: 10px; }
.cattable { width: 100%; border-collapse: collapse; font-size: 14px; }
.cattable td { padding: 4px 4px; border-top: 1px solid var(--line); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { display: flex; align-items: center; gap: 10px; font-size: 26px; }
.login .logo { width: 40px; height: 40px; }

/* ---------- toast, modal, update bar ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100% - 32px); width: 520px; font-size: 16px; }
.toast.bad { background: var(--c-g2); color: #fff; }
.toast.bad::after { content: "  ✕"; font-weight: 700; }
.toast b { font-size: 22px; }
.toast .cat { color: inherit; background: rgba(255,255,255,.14); }
.toast.bad .cat { background: rgba(0,0,0,.15); }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; padding: calc(12px + env(safe-area-inset-top)) 12px 12px; overflow: auto; }
.sheet { background: var(--bg); border-radius: 18px; width: 100%; max-width: 520px; padding: 14px; }
.sheet .head { display: flex; gap: 8px; margin-bottom: 8px; }
.sheet .head .btn { flex: 1; }
.sheet h2 { font-size: 18px; margin: 4px 0 8px; }
.timedisp { font-size: 52px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; background: var(--card); border: 2px solid var(--sel); border-radius: var(--radius); padding: 4px; }
.timedisp .d { color: var(--muted); }
.dayrow { display: grid; grid-template-columns: 48px 1fr 48px; gap: 6px; margin-top: 8px; }
.dayrow .chip { justify-content: center; padding: 0; }
.sheet .chips .chip.grow { padding: 0 8px; white-space: nowrap; }
.jumps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.jumps .chip { justify-content: center; }
.body-upd .toast { bottom: calc(64px + env(safe-area-inset-bottom)); }   /* above the update bar */
.savedline { font-weight: 700; color: var(--c-opt); font-size: 18px; }
.updbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 70; background: #f5c542; color: #222; text-align: center; padding: 12px; font-weight: 600; cursor: pointer; }

@media (min-width: 700px) {
  #app { max-width: 640px; }
  .key { min-height: 52px; }
}

/* ---------- doctor page / print ---------- */
.ptable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ptable th, .ptable td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ptable th { font-size: 13px; color: var(--ink2); }
.ptable .pev td { background: var(--accent-soft); }
@media print {
  :root, :root[data-theme="dark"] { --bg: #fff; --card: #fff; --ink: #000; --ink2: #333; --muted: #666; --line: #ccc; --accent: #a50f1e; --accent-soft: #f6e1e3;
    --sys: #2a78d6; --dia: #eb6834; --pulse: #1baf7a; color-scheme: light; }
  .noprint, .updbar, .toast { display: none !important; }
  #app { max-width: none; padding: 0; }
  body { font-size: 12pt; }
  .card { break-inside: avoid; border-color: #ccc; }
  .ptable tr { break-inside: avoid; }
}
