/* =========================================================
   Biz1 Finance — Executive Analytics (v2 design)
   ========================================================= */

:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef1f8;
  --border: #e5e9f2;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-soft: rgba(79, 70, 229, .10);
  --revenue: #10b981;
  --expense: #f43f5e;
  --cashin: #0ea5e9;
  --warn: #f59e0b;
  --orange: #f97316;
  --danger: #e11d48;
  --success: #059669;
  --wa: #1fae57;
  --wa-dark: #128c4a;
  --age-0: #10b981;
  --age-1: #f59e0b;
  --age-2: #f97316;
  --age-3: #ef4444;
  --age-4: #9f1239;
  --grid: #e8ecf4;
  --axis: #94a3b8;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .18);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: #0b1020;
  --sidebar-2: #131a2e;
  --sidebar-text: #cbd5e1;
  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Heebo", "Arial Hebrew", sans-serif;
}

[data-theme="dark"] {
  --bg: #080c18;
  --surface: #10172a;
  --surface-2: #0d1424;
  --surface-3: #18213a;
  --border: #1e2942;
  --text: #e8ecf5;
  --text-2: #cbd5e1;
  --muted: #8b98b2;
  --primary: #818cf8;
  --primary-2: #a5b4fc;
  --primary-soft: rgba(129, 140, 248, .14);
  --grid: #1a2440;
  --axis: #64748b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  --sidebar: #060913;
  --sidebar-2: #0f1528;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: end; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px;
  padding: 11px 18px; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, .28); }
.btn-primary:hover:not(:disabled) { background: var(--primary-2); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-wa { background: var(--wa); color: #fff; box-shadow: 0 8px 20px rgba(31, 174, 87, .28); line-height: 1.3; }
.btn-wa:hover:not(:disabled) { background: var(--wa-dark); }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: 15px; transition: background .15s;
}
.icon-btn:hover { background: var(--surface-3); }
.lang-btn { font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.link-btn { background: none; border: 0; padding: 6px 0 0; color: var(--primary); font-weight: 600; font-size: 13px; }
.link-btn:disabled { color: var(--muted); cursor: default; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600;
}

/* ---------- Brand ---------- */
.brand-mark { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff; letter-spacing: -.02em;
  background: linear-gradient(135deg, #6366f1, #10b981);
  box-shadow: 0 6px 18px rgba(99, 102, 241, .35);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }

/* =========================================================
   LOGIN
   ========================================================= */
.login-screen { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-art {
  position: relative; overflow: hidden; color: #e2e8f0;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(99, 102, 241, .45), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(16, 185, 129, .35), transparent 60%),
    #0b1020;
  display: flex; align-items: center; justify-content: center; padding: 56px;
}
.login-art::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}
.login-art-inner { position: relative; z-index: 1; max-width: 460px; }
.login-art .brand-name { color: #fff; }
.login-headline { margin-top: 44px; font-size: 40px; line-height: 1.1; letter-spacing: -.03em; color: #fff; font-weight: 800; }
.login-lead { margin-top: 16px; font-size: 16px; color: #aab6cc; }
.login-features { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-features li { display: flex; align-items: center; gap: 12px; font-weight: 500; color: #dbe3f0; }
.feat-dot { width: 22px; height: 22px; border-radius: 50%; background: rgba(16, 185, 129, .18); position: relative; flex: none; }
.feat-dot::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #34d399; }
.art-card {
  margin-top: 40px; padding: 18px; border-radius: 18px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(8px);
}
.art-card-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: #fff; margin-bottom: 10px; }
.art-chip { background: rgba(52, 211, 153, .18); color: #6ee7b7; padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.art-chart { width: 100%; height: auto; display: block; }

.login-panel { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; background: var(--bg); }
.login-toolbar { position: absolute; top: 20px; inset-inline-end: 20px; display: flex; gap: 8px; }
.login-box { width: 100%; max-width: 400px; }
.brand-mark--mobile { display: none; margin-bottom: 28px; }
.login-title { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.login-sub { margin-top: 6px; color: var(--muted); }
.login-form { margin-top: 28px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 110px; line-height: 1.5; font-size: 13px; }
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.password-wrap { position: relative; }
.password-wrap input { padding-inline-end: 46px; }
.password-toggle {
  position: absolute; top: 50%; inset-inline-end: 8px; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted); padding: 6px; border-radius: 8px; display: grid;
}
.password-toggle:hover { color: var(--text); background: var(--surface-3); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-error { padding: 10px 12px; border-radius: 10px; background: rgba(225, 29, 72, .08); color: var(--danger); font-size: 13px; font-weight: 500; }
.demo-box { margin-top: 22px; padding: 14px 16px; border: 1px dashed var(--border); border-radius: 14px; background: var(--surface); }
.demo-box-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.demo-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.demo-creds { font-size: 12.5px; color: var(--text-2); direction: ltr; }
.login-foot { position: absolute; bottom: 20px; font-size: 12px; color: var(--muted); }

/* =========================================================
   APP SHELL
   ========================================================= */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 22px 16px; background: var(--sidebar); color: var(--sidebar-text);
}
.sidebar-brand { padding: 4px 8px 26px; }
.sidebar-brand .brand-name { color: #fff; }
.nav { display: grid; gap: 4px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 12px; border: 0; background: none;
  color: var(--sidebar-text); font-weight: 500; text-align: start;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; flex: none; opacity: .85; }
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(99, 102, 241, .08)); color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; inset-inline-start: -16px; top: 10px; bottom: 10px; width: 3px;
  border-radius: 0 3px 3px 0; background: #818cf8;
}
[dir="rtl"] .nav-item.active::before { border-radius: 3px 0 0 3px; }
.nav-badge {
  margin-inline-start: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px;
  background: #e11d48; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.status-card { padding: 12px 14px; border-radius: 14px; background: var(--sidebar-2); display: grid; gap: 8px; font-size: 12.5px; }
.status-row { display: flex; align-items: center; gap: 8px; }
.status-row--muted { color: #8391ad; }
.status-text { font-weight: 600; color: #e2e8f0; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; flex: none; }
.live-dot.on { background: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: pulse 1.8s infinite; }
.live-dot.polling { background: #f59e0b; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); } 70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--sidebar-2); }
.avatar { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: #312e81; color: #c7d2fe; font-weight: 700; flex: none; }
.user-meta { min-width: 0; flex: 1; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-domain { color: #8391ad; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: start; }
.sidebar .icon-btn { background: transparent; border-color: rgba(255, 255, 255, .1); color: #cbd5e1; }
.sidebar .icon-btn:hover { background: rgba(255, 255, 255, .08); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 32px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.topbar-title p { margin-top: 2px; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync-text { font-size: 12px; color: var(--muted); margin-inline-end: 6px; white-space: nowrap; }
.btn.is-busy svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { margin: 16px 32px 0; padding: 10px 14px; border-radius: 12px; font-size: 13px; background: rgba(245, 158, 11, .12); color: #b45309; border: 1px solid rgba(245, 158, 11, .25); }
[data-theme="dark"] .notice { color: #fcd34d; }

.content { padding: 24px 32px 48px; }
.page { display: grid; gap: 20px; animation: pageIn .35s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; min-width: 0; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.panel-head p { margin-top: 3px; font-size: 12.5px; }
.panel-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.sub-head { font-size: 13px; font-weight: 700; margin: 18px 0 10px; color: var(--text-2); }
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; }
.grid-cash { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.grid-products { display: grid; grid-template-columns: 1.25fr 1fr; gap: 20px; align-items: stretch; }
.table.no-catalog .col-catalog { display: none; }
.cell-clip { max-width: 180px; margin-inline-start: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack { display: grid; gap: 20px; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-3); border: 1px solid var(--border); }
.seg-btn { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); transition: all .15s; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  position: relative; overflow: hidden; padding: 18px 20px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; min-height: 164px;
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--accent); }
.kpi--revenue { --accent: var(--revenue); }
.kpi--growth { --accent: var(--primary); }
.kpi--outstanding { --accent: var(--warn); }
.kpi--clients { --accent: var(--cashin); }
.kpi-head { display: flex; align-items: center; gap: 10px; }
.kpi-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.kpi-icon svg { width: 17px; height: 17px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: 6px; }
.kpi-value.up { color: var(--success); }
.kpi-value.down { color: var(--danger); }
.kpi-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); position: relative; z-index: 1; }
.kpi-spark { position: absolute; inset-inline: 0; bottom: 0; width: 100%; height: 52px; opacity: .9; pointer-events: none; }
.kpi-stack { margin-top: auto; display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.kpi-stack span { height: 100%; transition: width .6s ease; }
.kpi-ring { position: absolute; inset-inline-end: 16px; bottom: 14px; width: 56px; height: 56px; }
.delta { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 12px; }
.delta.up { background: rgba(16, 185, 129, .12); color: var(--success); }
.delta.down { background: rgba(225, 29, 72, .1); color: var(--danger); }

/* skeleton */
.is-loading .kpi-value, .is-loading .stat strong {
  color: transparent !important; border-radius: 8px; width: 60%;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart--lg { height: 320px; }
.chart--md { height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--axis); font-size: 11px; font-family: var(--font); }
.chart .guide { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0; transition: opacity .12s; }
.chart .guide.show { opacity: .8; }
.chart .dot { transition: r .12s; }
.chart .series-line { fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; animation: draw 1s ease forwards; }
.chart .series-area { animation: fadeIn .8s ease; }
.chart .bar { transform-box: fill-box; transform-origin: bottom; animation: grow .6s cubic-bezier(.2, .8, .2, 1) both; transition: opacity .15s; }
.chart svg.static .series-line, .chart svg.static .series-area, .chart svg.static .bar { animation: none; }
.chart .bar-col.dim .bar { opacity: .45; }
@keyframes draw { from { stroke-dashoffset: var(--len, 2000); stroke-dasharray: var(--len, 2000); } to { stroke-dashoffset: 0; stroke-dasharray: var(--len, 2000); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); border-radius: 12px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 170px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: 12.5px; opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
.chart-tip.show { opacity: 1; transform: none; }
.chart-tip-title { font-weight: 700; margin-bottom: 6px; }
.chart-tip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 2px 0; }
.chart-tip-row span:first-child { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.chart-tip-row strong { font-variant-numeric: tabular-nums; }
.chart-tip-row.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
.swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 12.5px; font-weight: 600; color: var(--text-2);
}
.legend-item.off { opacity: .45; }
.legend-item.off .swatch { background: var(--muted) !important; }

.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.mini-stat { display: grid; gap: 2px; }
.mini-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.mini-stat strong { font-size: 17px; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: start; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.num { text-align: end; }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .empty-row td { text-align: center; color: var(--muted); padding: 28px 10px; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }
.col-check { width: 36px; }
.col-rank { width: 44px; }
.col-share { min-width: 130px; }
.table input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--wa); }
.doc-link { color: inherit; text-decoration: none; font-weight: 600; }
.doc-link:hover { color: var(--primary); text-decoration: underline; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--paid { background: rgba(16, 185, 129, .12); color: var(--success); }
.pill--unpaid { background: rgba(245, 158, 11, .14); color: #b45309; }
.pill--partly { background: rgba(14, 165, 233, .12); color: #0369a1; }
.pill--canceled { background: var(--surface-3); color: var(--muted); }
.pill--neutral { background: var(--primary-soft); color: var(--primary); }
.pill--sent { background: rgba(31, 174, 87, .12); color: var(--wa-dark); }
.pill--failed { background: rgba(225, 29, 72, .1); color: var(--danger); }
[data-theme="dark"] .pill--unpaid { color: #fbbf24; }
[data-theme="dark"] .pill--partly { color: #7dd3fc; }
[data-theme="dark"] .pill--sent { color: #4ade80; }
.age-pill { color: #fff !important; }
.age-pill::before { background: rgba(255, 255, 255, .8); }

/* ---------- API perf ---------- */
.speed-badge { padding: 5px 11px; border-radius: 999px; font-weight: 800; font-size: 12.5px; background: rgba(16, 185, 129, .12); color: var(--success); font-variant-numeric: tabular-nums; }
.perf-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.perf-item { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; align-items: center; gap: 12px; font-size: 12.5px; }
.perf-route { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: start; }
.perf-route small { color: var(--muted); }
.perf-track { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.perf-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--revenue), var(--cashin)); }
.perf-fill.slow { background: linear-gradient(90deg, var(--warn), var(--orange)); }
.perf-fill.err { background: var(--danger); }
.perf-ms { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 58px; text-align: end; }

/* =========================================================
   CASH FLOW
   ========================================================= */
.stat-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
  padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); display: grid; gap: 4px; border-inline-start: 4px solid var(--primary);
}
.stat--danger { border-inline-start-color: var(--danger); }
.stat--success { border-inline-start-color: var(--success); }
.stat-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.stat strong { font-size: 24px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }

.aging-bar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: var(--surface-3); gap: 2px; }
.aging-seg { height: 100%; transition: width .6s ease, opacity .15s; min-width: 0; }
.aging-buckets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.bucket {
  text-align: start; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2);
  display: grid; gap: 4px; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.bucket:hover { border-color: var(--c); }
.bucket.active { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.bucket-top { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; color: var(--text-2); }
.bucket-top .swatch { background: var(--c); }
.bucket-amount { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.bucket-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

.wa-panel { position: sticky; top: 96px; display: grid; gap: 16px; }
.wa-head { display: flex; gap: 12px; align-items: center; }
.wa-head h2 { font-size: 16px; font-weight: 700; }
.wa-head p { font-size: 12.5px; margin-top: 2px; }
.wa-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(31, 174, 87, .12); color: var(--wa); flex: none; }
.wa-preview { display: grid; gap: 6px; }
.wa-bubble {
  position: relative; padding: 10px 12px; border-radius: 12px 12px 12px 4px; font-size: 13px; line-height: 1.5;
  background: #dcf8c6; color: #111b21; white-space: pre-wrap; word-break: break-word; max-height: 190px; overflow: auto;
}
[dir="rtl"] .wa-bubble { border-radius: 12px 12px 4px 12px; }
[data-theme="dark"] .wa-bubble { background: #005c4b; color: #e9edef; }
.wa-progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.wa-progress span { display: block; height: 100%; width: 0; background: var(--wa); transition: width .25s; }
.wa-status { font-size: 13px; color: var(--muted); min-height: 18px; }
.wa-status.ok { color: var(--success); font-weight: 600; }
.wa-status.err { color: var(--danger); font-weight: 600; }

/* =========================================================
   PRODUCTS
   ========================================================= */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search {
  margin-inline-start: auto; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 38px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); min-width: 240px;
}
.search input { border: 0; outline: none; background: none; flex: 1; height: 100%; color: var(--text); }
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }

.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.podium-card {
  position: relative; overflow: hidden; padding: 18px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); display: grid; gap: 10px;
}
.podium-card::after {
  content: attr(data-rank); position: absolute; inset-inline-end: 14px; top: -14px;
  font-size: 96px; font-weight: 900; line-height: 1; color: var(--medal); opacity: .12; letter-spacing: -.05em;
}
.podium-card.r1 { --medal: #eab308; background: linear-gradient(160deg, color-mix(in srgb, #eab308 10%, var(--surface)), var(--surface) 60%); }
.podium-card.r2 { --medal: #94a3b8; }
.podium-card.r3 { --medal: #c2410c; }
.medal { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: var(--medal); box-shadow: 0 4px 12px color-mix(in srgb, var(--medal) 40%, transparent); }
.podium-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; }
.podium-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.podium-meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.podium-empty { grid-column: 1 / -1; padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.rank-no { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 12px; background: var(--surface-3); color: var(--text-2); }
.rank-no.top { background: var(--primary-soft); color: var(--primary); }
.share-cell { display: flex; align-items: center; gap: 8px; }
.share-track { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 60px; }
.share-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--revenue)); }
.share-pct { font-size: 12px; font-weight: 700; min-width: 40px; text-align: end; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; margin-inline-start: 6px; padding: 1px 7px; border-radius: 6px; font-size: 10.5px; font-weight: 700; vertical-align: 1px; }
.badge--catalog { background: rgba(16, 185, 129, .12); color: var(--success); }
.badge--adhoc { background: var(--surface-3); color: var(--muted); }

.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.donut { width: 150px; height: 150px; }
.donut circle { transition: stroke-dasharray .6s ease; }
.donut-center-value { font-size: 17px; font-weight: 800; fill: var(--text); font-family: var(--font); }
.donut-center-label { font-size: 10px; fill: var(--muted); font-family: var(--font); text-transform: uppercase; letter-spacing: .06em; }
.donut-legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; font-size: 12.5px; min-width: 0; }
.donut-legend li { display: flex; align-items: center; gap: 8px; }
.donut-legend .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.donut-legend .pct { font-weight: 700; font-variant-numeric: tabular-nums; }

.coverage { display: flex; align-items: center; gap: 16px; }
.coverage-ring { width: 76px; height: 76px; flex: none; }
.coverage-text strong { display: block; font-size: 22px; font-weight: 800; }
.coverage-text span { font-size: 12.5px; color: var(--muted); }
.tag-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list li { padding: 4px 10px; border-radius: 8px; background: var(--surface-3); font-size: 12px; color: var(--text-2); }
.tag-list li.muted-item { background: none; padding: 0; color: var(--muted); }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(8, 12, 24, .55); backdrop-filter: blur(4px); animation: fadeIn .15s ease; }
.modal-card { width: 100%; max-width: 420px; padding: 24px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.modal-card h3 { font-size: 18px; font-weight: 800; }
.modal-card p { margin-top: 8px; color: var(--text-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.toast {
  position: fixed; z-index: 110; bottom: 24px; inset-inline-end: 24px; max-width: 360px;
  padding: 12px 16px; border-radius: 12px; background: #0f172a; color: #fff; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: pageIn .2s ease;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1280px) {
  .kpi-grid, .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .aging-buckets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .grid-2, .grid-cash, .grid-products { grid-template-columns: 1fr; }
  .wa-panel { position: static; }
}
@media (max-width: 900px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .brand-mark--mobile { display: flex; }

  .app { display: block; padding-bottom: 72px; }
  .sidebar {
    position: fixed; inset: auto 0 0 0; top: auto; height: 68px; z-index: 50;
    flex-direction: row; align-items: center; padding: 8px 10px; gap: 6px;
  }
  .sidebar-brand, .status-card, .avatar, .user-meta { display: none; }
  .nav { display: flex; flex: 1; gap: 4px; }
  .nav-item { flex: 1; flex-direction: column; gap: 3px; padding: 7px 4px; font-size: 10.5px; text-align: center; }
  .nav-item.active::before { display: none; }
  .nav-badge { position: absolute; top: 2px; inset-inline-end: 18%; margin: 0; height: 17px; min-width: 17px; font-size: 10px; padding: 0 5px; }
  .sidebar-foot { margin: 0; }
  .user-card { background: none; padding: 0; }
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 18px; }
  .topbar-title p, .sync-text { display: none; }
  .notice { margin: 12px 16px 0; }
  .content { padding: 16px 16px 32px; }
  .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .podium { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; margin: 0; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}
@media (max-width: 560px) {
  .kpi-grid, .stat-strip { grid-template-columns: 1fr; }
  .aging-buckets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart--lg { height: 260px; }
  .panel { padding: 16px; }
}
