/* A medication round sheet: blue form ink on white paper, colour only for dose status. */
:root {
  --desk: #eef2f6;
  --paper: #ffffff;
  --ink: #1d3557;
  --ink-2: #51637d;
  --rule: #d3dce7;
  --rule-soft: #e8edf3;
  --field: #f7f9fb;
  --taken: #1e8a4c;
  --waiting: #b8730a;
  --missed: #c62f2f;
  --later: #8795a8;
  --focus: #2f6fdb;
  --on-ink: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #0d1520;
    --paper: #142032;
    --ink: #dfe7f2;
    --ink-2: #9fb0c6;
    --rule: #2c3d55;
    --rule-soft: #1f2e44;
    --field: #1a2940;
    --taken: #3fbf78;
    --waiting: #e6a23c;
    --missed: #f06b6b;
    --later: #7f8ea3;
    --focus: #7aa7ff;
    --on-ink: #0d1520;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, sans-serif;
}
a { color: inherit; }
bdi { unicode-bidi: isolate; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.hide { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- frame: the page is one sheet of paper on the desk */
.sheet {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--paper);
  border-inline: 1px solid var(--rule);
}
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 6px;
}
.brand { font-weight: 700; font-size: 18px; margin: 0; flex: 1; display: flex; align-items: center; gap: 10px; }
.brand svg { flex: none; }
.link-state {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  font-size: 14px; color: var(--ink-2); text-decoration: none;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--rule);
}
.link-state .wide-only { margin-inline-end: -4px; }
.logout { white-space: nowrap; }
.link-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--later); }
.link-state.open::before { background: var(--taken); }
.link-state.bad::before { background: var(--missed); }
.link-state.busy::before { background: var(--waiting); }
.logout { font-size: 14px; color: var(--ink-2); background: none; border: 0; padding: 8px 4px; cursor: pointer; text-decoration: underline; }
nav.tabs { display: flex; gap: 4px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
nav.tabs a {
  text-decoration: none; padding: 10px 12px 11px; font-size: 15px; color: var(--ink-2);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
nav.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
main { padding: 20px 20px 64px; }

h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 20px; line-height: 1.3; margin: 32px 0 12px; padding-top: 14px; border-top: 1px solid var(--rule); }
p { margin: 0 0 12px; max-width: 68ch; }

/* ---- controls */
button, .btn {
  font: inherit; font-size: 15px; font-weight: 600;
  min-height: 44px; padding: 9px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--ink); background: var(--paper); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button.primary, .btn.primary { background: var(--ink); color: var(--on-ink); }
button.danger { border-color: var(--missed); color: var(--missed); }
button.quiet { border-color: var(--rule); font-weight: 500; }
button:disabled { opacity: .55; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
label .muted { font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--rule); border-radius: 8px; min-height: 44px; padding: 9px 12px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.fields { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
.fields .wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .fields { grid-template-columns: 1fr; } }
.panel { border: 1px solid var(--rule); border-radius: 12px; padding: 16px; margin: 0 0 20px; background: var(--paper); }
.error { color: var(--missed); font-weight: 600; }
.banner {
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between;
  border: 1px solid var(--missed); border-inline-start-width: 5px; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 20px;
}
.banner p { margin: 0; }

/* ---- status marks, drawn like stamps on a medication chart */
.mark { position: relative; flex: none; display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--later); vertical-align: middle; }
.mark-taken { background: var(--taken); border-color: var(--taken); }
.mark-taken::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid var(--paper); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.mark-missed { border-color: var(--missed); }
.mark-missed::before, .mark-missed::after {
  content: ""; position: absolute; left: 8px; top: 3px; width: 2.5px; height: 12px; background: var(--missed); border-radius: 2px;
}
.mark-missed::before { transform: rotate(45deg); }
.mark-missed::after { transform: rotate(-45deg); }
.mark-pending { border-color: var(--waiting); background: linear-gradient(to top, var(--waiting) 50%, transparent 50%); }
.mark-unsent { border-style: dashed; }
.mark.sm { width: 18px; height: 18px; }
.mark.sm.mark-taken::after { left: 4.5px; top: 1px; width: 4px; height: 9px; border-width: 0 2px 2px 0; }
.mark.sm.mark-missed::before, .mark.sm.mark-missed::after { left: 6px; top: 2px; height: 10px; width: 2px; }

.c-taken { color: var(--taken); }
.c-waiting { color: var(--waiting); }
.c-missed { color: var(--missed); }

/* ---- today: the day as a time rail */
.day-head { margin-bottom: 18px; }
.tally { font-size: 17px; margin: 4px 0 0; }
.round { list-style: none; margin: 0; padding: 0; }
.slot { display: grid; grid-template-columns: 76px 1fr; border-top: 1px solid var(--rule-soft); }
.slot:first-child { border-top: 0; }
.slot-time {
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 12px 12px 12px 0;
  border-inline-end: 2px solid var(--rule); letter-spacing: -.01em;
}
.slot-time.past { color: var(--ink-2); font-weight: 600; }
.slot ul { list-style: none; margin: 0; padding: 4px 0 4px 16px; }
.dose { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; }
.dose + .dose { border-top: 1px dashed var(--rule-soft); }
.dose .mark { margin-top: 2px; }
.dose-main { flex: 1; min-width: 0; }
.dose-who { font-weight: 600; text-decoration: none; }
.dose-who:hover { text-decoration: underline; }
.dose-meds { color: var(--ink-2); font-size: 15px; overflow-wrap: anywhere; }
.dose-state { font-size: 14px; text-align: end; white-space: nowrap; padding-top: 2px; }
.now-line { display: grid; grid-template-columns: 76px 1fr; align-items: center; margin: 2px 0; }
.now-line span { font-size: 13px; font-weight: 700; color: var(--missed); font-variant-numeric: tabular-nums; }
.now-line i { display: block; height: 2px; background: var(--missed); position: relative; }
.now-line i::before { content: ""; position: absolute; left: -6px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--missed); }
@media (max-width: 520px) {
  main { padding: 16px 14px 56px; }
  .top-row { padding: 10px 14px 4px; gap: 8px; }
  .brand { font-size: 16px; }
  .link-state .wide-only { display: none; }
  .slot, .now-line { grid-template-columns: 62px 1fr; }
  .slot-time { font-size: 19px; }
  .dose { flex-wrap: wrap; }
  .dose-state { flex-basis: 100%; text-align: start; padding-inline-start: 34px; padding-top: 0; }
}
.empty { padding: 28px 0; }
.empty p { font-size: 17px; }

/* ---- patients */
.plist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.plist li { border-bottom: 1px solid var(--rule); }
.plist a { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 14px 4px; text-decoration: none; }
.plist a:hover { background: var(--field); }
.pname { font-weight: 700; font-size: 17px; }
.pmeta { color: var(--ink-2); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.pside { text-align: end; font-size: 14px; grid-row: span 2; align-self: center; }
.pside b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 13px; font-weight: 600; padding: 1px 9px; border-radius: 999px; border: 1px solid currentColor; }
.tag.ok { color: var(--taken); }
.tag.warn { color: var(--waiting); }
.tag.off { color: var(--ink-2); }

/* ---- patient detail */
.back { display: inline-block; margin-bottom: 14px; font-size: 15px; color: var(--ink-2); }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); margin: 6px 0 14px; }
.join { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-bottom: 14px; }
.join figure { margin: 0; border: 1px solid var(--rule); border-radius: 12px; padding: 14px; text-align: center; }
.join img { width: 100%; max-width: 220px; aspect-ratio: 1; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 8px; }
.join figcaption { font-size: 14px; margin-top: 8px; }
.join code { unicode-bidi: isolate; }
code { font-family: inherit; font-weight: 700; background: var(--field); border: 1px solid var(--rule); padding: 1px 7px; border-radius: 6px; }

.meds { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.meds th { text-align: start; font-size: 13px; color: var(--ink-2); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.meds td { padding: 12px 8px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
.meds td:last-child { text-align: end; white-space: nowrap; }
.meds .mname { font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; padding: 2px 10px; border-radius: 999px; background: var(--field); border: 1px solid var(--rule); }
@media (max-width: 560px) {
  .meds thead { display: none; }
  .meds, .meds tbody, .meds tr, .meds td { display: block; width: 100%; }
  .meds tr { border-bottom: 1px solid var(--rule); padding: 10px 0; }
  .meds td { border: 0; padding: 3px 0; text-align: start !important; }
}
.times { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.times .t { display: flex; gap: 4px; }
.times input { width: 120px; }
.times button { min-height: 44px; padding: 0 12px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px; }
.presets button { min-height: 36px; padding: 4px 12px; font-size: 14px; font-weight: 500; border-color: var(--rule); }

/* 30-day chart: days down, dose times across */
.mar-wrap { display: inline-block; max-width: 100%; vertical-align: top; overflow-x: auto; border: 1px solid var(--rule); border-radius: 12px; }
.mar { border-collapse: collapse; font-size: 14px; }
.mar thead th, .mar td { min-width: 64px; }
.mar th, .mar td { border-bottom: 1px solid var(--rule-soft); padding: 7px 10px; text-align: center; white-space: nowrap; }
.mar thead th { font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--rule); background: var(--field); position: sticky; top: 0; }
.mar tbody th { text-align: start; font-weight: 500; position: sticky; left: 0; background: var(--paper); border-inline-end: 1px solid var(--rule); }
.mar tr:last-child th, .mar tr:last-child td { border-bottom: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; color: var(--ink-2); margin: 10px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---- whatsapp link */
.qr-box { display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: 24px; align-items: start; }
.qr-box img { width: 100%; aspect-ratio: 1; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--rule); }
.qr-wait { aspect-ratio: 1; border: 1px dashed var(--rule); border-radius: 12px; display: grid; place-items: center; color: var(--ink-2); text-align: center; padding: 20px; }
ol.steps { margin: 0 0 16px; padding-inline-start: 22px; }
ol.steps li { margin-bottom: 6px; }
.pair-code { font-size: 34px; font-weight: 700; letter-spacing: .08em; font-variant-numeric: tabular-nums; direction: ltr; margin: 8px 0; }
@media (max-width: 640px) { .qr-box { grid-template-columns: 1fr; } .qr-box img, .qr-wait { max-width: 320px; } }

/* ---- settings as sentences */
.sentence { font-size: 17px; line-height: 2.3; max-width: 62ch; margin-bottom: 6px; }
.sentence input { display: inline-block; width: 70px; min-height: 36px; height: 36px; text-align: center; font-weight: 700; padding: 2px 6px; margin: 0 4px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 16px; font-weight: 500; margin: 8px 0 10px; }
.check input { width: 22px; height: 22px; min-height: 0; }

/* ---- login */
.login { max-width: 360px; margin: 14vh auto 0; padding: 0 20px; }
.login h1 { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login button { width: 100%; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--on-ink); padding: 11px 18px; border-radius: 10px; font-weight: 600;
  max-width: calc(100vw - 32px); pointer-events: none; transition: opacity .18s, transform .18s; z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--missed); color: #fff; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media print { .top, .no-print { display: none !important; } .sheet { border: 0; } }
