:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #16211f;
  --muted: #5d6b68;
  --line: #e1e7e5;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f0;
  --warn: #b45309;
  --warn-soft: #fdf1e3;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --good: #15803d;
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --card: #18201f; --ink: #e9efed; --muted: #9aa9a5; --line: #2a3533;
    --accent: #2dd4bf; --accent-ink: #062b27; --accent-soft: #123a35;
    --warn: #f5a524; --warn-soft: #3a2a10; --bad: #f87171; --bad-soft: #3b1715; --good: #4ade80;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 6px;
  max-width: 560px; margin: 0 auto;
}
.brand { font-size: 22px; margin: 0; letter-spacing: -0.3px; }
.brand span { color: var(--accent); }
main { max-width: 560px; margin: 0 auto; padding: 6px 16px 24px; }
h2 { font-size: 26px; margin: 8px 2px 14px; letter-spacing: -0.4px; }
h3 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Buttons */
.btn, button.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 17px;
  cursor: pointer; width: 100%;
}
button.secondary {
  min-height: 48px; padding: 0 16px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; width: 100%;
}
button.ghost { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 8px; min-height: 40px; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; }
button:active { transform: scale(.98); }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--line); margin-bottom: 12px;
}
.pep-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pep-name { font-size: 19px; font-weight: 700; margin: 0; }
.pep-dose { color: var(--muted); margin-top: 2px; }
.draw { font-size: 30px; font-weight: 750; letter-spacing: -0.5px; margin: 10px 0 0; }
.draw small { font-size: 15px; font-weight: 500; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600;
}
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.plain { background: var(--bg); color: var(--muted); }
.tag.done { background: var(--accent-soft); color: var(--good); }
.card-actions { display: flex; gap: 10px; margin-top: 14px; }
.card-actions .primary { flex: 2; }
.card-actions .secondary { flex: 1; width: auto; }

.empty { text-align: center; padding: 34px 16px; }
.empty p { margin: 6px 0 18px; }

/* Forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
input, select, textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card); font-size: 17px; outline: none;
}
input[type=date], input[type=datetime-local] { -webkit-appearance: none; appearance: none; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.input-unit { position: relative; }
.input-unit input { padding-right: 56px; }
.input-unit em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-weight: 600; }
.seg { display: flex; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick button {
  min-height: 42px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; font-size: 15px;
}
.pick button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pick button .sug { font-size: 11px; font-weight: 700; text-transform: uppercase; margin-left: 4px; }

/* Result panel */
.result {
  background: var(--accent-soft); border-radius: var(--radius); padding: 16px; margin: 4px 0 16px;
}
.result .big { font-size: 40px; font-weight: 800; letter-spacing: -1px; color: var(--accent); line-height: 1.1; }
.result .line { margin-top: 4px; color: var(--ink); }
.result .warnline { margin-top: 8px; color: var(--warn); font-weight: 600; font-size: 14px; }
.syringe { width: 100%; height: 64px; margin-top: 12px; display: block; }

/* Presets */
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.presets button {
  text-align: left; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); cursor: pointer; min-height: 60px;
}
.presets button b { display: block; font-size: 15px; }
.presets button span { font-size: 13px; color: var(--muted); }
.presets button.custom { border-style: dashed; color: var(--accent); }

/* History */
.day { font-size: 14px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .4px; }
.hist { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.hist .when { width: 64px; color: var(--muted); font-size: 14px; }
.hist .what { flex: 1; }
.hist .what b { display: block; }
.hist + .hist { border-top: 1px solid var(--line); }
.list { padding: 0; overflow: hidden; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; max-width: 160px; min-height: 52px; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.active { color: var(--accent); }

/* Sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.38); animation: fade .15s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h3 { font-size: 21px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 12px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; z-index: 30; font-weight: 600;
  max-width: 90vw; text-align: center;
}
.login { padding-top: 6vh; }
.login h2 { font-size: 30px; }
.code-input { font-size: 30px; letter-spacing: 10px; text-align: center; font-weight: 700; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin-top: 26px; }
.spacer { height: 10px; }
[hidden] { display: none !important; }
