/* ============================================================
 * Finance Control Console — UI Components & Utilities (v2)
 * ------------------------------------------------------------
 * Hand-written, token-driven, no build step. Loaded ONLY on new
 * pages via base_v2.html. Legacy pages continue on styles.css.
 *
 * Structure:
 *   1.  Reset & base (new pages only — scoped, cannot affect
 *       legacy pages since they don't load this file)
 *   2.  Typography
 *   3.  Layout & utilities
 *   4.  Components (Button, Card, Input, etc.)
 *   5.  Responsive
 * ============================================================ */

/* ================================================================
 * 1. Reset & base (scoped to base_v2 pages only)
 * ================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11"; /* Inter stylistic alts */
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background: var(--color-surface-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--color-text-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button { cursor: pointer; }
button:disabled, [disabled] { cursor: not-allowed; }

hr {
  border: 0;
  border-top: 1px solid var(--color-border-subtle);
  margin: var(--space-6) 0;
}

img, svg { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ================================================================
 * 2. Typography
 * ================================================================ */

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--color-text-primary);
}
h1 { font-size: var(--font-size-3xl); font-weight: var(--font-weight-bold); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); font-weight: var(--font-weight-semibold); }
h6 { font-size: var(--font-size-sm); font-weight: var(--font-weight-semibold); text-transform: uppercase; letter-spacing: var(--letter-spacing-wide); color: var(--color-text-secondary); }

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

small { font-size: var(--font-size-sm); color: var(--color-text-secondary); }

code, kbd, samp, pre {
  font-family: var(--font-family-mono);
  font-size: 0.9em;
}
code {
  padding: 0.125em 0.375em;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
}

/* Numbers: always tabular so vertical columns line up */
.num, .numeric, td.numeric, th.numeric {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: right;
}

/* ================================================================
 * 3. Layout & utilities (narrow, pragmatic subset — not Tailwind)
 * ================================================================ */

/* Display */
.hidden { display: none !important; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

/* Flex */
.flex-col { flex-direction: column; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.items-stretch { align-items: stretch; }
.items-baseline { align-items: baseline; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.flex-1 { flex: 1 1 0; }
.flex-auto { flex: 1 1 auto; }
.flex-none { flex: none; }
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }

/* Grid */
.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-6 { grid-template-columns: repeat(6, 1fr); }
.grid-cols-12 { grid-template-columns: repeat(12, 1fr); }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }
.col-span-6 { grid-column: span 6 / span 6; }
.col-span-full { grid-column: 1 / -1; }

/* Spacing: gap, margin, padding (subset) */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.m-0 { margin: 0; }  .m-auto { margin: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.mt-1 { margin-top: var(--space-1); }  .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }  .mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }  .mt-8 { margin-top: var(--space-8); }
.mb-1 { margin-bottom: var(--space-1); }  .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }  .mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }  .mb-8 { margin-bottom: var(--space-8); }

.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }  .p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }  .p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.py-6 { padding-top: var(--space-6); padding-bottom: var(--space-6); }

/* Sizing */
.w-full { width: 100%; }
.w-auto { width: auto; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }
.max-w-xs { max-width: 20rem; }
.max-w-sm { max-width: 24rem; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.max-w-xl { max-width: 36rem; }
.max-w-2xl { max-width: 42rem; }
.max-w-4xl { max-width: 56rem; }
.max-w-6xl { max-width: 72rem; }
.max-w-screen { max-width: var(--content-max-width); }

/* Text */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }
.text-3xl { font-size: var(--font-size-3xl); }
.text-4xl { font-size: var(--font-size-4xl); }
.text-5xl { font-size: var(--font-size-5xl); }
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-regular { font-weight: var(--font-weight-regular); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }
.font-mono { font-family: var(--font-family-mono); font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uppercase { text-transform: uppercase; letter-spacing: var(--letter-spacing-wide); }

/* Colours */
.text-primary   { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary  { color: var(--color-text-tertiary); }
.text-brand     { color: var(--color-brand-primary); }
.text-success   { color: var(--color-success-600); }
.text-warning   { color: var(--color-warning-600); }
.text-danger    { color: var(--color-danger-600); }
.text-info      { color: var(--color-info-600); }

.bg-surface-0   { background-color: var(--color-surface-0); }
.bg-surface-1   { background-color: var(--color-surface-1); }
.bg-surface-2   { background-color: var(--color-surface-2); }

/* Borders */
.border { border: 1px solid var(--color-border-subtle); }
.border-t { border-top: 1px solid var(--color-border-subtle); }
.border-b { border-bottom: 1px solid var(--color-border-subtle); }
.border-strong { border-color: var(--color-border-default); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Shadow */
.shadow-xs { box-shadow: var(--shadow-xs); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Misc */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }
.transition { transition: all var(--duration-normal) var(--ease-out); }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }
.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; top: 0; }
.z-10 { z-index: 10; }

/* ================================================================
 * 4. Components
 * ================================================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  min-height: 36px;  /* 44px on small screens — below */
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--color-surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--color-brand-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-brand-primary);
}
.btn-primary:hover { background: var(--color-brand-primary-hover); border-color: var(--color-brand-primary-hover); }
.btn-primary:active { background: var(--color-brand-primary-active); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-primary);
}
.btn-ghost:hover { background: var(--color-surface-2); }

.btn-outline {
  background: transparent;
  border-color: var(--color-border-default);
  color: var(--color-text-primary);
}
.btn-outline:hover { background: var(--color-surface-2); }

.btn-danger {
  background: var(--color-danger-500);
  color: var(--color-text-inverse);
  border-color: var(--color-danger-500);
}
.btn-danger:hover { background: var(--color-danger-600); border-color: var(--color-danger-600); }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--font-size-xs); min-height: 28px; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--font-size-base); min-height: 44px; }
.btn-icon-only { padding: var(--space-2); aspect-ratio: 1; }

@media (max-width: 640px) {
  .btn { min-height: 44px; padding: var(--space-2-5) var(--space-4); }
  .btn-sm { min-height: 36px; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}
.card:hover { border-color: var(--color-border-default); }
.card-hoverable:hover { box-shadow: var(--shadow-md); }

.card-header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.card-title { margin: 0; font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); }
.card-subtitle { margin: var(--space-1) 0 0; font-size: var(--font-size-sm); color: var(--color-text-secondary); }

.card-body { padding: var(--space-6); }
.card-body-compact { padding: var(--space-4); }

.card-footer {
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface-1);
}

/* ---------- KPI tiles ---------- */
.kpi-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  min-height: 128px;
  transition: border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}
.kpi-tile:hover { border-color: var(--color-border-default); box-shadow: var(--shadow-sm); }
.kpi-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
}
.kpi-value {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}
.kpi-value-sm { font-size: var(--font-size-2xl); }
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  font-variant-numeric: tabular-nums;
}
.kpi-delta.positive { color: var(--color-success-600); }
.kpi-delta.negative { color: var(--color-danger-600); }
.kpi-delta.neutral { color: var(--color-text-tertiary); }
.kpi-hint { font-size: var(--font-size-xs); color: var(--color-text-tertiary); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1.4;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-secondary);
}
.badge-success { background: var(--color-success-soft); color: var(--color-success-text); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning-text); }
.badge-danger  { background: var(--color-danger-soft);  color: var(--color-danger-text); }
.badge-info    { background: var(--color-info-soft);    color: var(--color-info-text); }
.badge-brand   { background: var(--color-brand-primary-soft); color: var(--color-brand-primary); }
.badge-dot::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
}

/* ---------- Alerts (decision-first cards) ---------- */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid;
  background: var(--color-surface-0);
}
.alert-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
}
.alert-body { flex: 1; min-width: 0; }
.alert-title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  margin: 0 0 var(--space-1);
}
.alert-text { font-size: var(--font-size-sm); color: var(--color-text-secondary); margin: 0; }
.alert-verdict {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px dashed var(--color-border-subtle);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}
.alert-actions { margin-top: var(--space-3); display: flex; gap: var(--space-2); flex-wrap: wrap; }

.alert-critical { background: var(--color-danger-soft); border-color: var(--color-danger-500); }
.alert-critical .alert-title, .alert-critical .alert-icon { color: var(--color-danger-600); }
.alert-warning { background: var(--color-warning-soft); border-color: var(--color-warning-500); }
.alert-warning .alert-title, .alert-warning .alert-icon { color: var(--color-warning-600); }
.alert-info { background: var(--color-info-soft); border-color: var(--color-info-500); }
.alert-info .alert-title, .alert-info .alert-icon { color: var(--color-info-600); }
.alert-success { background: var(--color-success-soft); border-color: var(--color-success-500); }
.alert-success .alert-title, .alert-success .alert-icon { color: var(--color-success-600); }

/* ---------- Inputs ---------- */
.form-group { margin-bottom: var(--space-4); }
.form-label {
  display: block;
  margin-bottom: var(--space-1-5);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}
.form-hint { margin-top: var(--space-1); font-size: var(--font-size-xs); color: var(--color-text-tertiary); }
.form-error { margin-top: var(--space-1); font-size: var(--font-size-xs); color: var(--color-danger-600); }

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  min-height: 36px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--color-surface-2);
  color: var(--color-text-tertiary);
}
.input.error, .select.error, .textarea.error {
  border-color: var(--color-danger-500);
}
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2352525b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  appearance: none;
}
.textarea { min-height: 80px; resize: vertical; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--color-border-default);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: var(--radius-full);
  background: white;
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-fast) var(--ease-out);
}
.toggle[aria-checked="true"], .toggle.checked { background: var(--color-brand-primary); }
.toggle[aria-checked="true"]::after, .toggle.checked::after { transform: translateX(16px); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border-subtle);
  overflow-x: auto;
}
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}
.tab:hover { color: var(--color-text-primary); }
.tab.active, .tab[aria-selected="true"] {
  color: var(--color-brand-primary);
  border-bottom-color: var(--color-brand-primary);
}

/* ---------- Tables ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}
.data-table th, .data-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border-subtle);
}
.data-table th {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-secondary);
  background: var(--color-surface-1);
  position: sticky;
  top: 0;
}
.data-table tbody tr:hover { background: var(--color-surface-1); }
.data-table td.numeric, .data-table th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Mobile: table → cards */
@media (max-width: 640px) {
  .data-table-responsive thead { display: none; }
  .data-table-responsive, .data-table-responsive tbody,
  .data-table-responsive tr, .data-table-responsive td { display: block; }
  .data-table-responsive tr {
    margin-bottom: var(--space-3);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    background: var(--color-surface-0);
  }
  .data-table-responsive td {
    border: 0;
    padding: var(--space-1) 0;
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
  }
  .data-table-responsive td::before {
    content: attr(data-label);
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
  }
}

/* ---------- Skeleton loader ---------- */
.skeleton {
  display: block;
  background: linear-gradient(90deg,
    var(--color-surface-2) 0%,
    var(--color-surface-3) 50%,
    var(--color-surface-2) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.4s infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line { height: 1em; margin-bottom: var(--space-2); }
.skeleton-title { height: 1.5em; width: 40%; margin-bottom: var(--space-3); }
.skeleton-block { height: 120px; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--color-text-secondary);
}
.empty-state-icon {
  width: 48px; height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--color-text-tertiary);
}
.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2);
}
.empty-state-text { max-width: 28rem; margin: 0 auto var(--space-4); }

/* ---------- Tooltip (pure CSS, title-attr fallback) ---------- */
.has-tooltip { position: relative; }
.has-tooltip[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--color-text-primary);
  color: var(--color-surface-0);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip);
}

/* ---------- Breadcrumbs ---------- */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}
.breadcrumbs a { color: var(--color-text-secondary); }
.breadcrumbs a:hover { color: var(--color-brand-primary); }
.breadcrumbs .separator { color: var(--color-text-tertiary); }
.breadcrumbs .current { color: var(--color-text-primary); font-weight: var(--font-weight-medium); }

/* ---------- Dropdown (<details>-based, progressive) ---------- */
.dropdown { position: relative; }
.dropdown[open] .dropdown-menu { display: block; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 180px;
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: var(--z-dropdown);
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.dropdown-item:hover { background: var(--color-surface-2); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--color-border-subtle); margin: var(--space-1) 0; }

/* ---------- Modal (Alpine.js driven) ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--color-surface-overlay);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal {
  background: var(--color-surface-0);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  z-index: var(--z-modal);
}
.modal-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--color-border-subtle); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: var(--space-6); }
.modal-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border-subtle); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 420px;
  animation: toast-in var(--duration-normal) var(--ease-spring);
}
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Progress bar ---------- */
.progress { width: 100%; height: 6px; background: var(--color-surface-2); border-radius: var(--radius-full); overflow: hidden; }
.progress-bar { height: 100%; background: var(--color-brand-primary); transition: width var(--duration-normal) var(--ease-out); }
.progress-bar.success { background: var(--color-success-500); }
.progress-bar.warning { background: var(--color-warning-500); }
.progress-bar.danger  { background: var(--color-danger-500); }

/* ---------- Sidebar & top bar layout ---------- */
.app-shell {
  display: grid;
  grid-template-areas: "sidebar main";
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  background: var(--color-surface-1);
}
.app-sidebar {
  grid-area: sidebar;
  background: var(--color-surface-0);
  border-right: 1px solid var(--color-border-subtle);
  padding: var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.app-sidebar-brand {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
  padding: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sidebar-nav { display: flex; flex-direction: column; gap: var(--space-0-5); }
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  transition: background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}
.sidebar-nav-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  text-decoration: none;
}
.sidebar-nav-item.active {
  background: var(--color-brand-primary-soft);
  color: var(--color-brand-primary);
}
.sidebar-nav-section {
  margin-top: var(--space-4);
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-tertiary);
  font-weight: var(--font-weight-semibold);
}

.app-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0; /* prevents grid-blowout on wide tables */
}
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface-0);
  border-bottom: 1px solid var(--color-border-subtle);
  min-height: var(--topbar-height);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}
.app-content {
  flex: 1;
  padding: var(--space-6);
  max-width: var(--content-max-width);
  width: 100%;
  margin: 0 auto;
}

/* Bottom nav (mobile) — hidden on desktop */
.app-bottomnav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface-0);
  border-top: 1px solid var(--color-border-subtle);
  height: var(--bottomnav-height);
  padding: var(--space-1);
  z-index: var(--z-sticky);
  justify-content: space-around;
  align-items: center;
}
.bottomnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-1) var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
}
.bottomnav-item.active { color: var(--color-brand-primary); }
.bottomnav-item:hover { text-decoration: none; }

/* ================================================================
 * 5. Responsive — mobile-first overrides
 * ================================================================ */

@media (max-width: 960px) {
  .app-shell {
    grid-template-areas: "main";
    grid-template-columns: 1fr;
  }
  .app-sidebar { display: none; }
  .app-bottomnav { display: flex; }
  .app-content { padding: var(--space-4); padding-bottom: calc(var(--bottomnav-height) + var(--space-4)); }
  .app-topbar { padding: var(--space-3) var(--space-4); }
}

@media (max-width: 640px) {
  .grid-cols-2, .grid-cols-3, .grid-cols-4, .grid-cols-6 { grid-template-columns: 1fr; }
  .grid-cols-12 { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: var(--font-size-2xl); }
  h2 { font-size: var(--font-size-xl); }
  .kpi-value { font-size: var(--font-size-3xl); }
  .card-body { padding: var(--space-4); }
  .card-header { padding: var(--space-3) var(--space-4); }
  .hide-mobile { display: none !important; }
}

@media (min-width: 641px) {
  .show-mobile-only { display: none !important; }
}

/* ================================================================
 * 6. PREMIUM / FUTURISTIC LAYER (v2.1 — "fintech 2025")
 * ----------------------------------------------------------------
 * Aurora background, glass surfaces, gradient accents, springy
 * motion, glow on focus, animated KPI rollups, sparklines,
 * command palette, pulsing live indicators, custom scrollbars.
 * ================================================================ */

/* ---------- Aurora / mesh background ---------- */
.app-shell {
  position: relative;
  isolation: isolate;
  background: var(--color-surface-0);
}
.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--gradient-mesh-light);
  background-size: 200% 200%;
  opacity: 1;
  z-index: -1;
  pointer-events: none;
  animation: aurora-drift var(--duration-ambient) ease-in-out infinite alternate;
}
:root[data-theme="dark"] .app-shell::before,
:root:not([data-theme="light"]) .app-shell::before {
  background-image: var(--gradient-mesh-dark);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .app-shell::before {
    background-image: var(--gradient-mesh-dark);
  }
}
@keyframes aurora-drift {
  0%   { background-position: 0% 0%; }
  100% { background-position: 100% 100%; }
}

/* ---------- Custom scrollbars (thin, subtle, branded) ---------- */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--color-border-default);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--color-border-strong); background-clip: padding-box; }
* { scrollbar-width: thin; scrollbar-color: var(--color-border-default) transparent; }

/* ---------- Display font for headings (Space Grotesk) ---------- */
h1, h2, .app-sidebar-brand { font-family: var(--font-family-display); letter-spacing: -0.02em; }
.kpi-value { font-family: var(--font-family-display); letter-spacing: -0.025em; }

/* ---------- Glass surfaces (frosted card / sidebar) ---------- */
.app-sidebar {
  background: var(--glass-bg-light);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  border-right: 1px solid var(--color-border-subtle);
}
:root[data-theme="dark"] .app-sidebar,
:root:not([data-theme="light"]) .app-sidebar {
  background: var(--glass-bg-dark);
  border-right-color: var(--glass-border-dark);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .app-sidebar {
    background: var(--glass-bg-dark);
    border-right-color: var(--glass-border-dark);
  }
}

.app-topbar {
  background: var(--glass-bg-light);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  border-bottom: 1px solid var(--color-border-subtle);
}
:root[data-theme="dark"] .app-topbar,
:root:not([data-theme="light"]) .app-topbar {
  background: var(--glass-bg-dark);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .app-topbar { background: var(--glass-bg-dark); }
}

/* Glassmorphic KPI tiles + cards */
.kpi-tile, .card {
  background: var(--color-surface-0);
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  transition:
    border-color var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-spring);
}
.kpi-tile:hover, .card-hoverable:hover {
  transform: translateY(-2px);
  border-color: var(--color-border-default);
  box-shadow: var(--shadow-md);
}

/* Gradient top-border accent on KPI tiles (subtle depth signal) */
.kpi-tile {
  position: relative;
  overflow: hidden;
}
.kpi-tile::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
}
.kpi-tile:hover::before { opacity: 1; }
.kpi-tile.kpi-accent::before { opacity: 1; }
.kpi-tile.kpi-accent-danger::before { background: var(--gradient-danger); opacity: 1; }
.kpi-tile.kpi-accent-success::before { background: var(--gradient-success); opacity: 1; }
.kpi-tile.kpi-accent-warning::before { background: var(--gradient-warning); opacity: 1; }

/* ---------- Sparkline (tiny trend chart in KPI tile) ---------- */
.kpi-sparkline {
  position: absolute;
  right: var(--space-3);
  top: var(--space-3);
  width: 72px;
  height: 28px;
  pointer-events: none;
  opacity: 0.9;
}
.kpi-sparkline path.line {
  fill: none;
  stroke: var(--color-text-tertiary);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--duration-normal) var(--ease-out);
}
.kpi-sparkline path.area {
  fill: currentColor;
  opacity: 0.08;
}
.kpi-sparkline.positive path.line { stroke: var(--color-success-500); }
.kpi-sparkline.positive path.area { color: var(--color-success-500); }
.kpi-sparkline.negative path.line { stroke: var(--color-danger-500); }
.kpi-sparkline.negative path.area { color: var(--color-danger-500); }
.kpi-sparkline.neutral path.line { stroke: var(--color-brand-primary); }
.kpi-sparkline.neutral path.area { color: var(--color-brand-primary); }

/* ---------- Gradient value (for hero KPIs) ---------- */
.kpi-value-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ---------- Live pulsing dot (for real-time / active indicators) ---------- */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-success-500);
  box-shadow: 0 0 0 0 var(--color-success-500);
  animation: live-pulse 2s var(--ease-out) infinite;
}
.live-dot.stale { background: var(--color-warning-500); box-shadow: 0 0 0 0 var(--color-warning-500); }
.live-dot.offline { background: var(--color-danger-500); box-shadow: 0 0 0 0 var(--color-danger-500); }
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Primary button with gradient + glow ---------- */
.btn-primary {
  background: var(--gradient-brand);
  border-color: transparent;
  box-shadow: var(--shadow-sm), var(--glow-brand-sm);
}
.btn-primary:hover {
  box-shadow: var(--shadow-md), var(--glow-brand);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

/* Focus ring = glow (more premium than plain outline) */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-md);
}

/* ---------- Gradient border on active sidebar item ---------- */
.sidebar-nav-item.active {
  background: var(--color-brand-primary-soft);
  color: var(--color-brand-primary);
  position: relative;
  box-shadow: inset 2px 0 0 0 var(--color-brand-primary);
}

/* ---------- Card fade-in on page load (subtle entrance) ---------- */
.card, .kpi-tile {
  animation: fade-up var(--duration-slow) var(--ease-spring) backwards;
}
.card:nth-child(1), .kpi-tile:nth-child(1) { animation-delay: 0ms; }
.card:nth-child(2), .kpi-tile:nth-child(2) { animation-delay: 40ms; }
.card:nth-child(3), .kpi-tile:nth-child(3) { animation-delay: 80ms; }
.card:nth-child(4), .kpi-tile:nth-child(4) { animation-delay: 120ms; }
.card:nth-child(5), .kpi-tile:nth-child(5) { animation-delay: 160ms; }
.card:nth-child(6), .kpi-tile:nth-child(6) { animation-delay: 200ms; }
.card:nth-child(7), .kpi-tile:nth-child(7) { animation-delay: 240ms; }
.card:nth-child(8), .kpi-tile:nth-child(8) { animation-delay: 280ms; }
@keyframes fade-up {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---------- Command palette (Cmd+K) ---------- */
.command-palette-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  animation: cmd-fade var(--duration-normal) var(--ease-out);
}
.command-palette {
  width: 100%;
  max-width: 560px;
  background: var(--color-surface-0);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 40px rgba(45, 111, 245, 0.15);
  overflow: hidden;
  animation: cmd-spring var(--duration-slow) var(--ease-spring);
}
.command-palette-input {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
  outline: none;
}
.command-palette-input::placeholder { color: var(--color-text-tertiary); }
.command-palette-list {
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-2);
}
.command-palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
}
.command-palette-item:hover,
.command-palette-item.active {
  background: var(--color-brand-primary-soft);
  color: var(--color-brand-primary);
}
.command-palette-item-kbd {
  margin-left: auto;
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  font-family: var(--font-family-mono);
}
.command-palette-footer {
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-border-subtle);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}
@keyframes cmd-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes cmd-spring {
  from { opacity: 0; transform: translateY(-12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* kbd shortcut hint */
kbd, .kbd {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-family: var(--font-family-mono);
  font-size: 11px;
  color: var(--color-text-secondary);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-subtle);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- Cmd+K search trigger in topbar ---------- */
.cmd-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1-5) var(--space-3);
  min-width: 240px;
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}
.cmd-trigger:hover { border-color: var(--color-border-default); background: var(--color-surface-2); }
.cmd-trigger-kbd { margin-left: auto; }

@media (max-width: 640px) {
  .cmd-trigger { min-width: 0; padding: var(--space-1-5); }
  .cmd-trigger-text, .cmd-trigger-kbd { display: none; }
}

/* ---------- Animated counter for KPI values (JS-driven; CSS hides raw until rendered) ---------- */
.kpi-counter[data-target] { font-variant-numeric: tabular-nums; }

/* ---------- Enhanced badge with subtle glow when live ---------- */
.badge-brand { box-shadow: var(--glow-brand-sm); }

/* ---------- Hero heading (gradient text) ---------- */
.heading-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  letter-spacing: -0.03em;
}

/* ---------- Magnetic card hover glow (subtle colour wash) ---------- */
.card-interactive {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.card-interactive::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(300px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
                              rgba(45, 111, 245, 0.08), transparent 40%);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
  pointer-events: none;
}
.card-interactive:hover::after { opacity: 1; }

/* ---------- Alerts: subtle glow on critical ---------- */
.alert-critical { box-shadow: var(--shadow-sm), 0 0 24px rgba(220, 38, 38, 0.12); }
.alert-warning  { box-shadow: var(--shadow-sm), 0 0 24px rgba(245, 158, 11, 0.10); }

/* Disable ambient animation on reduced motion */
@media (prefers-reduced-motion: reduce) {
  .app-shell::before { animation: none; }
  .live-dot { animation: none; }
  .card, .kpi-tile { animation: none; }
}

