/* =====================================================================
   X Capital · Sales & CRM Dashboard — styles
   Tokens follow the data-viz reference palette (light + dark selected).
   ===================================================================== */

:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f1ed;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --deemph: #d6d5ce;
  --good: #0ca30c; --good-text: #006300; --good-soft: #e4f5e4;
  --warning: #fab219; --warning-text: #7a5200; --warning-soft: #fff3d6;
  --serious: #ec835a; --serious-text: #8a3a1a; --serious-soft: #fde7de;
  --critical: #d03b3b; --critical-text: #a21d1d; --critical-soft: #fbe3e3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px -16px rgba(0,0,0,.18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", "Noto Sans Myanmar", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono-nums: "tnum";
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e; --surface: #1a1a19; --surface-2: #222221;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255,255,255,.10); --border-strong: rgba(255,255,255,.2);
    --accent: #3987e5; --accent-soft: #15325a;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --deemph: #3a3a37;
    --good-text: #4cc94c; --good-soft: #163a16;
    --warning-text: #ffd166; --warning-soft: #3d2f0a;
    --serious-text: #ffb595; --serious-soft: #4a2416;
    --critical-text: #ff8585; --critical-soft: #4a1a1a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e; --surface: #1a1a19; --surface-2: #222221;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255,255,255,.10); --border-strong: rgba(255,255,255,.2);
  --accent: #3987e5; --accent-soft: #15325a;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --deemph: #3a3a37;
  --good-text: #4cc94c; --good-soft: #163a16;
  --warning-text: #ffd166; --warning-soft: #3d2f0a;
  --serious-text: #ffb595; --serious-soft: #4a2416;
  --critical-text: #ff8585; --critical-soft: #4a1a1a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--page);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.right { text-align: right; }
.center { text-align: center; }
.mm { font-family: "Noto Sans Myanmar", var(--font); }

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: var(--page); z-index: 100; color: var(--text-2); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--grid); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--text); color: var(--page); font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.1; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--muted); line-height: 1.2; }
.brand-lg .brand-mark { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }
.brand-lg .brand-name { font-size: 20px; }
.brand-lg .brand-sub { font-size: 13px; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 26px 20px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.auth-form input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--page); font-size: 14px; }
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.auth-foot { margin: 22px 0 0; font-size: 12px; text-align: center; }
.form-error { color: var(--critical-text); font-size: 12.5px; min-height: 1em; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12.5px; align-self: center; }
.link:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-block { width: 100%; padding: 11px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center; font-size: 15px; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.2) blur(10px); border-bottom: 1px solid var(--border); }
.nav { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 7px 12px; border-radius: 9px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--text); color: var(--page); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sync-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.sync-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync-badge.stale .dot { background: var(--warning); }
.sync-badge.error .dot { background: var(--critical); }
.user-menu { position: relative; }
.menu { position: absolute; right: 0; top: 40px; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 40; }
.menu-email { padding: 8px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; word-break: break-all; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }

/* ---------- filter bar ---------- */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 20px 2px; }
.presets { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.presets button { border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
.presets button:hover { color: var(--text); }
.presets button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.custom-range { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.custom-range input { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 12.5px; }
.period-label { font-size: 12.5px; color: var(--muted); margin-left: auto; }

/* ---------- layout ---------- */
main { padding: 12px 20px 60px; max-width: 1480px; margin: 0 auto; width: 100%; }
.view > h1 { font-size: 20px; font-weight: 700; margin: 10px 0 2px; letter-spacing: -.01em; }
.view-sub { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tiles.tiles-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .tiles, .tiles.tiles-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 14px; }
@media (max-width: 980px) { .cols-3, .cols-2, .cols-2-1 { grid-template-columns: 1fr; } }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-title { font-size: 13.5px; font-weight: 600; margin: 0; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }
.chart-wrap.short { height: 200px; }
.chart-wrap.refetching { opacity: .5; }
.empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

/* ---------- stat tiles ---------- */
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 6px; }
.tile-value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.tile-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile-foot { margin-top: 6px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical-text); }
.delta.flat { color: var(--muted); }
.tile.hero .tile-value { font-size: 34px; }

/* ---------- badges / pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.pill-good { background: var(--good-soft); color: var(--good-text); }
.pill-warning { background: var(--warning-soft); color: var(--warning-text); }
.pill-serious { background: var(--serious-soft); color: var(--serious-text); }
.pill-critical { background: var(--critical-soft); color: var(--critical-text); }
.pill-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.table-wrap.tall { max-height: 560px; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; vertical-align: middle; }
table.data th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: 11.5px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .sort-ind { opacity: .55; margin-left: 4px; font-size: 10px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.wrap { white-space: normal; min-width: 180px; }
table.data tfoot td { font-weight: 600; background: var(--surface-2); position: sticky; bottom: 0; }
.cell-sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.bar-cell .bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--series-1); flex: 0 0 auto; }
.bar-cell .bar.deemph { background: var(--deemph); }
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.table-tools input[type="search"], .table-tools select { padding: 6px 10px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 13px; min-width: 150px; }
.table-tools .spacer { flex: 1; }
.count-note { font-size: 12px; color: var(--muted); }

/* ---------- drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; height: 100dvh; width: min(760px, 100vw); background: var(--page); z-index: 51; overflow: auto; box-shadow: -12px 0 40px rgba(0,0,0,.25); padding: 18px 20px 40px; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; margin-bottom: 10px; }
.drawer-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.drawer-meta { color: var(--text-2); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.drawer .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section-title { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- misc ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 90; box-shadow: var(--shadow); max-width: 90vw; }
.notice { padding: 10px 14px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.notice.warn { background: var(--warning-soft); color: var(--warning-text); border-color: transparent; }
.notice.err { background: var(--critical-soft); color: var(--critical-text); border-color: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend .key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: 3px; margin-right: 6px; }
.legend .box { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-2); }
.chip.active { background: var(--text); color: var(--page); border-color: var(--text); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.steps { padding-left: 18px; margin: 6px 0; font-size: 13px; }
.steps li { margin: 4px 0; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 10px; flex-wrap: wrap; }
  .brand-sub { display: none; }
  .nav { order: 3; width: 100%; margin-left: 0; }
  .topbar-right { margin-left: auto; }
  .sync-badge span.txt { display: none; }
  .filterbar { padding: 10px 12px 0; }
  .period-label { margin-left: 0; width: 100%; }
  main { padding: 10px 12px 60px; }
  .tiles, .tiles.tiles-3, .drawer .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 20px; }
  .tile.hero .tile-value { font-size: 26px; }
  .card { padding: 14px; }
  .chart-wrap { height: 230px; }
  .drawer { padding: 14px 14px 40px; }
}
@media print {
  .topbar, .filterbar, .drawer, .drawer-backdrop, .toast { display: none !important; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
}
