/* Vitals Tracker styles. No inline styles anywhere in the app (the Content-Security-Policy forbids them),
   so every look is a class here. Light and dark follow the phone's setting. */

:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #1c1c1e; --sub: #636366; --line: #e5e5ea; --field: #f6f6f9;
  --accent: #0a6cff; --accent-text: #ffffff; --danger: #d92d20; --danger-bg: #ffe9e7;
  --good: #1f9d4c; --good-bg: #e3f6ea; --warn-bg: #fff4d6; --warn: #8a5a00;
  --sys: #e5413a; --dia: #0a6cff; --pulse: #9b4fd1; --weight: #1f9d4c; --grid: #dcdce2; --axis: #6e6e73;
  --c-normal: #1f9d4c; --c-raised: #b38600; --c-high1: #e07a00; --c-high2: #d92d20; --c-urgent: #8b0000;
  --tab-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --card: #1c1c1e; --text: #f2f2f7; --sub: #a1a1a6; --line: #38383a; --field: #2c2c2e;
    --accent: #4da3ff; --accent-text: #001a33; --danger: #ff6b61; --danger-bg: #3b1a18;
    --good: #46d374; --good-bg: #0f2a1a; --warn-bg: #33290a; --warn: #ffd166;
    --sys: #ff6b61; --dia: #4da3ff; --pulse: #c58bf0; --weight: #46d374; --grid: #38383a; --axis: #a1a1a6;
    --c-normal: #46d374; --c-raised: #f2c94c; --c-high1: #ff9f43; --c-high2: #ff6b61; --c-urgent: #ff453a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.grow { flex: 1; }
.right { text-align: right; }
.center { text-align: center; }
.muted { color: var(--sub); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; }
.mt-s { margin-top: 6px; }

/* ---------- layout ---------- */
.page { display: none; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; max-width: 640px; margin: 0 auto; }
.page.active { display: block; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.topbar h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; }
.card { background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.card > h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--sub); font-weight: 600; margin-bottom: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row.auto > * { flex: 0 1 auto; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack > * + * { margin-top: 10px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--sub); margin: 12px 0 4px; font-weight: 500; }
label:first-child { margin-top: 0; }
input[type=text], input[type=number], input[type=date], input[type=time], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--field); font-size: 18px; color: var(--text); font-family: inherit; -webkit-appearance: none; appearance: none;
}
select { padding-right: 30px; }
textarea { min-height: 76px; resize: vertical; font-size: 17px; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.field-note { font-size: 13px; color: var(--sub); margin-top: 8px; line-height: 1.45; }
.unit { font-size: 13px; color: var(--sub); margin-top: 4px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px;
  padding: 12px 18px; border-radius: 14px; border: none; font-size: 17px; font-weight: 600; cursor: pointer; margin-top: 14px;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--field); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { width: auto; min-height: 40px; padding: 8px 14px; font-size: 15px; margin-top: 0; }
.btn[disabled] { opacity: 0.5; }

.seg { display: flex; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: none; background: none; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--sub); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; gap: 12px; }

/* ---------- categories ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #fff; }
.cat-normal { background: var(--c-normal); } .cat-raised { background: var(--c-raised); color: #1c1c1e; }
.cat-high1 { background: var(--c-high1); color: #1c1c1e; } .cat-high2 { background: var(--c-high2); } .cat-urgent { background: var(--c-urgent); }
.txt-normal { color: var(--c-normal); } .txt-raised { color: var(--c-raised); } .txt-high1 { color: var(--c-high1); }
.txt-high2 { color: var(--c-high2); } .txt-urgent { color: var(--c-urgent); }

/* ---------- notices ---------- */
.notice { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; line-height: 1.45; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.good { background: var(--good-bg); color: var(--good); }
.notice.bad { background: var(--danger-bg); color: var(--danger); }
.notice button { margin-top: 8px; }

/* ---------- dashboard ---------- */
.range-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.range-tabs button { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; color: var(--sub); }
.range-tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--field); border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat .val { font-size: 22px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--sub); margin-top: 2px; }
.stat .sub { font-size: 12px; margin-top: 4px; font-weight: 600; min-height: 16px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.mid { font-size: 22px; font-weight: 700; line-height: 1.25; }
canvas.chart { width: 100%; height: 200px; display: block; touch-action: pan-y; }
.chart-caption { font-size: 14px; color: var(--text); min-height: 20px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; font-size: 12px; color: var(--sub); }
.legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.sys { background: var(--sys); } .dot.dia { background: var(--dia); } .dot.pulse { background: var(--pulse); } .dot.weight { background: var(--weight); }
.dot.avg { background: var(--text); width: 14px; height: 3px; border-radius: 2px; }
.compare { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 6px 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.compare .h { font-size: 12px; color: var(--sub); }
.compare .right { text-align: right; }
.progress { height: 10px; border-radius: 6px; background: var(--field); overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--weight); border-radius: 6px; }

/* ---------- history ---------- */
.day-head { font-size: 13px; font-weight: 600; color: var(--sub); padding: 12px 0 4px; }
.hist-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; background: none; border-left: none; border-right: none; border-bottom: none; width: 100%; text-align: left; min-height: 56px; }
.hist-row .when { font-size: 13px; color: var(--sub); }
.hist-row .vals { text-align: right; font-size: 15px; }
.hist-row .vals b { font-size: 17px; }
.empty { text-align: center; color: var(--sub); padding: 30px 10px; font-size: 15px; }

/* ---------- tab bar, modal, toast ---------- */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 50; }
.tabbar button { flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--sub); font-size: 11px; font-weight: 600; padding-top: 6px; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: none; align-items: flex-end; z-index: 100; }
.modal-bg.show { display: flex; }
.modal { background: var(--card); width: 100%; max-width: 640px; margin: 0 auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
.modal h2 { font-size: 20px; margin-bottom: 10px; }
.modal-handle { width: 38px; height: 5px; background: var(--line); border-radius: 3px; margin: 0 auto 14px; }
.toast { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%) translateY(-90px); background: #1c1c1ef2; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px; font-weight: 600; z-index: 600; transition: transform 0.25s ease; display: flex; align-items: center; gap: 14px; max-width: 92vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast button { background: none; border: none; color: #7fc0ff; font-weight: 700; font-size: 15px; padding: 4px 2px; }

/* ---------- lock screen ---------- */
.lockscreen { position: fixed; inset: 0; background: #0b0b0f; z-index: 500; display: none; flex-direction: column; align-items: center; justify-content: center; color: #fff; padding: 20px; }
.lockscreen.show { display: flex; }
.lockscreen h2 { font-size: 22px; }
.pin-dots { display: flex; gap: 14px; margin: 26px 0 8px; min-height: 16px; }
.pin-dots div { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid #fff; }
.pin-dots div.filled { background: #fff; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 16px; margin-top: 18px; }
.pin-pad button { width: 72px; height: 72px; border-radius: 50%; background: #1c1c1e; color: #fff; font-size: 26px; border: none; }
.pin-pad button:active { background: #3a3a3c; }
.pin-pad .blank { visibility: hidden; }
.lock-msg { color: #ff6b61; font-size: 14px; min-height: 20px; margin-top: 10px; text-align: center; }
.modal .pin-pad button { background: var(--field); color: var(--text); }
.modal .pin-dots div { border-color: var(--text); } .modal .pin-dots div.filled { background: var(--text); }
.modal .lock-msg { color: var(--danger); }
.modal .pin-wrap { display: flex; flex-direction: column; align-items: center; }

/* ---------- printable report (shown only when printing) ---------- */
#printReport { display: none; }
@media print {
  body * { visibility: hidden; }
  #printReport, #printReport * { visibility: visible; }
  #printReport { display: block !important; position: absolute; left: 0; top: 0; width: 100%; padding: 8mm; color: #000; background: #fff; font-family: Helvetica, Arial, sans-serif; }
  #printReport h1 { font-size: 22px; margin: 0 0 2px; }
  #printReport .meta { color: #444; font-size: 12px; margin-bottom: 12px; }
  #printReport table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 14px; }
  #printReport th { text-align: left; background: #eee; padding: 5px 6px; border-bottom: 1px solid #999; }
  #printReport td { padding: 4px 6px; border-bottom: 1px solid #ddd; }
  #printReport .summary td { font-size: 13px; padding: 5px 6px; }
  #printReport .note { font-size: 11px; color: #444; margin-top: 10px; }
  .tabbar, .toast, .modal-bg { display: none !important; }
}

.details { background: var(--field); border-radius: 12px; padding: 12px; font: 13px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-all; margin: 0 0 10px; }
