:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #1d2033;
  --muted: #6b7088;
  --border: #dfe2ef;
  --primary: #5b6ee1;
  --primary-text: #ffffff;
  --ok: #2f9e6e;
  --soon: #d68a00;
  --late: #d64545;
  --late-bg: #fdecec;
  --soon-bg: #fff5e0;
  --ok-bg: #e7f6ef;
  --shadow: 0 2px 10px rgba(30, 35, 70, .07);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c;
    --surface: #1b1e2b;
    --surface-2: #252939;
    --text: #e9ebf5;
    --muted: #9196ad;
    --border: #2d3245;
    --primary: #7d8cf0;
    --primary-text: #0f1220;
    --ok: #4cc28d;
    --soon: #f0aa30;
    --late: #ff6b6b;
    --late-bg: #3a1e22;
    --soon-bg: #3a2f17;
    --ok-bg: #173126;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--late); min-height: 1.4em; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 28px 4px 10px; }
h3 { margin: 0 0 14px; }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box h1 { margin-top: 12px; }
.login-box form { margin-top: 24px; display: grid; gap: 12px; }

/* Layout */
#app { min-height: 100%; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
}
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; background: none; border: 0; color: var(--muted);
  font: inherit; font-size: 12px; padding: 6px 0; display: grid; gap: 2px; justify-items: center; cursor: pointer;
}
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--primary); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }

.banner {
  max-width: 640px; margin: 0 auto 12px; padding: 12px 16px;
  background: var(--soon-bg); color: var(--text); border-radius: 12px; font-size: 14px;
  margin-left: 16px; margin-right: 16px;
}
@media (min-width: 672px) { .banner { margin-left: auto; margin-right: auto; } }

/* Buttons & inputs */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 12px;
  padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.block { width: 100%; }
.btn.big { padding: 16px; font-size: 17px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.danger-text { color: var(--late) !important; }

input, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-top: 4px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 6px; flex: 1; }
label.inline input { margin: 0; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
label.check input { width: 20px; height: 20px; margin: 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { margin-top: 18px; }
.spacer { flex: 1; }

.quick { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.quick button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}

/* Cards */
.cards { display: grid; gap: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; border: 1px solid var(--border); border-left: 6px solid var(--ok);
}
.card.soon { border-left-color: var(--soon); }
.card.late { border-left-color: var(--late); background: linear-gradient(0deg, var(--late-bg), var(--surface) 70%); }
.card.none { border-left-color: var(--border); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .emoji { font-size: 28px; }
.card-head .name { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.dose { color: var(--muted); font-size: 14px; margin-top: 2px; }

.countdown { margin: 14px 0 4px; font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.card.ok .countdown { color: var(--ok); }
.card.soon .countdown { color: var(--soon); }
.card.late .countdown { color: var(--late); }
.countdown small { display: block; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0 12px; }
.progress > div { height: 100%; width: 0; background: var(--ok); border-radius: inherit; transition: width .5s; }
.card.soon .progress > div { background: var(--soon); }
.card.late .progress > div { background: var(--late); }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 14px; margin-bottom: 14px; }
.meta div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.meta b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.meta span { color: var(--muted); font-size: 12px; }
.card-actions { display: flex; gap: 8px; }
.card-actions .btn.primary { flex: 1; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* Lists */
.list { display: grid; gap: 8px; margin-bottom: 12px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
  width: 100%; text-align: left; font: inherit; color: inherit;
}
.list-item .emoji { font-size: 22px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .sub { color: var(--muted); font-size: 13px; }
.list-item.inactive { opacity: .55; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.panel p { margin: 0; }
.hint { background: var(--soon-bg); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 0; }

.toolbar { margin-bottom: 12px; }
.day { margin: 18px 4px 8px; font-weight: 700; font-size: 14px; color: var(--muted); text-transform: capitalize; }
.hist-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; }

/* Dialog */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
  max-height: calc(100% - 32px); overflow: auto;
}
dialog::backdrop { background: rgba(10, 12, 25, .5); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 50;
  font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); text-align: center;
}
