/* ==========================================================================================
   FinHub design system — core/ui.css
   One source for tokens, base styles, the app shell and every shared component. Used by the app,
   the sign-in / sign-up pages, /support, /partners and /platform. Feature layout lives in
   assets/app.css (loaded after this file). Component names match the Figma library names
   (Button/Primary → .btn-primary, Badge/Success → .badge-success, DataTable → .dt …).

   Themes: light is the default; [data-theme="dark"] on <html> switches (account menu → Theme).
   Legacy aliases (--bg, --card, --muted …) map onto the tokens so older feature CSS follows along.
   ========================================================================================== */

:root {
  /* ---- colour: light ---- */
  --color-brand: #2456d8;
  --color-wordmark: #0b1a3a;
  --color-brand-hover: #1c47b8;
  --color-brand-subtle: #edf2fe;
  --color-brand-contrast: #ffffff;
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunken: #f2f4f7;
  --color-sidebar: #fbfbfc;
  --color-text: #101828;
  --color-text-secondary: #475467;
  --color-text-muted: #667085;
  --color-border: #e3e7ed;
  --color-border-subtle: #eef0f3;
  --color-border-strong: #cfd5de;
  --color-success: #11774a;
  --color-success-subtle: #eaf7f0;
  --color-warning: #a95a05;
  --color-warning-subtle: #fdf4e3;
  --color-danger: #c4302b;
  --color-danger-subtle: #fdeeed;
  --color-info: #0b6aa2;
  --color-info-subtle: #e9f4fb;
  --color-accent: #b7862a;                 /* brand gold — tiny accents only */
  --color-focus: rgba(36, 86, 216, .35);
  --color-overlay: rgba(16, 24, 40, .45);
  --color-hover: rgba(16, 24, 40, .04);
  --color-selected: #edf2fe;

  /* ---- type ---- */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, monospace;
  --text-xs: 12px;     /* meta, captions */
  --text-sm: 13px;     /* labels, table meta, helper */
  --text-md: 14px;     /* body, table text */
  --text-lg: 16px;     /* section title */
  --text-xl: 18px;     /* card title large */
  --text-2xl: 24px;    /* page title */
  --text-3xl: 30px;    /* marketing only */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --leading-tight: 1.25;
  --leading: 1.5;

  /* ---- space (4px grid) ---- */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px; --space-10: 64px;

  /* ---- radius ---- */
  --radius-sm: 6px;     /* badges, small controls */
  --radius-md: 8px;     /* buttons, inputs */
  --radius-lg: 10px;    /* cards, panels, tables */
  --radius-xl: 12px;    /* modals, drawers, large containers */
  --radius-full: 999px;

  /* ---- elevation (borders first; shadows are faint) ---- */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 6px 16px -4px rgba(16, 24, 40, .10), 0 2px 6px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .22);

  /* ---- motion ---- */
  --dur-fast: 120ms; --dur: 160ms; --dur-slow: 200ms;
  --ease: cubic-bezier(.2, 0, 0, 1);

  /* ---- layout ---- */
  --sidebar-w: 240px; --sidebar-w-collapsed: 64px; --topbar-h: 56px; --control-h: 36px; --control-h-sm: 30px;
  --content-max: 1320px; --view-px: 24px;

  /* ---- legacy aliases (older feature CSS and inline styles read these) ---- */
  --bg: var(--color-bg); --bg2: var(--color-surface-sunken); --card: var(--color-surface); --card2: var(--color-surface-raised);
  --border: var(--color-border); --text: var(--color-text); --muted: var(--color-text-muted);
  --primary: var(--color-brand); --primary-hover: var(--color-brand-hover);
  --gold: var(--color-accent); --teal: var(--color-success); --green: var(--color-success); --red: var(--color-danger); --amber: var(--color-warning);
  --radius: var(--radius-lg); --shadow: var(--shadow-md); --grad: var(--color-brand);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --color-brand: #5b86f2;
  --color-wordmark: #e6edf7;
  --color-brand-hover: #7a9df6;
  --color-brand-subtle: rgba(91, 134, 242, .14);
  --color-brand-contrast: #ffffff;
  --color-bg: #0b1120;
  --color-surface: #111a2c;
  --color-surface-raised: #152037;
  --color-surface-sunken: #0d1526;
  --color-sidebar: #0d1526;
  --color-text: #e8edf6;
  --color-text-secondary: #b3bfd3;
  --color-text-muted: #8a98b1;
  --color-border: #22304b;
  --color-border-subtle: #1a2640;
  --color-border-strong: #33456a;
  --color-success: #3ccf8e;
  --color-success-subtle: rgba(60, 207, 142, .12);
  --color-warning: #f2b544;
  --color-warning-subtle: rgba(242, 181, 68, .13);
  --color-danger: #f47a74;
  --color-danger-subtle: rgba(244, 122, 116, .13);
  --color-info: #5cc0f2;
  --color-info-subtle: rgba(92, 192, 242, .12);
  --color-accent: #e8b64c;
  --color-focus: rgba(91, 134, 242, .45);
  --color-overlay: rgba(2, 6, 16, .65);
  --color-hover: rgba(255, 255, 255, .04);
  --color-selected: rgba(91, 134, 242, .14);
  --shadow-xs: none;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 24px -6px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ==========================================================================================
   Base
   ========================================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-sans); font-size: var(--text-md); line-height: var(--leading);
  color: var(--color-text); background: var(--color-bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}
h1, h2, h3, h4 { margin: 0; font-weight: var(--weight-semibold); line-height: var(--leading-tight); letter-spacing: -.01em; }
h1 { font-size: var(--text-2xl); } h2 { font-size: var(--text-xl); } h3 { font-size: var(--text-lg); } h4 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3); }
a { color: var(--color-brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { vertical-align: middle; }
hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-4) 0; }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.muted, .text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.pos { color: var(--color-success); } .neg { color: var(--color-danger); }
:focus-visible { outline: 2px solid var(--color-brand); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--color-brand-subtle); }
* { scrollbar-width: thin; scrollbar-color: var(--color-border-strong) transparent; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; } }

/* Icon (Lucide sprite): <svg class="i"><use href="#i-name"/></svg> */
.i { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 14px; height: 14px; } .i-lg { width: 20px; height: 20px; } .i-xl { width: 24px; height: 24px; }

/* ==========================================================================================
   Buttons — Primary / Secondary (default) / Tertiary / Danger / Icon;  sizes sm / md / lg
   ========================================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-h); padding: 0 var(--space-3); border-radius: var(--radius-md);
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  box-shadow: var(--shadow-xs); text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast), transform var(--dur-fast);
}
.btn:hover { background: var(--color-surface-sunken); border-color: var(--color-border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--color-brand); border-color: var(--color-brand); color: var(--color-brand-contrast); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); color: var(--color-brand-contrast); }
.btn-tertiary, .btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--color-text-secondary); }
.btn-tertiary:hover, .btn-ghost:hover { background: var(--color-hover); border-color: transparent; color: var(--color-text); }
.btn-danger { color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-subtle); border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border)); color: var(--color-danger); }
.btn-danger-solid { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(.95); background: var(--color-danger); color: #fff; }
.btn-sm { height: var(--control-h-sm); padding: 0 10px; font-size: var(--text-xs); gap: 6px; }
.btn-lg { height: 42px; padding: 0 var(--space-5); font-size: var(--text-md); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn-block { width: 100%; }
.btn .i { width: 16px; height: 16px; } .btn-sm .i { width: 14px; height: 14px; }
.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* ==========================================================================================
   Form controls — Input, Select, Textarea, SearchInput, Checkbox, Radio, Toggle, Field
   ========================================================================================== */
input:is([type=text], [type=email], [type=number], [type=password], [type=search], [type=tel], [type=url],
        [type=date], [type=month], [type=time], [type=datetime-local], :not([type])),
select, textarea, .input {
  height: var(--control-h); padding: 0 10px; border-radius: var(--radius-md);
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text);
  font-size: var(--text-md); outline: none; max-width: 100%;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
textarea { height: auto; min-height: 84px; padding: 8px 10px; line-height: var(--leading); resize: vertical; }
select { padding-right: 30px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; }
select[multiple] { height: auto; padding: 6px; background-image: none; }
input::placeholder, textarea::placeholder { color: var(--color-text-muted); opacity: .85; }
input:is(:hover, :focus), select:is(:hover, :focus), textarea:is(:hover, :focus) { border-color: var(--color-border-strong); }
input:focus, select:focus, textarea:focus, .input:focus { border-color: var(--color-brand); box-shadow: 0 0 0 3px var(--color-focus); }
input:disabled, select:disabled, textarea:disabled { background: var(--color-surface-sunken); color: var(--color-text-muted); cursor: not-allowed; }
input[readonly] { background: var(--color-surface-sunken); }
input[type=file] { font-size: var(--text-sm); color: var(--color-text-secondary); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); margin-right: 10px; height: var(--control-h-sm);
  padding: 0 10px; border-radius: var(--radius-md); border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--color-brand); cursor: pointer; vertical-align: -3px; }
input[type=color] { width: 40px; height: var(--control-h); padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.input-sm, input.input-sm, select.input-sm { height: var(--control-h-sm); font-size: var(--text-sm); }
[aria-invalid="true"], .is-invalid { border-color: var(--color-danger) !important; }
[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--color-danger-subtle) !important; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > span:first-child, .field-label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text); }
.field-label .opt, .field .opt { color: var(--color-text-muted); font-weight: var(--weight-regular); }
.field-help { font-size: var(--text-xs); color: var(--color-text-muted); }
.field-error { font-size: var(--text-xs); color: var(--color-danger); display: flex; gap: 4px; align-items: center; }
.field input, .field select, .field textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { padding: var(--space-5) 0; border-top: 1px solid var(--color-border-subtle); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section > h4, .form-section-title { font-size: var(--text-md); font-weight: var(--weight-semibold); margin-bottom: 2px; }
.form-section > .form-section-desc { font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-4); }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-4); }
details.advanced > summary { cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-brand); list-style: none; padding: var(--space-2) 0; display: inline-flex; gap: 6px; align-items: center; }
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary::before { content: ''; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur); margin-right: 2px; }
details.advanced[open] > summary::before { transform: rotate(45deg); }

.search-input { position: relative; display: inline-flex; align-items: center; min-width: 0; }
.search-input .i { position: absolute; left: 10px; color: var(--color-text-muted); pointer-events: none; }
.search-input input { padding-left: 32px; width: 100%; }

.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); color: var(--color-text); cursor: pointer; }
.toggle { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-md); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track { width: 34px; height: 20px; border-radius: var(--radius-full); background: var(--color-border-strong); position: relative; transition: background var(--dur); flex-shrink: 0; }
.toggle .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.toggle input:checked + .track { background: var(--color-brand); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--color-brand); outline-offset: 2px; }

/* ==========================================================================================
   Tabs (underline) and Segmented control
   ========================================================================================== */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab, .tabs > button, .tabs > a {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 2px; margin: 0 var(--space-3) -1px 0; white-space: nowrap;
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--color-text-muted);
  font-size: var(--text-md); font-weight: var(--weight-medium); text-decoration: none; transition: color var(--dur-fast), border-color var(--dur-fast);
}
.tab:hover, .tabs > button:hover, .tabs > a:hover { color: var(--color-text); text-decoration: none; }
.tab.active, .tab[aria-selected="true"], .tabs > button.active, .tabs > a.active { color: var(--color-text); border-bottom-color: var(--color-brand); }
.tab .count { font-size: var(--text-xs); color: var(--color-text-muted); background: var(--color-surface-sunken); border-radius: var(--radius-full); padding: 1px 7px; font-weight: var(--weight-medium); }
.tab.active .count { color: var(--color-brand); background: var(--color-brand-subtle); }

.seg, .kind-tabs { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-md); background: var(--color-surface-sunken); border: 1px solid var(--color-border-subtle); }
.seg > button, .kind-tabs > button {
  height: 28px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--color-text-secondary); font-size: var(--text-sm); font-weight: var(--weight-medium); flex: 1; transition: background var(--dur-fast), color var(--dur-fast);
}
.seg > button:hover, .kind-tabs > button:hover { color: var(--color-text); }
.seg > button.active, .kind-tabs > button.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.kind-tabs { display: flex; margin-bottom: var(--space-4); }

/* ==========================================================================================
   Badge / StatusBadge
   ========================================================================================== */
.badge, .chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--radius-sm);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  background: var(--color-surface-sunken); color: var(--color-text-secondary); border: 1px solid var(--color-border-subtle);
}
.badge .i { width: 12px; height: 12px; }
.badge-dot::before, .chip .dot { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.chip .dot { content: none; }
.badge-success { background: var(--color-success-subtle); color: var(--color-success); border-color: transparent; }
.badge-warning { background: var(--color-warning-subtle); color: var(--color-warning); border-color: transparent; }
.badge-danger  { background: var(--color-danger-subtle);  color: var(--color-danger);  border-color: transparent; }
.badge-info    { background: var(--color-info-subtle);    color: var(--color-info);    border-color: transparent; }
.badge-brand   { background: var(--color-brand-subtle);   color: var(--color-brand);   border-color: transparent; }
.badge-neutral { background: var(--color-surface-sunken); color: var(--color-text-secondary); }
.badge-outline { background: transparent; }
.count-badge, .nav-badge.on {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-full); background: var(--color-danger); color: #fff; font-size: 11px; font-weight: var(--weight-semibold); line-height: 1;
}
.nav-badge { display: none; }
.nav-badge.on { margin-left: auto; }

/* ==========================================================================================
   Surfaces — Card, Panel (section), MetricCard
   ========================================================================================== */
.surface, .panel {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
}
.panel { padding: var(--space-5); }
.panel > h3, .panel .panel-head h3, .section-title {
  font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--color-text); margin: 0 0 var(--space-4);
  text-transform: none; letter-spacing: 0;
}
.panel .panel-head, .section-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.panel .panel-head h3, .section-head h3 { margin: 0; }
.section-head h3 { font-size: var(--text-lg); }
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush > .panel-head { padding: var(--space-4) var(--space-5) 0; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-4); margin-bottom: var(--space-5); }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.cards, .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.card, .metric {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-4); transition: border-color var(--dur-fast);
}
a.card:hover, .card.clickable:hover, .metric.clickable:hover { border-color: var(--color-border-strong); text-decoration: none; }
.card .label, .metric-label { display: flex; align-items: center; gap: 6px; color: var(--color-text-secondary); font-size: var(--text-sm); font-weight: var(--weight-medium); text-transform: none; letter-spacing: 0; }
.card .value, .metric-value { font-size: 22px; font-weight: var(--weight-semibold); margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.2; color: var(--color-text); }
.card .sub, .metric-sub { color: var(--color-text-muted); font-size: var(--text-xs); margin-top: 4px; }
.card .value.pos, .metric-value.pos { color: var(--color-success); } .card .value.neg, .metric-value.neg { color: var(--color-danger); }
.chart-box { position: relative; height: 260px; }

/* ==========================================================================================
   PageHeader
   ========================================================================================== */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-header h1, .ph-title { font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: -.02em; }
.ph-sub { color: var(--color-text-muted); font-size: var(--text-md); margin-top: 4px; }
.ph-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* ==========================================================================================
   Tables — DataTable (.dt) and plain tables
   ========================================================================================== */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
th {
  text-align: left; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text-muted);
  text-transform: none; letter-spacing: 0; padding: 9px 12px; border-bottom: 1px solid var(--color-border);
  white-space: nowrap; background: var(--color-surface);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--color-border-subtle); font-size: var(--text-md); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--dur-fast); }
tbody tr:hover td { background: var(--color-hover); }
tr.clickable, tr.click, tr[data-href] { cursor: pointer; }
td .sub, td .muted { font-size: var(--text-xs); }
.table-wrap, .dt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }
.row-actions button { display: inline-flex; align-items: center; justify-content: center; height: 28px; min-width: 28px; padding: 0 6px;
  background: none; border: 0; color: var(--color-text-muted); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.row-actions button:hover { color: var(--color-text); background: var(--color-hover); }

.dt { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.dt-toolbar { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-3); border-bottom: 1px solid var(--color-border); flex-wrap: wrap; }
.dt-toolbar .search-input { flex: 1 1 220px; max-width: 320px; }
.dt-toolbar .spacer { flex: 1; }
.dt-bulk { display: flex; gap: var(--space-2); align-items: center; padding: 8px var(--space-3); background: var(--color-brand-subtle); border-bottom: 1px solid var(--color-border); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.dt table th { position: sticky; top: 0; z-index: 1; background: var(--color-surface); }
.dt th.sortable { cursor: pointer; user-select: none; }
.dt th.sortable:hover { color: var(--color-text); }
.dt th .sort { display: inline-flex; vertical-align: -2px; margin-left: 2px; opacity: .35; }
.dt th.sorted .sort { opacity: 1; color: var(--color-text); }
.dt th.sel, .dt td.sel { width: 36px; padding-right: 0; }
.dt tr.selected td { background: var(--color-selected); }
.dt td.actions, .dt th.actions { width: 1%; text-align: right; white-space: nowrap; }
.dt-primary { font-weight: var(--weight-medium); color: var(--color-text); }
.dt-secondary { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.dt-footer { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: 10px var(--space-3); border-top: 1px solid var(--color-border); font-size: var(--text-sm); color: var(--color-text-muted); flex-wrap: wrap; }
.dt-pager { display: inline-flex; gap: var(--space-1); align-items: center; }
.dt-empty { padding: var(--space-7) var(--space-4); }
.dt-cards { display: none; }
.dt-card { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-subtle); cursor: pointer; }
.dt-card:last-child { border-bottom: 0; }
.dt-card:active { background: var(--color-hover); }
.dt-card .c-title { font-weight: var(--weight-semibold); }
.dt-card .c-amount { font-weight: var(--weight-semibold); text-align: right; font-variant-numeric: tabular-nums; }
.dt-card .c-sub { color: var(--color-text-secondary); font-size: var(--text-sm); }
.dt-card .c-meta { color: var(--color-text-muted); font-size: var(--text-xs); }
.dt-card .c-badge { text-align: right; }

/* Skeleton / loading */
.skeleton { display: block; height: 12px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--color-surface-sunken) 25%, var(--color-border-subtle) 37%, var(--color-surface-sunken) 63%); background-size: 400% 100%; animation: fh-shimmer 1.4s ease infinite; }
@keyframes fh-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.loading-state { display: flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-8) var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); }
.spin { animation: fh-spin .8s linear infinite; } @keyframes fh-spin { to { transform: rotate(360deg); } }

/* ==========================================================================================
   EmptyState, Alert, ErrorState
   ========================================================================================== */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-8) var(--space-5); gap: var(--space-2); }
.empty-state .es-icon { width: 44px; height: 44px; border-radius: var(--radius-xl); display: grid; place-items: center; background: var(--color-surface-sunken); color: var(--color-text-secondary); border: 1px solid var(--color-border-subtle); margin-bottom: var(--space-2); }
.empty-state .es-icon .i { width: 20px; height: 20px; }
.empty-state h3, .empty-state .es-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.empty-state p, .empty-state .es-text { color: var(--color-text-muted); max-width: 420px; margin: 0 0 var(--space-2); font-size: var(--text-md); }
.empty-state .es-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center; margin-top: var(--space-2); }
.empty { text-align: center; color: var(--color-text-muted); padding: var(--space-7) var(--space-4); font-size: var(--text-md); }

.alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); border: 1px solid var(--color-border); background: var(--color-surface); font-size: var(--text-sm); line-height: var(--leading); }
.alert > .i { margin-top: 2px; }
.alert b, .alert strong { font-weight: var(--weight-semibold); }
.alert .alert-body { flex: 1; min-width: 0; }
.alert .alert-actions { display: flex; gap: var(--space-2); align-items: center; }
.alert-info { background: var(--color-info-subtle); border-color: transparent; } .alert-info > .i { color: var(--color-info); }
.alert-success { background: var(--color-success-subtle); border-color: transparent; } .alert-success > .i { color: var(--color-success); }
.alert-warning { background: var(--color-warning-subtle); border-color: transparent; } .alert-warning > .i { color: var(--color-warning); }
.alert-danger { background: var(--color-danger-subtle); border-color: transparent; } .alert-danger > .i { color: var(--color-danger); }
.alert-brand { background: var(--color-brand-subtle); border-color: transparent; } .alert-brand > .i { color: var(--color-brand); }

/* ==========================================================================================
   Filter bar
   ========================================================================================== */
.filters, .filter-bar { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); flex-wrap: wrap; align-items: center; }
.filters input[type=text], .filters input[type=search], .filter-bar .search-input { min-width: 220px; }

/* ==========================================================================================
   Modal (Dialog), Drawer, ConfirmationDialog
   ========================================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--color-overlay); display: none; align-items: center; justify-content: center;
  z-index: 50; padding: var(--space-5); opacity: 0; transition: opacity var(--dur) var(--ease);
}
.modal-backdrop.open { display: flex; animation: fh-fade var(--dur) var(--ease) forwards; }
@keyframes fh-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fh-rise { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal {
  width: 480px; max-width: 100%; max-height: min(88vh, 860px); overflow-y: auto;
  background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-xl);
  padding: var(--space-6); box-shadow: var(--shadow-lg); animation: fh-rise var(--dur-slow) var(--ease);
}
.modal-lg { width: 680px; } .modal-xl { width: 920px; }
.modal > h3:first-child, .modal .modal-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); margin-bottom: var(--space-4); }
.modal .modal-desc { color: var(--color-text-muted); font-size: var(--text-sm); margin: -8px 0 var(--space-4); }
.modal label { display: block; margin-bottom: var(--space-3); color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.modal label > input:not([type=checkbox]):not([type=radio]), .modal label > select, .modal label > textarea { display: block; width: 100%; margin-top: 6px; }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.modal .check { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-regular); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--color-border-subtle); flex-wrap: wrap; }
.modal-close { position: absolute; top: 14px; right: 14px; }

.drawer-backdrop { position: fixed; inset: 0; background: var(--color-overlay); z-index: 55; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 56; display: flex; flex-direction: column;
  background: var(--color-surface-raised); border-left: 1px solid var(--color-border); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform var(--dur-slow) var(--ease);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.drawer-head h2 { font-size: var(--text-lg); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.drawer-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--color-border); }

/* ==========================================================================================
   Dropdown menu, Tooltip, Toast
   ========================================================================================== */
.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 45; min-width: 200px; padding: 4px;
  background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  display: none; flex-direction: column; animation: fh-rise var(--dur) var(--ease);
}
.menu.open { display: flex; }
.menu.menu-left { right: auto; left: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--color-text); font-size: var(--text-md); text-align: left; text-decoration: none; white-space: nowrap;
}
.menu-item .i { color: var(--color-text-muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--color-hover); text-decoration: none; outline: none; }
.menu-item.danger, .menu-item.danger .i { color: var(--color-danger); }
.menu-item .kbd { margin-left: auto; font-size: var(--text-xs); color: var(--color-text-muted); }
.menu-sep { height: 1px; background: var(--color-border-subtle); margin: 4px 0; }
.menu-label { padding: 6px 10px 4px; font-size: var(--text-xs); color: var(--color-text-muted); font-weight: var(--weight-medium); }

.tooltip-float {
  position: fixed; z-index: 200; pointer-events: none; background: #111827; color: #fff; font-size: var(--text-xs); font-weight: var(--weight-medium);
  padding: 5px 8px; border-radius: var(--radius-sm); white-space: nowrap; box-shadow: var(--shadow-md); opacity: 0; transition: opacity var(--dur-fast);
}
.tooltip-float.show { opacity: 1; }

.toast {
  position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%) translateY(12px);
  display: flex; align-items: center; gap: var(--space-2); max-width: min(520px, calc(100vw - 32px));
  background: #111827; color: #f9fafb; border: 1px solid #111827; padding: 10px 16px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
  z-index: 100; font-size: var(--text-md); font-weight: var(--weight-medium);
}
.toast::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--color-success); flex-shrink: 0; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error::before { background: #f47a74; }
:root[data-theme="dark"] .toast { background: var(--color-surface-raised); border-color: var(--color-border); color: var(--color-text); }

/* Dropzone (file upload) */
.drop {
  border: 1.5px dashed var(--color-border-strong); border-radius: var(--radius-lg); padding: var(--space-6) var(--space-4);
  text-align: center; color: var(--color-text-secondary); cursor: pointer; margin-bottom: var(--space-4); background: var(--color-surface-sunken);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.drop:hover, .drop.over { border-color: var(--color-brand); background: var(--color-brand-subtle); color: var(--color-text); }
.drop-icon { font-size: 0; margin-bottom: var(--space-2); color: var(--color-text-muted); }
.drop-icon .i { width: 24px; height: 24px; }
.drop-sub { font-size: var(--text-xs); margin-top: 4px; color: var(--color-text-muted); }

/* ==========================================================================================
   Sign-in / auth
   ========================================================================================== */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-5); background: var(--color-bg); }
.auth-card {
  width: 400px; max-width: 100%; text-align: left; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: var(--space-7); box-shadow: var(--shadow-sm);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: var(--space-6); text-align: center; }
.auth-logo-img { width: 84px; height: 84px; object-fit: contain; }
.auth-brand .wm { font-size: 24px; }
.auth-motto { font-size: 12.5px; letter-spacing: .3em; color: var(--color-wordmark); opacity: .75; padding-left: .3em; }
.auth-card h1 { font-size: 22px; font-weight: var(--weight-semibold); margin: 0 0 4px; letter-spacing: -.02em; }
.auth-sub, .auth-tagline { color: var(--color-text-muted); margin: 0 0 var(--space-5); font-size: var(--text-md); letter-spacing: 0; text-transform: none; font-weight: var(--weight-regular); }
.auth-note { color: var(--color-warning); font-size: var(--text-sm); }
.auth-card form { display: grid; gap: var(--space-3); }
.auth-card input { width: 100%; height: 40px; }
.auth-card button[type=submit] { width: 100%; height: 40px; border: 0; border-radius: var(--radius-md); background: var(--color-brand); color: #fff; font-weight: var(--weight-semibold); font-size: var(--text-md); transition: background var(--dur-fast); }
.auth-card button[type=submit]:hover { background: var(--color-brand-hover); }
.auth-error { color: var(--color-danger); min-height: 18px; font-size: var(--text-sm); margin-top: var(--space-3); }
.auth-ok { color: var(--color-success); background: var(--color-success-subtle); border-radius: var(--radius-md); padding: var(--space-3); font-size: var(--text-sm); margin-top: var(--space-3); }
.auth-forgot { margin: var(--space-3) 0 0; text-align: center; font-size: var(--text-sm); }
.auth-or { display: flex; align-items: center; gap: 10px; margin: var(--space-4) 0; color: var(--color-text-muted); font-size: var(--text-xs); }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--color-border); }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 40px; border-radius: var(--radius-md); text-decoration: none;
  background: var(--color-surface); color: var(--color-text); font-size: var(--text-md); font-weight: var(--weight-medium); border: 1px solid var(--color-border);
}
.btn-google:hover { background: var(--color-surface-sunken); text-decoration: none; }
.auth-foot { margin-top: var(--space-5); font-size: var(--text-sm); color: var(--color-text-muted); display: grid; gap: 6px; }

/* ==========================================================================================
   App shell — Sidebar, TopBar, content, MobileNavigation
   ========================================================================================== */
.app { display: flex; height: 100vh; overflow: hidden; background: var(--color-bg); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; display: flex; flex-direction: column; background: var(--color-sidebar);
  border-right: 1px solid var(--color-border); transition: width var(--dur-slow) var(--ease); position: relative; z-index: 20;
}
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); height: var(--topbar-h); padding: 0 var(--space-3) 0 var(--space-4); flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: var(--weight-bold); letter-spacing: -.02em; color: var(--color-text); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 30px; height: 30px; flex-shrink: 0; object-fit: contain; }
/* The product wordmark (fh_wordmark): a heavy, spaced first word in ink, the rest in the brand blue. */
.wm { display: inline-flex; align-items: baseline; gap: .3em; white-space: nowrap; letter-spacing: 0; }
.wm-a { font-weight: 800; letter-spacing: .06em; color: var(--color-wordmark); }
.wm-b { font-weight: 600; letter-spacing: -.01em; color: var(--color-brand); }
.brand b { color: var(--color-brand); font-weight: var(--weight-bold); }
.sb-collapse { color: var(--color-text-muted); }
#nav { flex: 1; display: flex; flex-direction: column; gap: 1px; padding: var(--space-2) var(--space-3); min-height: 0; overflow-y: auto; }
#nav a {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--radius-md);
  color: var(--color-text-secondary); text-decoration: none; font-size: var(--text-md); font-weight: var(--weight-medium); position: relative;
  transition: background var(--dur-fast), color var(--dur-fast);
}
#nav a .i { color: var(--color-text-muted); transition: color var(--dur-fast); }
#nav a:hover { background: var(--color-hover); color: var(--color-text); }
#nav a:hover .i { color: var(--color-text-secondary); }
#nav a.active { background: var(--color-brand-subtle); color: var(--color-brand); }
#nav a.active .i { color: var(--color-brand); }
#nav .nav-lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group { margin: var(--space-4) 10px 6px; font-size: 11px; font-weight: var(--weight-semibold); letter-spacing: .04em; text-transform: uppercase; color: var(--color-text-muted); white-space: nowrap; }
.nav-group-end { height: var(--space-2); }
.sb-foot { padding: var(--space-3); border-top: 1px solid var(--color-border); flex-shrink: 0; }
.sb-org { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: var(--radius-md); border: 0; background: none; text-align: left; color: var(--color-text); }
.sb-org:hover { background: var(--color-hover); }
.sb-org .org-avatar { width: 28px; height: 28px; border-radius: var(--radius-md); background: var(--color-brand); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: var(--weight-semibold); flex-shrink: 0; }
.sb-org .org-text { flex: 1; min-width: 0; line-height: 1.25; }
.sb-org .org-name { display: block; font-size: var(--text-sm); font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-org .org-plan { display: block; font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-foot .menu { bottom: calc(100% + 6px); top: auto; left: 0; right: 0; }

/* collapsed sidebar (desktop toggle; automatic on tablets) */
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.collapsed .brand-text, .sidebar.collapsed .nav-lbl, .sidebar.collapsed .nav-group, .sidebar.collapsed .org-text,
.sidebar.collapsed .sb-org .i, .sidebar.collapsed #nav .nav-badge.on { display: none; }
.sidebar.collapsed .sb-head { flex-direction: column; justify-content: center; gap: 6px; height: auto; padding: 14px 0 6px; }
.sidebar.collapsed #nav { padding: var(--space-2) 10px; }
.sidebar.collapsed #nav a { justify-content: center; padding: 0; width: 42px; height: 38px; margin: 0 auto; }
.sidebar.collapsed .nav-group-end, .sidebar.collapsed .nav-sep { display: block; height: 1px; background: var(--color-border-subtle); margin: 8px 6px; }
.sidebar.collapsed .sb-org { justify-content: center; padding: 6px 0; }
.sidebar.collapsed .sb-collapse .i { transform: rotate(180deg); }
.nav-sep { display: none; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: var(--space-3); height: var(--topbar-h); padding: 0 var(--space-6);
  border-bottom: 1px solid var(--color-border); background: var(--color-surface); flex-shrink: 0;
}
.topbar h2, .topbar .tb-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .tb-spacer { flex: 1; }
.topbar-controls { display: flex; gap: var(--space-2); align-items: center; }
.topbar-controls select, .topbar-controls input[type=month] { height: 32px; font-size: var(--text-sm); }
.tb-menu-btn { display: none; }
.acct { position: relative; }
.acct-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--color-border); background: var(--color-surface-sunken);
  color: var(--color-text); font-weight: var(--weight-semibold); font-size: var(--text-sm); display: grid; place-items: center; padding: 0;
}
.acct-btn:hover { border-color: var(--color-border-strong); }
.acct-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 45; min-width: 240px; padding: 4px;
  background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  display: none; flex-direction: column; animation: fh-rise var(--dur) var(--ease); }
.acct-pop.open { display: flex; }
.acct-who { padding: 8px 10px 10px; font-size: var(--text-sm); color: var(--color-text-muted); border-bottom: 1px solid var(--color-border-subtle); margin-bottom: 4px; line-height: 1.4; }
.acct-who b { display: block; color: var(--color-text); font-size: var(--text-md); font-weight: var(--weight-semibold); }
.acct-pop .btn { justify-content: flex-start; width: 100%; height: 34px; border: 0; background: none; box-shadow: none; font-weight: var(--weight-regular); font-size: var(--text-md); padding: 0 10px; color: var(--color-text); }
.acct-pop .btn:hover { background: var(--color-hover); }
.acct-pop .btn .i { color: var(--color-text-muted); }
.acct-pop .btn-danger, .acct-pop .btn-danger .i { color: var(--color-danger); }

.gsearch { position: relative; flex: 0 1 380px; min-width: 0; display: flex; align-items: center; }

.view { flex: 1; overflow-y: auto; padding: var(--space-6) var(--view-px) var(--space-10); }
.view > * { max-width: var(--content-max); margin-left: auto; margin-right: auto; }
.view > .de-root, .view > .full-bleed { max-width: none; }

/* ---------- welcome / first-run ---------- */
.welcome-card { max-width: 480px; margin: var(--space-8) auto; text-align: center; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-7); }
.welcome-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto var(--space-3); border-radius: var(--radius-xl); background: var(--color-brand-subtle); color: var(--color-brand); font-size: 0; }
.welcome-icon .i { width: 22px; height: 22px; }
.welcome-card h2 { font-size: var(--text-xl); margin-bottom: var(--space-2); }
.welcome-card p { color: var(--color-text-muted); margin: 0 0 var(--space-5); }
.welcome-hint { font-size: var(--text-sm); margin-top: var(--space-4) !important; }

/* settings grid (legacy) */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

/* ---------- mobile bottom navigation + More sheet ---------- */
.mobile-nav, .msheet, .msheet-backdrop { display: none; }

/* ==========================================================================================
   Responsive
   ========================================================================================== */
@media (max-width: 1200px) {
  :root { --view-px: 20px; }
  .view { padding: var(--space-5) var(--view-px) var(--space-10); }
  .topbar { padding: 0 var(--space-5); }
}
@media (max-width: 1000px) {
  .panel-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .app { flex-direction: column; height: 100dvh; }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--space-4); gap: var(--space-2); height: 52px; }
  .topbar .tb-title { font-size: var(--text-md); }
  .topbar .gsearch, .topbar .tb-desktop, .topbar #createBtn { display: none; }
  .topbar .tb-title { flex: 1; }
  .topbar .tb-mobile-brand { display: inline-flex; }
  :root { --view-px: 16px; }
  .view { padding: var(--space-4) var(--view-px) calc(88px + env(safe-area-inset-bottom, 0px)); }
  .page-header { margin-bottom: var(--space-4); }
  .page-header h1, .ph-title { font-size: 20px; }
  .ph-actions { width: 100%; }
  .ph-actions .btn-primary { flex: 1; }
  .panel { padding: var(--space-4); }
  .cards, .metrics { grid-template-columns: 1fr 1fr; gap: var(--space-2); }
  .card, .metric { padding: var(--space-3); }
  .card .value, .metric-value { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; max-height: 92dvh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)); }
  .modal .grid2 { grid-template-columns: 1fr; gap: 0; }
  .modal-actions { position: sticky; bottom: calc(-1 * var(--space-5)); background: var(--color-surface-raised); margin-bottom: calc(-1 * var(--space-5)); padding-bottom: var(--space-4); }
  .modal-actions .btn { flex: 1; }
  .filters, .filter-bar { gap: var(--space-2); }
  .filters input[type=text], .filters input[type=search], .filter-bar .search-input { min-width: 0; flex: 1 1 100%; }
  .dt-toolbar .search-input { max-width: none; }
  .dt.has-cards .dt-scroll { display: none; }
  .dt.has-cards .dt-cards { display: block; }
  .panel .table-wrap { margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
  .panel table:not(.keep) { min-width: 560px; }

  .mobile-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
    background: color-mix(in srgb, var(--color-surface) 94%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-top: 1px solid var(--color-border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-nav a, .mobile-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 48px;
    background: none; border: 0; text-decoration: none; color: var(--color-text-muted); font-size: 11px; font-weight: var(--weight-medium); position: relative;
  }
  .mobile-nav .i { width: 22px; height: 22px; }
  .mobile-nav a.active { color: var(--color-brand); }
  .mobile-nav .m-create { color: var(--color-brand-contrast); }
  .mobile-nav .m-create .m-create-dot { width: 44px; height: 44px; border-radius: 50%; background: var(--color-brand); display: grid; place-items: center; box-shadow: var(--shadow-md); margin-top: -2px; }
  .mobile-nav .m-create .m-lbl { display: none; }
  .mobile-nav .nav-badge.on { position: absolute; top: 2px; right: calc(50% - 20px); margin: 0; min-width: 16px; height: 16px; font-size: 10px; }

  .msheet-backdrop { display: block; position: fixed; inset: 0; z-index: 70; background: var(--color-overlay); opacity: 0; pointer-events: none; transition: opacity var(--dur-slow); }
  .msheet-backdrop.open { opacity: 1; pointer-events: auto; }
  .msheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; background: var(--color-surface-raised);
    border-top: 1px solid var(--color-border); border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--shadow-lg);
    transform: translateY(100%); transition: transform var(--dur-slow) var(--ease);
    padding: var(--space-2) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)); max-height: 84dvh; overflow-y: auto;
  }
  .msheet.open { transform: none; }
  .msheet::before { content: ''; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--color-border-strong); margin: 6px auto 10px; }
  .msheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); font-weight: var(--weight-semibold); font-size: var(--text-lg); }
  .msheet-group { font-size: 11px; font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); margin: var(--space-4) 4px 4px; }
  .msheet-grid { display: flex; flex-direction: column; }
  .msheet-grid a, .msheet-grid button {
    display: flex; align-items: center; gap: var(--space-3); min-height: 46px; padding: 0 var(--space-2); border: 0; background: none; width: 100%;
    color: var(--color-text); text-decoration: none; font-size: var(--text-md); font-weight: var(--weight-medium); border-radius: var(--radius-md); text-align: left; position: relative;
  }
  .msheet-grid a:active, .msheet-grid button:active { background: var(--color-hover); }
  .msheet-grid a .i, .msheet-grid button .i { color: var(--color-text-muted); width: 20px; height: 20px; }
  .msheet-grid a.active { color: var(--color-brand); } .msheet-grid a.active .i { color: var(--color-brand); }
  .msheet-grid .msheet-signout, .msheet-grid .msheet-signout .i { color: var(--color-danger); }
  .msheet-grid .nav-badge.on { margin-left: auto; }
}
@media (min-width: 768px) and (max-width: 1100px) {
  .sidebar:not(.expanded) { width: var(--sidebar-w-collapsed); }
  .sidebar:not(.expanded) .brand-text, .sidebar:not(.expanded) .nav-lbl, .sidebar:not(.expanded) .nav-group,
  .sidebar:not(.expanded) .org-text, .sidebar:not(.expanded) .sb-org .i, .sidebar:not(.expanded) #nav .nav-badge.on { display: none; }
  .sidebar:not(.expanded) .sb-head { flex-direction: column; justify-content: center; gap: 6px; height: auto; padding: 14px 0 6px; }
  .sidebar:not(.expanded) #nav { padding: var(--space-2) 10px; }
  .sidebar:not(.expanded) #nav a { justify-content: center; padding: 0; width: 42px; height: 38px; margin: 0 auto; }
  .sidebar:not(.expanded) .nav-group-end { height: 1px; background: var(--color-border-subtle); margin: 8px 6px; }
  .sidebar:not(.expanded) .sb-org { justify-content: center; padding: 6px 0; }
  .sidebar:not(.expanded) .sb-collapse .i { transform: rotate(180deg); }
  .gsearch { flex-basis: 260px; }
}
@media (min-width: 768px) { .tb-mobile-brand { display: none; } }

/* One page title at a time: pages with their own header hide the top-bar title on desktop;
   on phones the compact top bar keeps the title and the page header drops its own. */
@media (min-width: 768px) { .main:has(.view > .page-header) .topbar .tb-title { visibility: hidden; } }
@media (max-width: 767px) { .view > .page-header:not(.keep-title) .ph-title { display: none; } .view > .page-header:not(.keep-title) .ph-sub { margin-top: 0; } }

/* icons sitting inline with text (not inside flex components) get a little room */
label > .i, h2 > .i, h3 > .i, h4 > .i, p > .i, b > .i:first-child, td > .i:first-child:not(:only-child), .fam-badge .i, .file-chip .i, .chip > .i, .sup-file .i, .muted > .i, .text-secondary > .i, span.shared-badge .i { margin-right: 4px; vertical-align: -3px; }
.row-actions .i { width: 15px; height: 15px; }

/* inside dialogs and drawers, fields fill their column unless a component sets a width (zero specificity) */
.modal :where(input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]), select, textarea),
.drawer :where(input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]), select, textarea) { width: 100%; }

/* phones: a page header keeps its primary action (and the "…" menu); secondary actions live in that menu or in the Create menu */
@media (max-width: 767px) { .ph-actions > .btn:not(.btn-primary):not(.btn-icon):not(.keep-mobile), .ph-actions > label.btn:not(.btn-primary) { display: none; } }
