:root {
  --surface-1:      #ffffff;
  --page-plane:     #eef0f5;
  --text-primary:   #0f1322;
  --text-secondary: #555e72;
  --text-muted:     #8891a3;
  --grid:           #dfe3ec;
  --border:         rgba(15,19,34,0.1);
  --card-shadow:    none;
  --series-1:       #5c1a2e;
  --series-1-ink:   #ffffff;
  --series-1-deep:  #3f0f1f;
  --accent:         #d9a449;
  --accent-ink:     #2b1208;
  --mesh-b:         #5c1a2e;
  --good:           #2f8f5b;
  --good-bg:        rgba(47,143,91,0.12);
  --warning:        #b5790a;
  --warning-bg:     rgba(226,162,59,0.18);
  --critical:       #c2402f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1:      #161a26;
    --page-plane:     #0c0f18;
    --text-primary:   #f2f3f7;
    --text-secondary: #aab0c0;
    --text-muted:     #767e93;
    --grid:           #262c3d;
    --border:         rgba(242,243,247,0.1);
    --card-shadow:    none;
    --series-1:       #7a2e44;
    --series-1-deep:  #5c1a2e;
    --accent:         #d9a449;
    --accent-ink:     #2b1208;
    --mesh-b:         #7a2e44;
    --good:           #4fb57f;
    --good-bg:        rgba(79,181,127,0.16);
    --warning:        #f0b84e;
    --warning-bg:     rgba(240,184,78,0.16);
    --critical:       #e0695a;
  }
}
:root[data-theme="dark"] {
  --surface-1:      #161a26;
  --page-plane:     #0c0f18;
  --text-primary:   #f2f3f7;
  --text-secondary: #aab0c0;
  --text-muted:     #767e93;
  --grid:           #262c3d;
  --border:         rgba(242,243,247,0.1);
  --card-shadow:    none;
  --series-1:       #7a2e44;
  --series-1-deep:  #5c1a2e;
  --accent:         #d9a449;
  --accent-ink:     #2b1208;
  --mesh-b:         #7a2e44;
  --good:           #4fb57f;
  --good-bg:        rgba(79,181,127,0.16);
  --warning:        #f0b84e;
  --warning-bg:     rgba(240,184,78,0.16);
  --critical:       #e0695a;
}

* { box-sizing: border-box; }
html { background: var(--page-plane); }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-primary);
  padding-bottom: 60px;
  min-height: 100vh;
  background-color: var(--page-plane);
}
h1, h2, h3 { letter-spacing: -0.01em; }
body.has-tabs { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.topbar {
  background: var(--series-1);
  border-bottom: 3px solid var(--accent);
  position: sticky; top: 0; z-index: 20;
  padding: 16px 16px 14px;
}
.topbar .brand h1, .topbar .brand p { color: #fff; }
.topbar .brand p { opacity: 0.72; }
.topbar .lang-switch-btn, .topbar .logout-btn {
  background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.22); color: #fff;
}
.topbar .lang-switch-btn:hover, .topbar .logout-btn:hover { color: #fff; border-color: var(--accent); }
.topbar-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; justify-content: space-between; flex-wrap: wrap; row-gap: 8px; }
.brand-id { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: block; flex-shrink: 0; }
.brand-group { display: flex; flex-direction: column; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; font-weight: 700; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--text-secondary); }
.brand-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  background: var(--warning-bg); color: var(--warning); padding: 3px 8px; border-radius: 999px;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.lang-switch { position: relative; }
.lang-switch-btn {
  appearance: none; border: 1px solid var(--border); background: var(--page-plane); color: var(--text-secondary);
  border-radius: 999px; padding: 5px 10px 5px 9px; font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: inherit; display: flex; align-items: center; gap: 5px; transition: border-color .12s, color .12s;
}
.lang-switch-btn:hover { color: var(--text-primary); border-color: color-mix(in srgb, var(--series-1) 40%, var(--border)); }
.lang-flag { font-size: 14px; line-height: 1; }
.lang-name { white-space: nowrap; }
.lang-caret { flex-shrink: 0; opacity: .55; transition: transform .15s; }
.lang-switch.open .lang-caret { transform: rotate(180deg); }
.lang-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; min-width: 150px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--card-shadow); padding: 5px; flex-direction: column; gap: 2px;
}
.lang-option {
  appearance: none; border: none; background: none; cursor: pointer; text-align: left;
  font-family: inherit; font-size: 13px; color: var(--text-primary); padding: 8px 10px; border-radius: 8px;
  display: flex; align-items: center; gap: 8px; width: 100%;
}
.lang-option:hover { background: var(--page-plane); }
.lang-option.active { background: color-mix(in srgb, var(--series-1) 10%, var(--page-plane)); color: var(--series-1); font-weight: 700; }

.notice-banner {
  max-width: 640px; margin: 14px auto 0; padding: 11px 14px;
  background: var(--page-plane); border: 1px solid var(--border);
  border-radius: 12px; font-size: 12px; line-height: 1.5; color: var(--text-secondary);
}
.notice-banner.dev {
  background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 45%, transparent);
}
.notice-banner b { color: var(--text-primary); }

main.wrap { padding-top: 16px; }

/* On tall viewports (tablets, desktop browsers) the mobile-first single-card layout otherwise
   leaves a large empty gap below the content. Center the content vertically in the space below
   the sticky header instead — phones (max real-world CSS height ~932px) are unaffected. */
@media (min-height: 1000px) {
  body { display: flex; flex-direction: column; min-height: 100vh; }
  main.wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }
}

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--card-shadow); padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 14px; font-weight: 700; }
.card h2 .count { font-weight: 700; color: var(--text-secondary); }

.card.invoice-card {
  border-color: color-mix(in srgb, var(--series-1) 35%, var(--border));
  background: color-mix(in srgb, var(--series-1) 4%, var(--surface-1));
}

.notif-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px; margin-bottom: 16px;
}
.notif-hint { font-size: 12.5px; color: var(--text-secondary); flex: 1 1 200px; min-width: 0; }
.notif-hint.error { color: var(--critical); }
.notif-row .btn.secondary { width: auto; padding: 6px 14px; font-size: 12.5px; white-space: nowrap; flex: 0 0 auto; }
.notif-row .btn.secondary.active { border-color: var(--series-1); color: var(--series-1); }
.invoice-card h2 {
  font-size: 15px; text-transform: none; letter-spacing: 0; font-weight: 800;
  color: var(--series-1); display: flex; align-items: center; gap: 8px; margin: 0 0 6px;
}
.invoice-intro { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; margin: 0 0 14px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 600; }
.field input[type="text"], .field input[type="tel"], .field input[type="email"], .field input[type="password"], .field textarea {
  width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--page-plane); color: var(--text-primary); font-size: 14px; font-family: inherit;
  transition: border-color .12s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--series-1); }
.field .subtle { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.field .subtle.valid { color: var(--good); font-weight: 600; }

.reply-box {
  width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--page-plane); color: var(--text-primary); font-size: 14px; font-family: inherit;
  resize: vertical; min-height: 84px; line-height: 1.45; transition: border-color .12s;
}
.reply-box:focus { outline: none; border-color: var(--series-1); }

.reply-option {
  display: flex; align-items: flex-start; gap: 9px; margin-top: 10px; cursor: pointer;
  font-size: 12.5px; color: var(--text-secondary); line-height: 1.4;
}
.reply-option input { margin-top: 2px; accent-color: var(--series-1); flex-shrink: 0; }

.file-drop {
  border: 1.5px dashed var(--border); border-radius: 12px; padding: 14px; text-align: center;
  cursor: pointer; background: var(--page-plane); transition: border-color .12s;
}
.file-drop:hover { border-color: var(--series-1); }
.file-drop input { display: none; }
.file-drop .fd-label { font-size: 13px; color: var(--text-secondary); }
.file-drop .fd-sub { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-secondary);
  background: var(--page-plane); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px 4px 8px;
  text-decoration: none;
}
.file-chip button {
  appearance: none; border: none; background: none; color: var(--text-muted); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 0; font-family: inherit;
}
.file-chip button:hover { color: var(--critical); }

.fee-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.fee-option {
  display: flex; align-items: center; gap: 11px; cursor: pointer;
  padding: 12px 14px; border-radius: 10px; background: var(--surface-1); border: 1px solid var(--border);
  transition: border-color .12s, background .12s;
}
.fee-option:hover { border-color: color-mix(in srgb, var(--series-1) 40%, var(--border)); }
.fee-option.selected { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 6%, var(--surface-1)); }
.fee-option input[type="radio"] { accent-color: var(--series-1); width: 16px; height: 16px; flex-shrink: 0; }
.fee-option-title { flex: 1; margin-right: 10px; font-size: 13px; color: var(--text-primary); font-weight: 600; }
.fee-option-price { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--series-1); }
.fee-option-price.free { color: var(--good); }

.doctor-option { align-items: flex-start; }
.doctor-option-body { flex: 1; min-width: 0; }
.doctor-option-name { display: block; font-size: 13.5px; color: var(--text-primary); font-weight: 600; }
.doctor-option-specialty { display: block; font-size: 12px; color: var(--series-1); font-weight: 600; margin-top: 1px; }
.doctor-option-bio { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 3px; line-height: 1.4; }

.btn {
  appearance: none; border: none; cursor: pointer; width: 100%;
  background: var(--accent);
  color: var(--accent-ink); font-size: 14.5px; font-weight: 800;
  padding: 14px 16px; border-radius: 6px; transition: filter .12s, transform .1s, opacity .12s;
  font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }
.btn.secondary { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); box-shadow: none; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff; animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.empty-state { text-align: center; padding: 28px 12px; color: var(--text-muted); font-size: 13px; }
.error-text { font-size: 12.5px; color: var(--critical); margin-top: 8px; }

.case-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 13px 14px; margin-bottom: 10px;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.case-item:last-child { margin-bottom: 0; }
.case-item:hover { border-color: var(--series-1); }
.case-item.open { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 5%, var(--surface-1)); }
.case-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.case-who { font-size: 13.5px; font-weight: 700; }
.case-date { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.case-preview { font-size: 12.5px; color: var(--text-secondary); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.case-meta { display: flex; align-items: center; gap: 6px; margin-top: 9px; flex-wrap: wrap; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip.pending { background: var(--warning-bg); color: var(--warning); }
.chip.pending .dot { background: var(--warning); }
.chip.replied { background: var(--good-bg); color: var(--good); }
.chip.replied .dot { background: var(--good); }
.chip.paid { background: var(--page-plane); color: var(--text-muted); border: 1px solid var(--border); }
.chip.urgent { background: var(--warning-bg); color: var(--warning); font-weight: 800; }

.thread-detail { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.msg-bubble {
  background: var(--page-plane); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 13px; font-size: 13.5px; line-height: 1.5; color: var(--text-primary); white-space: pre-wrap;
}
.msg-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; margin: 12px 0 6px; }
.msg-label:first-child { margin-top: 0; }
.reply-bubble { background: color-mix(in srgb, var(--series-1) 10%, var(--surface-1)); border-color: color-mix(in srgb, var(--series-1) 30%, var(--border)); }

.phone-link { color: var(--series-1); text-decoration: none; font-weight: 600; }
.phone-link:hover { text-decoration: underline; }

.followup-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--good-bg); border: 1px solid color-mix(in srgb, var(--good) 40%, transparent);
}
.followup-box .fu-text { font-size: 11.5px; color: var(--text-secondary); line-height: 1.4; }
.followup-box .fu-code {
  font-family: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;
  font-size: 15px; font-weight: 700; letter-spacing: .06em; color: var(--good); white-space: nowrap;
}
.followup-box.used { background: var(--page-plane); border-color: var(--border); }
.followup-box.used .fu-code { color: var(--text-muted); text-decoration: line-through; }

footer.foot { max-width: 640px; margin: 24px auto 0; padding: 0 16px; font-size: 11px; color: var(--text-muted); line-height: 1.6; text-align: center; }

.status-hero { text-align: center; padding: 6px 0 10px; }
.status-hero .status-icon { font-size: 34px; line-height: 1; margin-bottom: 8px; }
.tier-banner {
  display: inline-flex; align-items: center; gap: 7px; margin: 6px 0 2px;
  padding: 7px 15px; border-radius: 999px; font-size: 13px; font-weight: 800;
  background: color-mix(in srgb, var(--series-1) 12%, var(--page-plane)); color: var(--series-1);
  border: 1px solid color-mix(in srgb, var(--series-1) 30%, transparent);
}
.tier-banner.urgent {
  background: var(--warning-bg); color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 16px rgba(0,0,0,0.06);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs-inner { display: flex; justify-content: space-around; max-width: 640px; margin: 0 auto; width: 100%; }
.tab-btn {
  appearance: none; border: none; background: none; cursor: pointer;
  padding: 6px 4px 5px; font-size: 10.5px; font-weight: 600; line-height: 1.3;
  color: var(--text-muted); border-radius: 12px; text-decoration: none;
  display: flex; flex: 1 1 0; flex-direction: column; align-items: center; gap: 3px;
  transition: color .12s, background .12s, transform .1s; min-width: 0;
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--series-1); background: color-mix(in srgb, var(--series-1) 10%, transparent); }
.tab-btn:active { transform: scale(0.94); }
.tab-btn svg { width: 22px; height: 22px; display: block; }
.tab-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab-icon-wrap { position: relative; display: inline-flex; }
.tab-badge {
  position: absolute; top: -4px; right: -8px;
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--text-muted) 18%, transparent); color: var(--text-secondary);
  min-width: 14px; text-align: center; line-height: 1.4;
}
.tab-btn.active .tab-badge { background: var(--series-1); color: #fff; }
@keyframes tabFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.tab-fade-in { animation: tabFadeIn .22s ease-out; }
@media (prefers-reduced-motion: reduce) { .tab-fade-in { animation: none; } }
