:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --accent: #2563eb;
  --danger: #b42318;
  --warn: #b54708;
  --good: #067647;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);

  /* Primary (teal) scale */
  --primary-50: #f0fdfa;
  --primary-100: #ccfbf1;
  --primary-200: #99f6e4;
  --primary-300: #5eead4;
  --primary-400: #2dd4bf;
  --primary-500: #14b8a6;
  --primary-600: #0f766e;
  --primary-700: #0b5f59;
  --primary-800: #134e4a;
  --primary-900: #0a3e3a;

  /* Neutral (gray) scale */
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-300: #cbd5e1;
  --neutral-400: #94a3b8;
  --neutral-500: #64748b;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1e293b;
  --neutral-900: #0f172a;

  /* Success (green) scale */
  --success-50: #ecfdf5;
  --success-100: #d1fae5;
  --success-200: #a7f3d0;
  --success-300: #6ee7b7;
  --success-400: #34d399;
  --success-500: #10b981;
  --success-600: #059669;
  --success-700: #047857;
  --success-800: #065f46;
  --success-900: #064e3b;

  /* Warn (amber) scale */
  --warn-50: #fffbeb;
  --warn-100: #fef3c7;
  --warn-200: #fde68a;
  --warn-300: #fcd34d;
  --warn-400: #fbbf24;
  --warn-500: #f59e0b;
  --warn-600: #d97706;
  --warn-700: #b45309;
  --warn-800: #92400e;
  --warn-900: #78350f;

  /* Danger (red) scale */
  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --danger-200: #fecaca;
  --danger-300: #fca5a5;
  --danger-400: #f87171;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;
  --danger-800: #991b1b;
  --danger-900: #7f1d1d;

  /* Radius scale */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Shadow scale */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.12);
  --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.18);

  /* Spacing scale */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 24px;
  --sp-2xl: 32px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 250ms;
}

/* Typography utility classes */
.text-display {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.text-h1 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.text-h2 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.text-eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.text-caption {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.num-tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, #121820 0%, #0b1117 100%);
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.panel p {
  margin: 0;
}

.brand h1 {
  font-size: 16px;
}

.brand p,
.side-note {
  color: #a7b0bd;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #d5dbe5;
  text-align: left;
  padding: 11px 12px 11px 16px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: white;
}

.nav-item.active {
  background: #26313d;
  color: white;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
}

.side-note {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #667085;
}

.dot.good {
  background: #12b76a;
}

.dot.bad {
  background: #f04438;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.topbar h2 {
  font-size: 28px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.api-key {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 10px;
  color: var(--text);
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 82px;
}

.tall {
  min-height: 160px;
  grid-column: 1 / -1;
}

.btn,
.icon-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: #aab4c3;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .hero-card.large {
    grid-column: span 2;
  }
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}

.metric:hover,
.panel:hover {
  box-shadow: var(--shadow-lg);
}

.metric {
  padding: 18px;
}

.metric span,
.panel p,
.item-meta {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 25px;
}

/* Hero metric cards */
.hero-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  transition: box-shadow var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}

.hero-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.hero-caption {
  margin-top: 2px;
  color: var(--muted, #64748b);
  font-style: italic;
  font-size: 11px;
}

.hero-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hero-value {
  display: block;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  margin: 8px 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

.hero-card.large .hero-value {
  font-size: 36px;
}

.hero-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  white-space: nowrap;
}

.hero-delta.delta-up {
  color: var(--success-700);
  background: var(--success-50);
  border-color: var(--success-200);
}

.hero-delta.delta-down {
  color: var(--danger-700);
  background: var(--danger-50);
  border-color: var(--danger-200);
}

.hero-delta.delta-flat {
  color: var(--neutral-600);
  background: var(--neutral-50);
  border-color: var(--neutral-200);
}

.sparkline-wrap {
  position: relative;
  width: 100%;
  height: 32px;
  margin-top: auto;
}

.hero-sparkline {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  opacity: 0.85;
  display: block;
}

/* Chart containers */
.chart-host {
  position: relative;
  width: 100%;
}

.chart-legend {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.chart-legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.chart-legend-row .legend-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-amount {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--muted);
  font-weight: 600;
}

/* Focus rings */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible {
  outline: 3px solid var(--primary-200);
  outline-offset: 2px;
}

.content-grid,
.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 1024px) {
  .content-grid,
  .two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.large {
  grid-column: span 1;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h3 {
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid button,
.form-grid textarea {
  grid-column: 1 / -1;
}

.filters,
.action-stack {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filters > * {
  flex: 1;
  min-width: 160px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 650;
}

.right {
  text-align: right;
}

.stack,
.bar-list {
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.item-title {
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  background: white;
}

.pill.good {
  color: var(--good);
  border-color: #abefc6;
  background: #ecfdf3;
}

.pill.warn {
  color: var(--warn);
  border-color: #fedf89;
  background: #fffaeb;
}

.pill.danger {
  color: var(--danger);
  border-color: #fecdca;
  background: #fef3f2;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #edf1f6;
  overflow: hidden;
  margin-top: 8px;
}

.bar > span {
  display: block;
  height: 100%;
  max-width: 100%;
  background: var(--accent);
}

.bar > span.good {
  background: var(--good);
}

.bar > span.warn {
  background: var(--warn);
}

.export-box {
  width: 100%;
  min-height: 520px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* Toast stack — fixed top-right, animated, auto-dismiss */
.alert-host {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  margin-bottom: 0;
}
.alert-host > * { pointer-events: auto; }

.alert {
  background: white;
  border-radius: var(--r-md, 8px);
  border: 1px solid var(--line);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg, 0 10px 25px rgba(0,0,0,0.1));
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 280px;
  max-width: 400px;
  animation: alert-enter 250ms var(--ease-out, ease-out);
}
.alert-leaving { animation: alert-leave 250ms var(--ease-out, ease-out) forwards; }
@keyframes alert-enter {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes alert-leave {
  to { transform: translateX(110%); opacity: 0; }
}
.alert-icon {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; flex-shrink: 0; color: white; font-size: 12px;
}
.alert-info  .alert-icon { background: var(--primary-500, #14b8a6); }
.alert-success .alert-icon { background: var(--success-500, #10b981); }
.alert-warn  .alert-icon { background: var(--warn-500, #f59e0b); }
.alert-error .alert-icon { background: var(--danger-500, #ef4444); }
.alert-message { flex: 1; font-size: 14px; color: var(--text, #0f172a); }
.alert-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 0; font-size: 18px; line-height: 1;
}
.alert-close:hover { color: var(--text); }

/* Legacy aliases (old call sites used class "success"/"error" on .alert) */
.alert.success { background: white; border-color: #abefc6; }
.alert.success::before {
  content: "✓"; display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--success-500, #10b981); color: #fff; font-weight: 700; font-size: 12px;
}
.alert.error { background: white; border-color: #fecdca; color: var(--text, #0f172a); }
.alert.error::before {
  content: "⚠"; display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--danger-500, #ef4444); color: #fff; font-weight: 700; font-size: 12px;
}

dialog {
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 28px 60px rgba(15, 23, 42, 0.22);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
}

.dialog-card {
  width: min(520px, calc(100vw - 28px));
  padding: 18px;
  display: grid;
  gap: 12px;
}

.dialog-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-card h3 {
  margin: 0;
}

.icon-btn {
  min-width: 40px;
  padding: 0;
}

@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric strong {
    font-size: 22px;
  }
}

/* ===========================
   Phase 2: Transactions workflow
   =========================== */

/* Row actions kebab + menu */
.row-actions {
  position: relative;
  display: inline-block;
  text-align: right;
}

.row-actions-btn {
  border: 0;
  background: transparent;
  color: var(--neutral-500);
  border-radius: var(--r-sm);
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.row-actions-btn:hover,
.row-actions-btn[aria-expanded="true"] {
  background: var(--neutral-100);
  color: var(--neutral-800);
}

.row-actions-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 100;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.row-actions-menu[hidden] {
  display: none;
}

.row-actions-menu button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  min-height: 0;
  width: 100%;
}

.row-actions-menu button:hover {
  background: var(--neutral-100);
}

.row-actions-menu button.danger {
  color: var(--danger-700);
}

.row-actions-menu button.danger:hover {
  background: var(--danger-50);
}

/* Inline delete confirmation */
.delete-confirm {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
  min-height: 0;
  border-radius: var(--r-sm);
}

.btn.danger {
  background: var(--danger-500);
  color: white;
  border-color: var(--danger-500);
}

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

/* Row fade on delete */
tr.tx-removing,
.tx-card.tx-removing {
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

/* Drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.drawer[hidden] {
  display: none;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  animation: drawer-fade var(--dur-base) var(--ease-out);
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 440px;
  max-width: 100vw;
  background: white;
  box-shadow: var(--shadow-xl);
  padding: 24px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform var(--dur-base) var(--ease-out);
  animation: drawer-slide-in var(--dur-base) var(--ease-out);
}

.drawer[data-state="closing"] .drawer-panel {
  transform: translateX(100%);
}

.drawer[data-state="closing"] .drawer-backdrop {
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

@keyframes drawer-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes drawer-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 18px;
}

.drawer-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .drawer-panel {
    width: 100%;
  }
}

/* Filter toggle */
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  min-height: 40px;
  cursor: pointer;
}

.filter-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  padding: 0;
  margin: 0;
}

/* Filter chips */
.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-chips:empty {
  display: none;
}

.chip {
  background: var(--primary-50);
  color: var(--primary-900);
  border: 1px solid var(--primary-200);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  min-height: 0;
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease-out);
}

.chip:hover {
  background: var(--primary-100);
}

.chip .chip-x {
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}

.chip.clear-all {
  background: var(--neutral-100);
  color: var(--neutral-700);
  border-color: var(--neutral-200);
}

.chip.clear-all:hover {
  background: var(--neutral-200);
}

/* Mobile transactions cards */
.tx-cards {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.tx-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  cursor: pointer;
  transition: box-shadow var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.tx-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--neutral-300);
}

.tx-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.tx-card-date {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tx-card-desc {
  font-weight: 600;
  margin-top: 4px;
  word-break: break-word;
}

.tx-card-amount {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 700;
  white-space: nowrap;
}

.tx-card-meta {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  align-items: center;
}

.tx-card-badge {
  background: var(--neutral-100);
  padding: 2px 8px;
  border-radius: 999px;
}

.tx-card .row-actions {
  margin-left: auto;
}

@media (max-width: 768px) {
  .table-wrap table {
    display: none;
  }
  .table-wrap .tx-cards {
    display: flex;
  }
}

@media (min-width: 769px) {
  .table-wrap .tx-cards {
    display: none;
  }
}

/* Empty states */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  opacity: 0.4;
  margin-bottom: 12px;
  line-height: 1;
}

.empty-state h4 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}

.empty-state p {
  margin: 0 0 20px;
  font-size: 14px;
}

.empty-state .cta-group {
  display: inline-flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.tx-empty[hidden] {
  display: none;
}

/* ============================
 * Phase 3: CSV Import Wizard
 * ============================ */
.wizard-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  display: flex;
  gap: 4px;
  counter-reset: step;
}
.wizard-steps li {
  flex: 1;
  padding: 10px 12px;
  background: var(--neutral-100);
  border-radius: var(--r-md, 8px);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.wizard-steps li::before {
  content: counter(step);
  counter-increment: step;
  background: var(--neutral-300);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.wizard-steps li.active {
  background: var(--primary-50);
  color: var(--primary-900);
}
.wizard-steps li.active::before {
  background: var(--primary-600);
}
.wizard-steps li.complete {
  color: var(--success-700);
  background: var(--success-50);
}
.wizard-steps li.complete::before {
  background: var(--success-600);
  content: "✓";
  counter-increment: none;
}
@media (max-width: 640px) {
  .wizard-steps li:not(.active):not(.complete) span { display: none; }
}

.wizard-step { display: block; }
.wizard-step[hidden] { display: none; }

.upload-zone {
  border: 2px dashed var(--line);
  border-radius: var(--r-lg, 12px);
  padding: 32px;
  text-align: center;
  background: var(--neutral-50);
  transition: all 200ms;
}
.upload-zone.drag-over {
  border-color: var(--primary-500);
  background: var(--primary-50);
}
.upload-zone .btn { margin-bottom: 8px; }

.divider {
  text-align: center;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  position: relative;
}
.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--line);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

#csvPaste {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 8px);
  background: var(--panel);
  resize: vertical;
}

.wizard-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 12px;
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.mapping-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.mapping-grid select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 8px);
  background: var(--panel);
  font-size: 14px;
  color: var(--text);
}
.mapping-grid details { grid-column: 1 / -1; }
.mapping-grid details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--primary-700);
  padding: 6px 0;
}

.preview-table { margin-top: 20px; }
.preview-table h5 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.preview-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 8px);
}
#mapPreviewTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
#mapPreviewTable th,
#mapPreviewTable td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: left;
}
#mapPreviewTable th {
  background: var(--neutral-100);
  color: var(--muted);
  font-weight: 600;
}
#mapPreviewTable th.mapped,
#mapPreviewTable td.mapped {
  background: var(--primary-50);
  color: var(--primary-900);
}
#mapPreviewTable th.mapped { font-weight: 700; }
#mapPreviewTable td.unmapped { color: var(--neutral-400); }
#mapPreviewTable th .map-tag {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--primary-700);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 12px 0 20px;
}
.summary-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: var(--neutral-50);
  border-radius: var(--r-md, 8px);
}
.summary-grid strong { font-size: 18px; }

.alert-warn {
  background: var(--warn-50);
  border: 1px solid var(--warn-200);
  color: var(--warn-800);
  padding: 12px 14px;
  border-radius: var(--r-md, 8px);
  margin-bottom: 12px;
  font-size: 13px;
}
.alert-warn details summary {
  cursor: pointer;
  font-weight: 600;
}
.alert-warn ul { margin: 8px 0 0; padding-left: 20px; }

.success-banner {
  background: var(--success-50);
  border: 1px solid var(--success-200);
  color: var(--success-800);
  padding: 16px;
  border-radius: var(--r-md, 8px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}
.success-banner strong { font-size: 16px; }

.error-text { color: var(--danger); }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
.btn.ghost:hover {
  background: var(--neutral-100);
  color: var(--text);
}

/* ============================
 * Phase 3: Duplicate review
 * ============================ */
.dup-bulk {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
  flex-wrap: wrap;
}

.dup-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-lg, 12px);
  padding: 20px;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(15,23,42,0.05));
}
.dup-card + .dup-card { margin-top: 12px; }

.dup-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 16px;
}

.score-pill {
  background: var(--neutral-100);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  margin-top: 4px;
}
.score-pill.score-high { background: var(--danger-100, #fee2e2); color: var(--danger-700, #b91c1c); }
.score-pill.score-mid  { background: var(--warn-100); color: var(--warn-700); }
.score-pill.score-low  { background: var(--neutral-100); color: var(--neutral-700); }

.dup-reason {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 60%;
  text-align: right;
}

.dup-compare {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: stretch;
  padding: 16px;
  background: var(--neutral-50);
  border-radius: var(--r-md, 8px);
}
.dup-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dup-amount {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.dup-meta {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dup-diff {
  background: rgba(245, 158, 11, 0.15);
  border-bottom: 2px solid var(--warn-500);
  color: var(--text);
  padding: 0 4px;
  border-radius: 2px;
  display: inline-block;
}
.dup-vs {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  align-self: center;
}

.dup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn.danger:hover { filter: brightness(0.95); }

@media (max-width: 640px) {
  .dup-compare { grid-template-columns: 1fr; }
  .dup-vs { transform: rotate(90deg); padding: 4px 0; }
  .dup-reason { max-width: 100%; text-align: left; }
  .dup-head { flex-direction: column; }
}

/* =====================================================================
   Phase 4B additions: skeletons, onboarding, kb hint, sticky, footer
   ===================================================================== */

/* ---- Loading skeletons (shimmer placeholders, replace spinners) ---- */
.skeleton {
  background: linear-gradient(90deg, var(--neutral-100, #f1f5f9), var(--neutral-200, #e2e8f0), var(--neutral-100, #f1f5f9));
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm, 4px);
  display: block;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line { height: 14px; margin: 8px 0; }
.skeleton-line.short  { width: 40%; }
.skeleton-line.medium { width: 60%; }
.skeleton-line.long   { width: 90%; }
.skeleton-block { height: 80px; }
.skeleton-card {
  padding: 16px;
  background: linear-gradient(90deg, var(--neutral-50, #f8fafc), var(--neutral-100, #f1f5f9), var(--neutral-50, #f8fafc));
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-md, 8px);
  margin-bottom: 8px;
}
.skeleton-card .skeleton { background: rgba(255,255,255,0.65); }

/* ---- Onboarding dialog ---- */
.onboarding::backdrop { background: rgba(15, 23, 42, 0.5); }
.onboarding[open] {
  border: none;
  padding: 0;
  border-radius: var(--r-xl, 16px);
  box-shadow: var(--shadow-xl, 0 20px 50px rgba(0,0,0,0.25));
  max-width: 560px;
  width: 90vw;
}
.onboarding-card { padding: 32px; }
.onboarding-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.onboarding-progress { display: flex; gap: 8px; align-items: center; }
.onboarding-progress .step {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--neutral-200, #e2e8f0);
  color: var(--muted, #64748b);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
}
.onboarding-progress .step.active   { background: var(--primary-600, #0d9488); color: #fff; }
.onboarding-progress .step.complete { background: var(--success-500, #10b981); color: #fff; }
.onboarding-step h2 { margin: 0 0 8px; font-size: 24px; }
.onboarding-step h3 { margin: 16px 0 4px; }
.onboarding-step p  { color: var(--muted, #64748b); margin: 0 0 16px; }
.onboarding-step .form-grid {
  display: grid;
  gap: 10px;
  margin: 8px 0 4px;
}
.onboarding-step .form-grid input,
.onboarding-step .form-grid select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md, 8px);
  font: inherit;
}
.onboarding-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 8px;
}
.onboarding-options { display: grid; gap: 12px; margin: 16px 0; }
.option-card {
  background: white;
  border: 2px solid var(--line);
  border-radius: var(--r-lg, 12px);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 200ms;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font: inherit;
}
.option-card:hover { border-color: var(--primary-500, #14b8a6); }
.option-card strong { font-size: 15px; }
.option-card .text-caption { color: var(--muted, #64748b); }
.onboarding header .icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted, #64748b);
  padding: 4px 8px;
}
.onboarding header .icon-btn:hover {
  color: var(--text, #0f172a);
  background: var(--neutral-100, #f1f5f9);
  border-radius: var(--r-sm, 4px);
}

/* ---- Keyboard shortcuts hint ---- */
.kb-hint {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--neutral-200, #e2e8f0);
  color: var(--muted, #64748b);
  border: none;
  cursor: pointer;
  font-weight: 700;
  z-index: 100;
  box-shadow: var(--shadow-md, 0 4px 10px rgba(0,0,0,0.1));
}
.kb-hint:hover { background: var(--primary-500, #14b8a6); color: white; }
.kb-popover {
  position: fixed;
  bottom: 64px;
  right: 20px;
  background: white;
  border-radius: var(--r-lg, 12px);
  box-shadow: var(--shadow-xl, 0 20px 50px rgba(0,0,0,0.25));
  padding: 16px;
  min-width: 240px;
  z-index: 100;
  border: 1px solid var(--line);
}
.kb-popover[hidden] { display: none; }
.kb-popover h4 { margin: 0 0 12px; }
.kb-popover dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
}
.kb-popover dt {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--neutral-100, #f1f5f9);
  padding: 2px 6px;
  border-radius: var(--r-sm, 4px);
  font-size: 12px;
  justify-self: start;
}
.kb-popover dd { margin: 0; font-size: 13px; color: var(--muted, #64748b); }

/* ---- Sticky table headers ---- */
.table-wrap { max-height: 600px; overflow-y: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--neutral-50, #f8fafc);
  z-index: 2;
  border-bottom: 1px solid var(--line);
}
.table-wrap tbody tr:hover { background: var(--primary-50, #f0fdfa); }

/* ---- Disclaimer / app footer ---- */
.app-footer {
  margin-top: 32px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted, #64748b);
  font-size: 13px;
}
.app-footer a {
  color: var(--primary-700, #0f766e);
  text-decoration: none;
}
.app-footer a:hover { text-decoration: underline; }

/* ============ Phase 4A: Charts, Budgets, Debt drawer, Account Detail ============ */

.chart-wrap { position: relative; width: 100%; height: 240px; }
.chart-wrap > canvas { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; }
.chart-wrap-tight { margin-top: 16px; height: 200px; }

/* Range toggle (Net Worth time range) */
.range-toggle {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--neutral-100); border-radius: 999px;
}
.range-toggle .range-btn {
  appearance: none; border: none; background: transparent;
  color: var(--muted, #64748b); font-weight: 600; font-size: 12px;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.range-toggle .range-btn:hover { color: var(--text, #0f172a); }
.range-toggle .range-btn.active {
  background: #ffffff; color: var(--primary-700, #0b5f59);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Budget summary doughnut */
.budget-summary { display: flex; justify-content: center; margin-bottom: 16px; }
.budget-doughnut-wrap {
  position: relative; width: 220px; height: 220px;
  display: flex; align-items: center; justify-content: center;
}
.budget-doughnut-wrap canvas { max-width: 100%; max-height: 100%; }
.budget-doughnut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
  text-align: center;
}
.budget-doughnut-center strong { font-size: 22px; line-height: 1.1; }

/* Budget rows */
.budget-row { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--line, #e2e8f0); border-radius: var(--r-md, 8px); background: #ffffff; }
.budget-row + .budget-row { margin-top: 8px; }
.budget-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.budget-row-title { font-weight: 600; }
.budget-row-amount { font-variant-numeric: tabular-nums; color: var(--muted, #64748b); font-size: 13px; }
.budget-row-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 12px; color: var(--muted, #64748b); }
.budget-bar { height: 6px; background: var(--neutral-100, #f1f5f9); border-radius: 999px; overflow: hidden; }
.budget-bar-fill { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 300ms ease; background: var(--success-500, #10b981); }
.budget-bar-fill.good { background: var(--success-500, #10b981); }
.budget-bar-fill.warn { background: var(--warn-500, #f59e0b); }
.budget-bar-fill.over { background: var(--danger-500, #ef4444); }
.budget-over-badge { background: var(--danger-500, #ef4444); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }

/* Dashboard debt items (rich card) */
.debt-item { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line, #e2e8f0); border-radius: var(--r-md, 8px); background: #ffffff; cursor: pointer; transition: box-shadow 150ms ease, transform 150ms ease; }
.debt-item + .debt-item { margin-top: 8px; }
.debt-item:hover { box-shadow: var(--shadow-md, 0 2px 8px rgba(15,23,42,0.06)); }
.debt-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.debt-item-name { font-weight: 600; }
.debt-item-balance { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.debt-item-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--neutral-100, #f1f5f9); color: var(--text, #0f172a); }
.chip-success { background: rgba(16, 185, 129, 0.12); color: var(--success-700, #047857); }
.chip-muted { background: var(--neutral-100, #f1f5f9); color: var(--muted, #64748b); }
.chip-primary { background: rgba(15, 118, 110, 0.12); color: var(--primary-700, #0b5f59); }

/* Debt drawer */
.drawer-body { padding: 16px 20px 20px; }
.debt-hero { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; padding: 16px; background: var(--neutral-50, #f8fafc); border-radius: var(--r-md, 8px); border: 1px solid var(--line, #e2e8f0); }
.debt-hero .hero-value { font-size: 28px; color: var(--success-700, #047857); }

/* Account detail screen */
.view-back { margin-bottom: 12px; }
.btn.ghost { background: transparent; color: var(--muted, #64748b); border: 1px solid transparent; }
.btn.ghost:hover { background: var(--neutral-100, #f1f5f9); color: var(--text, #0f172a); }
.account-detail-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 24px; background: #ffffff; border-radius: var(--r-lg, 12px); border: 1px solid var(--line, #e2e8f0); box-shadow: var(--shadow-md, 0 2px 8px rgba(15,23,42,0.06)); margin-bottom: 16px; gap: 24px; flex-wrap: wrap; }
.account-detail-head h3 { margin: 4px 0 2px; }
.account-detail-balance { text-align: right; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.account-detail-balance .hero-value { font-size: 28px; }
.link-btn { background: none; border: none; color: var(--primary-700, #0b5f59); text-decoration: underline; cursor: pointer; padding: 0; font-weight: 600; font: inherit; }
.link-btn:hover { color: var(--primary-900, #064e44); }

/* Mini transactions list in account detail */
.mini-tx { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line, #e2e8f0); }
.mini-tx:last-child { border-bottom: none; }
.mini-tx-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mini-tx-desc { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-tx-meta { font-size: 12px; color: var(--muted, #64748b); }
.mini-tx-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.mini-tx-amount.amount-pos { color: var(--success-600, #059669); }
.mini-tx-amount.amount-neg { color: var(--danger-600, #dc2626); }

/* Reconciliation timeline */
.reconciliation-row { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-left: 3px solid var(--primary-300, #5eead4); margin-left: 8px; background: var(--neutral-50, #f8fafc); border-radius: 0 var(--r-md, 8px) var(--r-md, 8px) 0; }
.reconciliation-row + .reconciliation-row { margin-top: 8px; }
.reconciliation-row .recon-date { font-weight: 600; font-size: 13px; }
.reconciliation-row .recon-amount { font-variant-numeric: tabular-nums; }
.reconciliation-row .recon-diff { font-size: 12px; }
.reconciliation-row .recon-diff.diff-zero { color: var(--success-600, #059669); }
.reconciliation-row .recon-diff.diff-nonzero { color: var(--warn-600, #d97706); }
.reconciliation-row .recon-notes { font-size: 12px; color: var(--muted, #64748b); margin-top: 4px; }

/* Account-detail mini transaction (uses .mini-tx-left + generic amount classes) */
.mini-tx-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mini-tx .amount-pos { color: var(--success-600, #059669); }
.mini-tx .amount-neg { color: var(--danger-600, #dc2626); }

/* Debt drawer summary row */
.debt-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line, #e2e8f0); margin-bottom: 12px; }
.debt-summary > div { display: flex; flex-direction: column; gap: 4px; }
.debt-summary strong { font-size: 16px; }

/* ============================================================
   UI POLISH PASS — iPhone / Tablet / Laptop refinements
   ============================================================ */

/* --- Group 1: iOS safe areas + text-size-adjust + overscroll --- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  overscroll-behavior-y: contain;
}
.app-shell {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}
.sidebar {
  padding-top: max(24px, env(safe-area-inset-top, 24px));
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.alert-host {
  top: max(20px, calc(env(safe-area-inset-top, 0px) + 12px));
  right: max(20px, calc(env(safe-area-inset-right, 0px) + 12px));
}
.kb-hint {
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  right: max(20px, calc(env(safe-area-inset-right, 0px) + 12px));
}
.drawer-panel {
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.app-footer {
  padding-bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px));
}

/* --- Group 2: Mobile hamburger nav --- */
.mobile-nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: var(--r-md, 10px);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(15,23,42,0.06));
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.mobile-nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text, #0f172a);
  border-radius: 1px;
  transition: transform 250ms var(--ease-out, ease-out), opacity 200ms;
  pointer-events: none;
}
.mobile-nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.mobile-nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.mobile-nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 199;
  opacity: 0;
  transition: opacity 250ms var(--ease-out, ease-out);
}
.sidebar-overlay:not([hidden]) { opacity: 1; }

@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .mobile-nav-toggle {
    display: flex;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 280ms var(--ease-out, ease-out);
    box-shadow: var(--shadow-xl, 0 24px 48px rgba(15,23,42,0.18));
    height: 100vh;
  }
  .sidebar[data-open="true"] {
    transform: translateX(0);
  }
  .topbar {
    align-items: center;
    flex-direction: row;
    gap: 12px;
  }
}
@media (min-width: 1024px) {
  .sidebar-overlay { display: none !important; }
}

/* --- Group 3: Tablet 2-col layouts (641-1023px) --- */
@media (min-width: 641px) and (max-width: 1023px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hero-card.large {
    grid-column: span 2;
  }
  .content-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .panel.large {
    grid-column: span 2;
  }
  .two-col {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }
  .topbar-actions {
    flex-wrap: wrap;
  }
  canvas {
    max-height: 280px;
  }
}

/* --- Group 4: iOS input zoom prevention + touch targets + tap highlight --- */
input, select, textarea, button {
  font-size: max(16px, 1rem);
}
button, .btn, .nav-item, .icon-btn, .row-actions-btn {
  min-height: 44px;
}
.btn.small, .chip {
  min-height: 32px;
}
.btn.small {
  padding: 8px 14px;
}
.icon-btn {
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
* {
  -webkit-tap-highlight-color: rgba(15, 118, 110, 0.15);
}
.nav-item, .btn, .icon-btn, .chip, .hero-card, .debt-item {
  -webkit-user-select: none;
  user-select: none;
}
.panel p, .panel h3, .mini-tx-desc, .text-caption, td, th {
  -webkit-user-select: text;
  user-select: text;
}

/* --- Group 5: Smooth/momentum scrolling --- */
.table-wrap, .main {
  -webkit-overflow-scrolling: touch;
}
.table-wrap {
  overscroll-behavior-x: contain;
}

.classification-row {
  border: 1px solid var(--border, #d9e2ec);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}
.classification-main {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.classification-controls {
  display: grid;
  grid-template-columns: minmax(120px, 160px) minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.classification-controls input,
.classification-controls select {
  width: 100%;
}

@media (max-width: 860px) {
  .classification-main {
    flex-direction: column;
  }
  .classification-controls {
    grid-template-columns: 1fr;
  }
}

/* --- Group 7: Laptop/desktop refinements --- */
@media (min-width: 1440px) {
  .main {
    max-width: 1600px;
    margin: 0 auto;
  }
  .metric-grid {
    gap: 20px;
  }
  .content-grid {
    gap: 24px;
  }
}
@media (min-width: 1920px) {
  .app-shell {
    grid-template-columns: 320px minmax(0, 1fr);
  }
}
@media (hover: hover) and (pointer: fine) {
  .hero-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg, 0 12px 28px rgba(15,23,42,0.12));
  }
  .debt-item:hover {
    transform: translateY(-1px);
    border-color: var(--primary-300, #5eead4);
  }
  .tx-card:hover {
    border-color: var(--primary-200, #99f6e4);
  }
}
@media (hover: none) {
  .hero-card:active,
  .debt-item:active {
    transform: scale(0.98);
  }
}

/* --- Group 8: Print styles --- */
@media print {
  .sidebar,
  .topbar-actions,
  .alert-host,
  .kb-hint,
  .mobile-nav-toggle,
  .sidebar-overlay,
  .row-actions-btn {
    display: none !important;
  }
  .app-shell {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 0;
  }
  .panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #000;
  }
  body {
    background: #ffffff;
  }
}
