:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e1e0d9;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6f6e69;
  --accent: #14615a;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --morning: #2a78d6;
  --evening: #eb6834;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1f7a3f;
  --warn: #a15c00;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151514;
    --surface: #1a1a19;
    --surface-2: #242422;
    --line: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #9a998f;
    --accent: #5cc2b2;
    --accent-ink: #0b1f1c;
    --accent-soft: #1d3330;
    --morning: #3987e5;
    --evening: #d95926;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --ok: #7fd49a;
    --warn: #f0b45a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151514; --surface: #1a1a19; --surface-2: #242422; --line: #2c2c2a;
  --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #9a998f;
  --accent: #5cc2b2; --accent-ink: #0b1f1c; --accent-soft: #1d3330;
  --morning: #3987e5; --evening: #d95926;
  --danger: #ff8a80; --danger-soft: #3a1d1b; --ok: #7fd49a; --warn: #f0b45a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.error { color: var(--danger); margin: .5rem 0 0; font-size: .9rem; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom));
}

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.brand { font-size: 1.35rem; font-weight: 720; letter-spacing: -.01em; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; color: var(--ink-2); cursor: pointer;
}
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.sync-pill.ok .dot { background: var(--ok); }
.sync-pill.pending .dot { background: var(--warn); }
.sync-pill.busy .dot { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow);
}
.card h3 + * { margin-top: 10px; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 22px 4px 8px; }

/* today */
.today .date { font-size: .85rem; color: var(--ink-2); }
.today-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.slot {
  border-radius: 12px; padding: 10px 12px; background: var(--surface-2);
  border-left: 4px solid var(--ink-3);
}
.slot.morning { border-left-color: var(--morning); }
.slot.evening { border-left-color: var(--evening); }
.slot .lbl { font-size: .78rem; color: var(--ink-2); }
.slot .val { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot .val.none { font-size: 1rem; font-weight: 500; color: var(--ink-3); padding: 7px 0; }
.slot .unit { font-size: .75rem; color: var(--ink-3); font-weight: 500; margin-left: 3px; }
.today .inh-line { margin-top: 10px; font-size: .9rem; color: var(--ink-2); }

/* big buttons */
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  border: none; border-radius: var(--radius); padding: 18px 16px; min-height: 132px;
  text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.big-btn.pf { background: var(--accent); color: var(--accent-ink); }
.big-btn.inh { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.big-btn:active { transform: scale(.98); }
.big-ico svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.big-ico svg circle { fill: currentColor; }
.big-label { font-size: 1.15rem; font-weight: 700; margin-top: auto; }
.big-sub { font-size: .85rem; opacity: .85; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.day-head { font-size: .8rem; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin: 16px 4px 2px; }
.day-head:first-child { margin-top: 4px; }
.row {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; text-align: left; width: 100%; cursor: pointer;
}
.row .t { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: .9rem; }
.row .main { font-weight: 600; }
.row .sub { font-size: .85rem; color: var(--ink-2); }
.row .badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.row .badge.morning { box-shadow: inset 3px 0 0 var(--morning); }
.row .badge.evening { box-shadow: inset 3px 0 0 var(--evening); }
.row .pending-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; margin-left: 6px; vertical-align: middle; }
.empty { text-align: center; color: var(--ink-3); padding: 28px 10px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: .85rem; color: var(--ink-2); }
.field > span { font-weight: 550; }
.field.inline { margin: 0; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 10px; padding: 11px 12px; font-size: 1rem; color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
.blows { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.blows .field { margin-bottom: 4px; }
.blows input { font-size: 1.35rem; font-weight: 650; text-align: center; padding: 12px 6px; font-variant-numeric: tabular-nums; }
.best-readout { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; }
.best-readout strong { font-size: 2rem; font-variant-numeric: tabular-nums; }
.when { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; font-size: .95rem; }
.when input { flex-basis: 100%; }

.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; font-size: .95rem;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.grow { flex: 1; }
.btn:disabled { opacity: .5; }
.link-btn { border: none; background: none; color: var(--accent); font-weight: 600; padding: 4px; cursor: pointer; }
.icon-btn { border: none; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1rem; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.file-btn { display: inline-block; position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* segmented + chips */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin: 6px 0; }
.seg button {
  flex: 1; border: none; background: transparent; border-radius: 9px; padding: 9px 6px;
  font-weight: 600; font-size: .9rem; color: var(--ink-2); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
#pfPeriod button[data-v="morning"][aria-checked="true"] { box-shadow: inset 0 -3px 0 var(--morning), 0 1px 3px rgba(0,0,0,.12); }
#pfPeriod button[data-v="evening"][aria-checked="true"] { box-shadow: inset 0 -3px 0 var(--evening), 0 1px 3px rgba(0,0,0,.12); }
.seg.range { margin-bottom: 14px; }
.custom-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: -4px 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: .9rem; cursor: pointer;
}
.chip[aria-checked="true"], .chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.stepper { display: flex; align-items: center; gap: 14px; margin: 8px 0; }
.stepper .step { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.4rem; cursor: pointer; }
.stepper output { font-size: 1.6rem; font-weight: 700; min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; }

/* sheets */
dialog.sheet {
  border: none; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92dvh; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.4); }
dialog.sheet form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92dvh; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { padding: 14px 16px; font-size: 1rem; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; max-width: 140px; border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: .75rem; font-weight: 600; color: var(--ink-3); cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* charts & stats */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--ink-2); flex-wrap: wrap; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key i { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--ink-3); }
.key-morning i { border-top-color: var(--morning); }
.key-evening i { border-top: 2px dashed var(--evening); }
.key-pb i { border-top: 1px dotted var(--ink-3); }
.key .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-box { position: relative; height: 240px; margin-top: 10px; }
.chart-box.short { height: 170px; }
table.stats { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--ink-2); font-weight: 600; font-size: .78rem; }
.facts { margin: 12px 0 0; padding: 0; list-style: none; font-size: .9rem; }
.facts li { padding: 4px 0; }
.facts strong { font-variant-numeric: tabular-nums; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

.login { margin-top: 24px; }
.login h2 + p { margin: 8px 0 4px; }

/* print (GP summary) */
.print-only { display: none; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .app, dialog, .toast { display: none !important; }
  .print-only { display: block; }
  #print h1 { font-size: 16pt; margin-bottom: 2pt; }
  #print h2 { font-size: 12pt; margin: 14pt 0 6pt; }
  #print .sub { color: #444; margin-bottom: 8pt; }
  #print img { width: 100%; max-height: 7cm; object-fit: contain; }
  #print table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  #print th, #print td { border-bottom: 1px solid #ccc; padding: 3pt 4pt; text-align: right; vertical-align: top; }
  #print th:first-child, #print td:first-child { text-align: left; }
  #print td.l, #print th.l { text-align: left; }
  #print ul { margin: 4pt 0; padding-left: 14pt; }
  #print tr { break-inside: avoid; }
  @page { margin: 14mm; }
}

/* sign-in settings */
.pk-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.pk-row .main { font-weight: 600; }
.pk-row .sub { font-size: .82rem; color: var(--ink-2); }
.pk-row .link-btn { color: var(--danger); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.toggle-row .main { font-weight: 600; }
.switch { flex: none; width: 52px; height: 32px; border-radius: 999px; border: none; background: var(--line); position: relative; cursor: pointer; padding: 0; }
.switch span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }
#loginDivider { margin: 18px 0 0; }
