:root {
  --accent: #2563EB;
  --accent-dark: #1D4ED8;
  --accent-soft: #DBEAFE;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;
  --danger: #DC2626;
  --good: #16A34A;
  --warn: #D97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", "Segoe UI", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* top bar */
.topbar {
  background: var(--accent);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.notif-btn {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
.notif-btn:hover { background: rgba(255,255,255,.25); }

/* tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 9;
}
.tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 16px; max-width: 640px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 24px 0 10px;
}
.empty { color: var(--text-3); font-size: 14px; padding: 12px 0; }

/* dose cards */
.dose-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.dose-card.overdue { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(220,38,38,.15); }
.dose-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.dose-card-head > div:nth-child(2) { flex: 1; }
.med-name.big { font-size: 17px; font-weight: 700; }
.med-sub { font-size: 13px; color: var(--text-2); }
.dose-time.big { font-size: 18px; font-weight: 700; color: var(--accent); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.big { width: 14px; height: 14px; }

.dose-actions { display: flex; gap: 8px; }
.dose-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-taken { background: var(--good); color: #fff; }
.btn-taken:hover { background: #15803D; }
.btn-snooze { background: var(--accent-soft); color: var(--accent-dark); }
.btn-snooze:hover { background: #BFDBFE; }
.btn-skip { background: var(--border); color: var(--text-2); }
.btn-skip:hover { background: var(--text-3); color: #fff; }

/* dose rows */
.dose-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 14px;
}
.dose-row .med-name { flex: 1; font-weight: 500; }
.dose-row .dose-time { color: var(--text-2); font-size: 13px; }
.dose-row .dose-status { font-size: 12px; font-weight: 600; color: var(--text-3); }
.dose-row.taken .dose-status { color: var(--good); }
.dose-row.skipped .dose-status { color: var(--text-3); }
.dose-row.upcoming { opacity: .7; }

.med-dosage { color: var(--text-2); font-weight: 500; font-size: .9em; }

/* med cards */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 14px;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
}
.btn-danger:hover { background: #FEF2F2; }

.med-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}
.med-card-main { flex: 1; }
.med-card .med-name { font-size: 16px; font-weight: 700; }
.med-card .med-sub { font-size: 13px; color: var(--text-2); margin: 2px 0 6px; }
.med-times { display: flex; gap: 6px; flex-wrap: wrap; }
.time-chip {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
}
.time-chip.editable { display: inline-flex; align-items: center; gap: 4px; }
.chip-x { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 11px; padding: 0; }
.time-input { padding: 4px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; }
.med-card-actions { display: flex; flex-direction: column; gap: 6px; }

/* stats */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}
.stat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.stat-head .med-name { flex: 1; font-weight: 700; }
.stat-pct { font-size: 18px; font-weight: 800; }
.stat-pct.good, .stat-fill.good { color: var(--good); }
.stat-pct.ok, .stat-fill.ok { color: var(--warn); }
.stat-pct.bad, .stat-fill.bad { color: var(--danger); }
.stat-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.stat-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.stat-sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 600px) { .modal { align-items: center; } }
.modal.hidden { display: none; }
.modal-card {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) { .modal-card { border-radius: 16px; } }
.modal-card h2 { font-size: 20px; margin-bottom: 16px; }
.modal-card h3 { font-size: 15px; margin: 18px 0 10px; color: var(--text-2); }
.modal-card form { display: flex; flex-direction: column; gap: 10px; }
.modal-card label { font-size: 13px; font-weight: 600; color: var(--text-2); display: flex; flex-direction: column; gap: 4px; }
.modal-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.modal-card input[type="text"], .modal-card input:not([type]) {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.modal-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-card input[type="color"] { width: 60px; height: 40px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.modal-card input[type="number"] { width: 80px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }

.sched-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--bg);
}
.sched-times { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.sched-days { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.day-chip {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.day-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sched-meta { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--text-2); }
.sched-meta label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.sched-meta input[type="number"] { padding: 6px 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn-primary { flex: 1; margin-bottom: 0; }
.modal-actions .btn-secondary { flex: 1; }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast.hidden { display: none; }
