:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1f27;
  --muted: #667085;
  --border: #e2e5ea;
  --primary: #3b6cf6;
  --primary-text: #ffffff;
  --ok: #16a34a;
  --ok-bg: #e8f7ee;
  --wait: #b45309;
  --wait-bg: #fdf3e6;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #181c24;
    --text: #e8eaef;
    --muted: #98a2b3;
    --border: #2a303c;
    --primary: #5b86ff;
    --ok: #4ade80;
    --ok-bg: #14281d;
    --wait: #fbbf24;
    --wait-bg: #2b2212;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Header + tabs */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem 0;
}
.top h1 { margin-bottom: 0.5rem; }
.tabs { display: flex; gap: 0.25rem; overflow-x: auto; }
.tabs button {
  background: none; border: 0; color: var(--muted);
  font: inherit; font-weight: 600; padding: 0.5rem 0.75rem;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

main { max-width: 960px; margin: 0 auto; padding: 1rem; }
.section-title { margin-top: 1.5rem; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 0.5rem 0.9rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 0.25rem 0.4rem; color: var(--muted); font-weight: 500; }
.btn.link:hover { color: var(--text); }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

/* Medicine cards */
.cards { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; border-top: 4px solid var(--med-color, var(--primary));
  display: flex; flex-direction: column; gap: 0.5rem;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.card-head h3 { margin: 0; font-size: 1.1rem; }
.card .dose { color: var(--muted); font-size: 0.9rem; }
.status {
  border-radius: 8px; padding: 0.6rem 0.75rem;
  font-variant-numeric: tabular-nums;
}
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.wait { background: var(--wait-bg); color: var(--wait); }
.status .big { font-size: 1.5rem; font-weight: 700; display: block; }
.status .sub { font-size: 0.85rem; opacity: 0.9; }
.reasons { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--muted); }
.reasons li.limiting { color: var(--text); font-weight: 600; }
.meta { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; }
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--med-color, var(--primary)); transition: width 1s linear; }
.card-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: auto; }
.card-actions .btn.primary { flex: 1; justify-content: center; }

/* Lists */
.dose-list, .item-list { list-style: none; margin: 0; padding: 0; }
.dose-list li, .item-list li {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.6rem 0.75rem; margin-bottom: 0.4rem;
}
.item-list.compact li { padding: 0.4rem 0.75rem; font-size: 0.9rem; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--med-color, var(--primary)); }
.grow { flex: 1; min-width: 0; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.day-heading { margin: 1rem 0 0.4rem; font-size: 0.9rem; color: var(--muted); }
.tag { font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--wait-bg); color: var(--wait); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 0.75rem;
}
.panel .btn { margin: 0.25rem 0.25rem 0 0; }
.disclaimer { margin-top: 2rem; font-size: 0.8rem; color: var(--muted); text-align: center; }

/* Dialogs + forms */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 2rem)); padding: 1.25rem;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
form label { display: block; margin-bottom: 0.75rem; font-weight: 600; font-size: 0.9rem; }
form input:not([type="checkbox"]):not([type="color"]), form select, form textarea {
  display: block; width: 100%; margin-top: 0.25rem;
  font: inherit; font-weight: 400; padding: 0.5rem 0.6rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
form input[type="color"] { display: block; margin-top: 0.25rem; width: 3rem; height: 2rem; border: 0; background: none; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; margin: 0 0 0.75rem; }
.sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.sentence select, .sentence input { width: auto !important; display: inline-block !important; margin: 0 !important; }
.sentence .narrow { width: 5rem !important; }
label.check, .checks label { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; margin: 0.25rem 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 0.5rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.dialog-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: 0.9rem; }
.warning {
  background: var(--wait-bg); color: var(--wait); border-radius: 8px;
  padding: 0.6rem 0.75rem; font-size: 0.9rem;
}
.warning ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }

.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px;
  display: flex; gap: 0.75rem; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,0.2); z-index: 20;
}
.toast button { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 700; cursor: pointer; }

@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
  .row-between { flex-wrap: wrap; }
}

/* Sync status + login */
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer;
  font: inherit; font-size: 0.8rem; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 0.2rem 0.65rem;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-pill[data-state="synced"] .sync-dot { background: var(--ok); }
.sync-pill[data-state="syncing"] .sync-dot { background: var(--primary); animation: pulse 1s infinite; }
.sync-pill[data-state="offline"] .sync-dot, .sync-pill[data-state="loggedout"] .sync-dot { background: var(--wait); }
@keyframes pulse { 50% { opacity: 0.3; } }
.login {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: grid; place-items: center; padding: 1rem;
}
.login-box { width: min(380px, 100%); }
.login-box .btn { width: 100%; justify-content: center; }
