/* ==========================================================================
   BP Family Investment Office — Design System
   Foundation stylesheet. Every page inherits from this file.
   Theme: Professional financial — dark sidebar, light content, blue/teal accents
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand — deep navy sidebar, teal accent */
  --brand-900: #0b1a2b;
  --brand-800: #10263d;
  --brand-700: #16334f;
  --brand-600: #1d4266;
  --brand-500: #2563a8;
  --brand-400: #3b82c4;
  --brand-300: #6ba3d6;

  /* Accent — teal */
  --accent-700: #0f766e;
  --accent-600: #0d9488;
  --accent-500: #14b8a6;
  --accent-400: #2dd4bf;
  --accent-100: #ccfbf1;

  /* Semantic — financial */
  --gain-700: #15803d;
  --gain-600: #16a34a;
  --gain-100: #dcfce7;
  --loss-700: #b91c1c;
  --loss-600: #dc2626;
  --loss-100: #fee2e2;
  --warn-700: #b45309;
  --warn-600: #d97706;
  --warn-100: #fef3c7;
  --info-700: #1d4ed8;
  --info-100: #dbeafe;

  /* Neutrals */
  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;
  --ink-50:  #f8fafc;
  --white:   #ffffff;

  /* Surfaces */
  --bg-app: #f4f6f9;
  --bg-surface: var(--white);
  --bg-sidebar: var(--brand-900);
  --bg-sidebar-hover: var(--brand-800);
  --bg-sidebar-active: var(--brand-700);
  --bg-subtle: var(--ink-50);
  --bg-header: var(--white);

  /* Borders */
  --border: var(--ink-200);
  --border-strong: var(--ink-300);
  --border-sidebar: rgba(255, 255, 255, 0.08);

  /* Text */
  --text-primary: var(--ink-900);
  --text-secondary: var(--ink-600);
  --text-muted: var(--ink-500);
  --text-faint: var(--ink-400);
  --text-on-dark: #e8eef5;
  --text-on-dark-muted: #8fa6bd;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas,
               "Liberation Mono", monospace;

  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 26px;
  --fs-3xl: 32px;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-full: 999px;

  /* Shadow */
  --sh-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --sh-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --sh-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --sh-lg: 0 12px 28px rgba(15, 23, 42, 0.12);

  /* Layout */
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 60px;
  --header-h: 56px;
  --content-max: 1600px;

  /* Motion */
  --t-fast: 120ms ease;
  --t-base: 200ms ease;
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }
input, select, textarea { font: inherit; color: inherit; }

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--t-base);
}

/* --- Collapsible groups --- */
.nav-group { display: flex; flex-direction: column; }

.nav-group__toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-on-dark-muted);
  transition: color var(--t-fast);
  text-align: left;
}

.nav-group__toggle:hover { color: var(--text-on-dark); }

.nav-group__chevron {
  width: 11px;
  height: 11px;
  margin-left: auto;
  transition: transform var(--t-base);
  flex-shrink: 0;
}

.nav-group.is-collapsed .nav-group__chevron { transform: rotate(-90deg); }

.nav-group__items {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  overflow: hidden;
  transition: max-height var(--t-base), opacity var(--t-fast);
  max-height: 600px;
  opacity: 1;
}

.nav-group.is-collapsed .nav-group__items {
  max-height: 0;
  opacity: 0;
}

.nav-group__count {
  font-size: 10px;
  font-weight: var(--fw-semibold);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-on-dark-muted);
  padding: 0 5px;
  border-radius: var(--r-full);
  line-height: 15px;
}

/* --- Sidebar collapse (whole menu) --- */
.sidebar__collapse {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-3);
  border-top: 1px solid var(--border-sidebar);
  font-size: var(--fs-xs);
  color: var(--text-on-dark-muted);
  transition: color var(--t-fast), background var(--t-fast);
}

.sidebar__collapse:hover {
  color: var(--text-on-dark);
  background: var(--bg-sidebar-hover);
}

.sidebar__collapse svg { width: 14px; height: 14px; transition: transform var(--t-base); }

/* Collapsed state — icons only, narrow rail */
.app.is-sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.app.is-sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.app.is-sidebar-collapsed .sidebar__title,
.app.is-sidebar-collapsed .sidebar__subtitle,
.app.is-sidebar-collapsed .nav-item span,
.app.is-sidebar-collapsed .nav-group__toggle span,
.app.is-sidebar-collapsed .nav-group__chevron,
.app.is-sidebar-collapsed .nav-group__count,
.app.is-sidebar-collapsed .sidebar__footer,
.app.is-sidebar-collapsed .sidebar__collapse span { display: none; }

.app.is-sidebar-collapsed .nav-group__toggle {
  padding: var(--sp-3) 0;
  justify-content: center;
  height: 1px;
  overflow: hidden;
}

.app.is-sidebar-collapsed .nav-group__items {
  max-height: 600px !important;
  opacity: 1 !important;
}

.app.is-sidebar-collapsed .nav-item {
  justify-content: center;
  padding: var(--sp-2);
}

.app.is-sidebar-collapsed .nav-item__badge {
  position: absolute;
  top: 2px;
  right: 4px;
  margin: 0;
  font-size: 9px;
  padding: 0 4px;
}

.app.is-sidebar-collapsed .sidebar__brand { justify-content: center; padding: var(--sp-4) var(--sp-2); }
.app.is-sidebar-collapsed .sidebar__collapse svg { transform: rotate(180deg); }

/* Tooltip on collapsed items */
.app.is-sidebar-collapsed .nav-item { position: relative; }

.app.is-sidebar-collapsed .nav-item::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--ink-900);
  color: var(--white);
  font-size: var(--fs-sm);
  padding: 4px var(--sp-3);
  border-radius: var(--r-md);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast);
  z-index: 100;
  box-shadow: var(--sh-md);
}

.app.is-sidebar-collapsed .nav-item:hover::after { opacity: 1; }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border-sidebar);
  min-height: var(--header-h);
}

.sidebar__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent-500), var(--brand-500));
  display: grid;
  place-items: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  color: var(--white);
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.sidebar__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  color: var(--white);
}

.sidebar__subtitle {
  font-size: var(--fs-xs);
  color: var(--text-on-dark-muted);
  line-height: 1.3;
}

.sidebar__nav {
  flex: 1;
  padding: var(--sp-4) var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.sidebar__section {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-on-dark-muted);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  color: var(--text-on-dark);
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}

.nav-item:hover { background: var(--bg-sidebar-hover); }

.nav-item.is-active {
  background: var(--bg-sidebar-active);
  color: var(--white);
  font-weight: var(--fw-medium);
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--accent-500);
}

.nav-item__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item.is-active .nav-item__icon { opacity: 1; }

.nav-item__badge {
  margin-left: auto;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--accent-600);
  color: var(--white);
}

.sidebar__footer {
  padding: var(--sp-4);
  border-top: 1px solid var(--border-sidebar);
  font-size: var(--fs-xs);
  color: var(--text-on-dark-muted);
}

/* --- Main --- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* --- Header --- */
.header {
  height: var(--header-h);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
}

.header__breadcrumb {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.header__spacer { flex: 1; }

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* --- Content --- */
.content {
  padding: var(--sp-6);
  max-width: var(--content-max);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

/* The `hidden` attribute must win over `display: flex` */
.content[hidden] { display: none; }

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-primary);
  transition: all var(--t-fast);
  white-space: nowrap;
}

.btn:hover { background: var(--ink-50); border-color: var(--border-strong); }

.btn--primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: var(--white);
}
.btn--primary:hover { background: var(--brand-700); border-color: var(--brand-700); }

.btn--accent {
  background: var(--accent-600);
  border-color: var(--accent-600);
  color: var(--white);
}
.btn--accent:hover { background: var(--accent-700); border-color: var(--accent-700); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--ink-100); border-color: transparent; }

.btn--sm { padding: 4px var(--sp-2); font-size: var(--fs-sm); }

.btn__icon { width: 14px; height: 14px; }

/* --- Segmented control --- */
.segmented {
  display: inline-flex;
  background: var(--ink-100);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
}

.segmented__item {
  padding: 5px var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  transition: all var(--t-fast);
}

.segmented__item:hover { color: var(--text-primary); }

.segmented__item.is-active {
  background: var(--white);
  color: var(--text-primary);
  box-shadow: var(--sh-xs);
}

/* --- Cards --- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  overflow: visible;
}

/* Cards that contain a scrolling table need clipping for the rounded corners */
.card--clip { overflow: hidden; }

/* The card body that holds a flush table clips its own corners */
.card__body--flush {
  padding: 0;
  border-bottom-left-radius: var(--r-lg);
  border-bottom-right-radius: var(--r-lg);
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
}

.card__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 1px;
}

.card__actions { margin-left: auto; display: flex; gap: var(--sp-2); align-items: center; }
.card__body { padding: var(--sp-5); }

/* --- KPI tiles --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--sp-4);
}

.kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--sh-xs);
  position: relative;
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--ink-300);
}

.kpi--brand::after { background: var(--brand-500); }
.kpi--accent::after { background: var(--accent-500); }
.kpi--gain::after { background: var(--gain-600); }
.kpi--loss::after { background: var(--loss-600); }
.kpi--warn::after { background: var(--warn-600); }

.kpi__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.kpi__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.02em;
  margin-top: var(--sp-2);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  flex-wrap: wrap;
}

.kpi__meta .delta { margin-right: var(--sp-1); }

.kpi__currency {
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  margin-right: 2px;
}

/* --- Delta / change indicators --- */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}

.delta--up { color: var(--gain-700); }
.delta--down { color: var(--loss-700); }
.delta--flat { color: var(--text-muted); }

.delta__arrow { font-size: 9px; line-height: 1; }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge--neutral { background: var(--ink-100); color: var(--ink-700); }
.badge--gain    { background: var(--gain-100); color: var(--gain-700); }
.badge--loss    { background: var(--loss-100); color: var(--loss-700); }
.badge--warn    { background: var(--warn-100); color: var(--warn-700); }
.badge--info    { background: var(--info-100); color: var(--info-700); }
.badge--accent  { background: var(--accent-100); color: var(--accent-700); }

.badge__dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}

/* --- Tables --- */
.table-wrap { overflow-x: auto; }

.table {
  font-size: var(--fs-base);
  font-variant-numeric: tabular-nums;
}

.table thead th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--ink-100);
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--ink-50); }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .mono { font-family: var(--font-mono); font-size: var(--fs-sm); }

.table__symbol {
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.table__name {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.table tfoot td {
  padding: var(--sp-3) var(--sp-4);
  border-top: 2px solid var(--border-strong);
  font-weight: var(--fw-semibold);
  background: var(--bg-subtle);
}

/* --- Grouped header (two stapled sheets) --- */
.table thead tr.table__group th {
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--white);
  background: var(--brand-700);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--brand-600);
  border-right: 2px solid var(--white);
  position: sticky;
  top: 0;
}

.table thead tr.table__group th:last-child { border-right: none; }

.table thead tr.table__group th.group--b { background: var(--accent-700); border-bottom-color: var(--accent-600); }

/* Second header row sits below the group row */
.table thead tr.table__cols th { top: 30px; }

/* Vertical divider between the two sheets */
.table .sheet-divide { border-left: 2px solid var(--border-strong); }

/* --- Sticky first column (wide tables) --- */
.table--sticky-first th:first-child,
.table--sticky-first td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-surface);
  box-shadow: 1px 0 0 var(--border);
}

.table--sticky-first thead th:first-child {
  z-index: 4;
  background: var(--bg-subtle);
}

.table--sticky-first tbody tr:hover td:first-child { background: var(--ink-50); }
.table--sticky-first tfoot td:first-child { background: var(--bg-subtle); }

/* --- Progress / allocation bars --- */
.bar {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--ink-100);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--brand-500);
  transition: width var(--t-base);
}

.bar__fill--accent { background: var(--accent-500); }
.bar__fill--gain { background: var(--gain-600); }
.bar__fill--loss { background: var(--loss-600); }
.bar__fill--warn { background: var(--warn-600); }

/* --- Allocation list --- */
.alloc { display: flex; flex-direction: column; gap: var(--sp-4); }

.alloc__row { display: flex; flex-direction: column; gap: var(--sp-2); }

.alloc__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
}

.alloc__label {
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.alloc__swatch {
  width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0;
}

.alloc__value {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}

.alloc__pct {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

/* --- Ownership dimension chips --- */
.dims { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.dim {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-subtle);
  min-width: 0;
}

.dim__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.dim__value {
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dim--diff { border-color: var(--warn-600); background: var(--warn-100); }
.dim--diff .dim__label { color: var(--warn-700); }

/* --- Sparkline / chart placeholder --- */
.chart {
  width: 100%;
  height: 220px;
  position: relative;
}

.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }

.chart__grid line { stroke: var(--ink-200); stroke-width: 1; }
.chart__axis text {
  font-size: var(--fs-xs);
  fill: var(--text-faint);
  font-family: var(--font-sans);
}
.chart__area { fill: url(#areaGradient); }
.chart__line { fill: none; stroke: var(--brand-500); stroke-width: 2; stroke-linejoin: round; }
.chart__dot { fill: var(--white); stroke: var(--brand-500); stroke-width: 2; }

/* --- Legend --- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.legend__item { display: flex; align-items: center; gap: var(--sp-2); }
.legend__swatch { width: 10px; height: 10px; border-radius: 2px; }

/* --- Notice / callout --- */
.notice {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  align-items: flex-start;
}

.notice--warn { background: var(--warn-100); border-color: var(--warn-600); color: var(--warn-700); }
.notice--info { background: var(--info-100); border-color: var(--info-700); color: var(--info-700); }
.notice--accent { background: var(--accent-100); border-color: var(--accent-600); color: var(--accent-700); }

.notice__icon { flex-shrink: 0; width: 15px; height: 15px; margin-top: 1px; }
.notice strong { font-weight: var(--fw-semibold); }

/* --- Grids ---
   minmax(0, …) is essential: without it, a grid child with a wide table
   forces the column wider than its share and the card overflows the page. */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-5); }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--sp-5); }
.grid-1-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: var(--sp-5); }

/* Grid children must be allowed to shrink below their content width */
.grid-2 > *, .grid-3 > *, .grid-2-1 > *, .grid-1-2 > * { min-width: 0; }

/* --- Utility --- */
.u-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.u-num { font-variant-numeric: tabular-nums; }
.u-right { text-align: right; }
.u-muted { color: var(--text-muted); }
.u-sm { font-size: var(--fs-sm); }
.u-xs { font-size: var(--fs-xs); }
.u-semibold { font-weight: var(--fw-semibold); }
.u-gain { color: var(--gain-700); }
.u-loss { color: var(--loss-700); }
.u-warn { color: var(--warn-700); }
.u-nowrap { white-space: nowrap; }
.u-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-flex { display: flex; align-items: center; gap: var(--sp-2); }
.u-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.u-stack { display: flex; flex-direction: column; gap: var(--sp-1); }
.u-mt-2 { margin-top: var(--sp-2); }
.u-mt-4 { margin-top: var(--sp-4); }

/* --- Mockup banner --- */
.mock-banner {
  background: linear-gradient(90deg, var(--brand-800), var(--brand-600));
  color: var(--white);
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-6);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.mock-banner__tag {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.18);
  padding: 2px 8px;
  border-radius: var(--r-sm);
}

/* --------------------------------------------------------------------------
   4a. User menu (header)
   -------------------------------------------------------------------------- */
.user {
  position: relative;
}

.user__trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-2) 4px 4px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--white);
  transition: all var(--t-fast);
}

.user__trigger:hover { background: var(--ink-50); border-color: var(--border-strong); }

.user__avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-600), var(--accent-600));
  color: var(--white);
  display: grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.user__name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user__caret { width: 12px; height: 12px; color: var(--text-muted); flex-shrink: 0; }

.user__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 250px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: var(--sp-2);
  z-index: 60;
  display: none;
}

.user__menu.is-open { display: block; }

.user__menu-head {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-2);
}

.user__menu-name { font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.user__menu-meta { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }

.user__menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  color: var(--text-primary);
  text-align: left;
  transition: background var(--t-fast);
}

.user__menu-item:hover { background: var(--ink-100); }
.user__menu-item svg { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.user__menu-item--danger { color: var(--loss-700); }
.user__menu-item--danger svg { color: var(--loss-600); }

.user__menu-sep { height: 1px; background: var(--border); margin: var(--sp-2) 0; }

/* --------------------------------------------------------------------------
   4b. Account selector (multi-select)
   -------------------------------------------------------------------------- */
.acct-select { position: relative; }

.acct-select__trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--white);
  min-width: 300px;
  transition: all var(--t-fast);
  text-align: left;
}

.acct-select__trigger:hover { border-color: var(--border-strong); background: var(--ink-50); }
.acct-select__trigger.is-open { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.12); }

.acct-select__icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

.acct-select__body { flex: 1; min-width: 0; }

.acct-select__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  line-height: 1.2;
}

.acct-select__value {
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.acct-select__count {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  background: var(--brand-500);
  color: var(--white);
  padding: 1px 7px;
  border-radius: var(--r-full);
  flex-shrink: 0;
}

.acct-select__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 420px;
  max-width: 520px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  z-index: 60;
  display: none;
  overflow: hidden;
}

.acct-select__panel.is-open { display: block; }

.acct-select__panel-head {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-subtle);
}

.acct-select__search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 5px var(--sp-3);
}

.acct-select__search svg { width: 14px; height: 14px; color: var(--text-faint); flex-shrink: 0; }

.acct-select__search input {
  border: none;
  outline: none;
  background: none;
  width: 100%;
  font-size: var(--fs-base);
}

.acct-select__list {
  max-height: 340px;
  overflow-y: auto;
  padding: var(--sp-2);
}

.acct-select__group {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
}

.acct-option {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast);
  border: 1px solid transparent;
}

.acct-option:hover { background: var(--ink-50); }
.acct-option.is-selected { background: var(--accent-100); border-color: var(--accent-500); }

.acct-option__check {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm);
  flex-shrink: 0;
  margin-top: 2px;
  display: grid;
  place-items: center;
  background: var(--white);
  transition: all var(--t-fast);
}

.acct-option.is-selected .acct-option__check {
  background: var(--accent-600);
  border-color: var(--accent-600);
}

.acct-option__check svg { width: 11px; height: 11px; color: var(--white); opacity: 0; }
.acct-option.is-selected .acct-option__check svg { opacity: 1; }

.acct-option__body { flex: 1; min-width: 0; }

.acct-option__top {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.acct-option__name { font-weight: var(--fw-medium); font-size: var(--fs-base); }

.acct-option__meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.acct-option__dims {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin-top: 3px;
}

.acct-select__panel-foot {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-subtle);
}

.acct-select__panel-foot .u-muted { font-size: var(--fs-sm); }

/* --- Selected account chips (below the selector) --- */
.acct-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.acct-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 3px var(--sp-2) 3px var(--sp-3);
  border-radius: var(--r-full);
  background: var(--brand-500);
  color: var(--white);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.acct-chip__x {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.22);
  font-size: 11px;
  line-height: 1;
  transition: background var(--t-fast);
}

.acct-chip__x:hover { background: rgba(255, 255, 255, 0.4); }

.acct-chip--all { background: var(--accent-600); }

/* --------------------------------------------------------------------------
   4c. Date range picker
   -------------------------------------------------------------------------- */
.daterange { position: relative; }

.daterange__trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--white);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: all var(--t-fast);
  white-space: nowrap;
}

.daterange__trigger:hover { background: var(--ink-50); border-color: var(--border-strong); }
.daterange__trigger.is-open { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.12); }
.daterange__trigger svg { width: 14px; height: 14px; color: var(--text-muted); }

.daterange__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 300px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: var(--sp-4);
  z-index: 60;
  display: none;
}

.daterange__panel.is-open { display: block; }

.daterange__presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.daterange__preset {
  padding: 6px var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-align: center;
  transition: all var(--t-fast);
}

.daterange__preset:hover { background: var(--ink-50); border-color: var(--border-strong); }

.daterange__preset.is-active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: var(--white);
}

.daterange__divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

.daterange__divider::before,
.daterange__divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.daterange__fields { display: flex; flex-direction: column; gap: var(--sp-3); }

.daterange__field { display: flex; flex-direction: column; gap: 4px; }

.daterange__field label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.daterange__field input {
  padding: 6px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  outline: none;
  transition: border-color var(--t-fast);
}

.daterange__field input:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.12);
}

.daterange__actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.daterange__actions .btn { flex: 1; justify-content: center; }

.daterange__summary {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  text-align: center;
}

/* --------------------------------------------------------------------------
   4d. Card toolbar (search + expand)
   -------------------------------------------------------------------------- */
.card__toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.card__search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px var(--sp-3);
  min-width: 180px;
  transition: all var(--t-fast);
}

.card__search:focus-within {
  border-color: var(--brand-500);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.12);
}

.card__search svg { width: 13px; height: 13px; color: var(--text-faint); flex-shrink: 0; }

.card__search input {
  border: none;
  outline: none;
  background: none;
  width: 100%;
  font-size: var(--fs-sm);
}

.card__search input::placeholder { color: var(--text-faint); }

.card__icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all var(--t-fast);
  flex-shrink: 0;
}

.card__icon-btn:hover {
  background: var(--ink-100);
  color: var(--text-primary);
  border-color: var(--border);
}

.card__icon-btn svg { width: 15px; height: 15px; }

/* --- Fullscreen card --- */
.card.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
  box-shadow: none;
}

.card.is-fullscreen .card__body {
  flex: 1;
  overflow: auto;
}

.card.is-fullscreen .table-wrap { max-height: none; }

.card.is-fullscreen .chart { height: 60vh; }

.card-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 199;
  display: none;
}

.card-backdrop.is-open { display: block; }

/* --- Table scroll container ---
   The container is the sticky context, so the header sticks to the top of
   the card body — not to the viewport. Without this the header escapes the
   card and collides with the page header on scroll. */
.table-scroll {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
  position: relative;
}

.table-scroll .table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  box-shadow: inset 0 -1px 0 var(--border);
}

/* Grouped header row (if used) sits above the column row */
.table-scroll .table thead tr.table__group th { z-index: 3; }
.table-scroll .table thead tr.table__cols th { top: 0; }

/* --- Empty state --- */
.empty {
  padding: var(--sp-10) var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-base);
}

.empty svg { width: 32px; height: 32px; margin-bottom: var(--sp-3); color: var(--text-faint); }

/* --------------------------------------------------------------------------
   4e. Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

/* Page-level tab strip sits directly under the header */
.page-tabs {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  position: sticky;
  top: var(--header-h);
  z-index: 15;
}

.page-tabs .tabs { border-bottom: none; }

.tab {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all var(--t-fast);
  margin-bottom: -1px;
}

.tab:hover { color: var(--text-primary); }

.tab.is-active {
  color: var(--brand-600);
  border-bottom-color: var(--brand-600);
  font-weight: var(--fw-semibold);
}

.tab__count {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  background: var(--ink-100);
  color: var(--ink-700);
  padding: 1px 6px;
  border-radius: var(--r-full);
  margin-left: var(--sp-2);
}

.tab.is-active .tab__count { background: var(--brand-500); color: var(--white); }

/* --------------------------------------------------------------------------
   4f. Document source strip
   -------------------------------------------------------------------------- */
.doc-source {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.doc-source svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

.doc-source__name { font-weight: var(--fw-medium); color: var(--text-primary); }

.doc-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-4);
}

.doc-meta__item { display: flex; flex-direction: column; gap: 2px; }

.doc-meta__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.doc-meta__value { font-size: var(--fs-md); font-weight: var(--fw-medium); }

/* --- Insight cards --- */
.insight {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
}

.insight__icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.insight__icon svg { width: 16px; height: 16px; }

.insight--warn { background: var(--warn-100); border-color: var(--warn-600); }
.insight--warn .insight__icon { background: var(--warn-600); color: var(--white); }
.insight--gain { background: var(--gain-100); border-color: var(--gain-600); }
.insight--gain .insight__icon { background: var(--gain-600); color: var(--white); }
.insight--loss { background: var(--loss-100); border-color: var(--loss-600); }
.insight--loss .insight__icon { background: var(--loss-600); color: var(--white); }
.insight--info { background: var(--info-100); border-color: var(--info-700); }
.insight--info .insight__icon { background: var(--info-700); color: var(--white); }

.insight__title { font-weight: var(--fw-semibold); font-size: var(--fs-base); }
.insight__text { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 2px; }

/* --- Lot table emphasis --- */
.lot-dup { background: var(--warn-100) !important; }
.lot-loss { color: var(--loss-700); }
.lot-gain { color: var(--gain-700); }

/* --------------------------------------------------------------------------
   5. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  .sidebar__title, .sidebar__subtitle, .nav-item span, .sidebar__section,
  .sidebar__footer { display: none; }
  .nav-item { justify-content: center; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: var(--sp-4); }
}

/* --------------------------------------------------------------------------
   5a. Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  :root {
    --header-h: auto;
    --fs-2xl: 22px;
    --fs-3xl: 26px;
  }

  /* Sidebar becomes a bottom bar */
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 100;
    border-top: 1px solid var(--border-sidebar);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .sidebar__brand,
  .sidebar__section,
  .sidebar__footer { display: none; }

  .sidebar__nav {
    flex-direction: row;
    padding: var(--sp-2);
    gap: var(--sp-1);
    width: 100%;
    justify-content: space-around;
  }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-2) var(--sp-3);
    font-size: 10px;
    min-width: 56px;
    text-align: center;
  }

  .nav-item span { display: block; font-size: 10px; line-height: 1.1; }
  .nav-item.is-active::before { display: none; }
  .nav-item__badge { position: absolute; top: 2px; right: 6px; margin: 0; }
  .nav-item__icon { width: 18px; height: 18px; }

  /* Main gets bottom padding for the nav bar */
  .main { padding-bottom: 68px; }

  /* Header stacks */
  .header {
    flex-wrap: wrap;
    height: auto;
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-3);
  }

  .header__title { font-size: var(--fs-md); }
  .header__breadcrumb { font-size: var(--fs-xs); }
  .header__spacer { display: none; }
  .header__actions { width: 100%; flex-wrap: wrap; gap: var(--sp-2); }

  .user__name { display: none; }
  .user__trigger { padding: 4px; }

  /* Content */
  .content { padding: var(--sp-3); gap: var(--sp-3); }

  /* Cards */
  .card__header { padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
  .card__body { padding: var(--sp-4); }
  .card__toolbar { width: 100%; margin-left: 0; margin-top: var(--sp-2); }
  .card__search { min-width: 0; flex: 1; }

  /* KPIs — two per row */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .kpi { padding: var(--sp-3) var(--sp-4); }
  .kpi__value { font-size: var(--fs-xl); }
  .kpi__label { font-size: 10px; }

  /* Account selector full width */
  .acct-select { width: 100%; }
  .acct-select__trigger { min-width: 0; width: 100%; }
  .acct-select__panel {
    min-width: 0;
    width: calc(100vw - var(--sp-6));
    max-width: none;
    left: 0;
  }

  /* Date range panel full width */
  .daterange__panel { width: calc(100vw - var(--sp-6)); right: auto; left: 0; }

  /* User menu */
  .user__menu { min-width: 0; width: calc(100vw - var(--sp-6)); right: 0; }

  /* Tables scroll horizontally */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: var(--fs-sm); }
  .table thead th, .table tbody td { padding: var(--sp-2) var(--sp-3); }

  /* Ownership dims stack */
  .dims { width: 100%; }
  .dim { flex: 1 1 calc(50% - var(--sp-2)); min-width: 0; }

  /* Charts shorter */
  .chart { height: 180px; }

  /* Fullscreen card on mobile */
  .card.is-fullscreen .chart { height: 40vh; }

  /* Tabs scroll */
  .tab { padding: var(--sp-3); font-size: var(--fs-sm); }

  /* Doc meta single column */
  .doc-meta { grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

  /* Mock banner */
  .mock-banner { padding: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); }

  /* A filter built from the data can be wider than the screen. Wrap it rather
     than letting it push the page into horizontal scroll. */
  .header__actions .segmented,
  .card__toolbar .segmented {
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
  }
  .header__actions .segmented__item,
  .card__toolbar .segmented__item { flex: 0 1 auto; }

  /* Card headers stack their toolbar rather than squeezing it. */
  .card__header { align-items: flex-start; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .doc-meta { grid-template-columns: 1fr; }
  .dim { flex: 1 1 100%; }
}

/* --------------------------------------------------------------------------
   5. Header alerts — notification bell
   -------------------------------------------------------------------------- */

.bell { position: relative; }

.bell__trigger {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.bell__trigger:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.bell__icon { width: 17px; height: 17px; }

.bell__count {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-full);
  background: var(--loss-600);
  color: var(--white);
  font-size: 10px; font-weight: var(--fw-bold); line-height: 1;
  border: 2px solid var(--bg-surface);
}

.bell__panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 300px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  padding: var(--sp-2);
  z-index: 60;
  display: none;
}
.bell__panel.is-open { display: block; }

.bell__head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-primary);
}
.bell__head-meta {
  font-size: var(--fs-xs); font-weight: var(--fw-normal); color: var(--text-muted);
}

.bell__item {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  text-decoration: none;
  color: inherit;
  transition: background var(--t-fast);
}
.bell__item:hover { background: var(--bg-subtle); }

.bell__dot {
  flex: none; width: 7px; height: 7px; margin-top: 5px;
  border-radius: var(--r-full);
  background: var(--text-faint);
}
.bell__dot--red   { background: var(--loss-600); }
.bell__dot--amber { background: var(--warn-600); }

.bell__item-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bell__item-title {
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-primary);
}
.bell__item-meta { font-size: var(--fs-xs); color: var(--text-muted); }

.bell__sep { height: 1px; background: var(--border); margin: var(--sp-2) 0; }

.bell__foot {
  display: block; padding: var(--sp-3);
  text-align: center; text-decoration: none;
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-600);
  border-radius: var(--r-sm);
}
.bell__foot:hover { background: var(--bg-subtle); }

/* --------------------------------------------------------------------------
   6. Utilities
   -------------------------------------------------------------------------- */

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   7. Portfolio - lot detail
   -------------------------------------------------------------------------- */

.lot-panel {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
}

.lot-panel__head {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

.lot-panel__caveat {
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--warn-700);
  background: var(--warn-100);
  border-left: 2px solid var(--warn-600);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
}

.table--compact { font-size: var(--fs-sm); }
.table--compact thead th,
.table--compact tbody td,
.table--compact tfoot td { padding: var(--sp-2) var(--sp-3); }

/* --------------------------------------------------------------------------
   7a. Segmented filters
   A segmented control carrying many options (e.g. sector) must wrap rather
   than widen its container, which would push the page into horizontal scroll.
   -------------------------------------------------------------------------- */

.segmented--wrap {
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
}
.segmented--wrap .segmented__item { flex: 0 1 auto; }

/* --------------------------------------------------------------------------
   8. Page components
   Shared by every screen. Additions here benefit all pages; avoid per-page CSS.
   -------------------------------------------------------------------------- */

/* Key/value list */
.kv { margin: 0; }
.kv__row {
  display: grid;
  grid-template-columns: minmax(110px, 34%) minmax(0, 1fr);
  gap: var(--sp-4);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.kv__row:last-child { border-bottom: 0; }
.kv__k {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding-top: 1px;
}
.kv__v { margin: 0; font-size: var(--fs-base); color: var(--text-primary);
  min-width: 0; overflow-wrap: anywhere; }
.kv--tight .kv__row { padding: var(--sp-1) 0; }

/* Checklist */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist__item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.checklist__item:last-child { border-bottom: 0; }
.checklist__icon {
  flex: none;
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: var(--fw-bold);
  background: var(--gain-100); color: var(--gain-700);
}
.checklist__item--warn .checklist__icon { background: var(--warn-100); color: var(--warn-700); }
.checklist__item--fail .checklist__icon { background: var(--loss-100); color: var(--loss-700); }
.checklist__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.checklist__label { font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--text-primary); }
.checklist__meta { font-size: var(--fs-xs); color: var(--text-muted); }
.checklist__action { flex: none; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-600); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 var(--sp-2) 0 var(--sp-4); }
.timeline__item { position: relative; padding: 0 0 var(--sp-4) var(--sp-5); }
.timeline__item::before {
  content: '';
  position: absolute; left: 5px; top: 14px; bottom: 0;
  width: 1px; background: var(--border);
}
.timeline__item:last-child::before { display: none; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: 0; top: 5px;
  width: 11px; height: 11px;
  border-radius: var(--r-full);
  background: var(--ink-300);
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 0 1px var(--border);
}
.timeline__dot--gain { background: var(--gain-600); }
.timeline__dot--loss { background: var(--loss-600); }
.timeline__dot--warn { background: var(--warn-600); }
.timeline__dot--brand { background: var(--brand-500); }
.timeline__body { display: flex; flex-direction: column; gap: 2px; }
.timeline__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.timeline__title { font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--text-primary); }
.timeline__time { flex: none; font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.timeline__detail { font-size: var(--fs-sm); color: var(--text-secondary); }
.timeline__meta { font-size: var(--fs-xs); color: var(--text-muted); }

/* Form grid */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4); }
.field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.field__label {
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}
.field__input, .field input, .field select {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit; font-size: var(--fs-base);
}
.field__input:focus, .field input:focus, .field select:focus {
  outline: none; border-color: var(--brand-400);
  box-shadow: 0 0 0 3px rgba(37, 99, 168, .12);
}
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* Step bar */
.step-bar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.step {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--fs-sm); color: var(--text-secondary);
  background: var(--bg-surface);
}
.step__n {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-full);
  background: var(--ink-100); color: var(--text-muted);
  font-size: 10px; font-weight: var(--fw-bold);
}
.step.is-active { border-color: var(--brand-400); color: var(--text-primary); font-weight: var(--fw-semibold); }
.step.is-active .step__n { background: var(--brand-500); color: var(--white); }
.step.is-done .step__n { background: var(--gain-600); color: var(--white); }

/* Document grid */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-4); }
.doc-card {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-surface);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.doc-card:hover { border-color: var(--border-strong); box-shadow: var(--sh-sm); }
.doc-card__thumb {
  height: 106px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 22px; font-weight: var(--fw-bold); color: var(--text-faint);
  letter-spacing: .04em;
}
.doc-card__body { padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.doc-card__name { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card__meta { font-size: var(--fs-xs); color: var(--text-muted); }

/* Section divider inside a card body */
.section-split { border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

/* Small inline stat used in card headers */
.inline-stat { display: inline-flex; align-items: baseline; gap: var(--sp-2); }
.inline-stat__v { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-primary); }
.inline-stat__l { font-size: var(--fs-xs); color: var(--text-muted); }

/* Dense data table (config screens) */
.table--dense thead th, .table--dense tbody td { padding: var(--sp-2) var(--sp-3); }
.table--dense { font-size: var(--fs-sm); }

/* Monospace figure, for codes and ids */
.mono { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-secondary); }

/* Swatch row for legend items */
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.legend__item { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-muted); }
.legend__sw { width: 9px; height: 9px; border-radius: 2px; }

/* --------------------------------------------------------------------------
   9. Ownership matrix and map
   -------------------------------------------------------------------------- */

.dim-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.dim-cell:hover { background: var(--bg-subtle); border-color: var(--border); }
.dim-cell__name { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-primary); }
.dim-cell__pct { font-size: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.dim-cell--diff .dim-cell__name { color: var(--warn-700); }
.dim-cell--diff { border-color: var(--warn-100); background: var(--warn-100); background: rgba(217, 119, 6, .06); }

.map__group { margin-bottom: var(--sp-4); }
.map__group:last-child { margin-bottom: 0; }
.map__person {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
}
.map__links { padding-left: var(--sp-2); }
.map__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 3px 0 3px var(--sp-5);
}
.map__line {
  position: absolute;
  left: 3px; top: 50%;
  width: 14px; height: 1px;
  background: var(--border-strong);
}
.map__link::before {
  content: '';
  position: absolute; left: 3px; top: 0; bottom: 50%;
  width: 1px; background: var(--border-strong);
}
.map__link:last-child::before { bottom: 50%; }
.map__acct {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  min-width: 68px;
}
.map__dims { display: inline-flex; gap: 3px; }
.map__dim { width: 9px; height: 9px; border-radius: 2px; }

/* Segmented control scroll behaviour is handled by .segmented--wrap;
   within a table cell the dim cells supply their own padding. */
.table--sticky-first td .dim-cell { min-width: 120px; }

/* --------------------------------------------------------------------------
   10. Extracted document text
   -------------------------------------------------------------------------- */

.doc-text {
  margin: 0;
  padding: var(--sp-3);
  max-height: 190px;
  overflow: auto;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Rule row used by configuration screens */
.rule-row { display: flex; align-items: flex-start; gap: var(--sp-3); }
.rule-row__body { flex: 1; min-width: 0; }
.rule-row__title { font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--text-primary); }
.rule-row__meta { font-size: var(--fs-xs); color: var(--text-muted); }

/* Small pill used to show a version or effective range */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
}
.pill--current { border-color: var(--gain-600); color: var(--gain-700); background: var(--gain-100); }

/* --------------------------------------------------------------------------
   8. Print
   -------------------------------------------------------------------------- */
@media print {
  .sidebar, .header__actions, .mock-banner { display: none; }
  .app { grid-template-columns: 1fr; }
  .card { box-shadow: none; break-inside: avoid; }
}