:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #e3e6eb;
  --gold: #9a7420;
  --gold-bright: #c9a23f;
  --gold-soft: #f7f0dc;
  --red: #b42318;
  --red-soft: #fdecea;
  --green: #1f7a4d;
  --green-soft: #e6f4ec;
  --blue: #2f5aa8;
  --blue-soft: #e9effa;
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  font-family: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.5; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin-top: 0.5rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- brand & chrome ---------- */
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand em { font-style: normal; font-weight: 500; color: var(--gold); }
.brand .mark { width: 22px; height: 24px; background: linear-gradient(160deg, #e2c46b, #a67c1f); border-radius: 45% 45% 40% 40% / 40% 40% 60% 60%; position: relative; }
.brand .mark::after { content: ""; position: absolute; left: 50%; bottom: -1px; width: 6px; height: 9px; background: var(--surface); transform: translateX(-50%); border-radius: 3px 3px 0 0; }
.brand.big { font-size: 1.4rem; margin-bottom: 0.5rem; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1.5rem; padding: calc(env(safe-area-inset-top, 0px) + 0.7rem) 1.25rem 0.7rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.mainnav { display: flex; gap: 0.25rem; }
.mainnav a { position: relative; padding: 0.45rem 0.8rem; border-radius: 99px; color: var(--muted); text-decoration: none; font-weight: 600; }
.mainnav a.on { color: var(--ink); background: var(--gold-soft); }
.topbar .sched { margin-left: auto; }
.count { display: inline-block; min-width: 1.35em; padding: 0 0.4em; margin-left: 0.35em; border-radius: 99px; background: var(--red); color: #fff; font-size: 0.72rem; line-height: 1.35em; text-align: center; font-weight: 700; }

.tabbar { display: none; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

@media (max-width: 760px) {
  .mainnav, .topbar .sched { display: none; }
  .topbar { padding: calc(env(safe-area-inset-top, 0px) + 0.6rem) 1rem 0.6rem; }
  .wrap { padding: 1rem 0.85rem calc(env(safe-area-inset-bottom, 0px) + 5.5rem); }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .tabbar a { position: relative; display: flex; justify-content: center; align-items: center; padding: 0.85rem 0 0.9rem; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
  .tabbar a.on { color: var(--gold); box-shadow: inset 0 3px 0 var(--gold-bright); }
  .tabbar .count { position: absolute; top: 0.35rem; right: calc(50% - 2.6rem); margin: 0; }
  h1 { font-size: 1.5rem; }
}

/* ---------- common ---------- */
.page-head { margin-bottom: 1.25rem; }
.page-head.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head h1 .sub { display: block; font-size: 1rem; font-weight: 500; color: var(--muted); margin-top: 0.2rem; letter-spacing: 0; }
.summary { color: var(--muted); margin-top: 0.35rem; }
.crumb { display: inline-block; margin-bottom: 0.35rem; font-weight: 600; text-decoration: none; }
.crumb::before { content: "‹ "; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.1rem 1.15rem; margin-bottom: 1rem; }
.panel.narrow { max-width: 620px; }
.gap { margin-top: 1.5rem; }
.empty { color: var(--muted); padding: 1rem 0; }
.more { display: inline-block; margin-top: 0.75rem; font-weight: 600; text-decoration: none; }
.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; }
.alert.ok { background: var(--green-soft); color: var(--green); }
.alert.bad { background: var(--red-soft); color: var(--red); }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 0.45rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.plain li:last-child { border-bottom: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; padding: 0.6rem 1rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 42px; }
.btn:hover { border-color: #c9ced6; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2c3548; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.35rem 0.75rem; min-height: 36px; font-size: 0.88rem; }

.chip { display: inline-block; padding: 0.08rem 0.5rem; border-radius: 99px; font-size: 0.74rem; font-weight: 600; background: #eef0f3; color: var(--muted); vertical-align: 1px; white-space: nowrap; }
.chip.t-patient { background: var(--blue-soft); color: var(--blue); }
.chip.t-lab { background: var(--gold-soft); color: var(--gold); }
.chip.t-inquiry { background: #f0ecfa; color: #5b3fa0; }
.chip.urgent, .chip.s-resched, .chip.s-failed { background: var(--red-soft); color: var(--red); }
.chip.s-confirmed, .chip.s-sent { background: var(--green-soft); color: var(--green); }
.chip.case { background: var(--gold-soft); color: var(--gold); }
.chip.wl { background: #e8f5f5; color: #1c6b6b; }
.tag { display: inline-block; font-size: 0.74rem; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 0.45rem; margin: 0.2rem 0.25rem 0 0; }

/* forms */
label { display: block; font-size: 0.86rem; font-weight: 600; color: #3a4252; }
input, select, textarea { display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.7rem; font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid #d3d8df; border-radius: var(--radius-sm); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold-bright); box-shadow: 0 0 0 3px var(--gold-soft); }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
label.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--gold); }
.stack { display: grid; gap: 0.9rem; }
.stack.tight { gap: 0.65rem; margin-top: 0.75rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.presets { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.presets button { font: inherit; font-size: 0.82rem; padding: 0.3rem 0.6rem; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.presets button.on { border-color: var(--gold-bright); background: var(--gold-soft); color: var(--gold); }

/* ---------- today ---------- */
.grid-today { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .grid-today { grid-template-columns: 1fr; } }
.todos { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.todo { display: flex; gap: 0.75rem; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 0.75rem 0.85rem; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); }
.todo.overdue { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-soft), var(--surface) 40%); }
.todo.today { border-left-color: var(--gold-bright); }
.todo-main { flex: 1 1 220px; min-width: 0; }
.todo-title { font-weight: 700; }
.todo-meta { margin-top: 0.2rem; font-size: 0.88rem; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.todo-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.todo-actions form { margin: 0; }
.due { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.overdue .due, .step-due.overdue { color: var(--red); }
.today .due, .step-due.today { color: var(--gold); }
.upcoming { margin-top: 1rem; }
.upcoming summary { cursor: pointer; font-weight: 600; color: var(--muted); margin-bottom: 0.5rem; }

/* people */
.people { list-style: none; margin: 0; padding: 0; }
.person { display: flex; gap: 0.75rem; align-items: center; padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.people li:last-child .person { border-bottom: 0; }
.person:hover { background: var(--bg); }
.person.is-urgent { box-shadow: inset 3px 0 0 var(--red); padding-left: 0.7rem; }
.person-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.person-name { font-weight: 600; }
.person.needs .person-name { font-weight: 800; }
.preview { color: var(--muted); font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wait { font-size: 0.8rem; color: var(--muted); white-space: nowrap; text-align: right; }
.person.needs .wait { color: var(--red); font-weight: 600; }
.people.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.25rem 0.75rem; }
.av { --s: 40px; position: relative; flex: none; width: var(--s); height: var(--s); border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: #eef0f3; color: var(--muted); overflow: hidden; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.av.t-lab { background: var(--gold-soft); color: var(--gold); }
.av.t-patient { background: var(--blue-soft); color: var(--blue); }

.filters { display: flex; gap: 0.35rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: 2px; }
.filters a { flex: none; padding: 0.4rem 0.85rem; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; font-size: 0.88rem; text-decoration: none; }
.filters a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search input { margin: 0; min-width: 240px; }
@media (max-width: 760px) { .search, .search input { width: 100%; min-width: 0; } }

/* ---------- chat ---------- */
.chat-layout, .case-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .chat-layout, .case-layout { grid-template-columns: 1fr; } }
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); display: flex; flex-direction: column; min-height: 60vh; overflow: hidden; }
.chat-head { display: flex; gap: 0.7rem; align-items: center; padding: 0.8rem 1rem; border-bottom: 1px solid var(--line); }
.chat-head h1 { font-size: 1.15rem; }
.chat-head .push { margin-left: auto; }
.back { font-size: 1.8rem; line-height: 1; text-decoration: none; color: var(--muted); padding: 0 0.2rem; }
.messages { flex: 1; overflow-y: auto; max-height: 62vh; padding: 1rem; display: flex; flex-direction: column; gap: 0.4rem; background: #fafbfc; }
.day { align-self: center; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin: 0.6rem 0 0.2rem; }
.msg { max-width: 78%; padding: 0.5rem 0.75rem; border-radius: 16px; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: #eef0f3; border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 5px; }
.msg.out.src-auto { background: #4a5468; }
.msg.out a { color: #fff; }
.msg .meta { display: block; font-size: 0.7rem; opacity: 0.65; margin-top: 0.15rem; }
.window-note { padding: 0.6rem 1rem; font-size: 0.85rem; background: var(--gold-soft); color: #6b5217; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--line); }
.composer .saved { grid-column: 1 / -1; margin: 0; width: auto; justify-self: start; font-size: 0.88rem; padding: 0.35rem 0.5rem; }
.composer textarea { margin: 0; }
.composer .btn { align-self: end; }

.side .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.85rem 1rem; margin-bottom: 0.75rem; }
.side summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
.side summary::after { content: "+"; color: var(--muted); }
.side details[open] summary::after { content: "–"; }
.side summary::-webkit-details-marker { display: none; }
.fu, .appt { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.fu > div, .appt > div { display: flex; flex-direction: column; gap: 0.1rem; }
.fu form, .appt form { margin: 0; }
.case-mini { display: block; padding: 0.55rem 0.7rem; margin: 0.6rem 0; border-radius: var(--radius); border: 1px solid var(--line); border-left: 4px solid var(--line); text-decoration: none; color: var(--ink); }
.case-mini span { display: block; font-size: 0.85rem; color: var(--muted); }
.case-mini.overdue { border-left-color: var(--red); }
.case-mini.today { border-left-color: var(--gold-bright); }

/* ---------- cases ---------- */
.case-group { margin-bottom: 1.5rem; }
.case-group h2 .muted { font-weight: 500; }
.case-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.case-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.2rem 1rem; padding: 0.75rem 0.9rem; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.case-row.overdue { border-left-color: var(--red); }
.case-row.today { border-left-color: var(--gold-bright); }
.case-row .case-next { grid-column: 1; color: var(--muted); font-size: 0.9rem; }
.case-row .due { grid-column: 2; grid-row: 1 / span 2; align-self: center; }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step { position: relative; padding: 0 0 1.4rem 2.6rem; counter-increment: step; }
.step::before { content: counter(step); position: absolute; left: 0; top: -2px; width: 1.75rem; height: 1.75rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.85rem; font-weight: 700; border: 2px solid var(--line); background: var(--surface); color: var(--muted); }
.step::after { content: ""; position: absolute; left: calc(0.875rem - 1px); top: 1.75rem; bottom: 0; width: 2px; background: var(--line); }
.step:last-child::after { display: none; }
.step.done::before { content: "✓"; background: var(--green); border-color: var(--green); color: #fff; }
.step.done .step-label { color: var(--muted); text-decoration: line-through; text-decoration-color: #c7ccd4; }
.step.now::before { border-color: var(--gold-bright); background: var(--gold-soft); color: var(--gold); }
.step.now .step-label { font-weight: 700; font-size: 1.08rem; }
.step.next .step-label { color: var(--muted); }
.step-due { font-size: 0.88rem; font-weight: 600; margin-top: 0.15rem; }
.step-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; align-items: flex-start; }
.step-actions form { margin: 0; }
.step-actions .full { flex-basis: 100%; }
.log { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.log li { display: flex; flex-direction: column; padding: 0.45rem 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.danger-zone { margin-top: 0.75rem; }

.types { border: 0; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.types legend { font-size: 0.86rem; font-weight: 600; color: #3a4252; margin-bottom: 0.4rem; }
.type-opt { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; font-weight: 400; }
.type-opt input { width: 20px; height: 20px; margin: 0.1rem 0 0; accent-color: var(--gold); flex: none; }
.type-opt small { display: block; color: var(--muted); }
.type-opt:has(input:checked) { border-color: var(--gold-bright); background: var(--gold-soft); }

/* scheduled & settings */
.sched-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.sched { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem 0.9rem; }
.sched-head { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.sched-text { margin-top: 0.4rem; color: #3a4252; font-size: 0.92rem; }
.settings .panel { display: grid; gap: 0.75rem; max-width: 760px; }
.settings .panel h2 { margin-bottom: 0; }
.panel h2 + .muted { margin-top: -0.4rem; }
.sticky-save { position: sticky; bottom: 0; padding: 0.75rem 0; background: linear-gradient(transparent, var(--bg) 35%); max-width: 760px; }
@media (max-width: 760px) { .sticky-save { bottom: calc(env(safe-area-inset-bottom, 0px) + 3.3rem); } }

/* auth */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at 50% 0%, var(--gold-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.75rem; display: grid; gap: 1rem; }
.auth-card h1 { font-size: 1.4rem; }
