:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --ink: #152424;
  --muted: #5a6b6b;
  --line: #dde4e4;
  --accent: #0b5f62;
  --accent-ink: #ffffff;
  --accent-soft: #e0eff0;
  --plus: #17693a;
  --minus: #a8321f;
  --warn-bg: #fdf3d8;
  --warn-ink: #6b4e00;
  --danger-bg: #fbe6e2;
  --danger-ink: #8c2a1a;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a1a;
    --surface: #182525;
    --ink: #eaf1f1;
    --muted: #9db0b0;
    --line: #2b3b3b;
    --accent: #3fb6ba;
    --accent-ink: #062526;
    --accent-soft: #1d3a3b;
    --plus: #6fd199;
    --minus: #f29a89;
    --warn-bg: #3a3014;
    --warn-ink: #f0d58a;
    --danger-bg: #40201a;
    --danger-ink: #f5b2a5;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
}

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

button { cursor: pointer; border: 0; background: none; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 12px;
}

.topbar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { display: flex; gap: 4px; flex-shrink: 0; }

.link {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--accent);
  font-weight: 600;
}

.back { margin-left: -10px; }

.login { padding-top: 32px; }

.login h1 { font-size: 26px; line-height: 1.2; }

.login-sub { color: var(--muted); margin: 4px 0 24px; }

.field { display: block; margin-bottom: 16px; }

.field-label { display: block; font-size: 15px; font-weight: 600; margin-bottom: 6px; }

.input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
}

.input:focus { border-color: var(--accent); outline: none; }

.pin { font-size: 26px; letter-spacing: 8px; text-align: center; }

.choices { display: grid; gap: 8px; }

.choice {
  min-height: 52px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  font-weight: 600;
}

.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 18px;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn:disabled { opacity: .55; cursor: default; }

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

.segments {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--line);
  border-radius: var(--radius);
}

.segment {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--muted);
}

.segment[aria-pressed="true"] { background: var(--surface); color: var(--ink); }

.banner {
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 15px;
}

.banner-danger { background: var(--danger-bg); color: var(--danger-ink); }

.drug-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}

.drug-list li + li { border-top: 1px solid var(--line); }

.drug {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  text-align: left;
}

.drug-name { overflow-wrap: anywhere; }

.drug-balance { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.drug-balance.empty { color: var(--minus); }

.empty-note { padding: 24px 14px; color: var(--muted); text-align: center; }

.title { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }

.journal-tag { color: var(--muted); font-size: 15px; }

.balance-card {
  margin: 12px 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.balance-label { color: var(--muted); font-size: 15px; }

.balance-value { font-size: 40px; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }

.section-title { font-size: 15px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }

.entry {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.entry-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

.entry-qty { font-weight: 700; font-size: 19px; font-variant-numeric: tabular-nums; }

.entry-qty.plus { color: var(--plus); }

.entry-qty.minus { color: var(--minus); }

.entry-rest { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.entry-who { overflow-wrap: anywhere; }

.entry-meta { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }

.entry-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }

.chip { font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); }

.chip-wait { background: var(--warn-bg); color: var(--warn-ink); }

.undo { min-height: 40px; padding: 0 10px; color: var(--minus); font-weight: 600; font-size: 15px; }

.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }

.step {
  min-height: 56px;
  font-size: 26px;
  font-weight: 700;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent);
}

.qty { text-align: center; font-size: 24px; font-weight: 700; }

.after { color: var(--muted); margin: -8px 0 16px; font-variant-numeric: tabular-nums; }

.after strong { color: var(--ink); }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin-bottom: 16px;
}

.check input { width: 24px; height: 24px; flex-shrink: 0; accent-color: var(--accent); }

.quick {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  margin-bottom: 16px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  text-align: left;
}

.quick small { display: block; color: var(--muted); font-size: 13px; }

.after-list { margin-top: 16px; }

.section-gap { margin-top: 20px; }

.field-hint { display: block; color: var(--muted); font-size: 14px; margin-top: 6px; }

.pin-card {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  text-align: center;
}

.pin-card-name { font-weight: 600; }

.pin-card-value { font-size: 40px; line-height: 1.2; font-weight: 700; letter-spacing: 6px; font-variant-numeric: tabular-nums; }

.pin-card-note { color: var(--muted); font-size: 14px; }

.user-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.user-name { font-weight: 600; margin-right: 4px; overflow-wrap: anywhere; }

.user-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.mini {
  min-height: 44px;
  padding: 0 12px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}

.entry-off { opacity: .65; }

.error { color: var(--danger-ink); background: var(--danger-bg); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: 528px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
}
