/* =====================================================================
   Totalite mobile app (PWA) — app-like UI, light & dark, safe areas.
   ===================================================================== */
:root {
  --accent: #0e7490;            /* default / welcome */
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 116, 144, .12);
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e8ef;
  --good: #047857; --good-soft: #d1fae5;
  --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c;  --bad-soft: #fee2e2;
  --info: #4338ca; --info-soft: #e0e7ff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 4px 14px rgba(17, 24, 39, .06);
  --bar-h: 56px;
  --tab-h: 62px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #121a2b; --surface-2: #0f1626; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2a3d;
    --good: #34d399; --good-soft: rgba(52, 211, 153, .14);
    --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
    --bad: #f87171;  --bad-soft: rgba(248, 113, 113, .14);
    --info: #a5b4fc; --info-soft: rgba(165, 180, 252, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
body[data-aud="patient"]   { --accent: #ea580c; --accent-soft: rgba(234, 88, 12, .12); }
body[data-aud="clinician"] { --accent: #0d9488; --accent-soft: rgba(13, 148, 136, .13); }
body[data-aud="doctor"]    { --accent: #7c3aed; --accent-soft: rgba(124, 58, 237, .12); }
body[data-aud="marketing"] { --accent: #db2777; --accent-soft: rgba(219, 39, 119, .12); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--ink); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Boot splash */
.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 22px; background: var(--bg); }
.boot img { border-radius: 18px; }
.boot-bar { width: 120px; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; position: relative; }
.boot-bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--accent); animation: boot 1s ease-in-out infinite; border-radius: 4px; }
@keyframes boot { 0% { left: -40%; } 100% { left: 100%; } }

/* ---------- Shell ---------- */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid transparent;
}
.appbar.scrolled { border-bottom-color: var(--line); }
.appbar-row { height: var(--bar-h); display: flex; align-items: center; gap: 4px; padding: 0 8px; max-width: 760px; margin: 0 auto; }
.appbar h1 { flex: 1; margin: 0 6px; font-size: 1.12rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; font-size: 1.3rem; cursor: pointer; position: relative; flex: 0 0 auto; }
.icon-btn:active { background: var(--line); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

.content { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 16px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom, 0px)); }
.content.no-tabs { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }

.tabbar {
  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-row { display: flex; max-width: 760px; margin: 0 auto; height: var(--tab-h); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .7rem; font-weight: 600; border: 0; background: none; cursor: pointer; position: relative; }
.tab i { font-size: 1.32rem; line-height: 1; transition: transform .15s; }
.tab.on { color: var(--accent); }
.tab.on i { transform: translateY(-1px); }
.tab .dot { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: .62rem; display: grid; place-items: center; padding: 0 4px; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom, 0px)); z-index: 25;
  height: 56px; min-width: 56px; padding: 0 20px; border-radius: 28px; border: 0; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 8px; font-weight: 700; box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent); cursor: pointer;
}
.fab i { font-size: 1.35rem; }

.offline-banner { background: var(--warn-soft); color: var(--warn); font-size: .82rem; font-weight: 600; text-align: center; padding: 6px 12px; }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.num { font-variant-numeric: tabular-nums; }
.b { font-weight: 700; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pre { white-space: pre-line; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; }
.section-head h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0; font-weight: 700; }
.section-head a, .section-head button { font-size: .88rem; font-weight: 600; background: none; border: 0; color: var(--accent); cursor: pointer; }

.hero { border-radius: 22px; padding: 20px; color: #fff; background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #0b1220)); position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -50px; top: -60px; width: 190px; height: 190px; border-radius: 50%; background: rgba(255, 255, 255, .1); }
.hero small { opacity: .85; }
.hero h2 { margin: 2px 0 6px; font-size: 1.5rem; }
.hero .btn { background: #fff; color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; position: relative; }
.stat i { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 1.05rem; margin-bottom: 8px; }
.stat .v { font-size: 1.32rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .l { font-size: .76rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat.good i { background: var(--good-soft); color: var(--good); }
.stat.warn i { background: var(--warn-soft); color: var(--warn); }
.stat.bad i { background: var(--bad-soft); color: var(--bad); }
.stat.info i { background: var(--info-soft); color: var(--info); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); color: var(--ink); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item .lead { width: 42px; height: 42px; border-radius: 12px; flex: 0 0 42px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 1.15rem; font-weight: 700; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .end { text-align: right; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item .chev { color: var(--muted); }
.item.unread { background: var(--accent-soft); }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.kv { display: grid; grid-template-columns: minmax(96px, 40%) 1fr; gap: 8px 12px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty i { font-size: 2.6rem; display: block; margin-bottom: 10px; opacity: .55; }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 1.05rem; }

.skeleton { border-radius: 12px; background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 14px; border: 0; font-weight: 700; font-size: 1rem; cursor: pointer; background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.sm { height: 38px; padding: 0 14px; border-radius: 11px; font-size: .9rem; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn .spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: .86rem; font-weight: 600; }
.field .hint { font-size: .78rem; color: var(--muted); }
.field .err { font-size: .8rem; color: var(--bad); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: 50px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface); padding: 12px 14px; font-size: 1rem; outline: none; appearance: none;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 38px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.bad, .select.bad, .textarea.bad { border-color: var(--bad); }
.otp { letter-spacing: .55em; text-align: center; font-size: 1.6rem; font-weight: 800; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 360px) { .two { grid-template-columns: 1fr; } }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; padding: 4px; gap: 4px; overflow-x: auto; }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; border: 0; background: transparent; font-weight: 600; font-size: .88rem; color: var(--muted); cursor: pointer; white-space: nowrap; padding: 0 10px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: 0 0 auto; height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: .86rem; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.search { position: relative; }
.search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 40px; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); margin: 1px 0 0; flex: 0 0 auto; }
.check.on { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Sheets, dialogs, toasts ---------- */
.scrim { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 60; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  animation: up .2s ease-out; max-width: 760px; margin: 0 auto;
}
.sheet .grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 6px; font-size: 1.18rem; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

.toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top, 0px) + 10px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: #111827; color: #fff; padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: .92rem; display: flex; gap: 10px; align-items: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); animation: drop .2s ease-out; }
.toast.good i { color: #34d399; } .toast.bad i { color: #f87171; } .toast.warn i { color: #fbbf24; }
@keyframes drop { from { transform: translateY(-12px); opacity: 0; } }

/* ---------- Auth ---------- */
.auth { min-height: 100%; display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top, 0px) + 26px) 20px calc(env(safe-area-inset-bottom, 0px) + 26px); max-width: 480px; margin: 0 auto; }
.auth .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth .brand img { width: 52px; height: 52px; border-radius: 14px; }
.auth h1 { font-size: 1.7rem; margin: 0 0 6px; line-height: 1.15; }
.aud-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.aud { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); padding: 16px 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 10px; min-height: 132px; box-shadow: var(--shadow); }
.aud i { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 1.35rem; color: #fff; }
.aud b { font-size: 1rem; }
.aud span { font-size: .8rem; color: var(--muted); line-height: 1.3; }

.install { display: flex; gap: 12px; align-items: center; }
.install img { width: 44px; height: 44px; border-radius: 12px; }

/* Payment / money */
.amount-big { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.total-line { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.total-line.grand { font-size: 1.15rem; font-weight: 800; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 12px; }

/* Rich text (reports) */
.rich { font-size: .95rem; overflow-wrap: anywhere; }
.rich table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.rich td, .rich th { border: 1px solid var(--line); padding: 6px; }
.editor { min-height: 220px; border: 1px solid var(--line); border-radius: 13px; padding: 12px 14px; background: var(--surface); outline: none; }
.editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.toolbar button { width: 38px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 28px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); background: var(--surface); }
.timeline li.done::after { border-color: var(--accent); background: var(--accent); }
.timeline li.now::after { border-color: var(--accent); }

.bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.bubble.mine { margin-left: auto; background: var(--accent-soft); border-color: transparent; }

@media (min-width: 768px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Shared fixes ---------- */
.empty .btn i { font-size: 1em; display: inline; margin: 0; opacity: 1; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
.sheet[role="alertdialog"] { z-index: 71; }
.scrim.over { z-index: 70; }
@media (max-width: 400px) { .seg button { padding: 0 6px; font-size: .82rem; } }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
