/* ============================================================================
   STG ANALYTICS — Layout & Components v2 (Stripe-caliber, light)
   ============================================================================ */

#app { height: 100vh; display: flex; overflow: hidden; }

/* ─── Sidebar (light, minimalist) ───────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--side-bg);
  border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column;
  height: 100vh; z-index: 50;
  transition: transform .3s var(--ease);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
}
.sidebar-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: -0.5px;
  flex-shrink: 0;
}
.sidebar-brand-text { line-height: 1.2; }
.sidebar-brand-text b { color: var(--n-900); font-size: 14px; font-weight: 650; letter-spacing: -0.2px; display: block; }
.sidebar-brand-text span { color: var(--side-fg-dim); font-size: 11px; letter-spacing: 0; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-group-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--side-fg-dim);
  padding: 14px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  color: var(--side-fg); font-size: 13.5px; font-weight: 500;
  transition: background .13s, color .13s;
  margin-bottom: 1px; position: relative; width: 100%; text-align: left;
}
.nav-item i { width: 16px; text-align: center; font-size: 13.5px; color: var(--side-fg-dim); transition: color .13s; }
.nav-item:hover { background: var(--n-75); color: var(--n-900); }
.nav-item:hover i { color: var(--n-600); }
.nav-item.active { background: var(--side-active-bg); color: var(--side-active-fg); font-weight: 600; }
.nav-item.active i { color: var(--brand); }
.nav-item .nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--n-100); color: var(--n-500);
  padding: 1px 7px; border-radius: 999px; min-width: 20px; text-align: center;
}
.nav-item.active .nav-badge { background: #fff; color: var(--brand-700); }
.nav-item.danger-badge .nav-badge { background: var(--neg-tint); color: var(--neg); }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--side-border); }
.sidebar-footer .nav-item { font-size: 13px; }

/* ─── Main column ───────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  height: var(--header-h); flex-shrink: 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px; z-index: 30;
}
.topbar-title { font-size: 15px; font-weight: 640; color: var(--n-900); letter-spacing: -0.3px; }
.topbar-sub { font-size: 12px; color: var(--n-400); margin-top: 0px; }
.topbar-spacer { flex: 1; }
.hamburger { display: none; width: 36px; height: 36px; border-radius: 8px; align-items: center; justify-content: center; color: var(--n-600); font-size: 17px; }
.hamburger:hover { background: var(--n-100); }

/* Period selector */
.period-picker {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: 3px 4px 3px 10px;
  position: relative; box-shadow: var(--shadow-xs);
}
.period-picker > i.fa-calendar { color: var(--n-400); font-size: 12px; margin-right: 4px; }
.period-select {
  border: none; background: transparent; font-weight: 600; font-size: 13px;
  color: var(--n-900); cursor: pointer; padding: 5px 2px; appearance: none;
  outline: none; max-width: 150px;
}
.period-nav-btn { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--n-500); font-size: 11px; transition: background .13s; }
.period-nav-btn:hover:not(:disabled) { background: var(--n-100); color: var(--n-800); }
.period-nav-btn:disabled { opacity: .3; cursor: default; }

.content { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.page { max-width: 1200px; margin: 0 auto; padding: 26px 30px 96px; }

/* ─── Page head ─────────────────────────────────────────────────────── */
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.section-title { font-size: 21px; font-weight: 680; color: var(--n-900); letter-spacing: -0.5px; }
.section-sub { font-size: 13px; color: var(--n-500); margin-top: 2px; }
.section-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font-size: 13px; font-weight: 550; border-radius: var(--r-sm);
  padding: 8px 13px; transition: all .13s var(--ease); white-space: nowrap;
  border: 1px solid transparent; line-height: 1;
}
.btn i { font-size: 12px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-primary:active { transform: translateY(0.5px); }
.btn-secondary { background: var(--surface-1); color: var(--n-800); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--n-75); border-color: var(--n-250); }
.btn-ghost { background: transparent; color: var(--n-600); }
.btn-ghost:hover { background: var(--n-100); color: var(--n-900); }
.btn-danger { background: var(--neg); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-danger-soft { background: var(--neg-tint); color: var(--neg); }
.btn-danger-soft:hover { background: var(--neg); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 18px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-icon {
  width: 30px; height: 30px; border-radius: 7px; display: inline-grid; place-items: center;
  color: var(--n-500); transition: all .13s; font-size: 13px;
}
.btn-icon:hover { background: var(--n-100); color: var(--n-900); }
.btn-icon.danger:hover { background: var(--neg-tint); color: var(--neg); }

/* ─── Cards / panels ────────────────────────────────────────────────── */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.stack > * + * { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--border-subtle);
}
.card-head h3 { font-size: 14px; font-weight: 620; color: var(--n-900); letter-spacing: -0.2px; }
.card-head .card-head-sub { font-size: 12px; color: var(--n-400); margin-top: 1px; font-weight: 400; }
.card-head-tools { display: flex; align-items: center; gap: 6px; }
.card-body { padding: 18px 20px; }
.card-body.tight { padding: 8px 20px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3,1fr); }
.grid-4 { grid-template-columns: repeat(4,1fr); }
.grid-5 { grid-template-columns: repeat(5,1fr); }
.col-span-2 { grid-column: span 2; }

/* ─── Metric tiles (uniform KPI grid, Vercel/Stripe style) ──────────── */
.metrics { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); overflow: hidden; }
.metrics.cols-4 { grid-template-columns: repeat(4, 1fr); }
.metrics.cols-3 { grid-template-columns: repeat(3, 1fr); }
.metrics.cols-2 { grid-template-columns: repeat(2, 1fr); }
.metric {
  padding: 16px 18px 18px; border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; min-width: 0; position: relative;
}
.metric:last-child { border-right: none; }
.metric-label {
  font-size: 12px; font-weight: 500; color: var(--n-500);
  display: flex; align-items: center; gap: 6px;
}
.metric-label i { font-size: 11px; color: var(--n-400); }
.metric-value {
  font-size: 24px; font-weight: 660; color: var(--n-900);
  letter-spacing: -0.8px; line-height: 1.15; margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.metric-value.sm { font-size: var(--v-detail); font-weight: 620; letter-spacing: -0.3px; }
.metric-foot { margin-top: 7px; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--n-400); flex-wrap: wrap; }
.metric-spark { margin-top: auto; padding-top: 12px; height: 34px; position: relative; }

/* ─── Value hierarchy: hero / support / detail ───────────────────────────
   Applied via modifier classes so the same .metric grid can carry weight. */

/* HERO — the single dominant number of a screen. Spans wider, big type. */
.metric.hero { padding: 22px 24px 24px; }
.metric.hero .metric-label { font-size: 12px; color: var(--n-500); }
.metric.hero .metric-value { font-size: var(--v-hero); font-weight: 680; letter-spacing: -1.6px; margin-top: 10px; }
.metric.hero .metric-foot { margin-top: 10px; font-size: 12.5px; }

/* SUPPORT — secondary metrics, clearly smaller than hero. */
.metric.support .metric-value { font-size: var(--v-support); font-weight: 640; letter-spacing: -0.6px; }

/* DETAIL / MUTED — tertiary metrics recede: neutral ink, quieter label. */
.metric.muted { background: var(--surface-2); }
.metric.muted .metric-label { color: var(--n-400); font-weight: 500; }
.metric.muted .metric-label i { color: var(--n-300); }
.metric.muted .metric-value { font-size: var(--v-detail); font-weight: 600; color: var(--n-700); letter-spacing: -0.3px; }
.metric.muted .metric-foot { color: var(--n-400); }

/* A metrics container that carries a hero as its first, wider column. */
.metrics.hero-split { grid-template-columns: 1.6fr 1fr 1fr 1fr; }
.metrics.hero-split-3 { grid-template-columns: 1.7fr 1fr 1fr; }

/* Label used to introduce a group of muted detail metrics. */
.group-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--n-400); margin: 22px 0 9px 2px;
}

/* Section group: a band of related panels sitting on a recessed surface,
   giving separation between topics without more borders. */
.section-group { margin-top: 26px; }
.section-group + .section-group { margin-top: 30px; }

/* delta pill */
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--pos); }
.delta.down { color: var(--neg); }
.delta.flat { color: var(--n-400); }
.delta i { font-size: 9px; }

/* standalone stat (used inside panels) */
.stat-row { display: grid; gap: 1px; }
.stat { padding: 14px 0; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.stat:last-child { border-bottom: none; }
.stat-k { font-size: 13px; color: var(--n-600); }
.stat-v { font-size: 14px; font-weight: 620; color: var(--n-900); font-variant-numeric: tabular-nums; }

/* ─── Ledger (DRE / breakdown lines) ────────────────────────────────── */
.ledger { display: flex; flex-direction: column; }
.ledger-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.ledger-line:last-child { border-bottom: none; }
.ledger-k { color: var(--n-600); display: flex; align-items: center; gap: 9px; }
/* Operator sign is a quiet monochrome glyph, not a colored chip — less noise. */
.ledger-op { display: inline-block; width: 12px; text-align: center; font-size: 12px; font-weight: 600; color: var(--n-300); }
.ledger-op.plus { color: var(--pos); }
.ledger-op.eq { color: var(--n-900); }
.ledger-v { font-weight: 550; font-variant-numeric: tabular-nums; color: var(--n-700); }
/* Expense (subtraction) lines recede — they are supporting detail. */
.ledger-line.expense .ledger-k { color: var(--n-500); }
.ledger-line.expense .ledger-v { color: var(--n-500); font-weight: 500; }
.ledger-total { border-top: 1.5px solid var(--border-strong); margin-top: 6px; padding-top: 14px; }
.ledger-total .ledger-k { font-weight: 660; color: var(--n-900); font-size: 14.5px; }
.ledger-total .ledger-v { font-size: 18px; font-weight: 680; letter-spacing: -0.4px; }

/* ─── Rank list (clean, no colored numbers) ─────────────────────────── */
.rank { display: flex; flex-direction: column; }
.rank-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-subtle); }
.rank-item:last-child { border-bottom: none; }
.rank-idx { width: 20px; font-size: 12px; font-weight: 600; color: var(--n-300); text-align: center; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.rank-body { flex: 1; min-width: 0; }
.rank-name { font-size: 13px; font-weight: 520; color: var(--n-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar { height: 3px; border-radius: 999px; background: var(--n-100); margin-top: 7px; overflow: hidden; }
.rank-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--n-250); }
/* Only the leader gets the brand accent — draws the eye to #1. */
.rank-item:first-child .rank-bar > span { background: var(--brand); }
.rank-item:first-child .rank-name { font-weight: 600; color: var(--n-900); }
.rank-val { text-align: right; flex-shrink: 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--n-800); white-space: nowrap; }
.rank-val small { display: block; font-size: 11px; font-weight: 400; color: var(--n-400); }

/* ─── Distribution rows (Vercel-style proportion bars) ──────────────── */
.dist { display: flex; flex-direction: column; gap: 14px; }
.dist-row { display: flex; flex-direction: column; gap: 6px; }
.dist-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dist-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--n-700); font-weight: 500; }
.dist-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.dist-val { font-size: 13px; font-weight: 620; color: var(--n-900); font-variant-numeric: tabular-nums; }
.dist-val small { color: var(--n-400); font-weight: 400; margin-left: 5px; }
.dist-track { height: 6px; border-radius: 999px; background: var(--n-100); overflow: hidden; }
.dist-track > span { display: block; height: 100%; border-radius: 999px; transition: width .5s var(--ease); }

/* ─── Tables ────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--n-400); padding: 10px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
.data-table thead th.num { text-align: right; }
.data-table th.sortable { cursor: pointer; user-select: none; transition: color .13s; }
.data-table th.sortable:hover { color: var(--n-600); }
.data-table th.sortable .sort-ind { margin-left: 4px; opacity: .6; font-size: 9px; }
.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-subtle); color: var(--n-700); vertical-align: middle; }
.data-table tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot td { padding: 12px 14px; font-weight: 640; color: var(--n-900); border-top: 1.5px solid var(--border-strong); background: var(--surface-2); font-variant-numeric: tabular-nums; }
.data-table tfoot td.num { text-align: right; }
.cell-strong { font-weight: 560; color: var(--n-900); }
.cell-dim { color: var(--n-400); }
.cell-mono { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 1px; justify-content: flex-end; }

/* ─── Badges / status ───────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 550;
  padding: 2px 8px; border-radius: var(--r-full); border: 1px solid transparent;
}
.tag-dot { width: 6px; height: 6px; border-radius: 50%; }
.tag.neutral { background: var(--n-75); color: var(--n-600); border-color: var(--border); }
.tag.brand { background: var(--brand-tint); color: var(--brand-700); }
.tag.pos { background: var(--pos-tint); color: var(--pos); }
.tag.neg { background: var(--neg-tint); color: var(--neg); }
.tag.warn { background: var(--warn-tint); color: var(--warn); }
.tag.info { background: var(--info-tint); color: var(--info); }
.tag-hint { font-size: 10px; font-weight: 600; color: var(--n-400); background: var(--n-100); padding: 1px 6px; border-radius: 5px; margin-left: 6px; }

/* ─── Toolbar (search / filter / segmented) ─────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search-box i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--n-400); font-size: 12px; pointer-events: none; }
.search-box input {
  width: 100%; padding: 8px 12px 8px 32px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: var(--surface-1); font-size: 13px; outline: none;
  transition: border .13s, box-shadow .13s;
}
.search-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.filter-select {
  padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface-1); font-size: 13px; font-weight: 500; color: var(--n-700); cursor: pointer; outline: none;
}
.filter-select:focus { border-color: var(--brand); }
.tool-spacer { flex: 1; }

/* segmented control */
.segmented { display: inline-flex; padding: 2px; background: var(--n-100); border-radius: var(--r-sm); gap: 2px; }
.segmented button { padding: 6px 12px; border-radius: 5px; font-size: 12.5px; font-weight: 550; color: var(--n-500); transition: all .13s; }
.segmented button.active { background: var(--surface-1); color: var(--n-900); box-shadow: var(--shadow-xs); }
.segmented button:not(.active):hover { color: var(--n-800); }

/* ─── Chart box ─────────────────────────────────────────────────────── */
.chart-box { position: relative; }

/* ─── Empty state ───────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 52px 24px; color: var(--n-400); }
.empty-state .es-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--n-75); border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto 16px; font-size: 18px; color: var(--n-300); }
.empty-state h4 { font-size: 15px; font-weight: 620; color: var(--n-700); margin-bottom: 5px; }
.empty-state p { font-size: 13px; max-width: 340px; margin: 0 auto 18px; color: var(--n-500); }

/* ─── Toggle switch ─────────────────────────────────────────────────── */
.stg-toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; color: var(--n-600); font-weight: 500; user-select: none; }
.stg-toggle input { display: none; }
.stg-toggle .track { width: 38px; height: 22px; border-radius: 999px; background: var(--n-200); position: relative; transition: background .18s; flex-shrink: 0; }
.stg-toggle .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .18s var(--ease); }
.stg-toggle input:checked + .track { background: var(--brand); }
.stg-toggle input:checked + .track::after { transform: translateX(16px); }

/* ─── Utilities ─────────────────────────────────────────────────────── */
.text-pos   { color: var(--pos) !important; }
.text-neg   { color: var(--neg) !important; }
.text-brand { color: var(--brand-700) !important; }
.text-dim   { color: var(--n-400) !important; }
.money { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0 !important; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border-subtle); margin: 4px 0; }
