:root {
  --surface-1:      #fcfcfb;
  --page-plane:     #f4f3f0;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --border:         rgba(11,11,11,0.08);
  --card-shadow:    0 4px 16px rgba(11,11,11,0.045), 0 1px 2px rgba(11,11,11,0.04);
  --series-1:       #2a78d6;
  --series-1-ink:   #ffffff;
  --good:           #0ca30c;
  --good-bg:        rgba(12,163,12,0.12);
  --warning:        #b5790a;
  --warning-bg:     rgba(250,178,25,0.18);
  --critical:       #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --border:         rgba(255,255,255,0.09);
    --card-shadow:    0 4px 16px rgba(0,0,0,0.32), 0 1px 2px rgba(0,0,0,0.3);
    --series-1:       #3987e5;
    --good:           #24c02c;
    --good-bg:        rgba(36,192,44,0.16);
    --warning:        #fab219;
    --warning-bg:     rgba(250,178,25,0.16);
    --critical:       #e66767;
  }
}
:root[data-theme="dark"] {
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --border:         rgba(255,255,255,0.09);
  --card-shadow:    0 4px 16px rgba(0,0,0,0.32), 0 1px 2px rgba(0,0,0,0.3);
  --series-1:       #3987e5;
  --good:           #24c02c;
  --good-bg:        rgba(36,192,44,0.16);
  --warning:        #fab219;
  --warning-bg:     rgba(250,178,25,0.16);
  --critical:       #e66767;
}

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

.topbar {
  background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  padding: 14px 16px 12px;
}
.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; }
.brand-id { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; display: block; flex-shrink: 0; }
.brand-group { display: flex; flex-direction: column; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.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-shrink: 0; }

.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; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--card-shadow); padding: 18px; 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: 12px; background: var(--page-plane); 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(--page-plane)); }
.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; }
.fee-option-price.free { color: var(--good); }

.btn {
  appearance: none; border: none; cursor: pointer; width: 100%;
  background: var(--series-1); color: var(--series-1-ink); font-size: 14px; font-weight: 700;
  padding: 13px 16px; border-radius: 14px; 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.08); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }
.btn.secondary { background: var(--page-plane); color: var(--text-primary); border: 1px solid var(--border); }
.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: 14px; 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); }
.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; } }
