/* Neendut Medical. Phone first; light/dark tokens. */
:root {
  --brand: #0e7490;
  --brand-ink: #ffffff;
  --brand-soft: #e3f4f8;
  --water: #0284c7; --water-soft: #e0f2fe;
  --out: #b45309;   --out-soft: #fdf3e2;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --border: #e2e6eb;
  --text: #14181f;
  --muted: #5d6573;
  --success: #15803d; --success-soft: #e8f6ed;
  --warn: #a15c07;    --warn-soft: #fdf3e2;
  --danger: #b91c1c;  --danger-soft: #fdecec;
  --info: #1d4ed8;    --info-soft: #eaf0ff;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #22a3c2; --brand-ink: #04151b; --brand-soft: #0f2a33;
    --water: #38bdf8; --water-soft: #0c2536;
    --out: #f59e0b;   --out-soft: #2c210c;
    --bg: #0d1015; --surface: #161a21; --border: #262c36;
    --text: #eceef2; --muted: #9aa1ad;
    --success: #4ade80; --success-soft: #10291a;
    --warn: #fbbf24;    --warn-soft: #2c230f;
    --danger: #f87171;  --danger-soft: #2e1416;
    --info: #93b4ff;    --info-soft: #142042;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.xs { font-size: .78rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 14px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.nowrap { white-space: nowrap; }

/* ---------- App frame ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar .in { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; color: var(--text); text-decoration: none; }
.mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.topbar .who { margin-left: auto; font-size: .85rem; color: var(--muted); text-decoration: none; }
.wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px 110px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.tabs a.on { color: var(--brand); }
.tabs a.scan .ic { background: var(--brand); color: var(--brand-ink); border-radius: 14px; padding: 6px; margin-top: -18px; box-shadow: var(--shadow); width: 44px; height: 44px; }
@media (min-width: 900px) {
  .tabs { position: sticky; top: 51px; bottom: auto; max-width: 760px; margin: 0 auto; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 14px 14px; }
  .tabs a.scan .ic { margin-top: 0; width: 34px; height: 34px; padding: 4px; border-radius: 10px; }
  .wrap { padding-bottom: 48px; }
}
.ic { width: 22px; height: 22px; flex: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  font: 600 .97rem/1.2 inherit; cursor: pointer; background: var(--brand); color: var(--brand-ink); text-decoration: none; }
.btn:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btn-lg { min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; text-decoration: underline; }
.inline { display: inline; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields .full { grid-column: 1 / -1; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); font: inherit; font-size: 16px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; border-color: var(--brand); }
input[type=checkbox] { accent-color: var(--brand); width: 20px; height: 20px; flex: none; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: .84rem; margin-top: 4px; }
.hint { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 3px; background: var(--bg); }
.seg label { margin: 0; padding: 9px 10px; border-radius: 9px; cursor: pointer; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--surface); box-shadow: var(--shadow); color: var(--brand); }

/* ---------- Cards / alerts ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: .94rem; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); }
.badge { display: inline-flex; align-items: center; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.disclaimer { font-size: .82rem; color: var(--muted); border-left: 3px solid var(--warn); padding: 6px 10px; margin: 0 0 16px; background: var(--surface); border-radius: 0 8px 8px 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- Day nav ---------- */
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.daynav h1 { margin: 0; font-size: 1.35rem; }
.daynav a { text-decoration: none; }

/* ---------- Dose checklist ---------- */
.progress { height: 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress.water > span { background: var(--water); }
.slot-time { font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.dose { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  font: inherit; color: inherit; text-align: left; cursor: pointer; margin-bottom: 8px; }
.dose .box { width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--border); display: grid; place-items: center; flex: none; color: transparent; }
.dose.done { background: var(--success-soft); border-color: transparent; }
.dose.done .box { background: var(--success); border-color: var(--success); color: #fff; }
.dose.done .name { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 40%, transparent); }
.dose .name { font-weight: 700; }
.dose .sub { font-size: .85rem; color: var(--muted); }

/* ---------- Fluids ---------- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.totals > div { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.totals strong { display: block; font-size: 1.15rem; }
.totals .in strong { color: var(--water); }
.totals .out strong { color: var(--out); }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick .btn { background: var(--water-soft); color: var(--water); padding: 8px 4px; flex-direction: column; gap: 0; font-size: .9rem; }
.quick .btn small { font-weight: 500; font-size: .72rem; opacity: .85; }
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry .dir { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; flex: none; }
.entry .dir.in { background: var(--water-soft); color: var(--water); }
.entry .dir.out { background: var(--out-soft); color: var(--out); }
table.hist { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.hist th, table.hist td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: right; }
table.hist th:first-child, table.hist td:first-child { text-align: left; }
table.hist th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ---------- Medicines ---------- */
.med { padding: 12px 0; border-bottom: 1px solid var(--border); }
.med:last-child { border-bottom: 0; }
.med .name { font-weight: 700; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- Scan / review ---------- */
.drop { display: block; border: 2px dashed color-mix(in srgb, var(--brand) 45%, var(--border)); border-radius: 18px; padding: 28px 16px; text-align: center; cursor: pointer; background: var(--surface); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop .big { font-size: 1.1rem; font-weight: 700; display: block; margin-top: 8px; }
.drop img { max-height: 320px; margin: 12px auto 0; border-radius: 12px; }
.review { display: grid; gap: 16px; }
@media (min-width: 900px) { .review { grid-template-columns: 340px 1fr; align-items: start; } .review .photo-col { position: sticky; top: 120px; } }
.photo-col img { width: 100%; max-height: 55vh; object-fit: contain; background: #fff; border-radius: 14px; border: 1px solid var(--border); }
@media (min-width: 900px) { .photo-col img { max-height: 80vh; } }
.photo-col details > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.med-row { border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--surface); margin-bottom: 12px; }
.med-row.flagged { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.med-row .flags { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: .86rem; margin-bottom: 12px; }
.med-row .flags ul { margin: 0; padding-left: 18px; }
.busy { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 85%, transparent); display: none; place-items: center; text-align: center; padding: 24px; }
.busy.on { display: grid; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--brand); animation: spin 1s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth .card { width: 100%; max-width: 440px; }
.auth .brand { margin-bottom: 18px; }
.hero { text-align: center; max-width: 520px; }
.hero h1 { font-size: 1.9rem; }
.features { text-align: left; display: grid; gap: 12px; margin: 22px 0; }
.features div { display: flex; gap: 12px; align-items: flex-start; }
.features .ic { color: var(--brand); margin-top: 2px; }

/* ---------- Weekly pill box ---------- */
.kit { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 8px 12px; box-shadow: var(--shadow); }
.kit-grid { display: grid; grid-template-columns: 46px repeat(7, minmax(0, 1fr)); gap: 4px; }
.kit-corner { }
.kit-lid { display: flex; flex-direction: column; align-items: center; padding: 6px 0; border-radius: 10px 10px 4px 4px; background: var(--brand-soft); color: var(--brand); text-decoration: none; line-height: 1.1; }
.kit-lid strong { font-size: .78rem; }
.kit-lid span { font-size: .68rem; opacity: .8; }
.kit-lid.today { background: var(--brand); color: var(--brand-ink); }
.kit-lid.future { opacity: .75; }
.kit-slot { display: flex; align-items: center; font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.kit-cell { position: relative; min-height: 58px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 4px 2px; box-shadow: inset 0 2px 4px rgba(0,0,0,.06); }
.kit-cell.empty { background: transparent; border-style: dashed; opacity: .55; }
.kit-cell.done { border-color: color-mix(in srgb, var(--success) 55%, transparent); background: var(--success-soft); }
.kit-cell.missed { border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: var(--danger-soft); }
.kit-cell.partial { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.kit-cell.today:not(.empty) { box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 35%, transparent); }
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 100%; }
.pill { display: inline-block; width: 18px; height: 9px; border-radius: 6px; background: var(--pc); border: 1px solid color-mix(in srgb, var(--pc) 60%, black);
  background-image: linear-gradient(90deg, transparent 50%, rgba(255,255,255,.55) 50%); }
.pill.taken { opacity: .28; }
.pill.c0 { --pc: #ef4444; } .pill.c1 { --pc: #3b82f6; } .pill.c2 { --pc: #f59e0b; } .pill.c3 { --pc: #10b981; }
.pill.c4 { --pc: #a855f7; } .pill.c5 { --pc: #ec4899; } .pill.c6 { --pc: #14b8a6; } .pill.c7 { --pc: #84cc16; }
.kit-mark { position: absolute; top: 2px; right: 4px; font-size: .7rem; font-weight: 800; }
.kit-mark.ok { color: var(--success); } .kit-mark.bad { color: var(--danger); }
.kit-key .kit-mark { position: static; }
.kit-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: .85rem; }
.kit-legend span, .kit-key span { display: inline-flex; align-items: center; gap: 6px; }
.kit-key { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; }
@media (min-width: 600px) { .kit-grid { grid-template-columns: 70px repeat(7, minmax(0, 1fr)); gap: 6px; } .kit-cell { min-height: 72px; } .pill { width: 22px; height: 11px; } .kit-slot { font-size: .78rem; } }

/* ---------- Pill box check result ---------- */
.chk-n { font-weight: 800; font-size: 1rem; }
.chk-n small { font-weight: 500; font-size: .7rem; color: var(--muted); }
.kit-cell.chk-ok:not(.empty) { border-color: color-mix(in srgb, var(--success) 55%, transparent); background: var(--success-soft); }
.kit-cell.chk-missing, .kit-cell.chk-extra { border-color: var(--danger); background: var(--danger-soft); }
.kit-cell.chk-different { border-color: var(--out); background: var(--out-soft); }
.kit-cell.chk-unclear { border-color: var(--warn); border-style: dashed; background: var(--warn-soft); }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1.5px solid var(--border); }
.sw.chk-ok { background: var(--success-soft); border-color: var(--success); }
.sw.chk-missing { background: var(--danger-soft); border-color: var(--danger); }
.sw.chk-different { background: var(--out-soft); border-color: var(--out); }
.sw.chk-unclear { background: var(--warn-soft); border-color: var(--warn); border-style: dashed; }
.kit-slot .short { display: none; }
@media (max-width: 599px) { .kit-slot .long { display: none; } .kit-slot .short { display: inline; } }

/* Drawn tablets (public/js/pill.js): sized by font-size, width follows the shape */
.pi { display: inline-block; vertical-align: middle; flex: none; font-size: 12px; overflow: visible; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .25)); }
.pi.taken { opacity: .28; filter: grayscale(.4); }
.kit-cell .pills { gap: 2px 3px; }
.kit-cell .pi { font-size: 13px; }
@media (min-width: 600px) { .kit-cell .pi { font-size: 17px; } }
.kit-legend a { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; }
.kit-legend .pi { font-size: 14px; }
.kit-key .pi { font-size: 10px; }
.pi-name { font-size: 15px; margin-right: 2px; }
.pi-lg { font-size: 30px; }
.fill-look { display: grid; place-items: center; min-width: 52px; flex: none; }
.look-top { display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap; }
.look-preview { display: grid; place-items: center; min-height: 120px; min-width: 160px; border-radius: 16px;
  background: repeating-conic-gradient(var(--bg) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; padding: 12px; }
.look-preview .pi { font-size: 84px; filter: drop-shadow(0 3px 4px rgb(0 0 0 / .3)); }
.look-photo { margin: 0; text-align: center; }
.look-photo img { width: 120px; height: 120px; object-fit: cover; border-radius: 16px; border: 1px solid var(--border); display: block; }
.shape-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.shape-pick label { position: relative; margin: 0; display: grid; justify-items: center; gap: 4px; padding: 10px 4px 8px; border: 1px solid var(--border);
  border-radius: 12px; cursor: pointer; font-size: .72rem; font-weight: 600; text-align: center; background: var(--bg); }
.shape-pick input { position: absolute; opacity: 0; pointer-events: none; }
.shape-pick .pi { font-size: 22px; }
.shape-pick label:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); color: var(--brand); }
.shape-pick label:has(input:focus-visible) { outline: 2px solid var(--brand); }
input[type=color] { width: 100%; height: 44px; padding: 3px; border-radius: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw-btn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: var(--sw); cursor: pointer; padding: 0; }
.sw-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Prescription pages */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.pages { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.pages li { position: relative; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 6px; text-align: center; }
.pages img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; background: #fff; margin-bottom: 4px; }
.page-rm { position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgb(0 0 0 / .6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.drop.disabled { opacity: .5; pointer-events: none; }
.rx-page { margin: 0 0 10px; }
.rx-page figcaption { margin-bottom: 4px; font-weight: 600; }
.rx-pages { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; }
.rx-pages .rx-page { flex: 0 0 86%; scroll-snap-align: start; }
.rx-pages .rx-page:only-child { flex-basis: 100%; }
@media (min-width: 900px) { .rx-pages { display: block; overflow: visible; } }
