:root {
  --bg: #f3f6f8; --card: #ffffff; --ink: #1d2b33; --muted: #5b6b74; --line: #d7e0e5;
  --brand: #0f6b6b; --brand-ink: #ffffff; --brand-soft: #e3f3f1;
  --warn: #a15c00; --warn-soft: #fff3df; --bad: #b3261e; --bad-soft: #fde8e7; --ok: #1e7a3c; --ok-soft: #e5f5ea;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1518; --card: #182226; --ink: #e6edf0; --muted: #9aabb3; --line: #2a3a40;
    --brand: #4fb3a9; --brand-ink: #062320; --brand-soft: #18332f;
    --warn: #f0b35a; --warn-soft: #33270f; --bad: #f28b82; --bad-soft: #3a1c1a; --ok: #7fd39a; --ok-soft: #15301f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: Vazirmatn, Tahoma, system-ui, sans-serif; font-size: 15px; line-height: 1.7; -webkit-text-size-adjust: 100%; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* layout */
.top { position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.top .logo { font-weight: 700; font-size: 1.2rem; color: var(--brand-ink); }
.top nav { display: flex; gap: 4px; margin-inline-start: auto; }
.top nav a { color: var(--brand-ink); opacity: .85; padding: 6px 12px; border-radius: 999px; }
.top nav a.on { background: rgba(255,255,255,.18); opacity: 1; }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 96px; }
.tabbar { display: none; }
@media (max-width: 720px) {
  .top nav { display: none; }
  .tabbar { display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 10; background: var(--card);
    border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); }
  .tabbar a { flex: 1; text-align: center; color: var(--muted); font-size: .78rem; padding: 4px 0; }
  .tabbar a .i { display: block; font-size: 1.3rem; line-height: 1.2; }
  .tabbar a.on { color: var(--brand); font-weight: 700; }
}

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); } .stat.ok b { color: var(--ok); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.item { display: flex; gap: 10px; align-items: center; padding: 10px 2px; color: inherit; }
.item .name { font-weight: 600; }
.pill { display: inline-block; font-size: .78rem; padding: 1px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.gray { background: var(--bg); color: var(--muted); }

/* forms */
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; min-height: 42px; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[dir="ltr"] { text-align: right; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid.two { grid-template-columns: repeat(2, 1fr); }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 720px) { .grid, .grid.two { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .grid, .grid.two { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0 0 14px; background: var(--card); }
legend { padding: 0 6px; font-weight: 700; color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: .92rem; margin: 0; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
.date-wrap { display: flex; gap: 6px; }
.date-wrap input { flex: 1; }
.date-wrap button { flex: none; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px;
  padding: 8px 16px; min-height: 42px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; }
button:disabled { opacity: .6; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; z-index: 5; }
@media (max-width: 720px) { .sticky-actions { bottom: calc(env(safe-area-inset-bottom) + 58px); } }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.note { color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; font-size: .88rem; }

/* auth */
.auth { max-width: 400px; margin: 8vh auto 40px; padding: 0 16px; }
.auth .brand { text-align: center; color: var(--brand); font-size: 2rem; font-weight: 700; margin-bottom: 4px; }
.auth .tag { text-align: center; color: var(--muted); margin-bottom: 20px; }
.auth form > * + * { margin-top: 12px; }
.auth .switch { text-align: center; margin-top: 14px; }
.or { text-align: center; color: var(--muted); margin: 14px 0; font-size: .85rem; }

/* patient page */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px; }
@media (max-width: 720px) { .facts { grid-template-columns: 1fr 1fr; } }
.facts div span { display: block; font-size: .8rem; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { border-inline-start: 3px solid var(--brand-soft); padding: 2px 14px 14px; position: relative; }
.timeline > li::before { content: ""; position: absolute; inset-inline-start: -8px; top: 8px; width: 13px; height: 13px; border-radius: 50%; background: var(--brand); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .82rem; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: middle; }
table.sched { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.sched th, table.sched td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: start; }
table.sched input { min-height: 34px; padding: 4px 8px; width: 70px; }
.imaging-row { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }

#toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: .95; }
.search { margin-bottom: 12px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button { min-height: 34px; padding: 4px 12px; border-radius: 999px; }
.filters button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
@media print { .top, .tabbar, .actions, .sticky-actions { display: none !important; } body { background: #fff; } .card { box-shadow: none; } }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.file { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.file .thumb { display: flex; align-items: center; justify-content: center; height: 110px; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file > div { padding: 6px 8px; word-break: break-word; }
details > summary { cursor: pointer; color: var(--brand); }
details.fs { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; background: var(--card); }
details.fs > summary { font-weight: 700; margin-bottom: 4px; }
details.fs[open] > summary { margin-bottom: 10px; }
.doc-card { text-align: center; }
.doc-mark { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 10px; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 700; }
.creds { list-style: none; padding: 0; margin: 10px 0 0; font-size: .9rem; }
.creds li { padding: 2px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 6px; }
.chips .pill { white-space: normal; }
