:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
}

button, input { font: inherit; }
h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
p { margin: .25rem 0 .75rem; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--teal);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.header-label { font-size: .8rem; opacity: .9; }
.header-total { font-size: 2.5rem; font-weight: 700; line-height: 1.1; }
.header-unit { font-size: 1.1rem; font-weight: 500; }
.header-breakdown {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  margin-top: 4px; font-size: .85rem; opacity: .95;
}
.risk {
  padding: 4px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.risk-amber { background: #fef3c7; color: #92400e; }
.risk-red { background: #fee2e2; color: #991b1b; }
.pill {
  display: inline-block; margin-top: 8px; padding: 4px 12px;
  border-radius: 999px; background: rgba(255,255,255,.2);
  font-size: .85rem; font-weight: 600;
}
.pill-danger { background: var(--red); color: #fff; }

/* Content */
.content { padding: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.notice { text-align: center; color: var(--muted); }
.notice-error { color: var(--red); }
.muted { color: var(--muted); font-size: .9rem; }
.onboarding p { color: var(--muted); }

/* Buttons */
.btn {
  border: 0; border-radius: 10px; padding: 12px 16px;
  min-height: 44px; font-weight: 600; cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-grey { background: #94a3b8; color: #fff; }
.btn-outline { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* Dose cards */
.dose-card {
  display: flex; flex-direction: column; gap: 4px;
  width: 100%; text-align: left; cursor: pointer;
  background: var(--card); color: var(--text);
  border: 2px solid var(--border); border-left: 6px solid var(--teal);
  border-radius: 14px; padding: 16px;
  min-height: 110px;
  transition: transform .08s;
}
.dose-card:active { transform: scale(.98); background: #ecfeff; }
.dose-card-patch { border-left-color: #7c3aed; }
.card-title { font-size: 1.4rem; font-weight: 700; }
.card-dose {
  margin-left: 8px; font-size: 1rem; font-weight: 600;
  background: #e6fffa; color: var(--teal-dark);
  padding: 2px 8px; border-radius: 8px;
}
.card-generic { color: var(--muted); font-size: .95rem; }
.card-ome { font-weight: 700; color: var(--teal-dark); font-size: 1.05rem; }
.card-status { font-size: .9rem; color: var(--muted); }
.card-status-active { color: var(--green); font-weight: 600; }
.card-status-due { color: var(--amber); font-weight: 700; }
.progress { display: block; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.progress-fill { display: block; height: 100%; background: #7c3aed; }

/* History */
.history-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.history-main { flex: 1; min-width: 0; }
.history-time { font-size: .85rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.history-name { font-weight: 700; font-size: 1.1rem; }
.history-ome { font-weight: 600; color: var(--teal-dark); }
.history-actions { display: flex; flex-direction: column; gap: 6px; }

/* Usual meds */
.search {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  border: 2px solid var(--border); border-radius: 12px; background: #fff;
}
.search:focus { outline: none; border-color: var(--teal); }
.med-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.med-brands { font-weight: 700; font-size: 1.1rem; }
.med-meta { font-size: .85rem; color: var(--muted); margin: 6px 0 8px; }
.badge {
  padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: #dbeafe; color: #1e40af;
}
.badge-patch { background: #ede9fe; color: #5b21b6; }
.badge-oral { background: #dbeafe; color: #1e40af; }
.badge-sublingual { background: #fef3c7; color: #92400e; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--border); background: #fff; color: var(--text); font-weight: 600;
}
.chip-active { background: var(--green); border-color: var(--green); color: #fff; }

/* Toast */
.toast {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  max-width: 536px; margin: 0 auto; z-index: 30;
  background: #0f172a; color: #fff; padding: 12px 16px;
  border-radius: 12px; text-align: center; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; height: var(--tabbar-h); border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .8rem; font-weight: 600; color: var(--muted);
}
.tab-icon { font-size: 1.4rem; }
.tab-active { color: var(--teal); box-shadow: inset 0 3px 0 var(--teal); }
