:root {
  --bg: #0b1020;
  --panel: #151b2e;
  --panel-2: #1d2540;
  --line: #2a3350;
  --text: #eef2ff;
  --muted: #9aa6c7;
  --blue: #3b82f6;
  --green: #2f9e6f;
  --amber: #f5b73c;
  --danger: #ef4444;
  --radius: 18px;
}

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

html, body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  min-height: 100%;
}
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 120px; }
.loading { text-align: center; color: var(--muted); padding: 80px 0; }

/* Header */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 44px; }
.topbar h1 { font-size: 21px; margin: 0; flex: 1; letter-spacing: .3px; }
.back-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; width: 44px; height: 44px; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; height: 40px; padding: 0 14px; cursor: pointer; font-size: 14px; }
.date-chip { color: var(--muted); font-size: 13px; background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; }

/* Banners / nudges */
.banner { background: color-mix(in srgb, var(--danger) 18%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  color: #ffd7d7; padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 14px; }
.banner.warn { background: color-mix(in srgb, var(--amber) 16%, var(--panel)); border-color: #9a7b16; color: #fde68a; }
.nudge { width: 100%; margin-bottom: 14px; cursor: pointer;
  background: color-mix(in srgb, var(--blue) 22%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--blue) 55%, var(--line));
  color: var(--text); border-radius: 14px; padding: 14px; font-size: 15px; font-weight: 600; }
.nudge:active { transform: scale(.99); }

/* Progress */
.progress-row { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.progress-txt { font-size: 13px; color: var(--muted); white-space: nowrap; }
.progress-bar { flex: 1; height: 8px; background: var(--panel); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #46c38a); }

/* Low-stock cards */
.section-low { display: grid; gap: 10px; margin-bottom: 14px; }
.low-card { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: color-mix(in srgb, var(--amber) 14%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--amber) 50%, var(--line));
  color: var(--text); border-radius: 14px; padding: 14px; }
.low-card.out { background: color-mix(in srgb, var(--danger) 16%, var(--panel)); border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.low-card .lc-ic { font-size: 22px; }
.low-card .lc-tx { display: flex; flex-direction: column; flex: 1; }
.low-card .lc-tx small { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.chev { color: var(--muted); font-size: 22px; margin-left: auto; }

/* Dose rows (Today) */
.dose { display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 12px; margin-bottom: 10px; }
.dose.taken { opacity: .72; }
.dose.due { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); }
.dose-time { width: 66px; flex: 0 0 auto; font-weight: 700; font-size: 14px; display: flex; flex-direction: column; }
.dose-time small { font-weight: 500; color: var(--muted); font-size: 11px; margin-top: 2px; }
.dose-main { flex: 1; min-width: 0; cursor: pointer; }
.dose-name { font-size: 16px; font-weight: 600; }
.dose-sub { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dose-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.ok { background: color-mix(in srgb, var(--green) 22%, var(--panel)); color: #9ff0c6; border-color: transparent; }
.tag.due { background: color-mix(in srgb, var(--amber) 22%, var(--panel)); color: #ffe6a8; border-color: transparent; }
.tag.muted { opacity: .8; }

.mini { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 13px; font-weight: 600; cursor: pointer; }
.mini.take { background: linear-gradient(135deg, #37c784, var(--green)); border-color: transparent; color: #042016; }
.mini.skip { color: var(--muted); }

/* Week strip */
.week { display: flex; justify-content: space-between; gap: 6px; margin: 18px 2px 4px; }
.wd { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.wd .wl { font-size: 11px; color: var(--muted); }
.wd .wdot { width: 9px; height: 9px; border-radius: 999px; background: var(--line); }
.wd.full .wdot { background: var(--green); }
.wd.part .wdot { background: var(--amber); }
.wd.miss .wdot { background: var(--danger); }
.wd.todo .wdot, .wd.todaynone .wdot { background: var(--panel-2); border: 1px solid var(--muted); }
.wd.now { border-color: var(--blue); }

/* Medicine cards */
.med-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; color: var(--text); }
.med-card.inactive { opacity: .6; }
.med-emoji { font-size: 26px; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--panel-2); flex: 0 0 auto; }
.med-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.med-name { font-size: 16.5px; font-weight: 600; }
.med-name .paused { color: var(--amber); font-weight: 500; font-size: 12px; }
.med-sched { color: var(--muted); font-size: 13px; }
.pill-inv { align-self: flex-start; margin-top: 4px; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.pill-inv.low { background: color-mix(in srgb, var(--amber) 20%, var(--panel)); color: #ffe6a8; border-color: transparent; }
.pill-inv.out { background: color-mix(in srgb, var(--danger) 22%, var(--panel)); color: #ffd7d7; border-color: transparent; }

/* Cards / detail */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-h { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 12px; }
.row-kv { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.row-kv:last-child { border-bottom: none; }
.row-kv span { color: var(--muted); flex: 0 0 auto; }
.row-kv b { text-align: right; font-weight: 600; }
.row-kv.notes b { font-weight: 500; }
.inv-big { font-size: 34px; font-weight: 800; }
.inv-big small { font-size: 15px; font-weight: 500; color: var(--muted); }
.inv-big.low { color: var(--amber); } .inv-big.out { color: var(--danger); }
.inv-sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.inv-actions, .set-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* Prescriptions */
.rx-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.rx-thumb { position: relative; background: #fff; border-radius: 12px; overflow: hidden; aspect-ratio: 1; }
.rx-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.rx-thumb small { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 3px 5px; }
.rx-del { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 999px; border: none; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 12px; }

/* Forms */
.form { display: grid; gap: 16px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px; font-size: 16px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row input { width: 22px; height: 22px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 9px 13px; font-size: 13.5px; cursor: pointer; }
.chip.on { background: color-mix(in srgb, var(--blue) 24%, var(--panel)); border-color: var(--blue); }

.seg3 { display: flex; gap: 8px; }
.seg3 button { flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 6px; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg3 button.active { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 22%, var(--panel)); }
.inline-n { margin-top: 12px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-n input { width: 72px; padding: 8px; }
.inline-n small { flex-basis: 100%; }

.dow { display: flex; gap: 6px; margin-top: 12px; }
.dow-b { flex: 1; aspect-ratio: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer; }
.dow-b.on { background: color-mix(in srgb, var(--blue) 26%, var(--panel)); border-color: var(--blue); }

.time-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.time-row .t-label { flex: 1; }
.time-row .t-time { width: 130px; }
.t-del { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 10px; width: 42px; height: 46px; cursor: pointer; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.preset { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 7px 11px; font-size: 13px; cursor: pointer; }

.filedrop { display: block; border: 1.5px dashed var(--line); border-radius: 14px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; background: var(--panel); }
.filedrop.small { padding: 14px; font-size: 14px; }

.btn-primary { background: linear-gradient(135deg, #5b8cff, var(--blue)); color: #fff; border: none;
  border-radius: 14px; padding: 16px; font-size: 17px; font-weight: 700; cursor: pointer; width: 100%; }
.btn-primary:disabled { opacity: .5; }
.btn-danger { background: color-mix(in srgb, var(--danger) 16%, var(--panel)); color: #ffb4b4;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line)); border-radius: 14px;
  padding: 15px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; }

.empty { text-align: center; color: var(--muted); padding: 60px 10px; }
.empty .big { font-size: 42px; margin-bottom: 10px; }
.muted-note { color: var(--muted); font-size: 13px; }

/* FAB */
.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom));
  background: linear-gradient(135deg, #5b8cff, var(--blue)); color: #fff; border: none; border-radius: 999px;
  padding: 14px 24px; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: 0 10px 30px rgba(59,130,246,.45); z-index: 40; }

/* Bottom nav */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: color-mix(in srgb, var(--panel) 92%, #000);
  border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); backdrop-filter: blur(8px); }
.nav-tab { flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; font-size: 11px; }
.nav-tab .ni { font-size: 20px; }
.nav-tab.active { color: var(--text); }

/* Modals */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.62); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--panel-2); border: 1px solid var(--line); border-radius: 18px; padding: 22px; max-width: 360px; width: 100%; }
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions button { flex: 1; padding: 14px; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; border: 1px solid var(--line); }
.modal .cancel { background: var(--panel); color: var(--text); }
.modal .confirm-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Fullscreen image */
.img-overlay { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.img-overlay img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.img-overlay .img-close { position: fixed; top: calc(16px + env(safe-area-inset-top)); right: 16px; width: 44px; height: 44px; border-radius: 999px; border: none; background: rgba(255,255,255,.15); color: #fff; font-size: 18px; cursor: pointer; }

/* Login */
.login-wrap { max-width: 360px; margin: 13vh auto 0; text-align: center; }
.login-wrap .logo { font-size: 54px; margin-bottom: 8px; }
.login-wrap h1 { margin: 0 0 4px; font-size: 26px; }
.login-wrap p { color: var(--muted); margin: 0 0 24px; }
.gbtn { display: flex; justify-content: center; min-height: 44px; margin-bottom: 10px; }

/* ===== default big-card emoji background (Health hub) ===== */
.big-card .emoji { background: var(--panel-2); }

/* ===== Today: appointments banner + as-needed ===== */
.appt-banner { width: 100%; text-align: left; margin-bottom: 14px; cursor: pointer;
  background: color-mix(in srgb, var(--blue) 16%, var(--panel)); border: 1px solid color-mix(in srgb, var(--blue) 45%, var(--line));
  color: var(--text); border-radius: 14px; padding: 13px 14px; font-size: 14px; }
.prn-wrap { margin-top: 20px; }
.prn-h, .card-h.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 2px 10px; }

/* ===== schedule 2x2 grid ===== */
.sched-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sched-grid button { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 6px; font-size: 14px; font-weight: 600; cursor: pointer; }
.sched-grid button.active { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 22%, var(--panel)); }

/* ===== Health calendar ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-title { font-weight: 700; font-size: 16px; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-dow span { text-align: center; color: var(--muted); font-size: 11px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { aspect-ratio: 1; border-radius: 10px; background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; position: relative; }
.cal-cell.blank { background: none; border: none; cursor: default; }
.cal-cell .cn { font-size: 13px; color: var(--text); }
.cal-cell .cdot { width: 7px; height: 7px; border-radius: 999px; background: var(--line); }
.cal-cell.full .cdot { background: var(--green); } .cal-cell.full { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.cal-cell.part .cdot { background: var(--amber); }
.cal-cell.miss .cdot { background: var(--danger); }
.cal-cell.todo .cdot { background: var(--panel-2); border: 1px solid var(--muted); }
.cal-cell.now { outline: 2px solid var(--blue); }
.cal-legend { display: flex; gap: 16px; justify-content: center; margin-top: 14px; color: var(--muted); font-size: 12px; }
.cal-legend span { display: flex; align-items: center; gap: 6px; }
.cal-legend i.d { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.cal-legend i.full { background: var(--green); } .cal-legend i.part { background: var(--amber); } .cal-legend i.miss { background: var(--danger); }
.st-taken { color: #9ff0c6; } .st-skipped { color: var(--muted); } .st-snoozed { color: var(--amber); } .st-missed { color: #ffb4b4; }

/* ===== Vitals ===== */
.vk-chips { margin-bottom: 14px; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
.vk-chips .chip { white-space: nowrap; }
.vform { display: grid; gap: 10px; }
.vrow { display: flex; align-items: center; gap: 8px; }
.vrow input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 12px; font-size: 16px; }
.vrow .vslash { color: var(--muted); font-size: 18px; }
.vrow .vunit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.vform #v_note { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 11px; font-size: 14px; }
.vitem { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.vitem b { font-size: 17px; }
.chart { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* ===== Appointments ===== */
.appt-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 40px 14px 14px; margin-bottom: 10px; cursor: pointer; }
.appt-when { color: var(--blue); font-size: 13px; }
.appt-title { font-size: 16px; font-weight: 600; margin: 3px 0; }
.appt-del { background: var(--panel-2); }

/* ===== Scan bill ===== */
.scan-head { display: grid; grid-template-columns: 1fr 64px 40%; gap: 8px; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.scan-row { display: grid; grid-template-columns: 1fr 64px 40%; gap: 8px; margin-bottom: 8px; }
.scan-row input, .scan-row select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px; font-size: 14px; min-width: 0; }
.tel { color: var(--blue); text-decoration: none; }

/* ===== Report ===== */
.report { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.report h1 { font-size: 22px; margin: 0 0 2px; }
.report h2 { font-size: 16px; margin: 22px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.report h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
.rep-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.rep-kpis { display: flex; gap: 10px; }
.rep-kpi { flex: 1; background: var(--panel-2); border-radius: 12px; padding: 14px; text-align: center; }
.rep-kpi .rk-n { font-size: 24px; font-weight: 800; }
.rep-kpi .rk-l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rep-tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.rep-tbl th, .rep-tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.rep-tbl th { color: var(--muted); font-weight: 600; }

@media print {
  body, #app { background: #fff !important; color: #000 !important; padding: 0 !important; max-width: none !important; }
  .bottom-nav, .fab, .no-print { display: none !important; }
  .report { border: none; background: #fff; color: #000; padding: 0; }
  .report h1, .report h2, .report h3, .rep-kpi .rk-n, .vitem b, .report b { color: #000 !important; }
  .report h3, .rep-sub, .rep-kpi .rk-l, .rep-tbl th { color: #444 !important; }
  .rep-kpi { background: #f3f4f6; }
  .rep-tbl th, .rep-tbl td { border-color: #ccc !important; }
  .chart text { fill: #444 !important; }
  .chart line { stroke: #ddd !important; }
}

/* =========================================================
   Responsive / small-screen hardening
   ========================================================= */

/* Never allow the page itself to scroll sideways; clip stray overflow. */
html, body { overflow-x: hidden; max-width: 100%; }
#app { width: 100%; overflow-x: hidden; }
img, svg, video, table, pre, canvas { max-width: 100%; }

/* Long unbroken words (medicine/brand names) must wrap, not overflow. */
.dose-name, .med-name, .appt-title, .low-card .lc-tx, .vitem, .row-kv b, .card-h { overflow-wrap: anywhere; word-break: break-word; min-width: 0; }

/* Single-line titles in top bars truncate instead of shoving buttons off-screen. */
.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dose rows: let the action buttons drop to a second line when space is tight. */
.dose { flex-wrap: wrap; }
.dose-time { width: 58px; }
.dose-main { flex: 1 1 55%; min-width: 0; }
.dose-actions { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.dose-actions .mini { white-space: nowrap; }

/* Low-stock cards wrap text cleanly. */
.low-card .lc-tx small { overflow-wrap: anywhere; }

/* Vitals entry row: wrap the Add button below the inputs on narrow screens. */
.vrow { flex-wrap: wrap; }
.vrow input { flex: 1 1 70px; }
.vrow .mini.take { flex: 0 0 auto; }

/* Report tables: fixed layout + wrapping so 4 columns never force a sideways scroll. */
.rep-tbl { table-layout: fixed; }
.rep-tbl th, .rep-tbl td { overflow-wrap: anywhere; word-break: break-word; vertical-align: top; }
.rep-kpis { flex-wrap: wrap; }
.rep-kpi { min-width: 86px; }

/* Scan review rows stay inside the viewport. */
.scan-head, .scan-row { grid-template-columns: 1fr 56px 38%; }
.scan-row input, .scan-row select { min-width: 0; }

/* Forms: two-up fields stack on very narrow phones. */
@media (max-width: 380px) {
  #app { padding-left: 12px; padding-right: 12px; }
  .field.two { grid-template-columns: 1fr; }
  .sched-grid { grid-template-columns: 1fr; }
  .dose-time { width: 100%; flex-direction: row; gap: 6px; align-items: baseline; }
  .dose-time small { margin-top: 0; }
  .nav-tab .nl { font-size: 10px; }
}

/* Tiny phones (≤340px): tighten chips/buttons so nothing clips. */
@media (max-width: 340px) {
  .mini { padding: 8px 9px; font-size: 12px; }
  .chip { padding: 8px 10px; font-size: 12.5px; }
  .rep-kpi .rk-n { font-size: 20px; }
}

/* Small polish: give the time control room for "AM/PM", and clear the FAB. */
.time-row .t-time { width: 150px; }
#app { padding-bottom: 150px; }

/* Telegram connect button (green link styled as a button) */
.take-link { display: block; text-align: center; text-decoration: none;
  background: color-mix(in srgb, var(--green) 22%, var(--panel));
  border-color: color-mix(in srgb, var(--green) 55%, var(--line)); color: var(--text); }

/* Prescriptions (grouped by doctor) */
.group-btn { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px;
  color: var(--text); font-size: 16px; font-weight: 600; }
.group-btn .count { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 14px; }
.pass { margin-bottom: 22px; }
.pass .pass-label { color: var(--muted); font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.pass .pass-label .del { margin-left: auto; background: transparent; border: none; color: var(--danger); font-size: 13px; cursor: pointer; padding: 6px; }
.imgcard { background: #fff; border-radius: 16px; padding: 12px; display: flex; align-items: center; justify-content: center; }
.imgcard img { width: 100%; height: auto; max-width: 100%; display: block; border-radius: 6px; cursor: pointer; }
.preview { margin-top: 12px; background: #fff; border-radius: 12px; padding: 10px; }
.preview img { width: 100%; display: block; border-radius: 6px; }

/* Health hub — stat + tile grid */
.hub-stat { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px; margin-bottom: 14px; }
.hs-ring { width: 56px; height: 56px; border-radius: 50%; flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--green) calc(var(--pct) * 1%), var(--panel-2) 0); }
.hs-ring span { width: 42px; height: 42px; border-radius: 50%; background: var(--panel); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.hs-txt { display: flex; flex-direction: column; }
.hs-txt b { font-size: 15px; } .hs-txt small { color: var(--muted); font-size: 13px; margin-top: 2px; }

.hub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hub-tile { display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 15px; }
.hub-tile:active { transform: scale(.98); }
.hub-tile .ht-ic { width: 44px; height: 44px; border-radius: 13px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.hub-tile .ht-txt { display: flex; flex-direction: column; min-width: 0; }
.hub-tile .ht-title { font-size: 15px; font-weight: 700; }
.hub-tile .ht-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.hub-tile.t-blue .ht-ic { background: color-mix(in srgb, var(--blue) 24%, var(--panel)); }
.hub-tile.t-red .ht-ic { background: color-mix(in srgb, #e5588a 26%, var(--panel)); }
.hub-tile.t-amber .ht-ic { background: color-mix(in srgb, var(--amber) 24%, var(--panel)); }
.hub-tile.t-green .ht-ic { background: color-mix(in srgb, var(--green) 26%, var(--panel)); }
.hub-tile.t-purple .ht-ic { background: color-mix(in srgb, #8b7cf0 28%, var(--panel)); }

/* 5-tab bottom nav: tighten labels so nothing clips */
.bottom-nav .nav-tab .nl { font-size: 10.5px; }
.bottom-nav .nav-tab .ni { font-size: 19px; }

/* In-header "+ Add" button (replaces the floating FAB on the Meds tab) */
.topbar .add-btn { flex: 0 0 auto; background: linear-gradient(135deg, #5b8cff, var(--blue));
  color: #fff; border: none; border-radius: 999px; height: 40px; padding: 0 16px;
  font-size: 14px; font-weight: 700; cursor: pointer; }
.topbar .add-btn:active { transform: scale(.97); }
