/* MerciSync — design tokens + components. Tailwind (CDN, Preflight off) supplies layout utilities;
   everything themed reads these CSS variables so day and night modes never hardcode colours. */
:root {
  --bg: #f5f6fb; --surface: #ffffff; --surface-2: #f0f2f8; --border: #dfe3ee; --text: #161a2b; --muted: #5d6478;
  --brand: #4f46e5; --brand-ink: #ffffff; --brand-soft: #eceafe; --accent: #0ea5a4;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #a15c07; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06); --radius: 12px; --focus: 0 0 0 3px rgba(79,70,229,.35);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0d1020; --surface: #161a2e; --surface-2: #1d2238; --border: #2c3350; --text: #e8eaf4; --muted: #a2a9c2;
  --brand: #8b85ff; --brand-ink: #0d0d0d; --brand-soft: #262a52; --accent: #2dd4bf;
  --ok: #4ade80; --ok-soft: #12321f; --warn: #fbbf24; --warn-soft: #3a2c0b; --bad: #f87171; --bad-soft: #3b1518; --info: #93c5fd; --info-soft: #172a4d;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35); --focus: 0 0 0 3px rgba(139,133,255,.45);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 Inter, "Segoe UI", system-ui, -apple-system, sans-serif; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons — every action button gets the busy-lock from app.js */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .55rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus, .select:focus, textarea.input:focus { outline: none; box-shadow: var(--focus); border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
[data-theme="dark"] .btn-danger { color: #0d0d0d; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .875rem; }
.btn[disabled], .btn.is-busy { opacity: .65; cursor: not-allowed; pointer-events: none; }
.spinner { width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Form controls — 16px text so iOS never zooms */
.input, .select { width: 100%; min-height: 44px; padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 16px; }
textarea.input { min-height: 90px; }
.label { display: block; font-weight: 600; font-size: .875rem; margin-bottom: .3rem; }
.field { margin-bottom: .9rem; }
.field-err { color: var(--bad); font-size: .8rem; margin-top: .25rem; }
.check { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.1rem; }
.kpi { padding: 1rem 1.1rem; }
.kpi .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.kpi .l { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); } .b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); } .b-info { background: var(--info-soft); color: var(--info); } .b-brand { background: var(--brand-soft); color: var(--brand); }
.alert { padding: .8rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.alert-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* Tables: scroll inside their card; collapse to labelled cards under 640px */
.tbl-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .65rem .8rem; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
.tbl td { padding: .65rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 639px) {
  .tbl.stack thead { display: none; }
  .tbl.stack, .tbl.stack tbody, .tbl.stack tr, .tbl.stack td { display: block; width: 100%; }
  .tbl.stack tr { border-bottom: 1px solid var(--border); padding: .5rem .2rem; }
  .tbl.stack td { border: none; padding: .3rem .6rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .tbl.stack td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; text-transform: uppercase; text-align: left; flex: 0 0 auto; }
  .tbl.stack td.num { text-align: right; }
  .tbl.stack td[data-label=""]::before { content: none; }
}
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* App shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 248px; flex: 0 0 248px; background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .75rem; }
.side a.nav { display: flex; align-items: center; gap: .7rem; min-height: 42px; padding: .45rem .75rem; border-radius: 10px; color: var(--text); font-weight: 500; }
.side a.nav:hover { background: var(--surface-2); text-decoration: none; }
.side a.nav.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.side .nav-h { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1rem .75rem .35rem; }
.side svg { width: 18px; height: 18px; flex: 0 0 18px; }
.main { flex: 1; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.content { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.page-h { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.page-h h1 { font-size: 1.45rem; font-weight: 700; margin-right: auto; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--accent)); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.brand b { color: var(--brand); }
.imp-banner { background: var(--warn-soft); color: var(--warn); padding: .45rem 1rem; font-weight: 600; text-align: center; }
@media (max-width: 1023px) {
  .side { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .content { padding: 1rem .8rem; }
}
.scrim { position: fixed; inset: 0; background: rgba(5,8,20,.55); z-index: 55; display: none; }
.scrim.show { display: block; }

/* Modal / dialogs (fancy confirm/alert) */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(5,8,20,.55); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 2rem); overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 1.05rem; }
.modal-b { padding: 1.1rem 1.2rem; }
.modal-f { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; padding: .9rem 1.2rem; border-top: 1px solid var(--border); }
.dlg-ico { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 38px; }
.toast-wrap { position: fixed; right: 1rem; bottom: 1rem; z-index: 120; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast { padding: .75rem 1rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); min-width: 240px; }
.toast.ok { border-left: 4px solid var(--ok); } .toast.bad { border-left: 4px solid var(--bad); }

/* Wizard steps */
.steps { display: flex; gap: .4rem; flex-wrap: wrap; }
.step { flex: 1 1 120px; padding: .55rem .7rem; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: .85rem; font-weight: 600; }
.step.done { background: var(--ok-soft); color: var(--ok); } .step.cur { background: var(--brand); color: var(--brand-ink); }

/* Public site */
.pub-nav { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.1; font-weight: 800; letter-spacing: -.02em; }
.hero .grad { background: linear-gradient(90deg, var(--brand), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.feature svg { width: 26px; height: 26px; color: var(--brand); }
.price-card.featured { border: 2px solid var(--brand); }
.prose h2 { font-size: 1.25rem; margin: 1.6rem 0 .5rem; } .prose p, .prose li { color: var(--text); margin-bottom: .6rem; } .prose ul { padding-left: 1.2rem; }
footer.site { border-top: 1px solid var(--border); padding: 2rem 0; color: var(--muted); font-size: .9rem; }
.chart { width: 100%; height: 300px; }
@media (max-width: 639px) { .chart { height: 240px; } .kpi .v { font-size: 1.3rem; } }
/* Grid/flex children may shrink below their content (wide tables scroll inside .tbl-wrap instead of widening the page). */
.grid > *, .shell > .main { min-width: 0; }
.mono { overflow-wrap: anywhere; }
.tbl td.mono { white-space: nowrap; }
.btn svg { width: 18px; height: 18px; flex: 0 0 18px; }
