:root {
  --bg: #202123;
  --panel: #17181a;
  --panel-alt: #242628;
  --panel-soft: #2b2d31;
  --line: #34363c;
  --line-strong: #42454d;
  --text: #e9ebef;
  --text-soft: #b8bcc5;
  --text-dim: #8f949d;
  --success: #2a9d62;
  --warning: #d6a34a;
  --danger: #b85a62;
  --accent: #6c7785;
  --radius: 14px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
  font-family: "Segoe UI", "SF Pro Text", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1b1c1f; color: var(--text); }
body { font-size: 14px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.mobile-header,
.shell-overlay { display: none; }

.app-shell {
  --detail-width: 420px;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 16px var(--detail-width);
  height: 100vh;
  background: linear-gradient(180deg, #1d1f22 0%, #1b1c1f 100%);
  overflow: hidden;
}
.app-shell.panel-collapsed { grid-template-columns: 272px minmax(0, 1fr) 16px 0px; }

.sidebar, .detail-panel {
  background: rgba(23, 24, 26, 0.95);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.detail-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
  padding: 22px;
  height: 100vh;
  overflow: hidden;
}
.app-shell.panel-collapsed .detail-panel {
  padding: 0;
  border-left: 0;
}
.panel-rail {
  position: relative;
  height: 100vh;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: rgba(20, 21, 24, 0.96);
  cursor: col-resize;
}
.panel-toggle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 64px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #2b3037;
  color: var(--text-soft);
  z-index: 2;
  cursor: pointer;
}
.panel-toggle:hover { background: #353b45; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}
.brand-block { display: flex; gap: 12px; align-items: center; padding: 10px 8px 18px; border-bottom: 1px solid var(--line); }
.brand-block p { margin: 2px 0 0; color: var(--text-dim); font-size: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: #2d3138; border: 1px solid var(--line-strong); font-weight: 700;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 18px; overflow: auto; min-height: 0; padding-right: 4px; }
.nav-group h2 { margin: 0 0 8px; color: var(--text-dim); text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; }
.nav-link {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 10px;
  color: var(--text-soft); cursor: pointer;
}
.nav-link:hover, .nav-link.active { background: #2b2d31; color: var(--text); }
.sidebar-logout { margin-top: auto; }

.main-column {
  min-width: 0;
  height: 100vh;
  padding: 26px;
  overflow: hidden;
}
.page-root {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding-right: 6px;
  animation: fadeIn 160ms ease;
}
.page-loading { opacity: 0.72; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.page-head h1 { margin: 0; font-size: 28px; font-weight: 650; }
.page-head p { margin: 6px 0 0; color: var(--text-soft); max-width: 72ch; }
.split-head { align-items: center; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

.panel-card, .stat-card, .muted-box, .login-card {
  background: rgba(29, 31, 34, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-card { padding: 18px; }
.stat-card { padding: 18px; min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-card span, .eyebrow, .meta-list span, .detail-grid span { color: var(--text-dim); font-size: 12px; }
.stat-card strong { font-size: 25px; letter-spacing: -0.02em; }

.stats-grid, .three-col-grid, .two-col-grid {
  display: grid;
  gap: 16px;
}
.stats-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.three-col-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-col-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.learning-grid { align-items: start; }
.learning-grid .panel-card { height: 100%; }
.col-span-2 { grid-column: span 2; }

.section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-header h2, .detail-section h4 { margin: 0; font-size: 15px; font-weight: 600; }
.list-tight, .list-stack, .queue-list { display: flex; flex-direction: column; gap: 10px; }
.row-card, .row-action, .queue-item {
  width: 100%; border: 1px solid var(--line); background: var(--panel-alt); border-radius: 12px; padding: 12px 14px;
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.row-card span, .row-action span { color: var(--text-soft); }
.row-action { cursor: pointer; text-align: left; }
.row-action:hover { border-color: var(--line-strong); background: #30333a; }
.queue-item { align-items: stretch; flex-direction: column; }
.queue-item-body { display: flex; flex-direction: column; gap: 6px; }
.queue-item-body p { margin: 0; color: var(--text-soft); }
.inline-actions { display: flex; gap: 8px; margin-left: auto; }
.account-row { cursor: pointer; }
.account-statements { margin-top: 14px; }
.statement-row { align-items: flex-start; }
.statement-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.statement-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.statement-error { color: #f0b0b5; }
.statement-progress { display: flex; flex-direction: column; gap: 14px; }
.statement-progress-native {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #23262a;
  color: #6b778a;
}
.statement-progress-native::-webkit-progress-bar {
  background: #23262a;
}
.statement-progress-native::-webkit-progress-value {
  background: linear-gradient(90deg, #4a5362 0%, #6b778a 100%);
}
.statement-progress-native::-moz-progress-bar {
  background: linear-gradient(90deg, #4a5362 0%, #6b778a 100%);
}
.statement-progress-meta { display: flex; flex-direction: column; gap: 6px; }
.reports-goals-stream-output {
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
}
.category-stat-line {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.category-stat-chip {
  min-width: 148px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.category-stat-chip strong {
  font-size: 18px;
  letter-spacing: -0.02em;
}
.category-stat-chip small {
  color: var(--text-dim);
  font-size: 12px;
}
.plan-output {
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #1d2024;
  color: var(--text);
  line-height: 1.55;
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 9, 11, 0.72);
  backdrop-filter: blur(8px);
  z-index: 40;
}
.modal-backdrop[hidden] { display: none; }

.modal-card {
  width: min(560px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  padding: 20px;
  background: rgba(24, 26, 29, 0.98);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.table-wrap { overflow: auto; border-radius: 12px; border: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; min-width: 860px; }
.data-table th, .data-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table th { text-align: left; color: var(--text-dim); font-size: 12px; font-weight: 600; }
.data-table td span { display: block; color: var(--text-dim); margin-top: 4px; }
.data-table tbody tr { cursor: pointer; background: rgba(36, 38, 40, 0.58); }
.data-table tbody tr:hover { background: rgba(52, 54, 60, 0.55); }

.button {
  border: 1px solid var(--line-strong);
  background: #2d3138;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.button:hover { background: #363b44; }
.button-primary { background: #3a424f; }
.button-small { padding: 7px 10px; font-size: 12px; }
.settings-tabs { display: flex; flex-direction: column; gap: 16px; }
.settings-tab.active { background: #414956; border-color: #5e6878; }
.settings-workbench { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.settings-subpanel { min-height: 100%; }
.accounts-tabs { display: flex; flex-direction: column; gap: 18px; }
.accounts-tab-row { justify-content: flex-start; gap: 10px; flex-wrap: wrap; }
.accounts-tab.active { background: #414956; border-color: #5e6878; }
.nested-page-head { padding: 0; border: 0; background: transparent; }
.form-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.neutral-note { color: var(--text-soft); min-height: 0; }
.settings-panel[hidden] { display: none; }
.review-tabs { display: flex; flex-direction: column; gap: 16px; }
.review-tab-row { justify-content: flex-start; gap: 10px; }
.review-tab.active { background: #414956; border-color: #5e6878; }
.review-tab span { color: var(--text-soft); margin-left: 6px; }
.review-panel[hidden] { display: none; }
.review-filter-bar { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1fr) repeat(2, minmax(150px, 0.8fr)) auto; gap: 12px; align-items: end; }
.transaction-filter-bar { grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1fr) repeat(4, minmax(130px, 0.8fr)) auto; }
.bulk-review-modal { width: min(980px, 100%); }
.bulk-review-layout { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
.bulk-review-list { max-height: 60vh; overflow: auto; padding-right: 4px; }

input, select, textarea {
  width: 100%;
  background: #202328;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #5f6774; }

.stack-form { display: flex; flex-direction: column; gap: 12px; }
.stack-form label { display: flex; flex-direction: column; gap: 6px; }
.upload-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 12px; }

.chip {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #272a30;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.chip-success { color: #b8f0cc; border-color: rgba(42, 157, 98, 0.55); }
.chip-warning { color: #f3d7a0; border-color: rgba(214, 163, 74, 0.55); }
.chip-danger { color: #f0b0b5; border-color: rgba(184, 90, 98, 0.55); }

.positive { color: #7ee0a4; }
.negative { color: #ee8e97; }
.muted-box { padding: 14px; color: var(--text-soft); background: #23262a; border-radius: 12px; border: 1px dashed var(--line-strong); }
.stat-inline { color: var(--text-soft); }
.stat-inline strong { color: var(--text); font-size: 22px; display: block; margin-top: 4px; }

.panel-empty { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 8px; color: var(--text-soft); }
.panel-empty h3, .panel-header h3 { margin: 0; font-size: 22px; }
.panel-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.detail-stack { display: flex; flex-direction: column; gap: 18px; height: 100%; min-height: 0; overflow: auto; padding-right: 4px; animation: slideIn 180ms ease; }
.detail-grid, .meta-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.detail-grid > div, .meta-list > div { background: #23262a; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.detail-grid strong, .meta-list strong { display: block; margin-top: 6px; }
.detail-section { display: flex; flex-direction: column; gap: 10px; }
.document-preview { min-height: 520px; background: #101113; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.document-preview iframe, .document-preview img { width: 100%; height: 520px; display: block; border: 0; object-fit: contain; background: #151618; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { margin: 4px 0 8px; }
.form-note { min-height: 20px; color: #f0b0b5; margin: 0; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.queue-actions { justify-content: flex-start; margin-left: 0; padding-top: 8px; border-top: 1px solid var(--line); min-height: 44px; align-content: flex-start; }

@keyframes fadeIn { from { opacity: 0.7; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0.7; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 1280px) {
  .app-shell, .app-shell.panel-collapsed { grid-template-columns: 228px minmax(0, 1fr); }
  .panel-rail { display: none; }
  .main-column { padding: 20px; }
  .accounts-tab-row { overflow: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .form-split { grid-template-columns: 1fr; }
  .settings-workbench { grid-template-columns: 1fr; }
  .review-filter-bar { grid-template-columns: 1fr; }
  .bulk-review-layout { grid-template-columns: 1fr; }
  .detail-panel { position: fixed; top: 0; right: 0; width: min(420px, 100vw); height: 100vh; z-index: 10; background: rgba(18, 19, 22, 0.98); }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .three-col-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  html, body { height: 100%; }
  body { overflow: hidden; }
  .app-shell, .app-shell.panel-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 56px minmax(0, 1fr);
    height: 100vh;
  }
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(23, 24, 26, 0.98);
    position: sticky;
    top: 0;
    z-index: 32;
  }
  .shell-overlay {
    position: fixed;
    inset: 56px 0 0 0;
    background: rgba(8, 9, 11, 0.58);
    z-index: 28;
  }
  .shell-overlay[hidden] { display: none; }
  .shell-overlay:not([hidden]) { display: block; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    width: min(320px, 86vw);
    height: calc(100vh - 56px);
    z-index: 31;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .main-column {
    height: calc(100vh - 56px);
    padding: 14px;
    overflow: hidden;
  }
  .page-root {
    height: 100%;
    overflow: auto;
    padding-right: 0;
    padding-bottom: 20px;
  }
  .panel-rail { display: none; }
  .detail-panel {
    position: fixed;
    top: 56px;
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    height: auto;
    z-index: 30;
    overflow: hidden;
    border-left: 0;
    border-top: 1px solid var(--line);
    transform: translateY(100%);
    transition: transform 180ms ease;
    padding: 16px;
  }
  .app-shell.panel-open-mobile.has-active-panel .detail-panel { transform: translateY(0); }
  .detail-stack { height: 100%; overflow: auto; padding-right: 0; padding-bottom: 24px; }
  .stats-grid, .three-col-grid, .two-col-grid { grid-template-columns: 1fr; gap: 12px; }
  .col-span-2 { grid-column: auto; }
  .upload-form { grid-template-columns: 1fr; }
  .page-head,
  .split-head,
  .panel-header,
  .section-header,
  .row-card,
  .row-action {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-head h1 { font-size: 24px; }
  .inline-actions,
  .toolbar,
  .quick-actions,
  .accounts-tab-row,
  .review-tab-row {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .button { width: auto; }
  .review-filter-bar,
  .form-split,
  .bulk-review-layout,
  .settings-workbench {
    grid-template-columns: 1fr;
  }
  .panel-card,
  .stat-card,
  .login-card,
  .modal-card { padding: 14px; }
  .modal-backdrop { padding: 12px; align-items: end; }
  .modal-card {
    width: 100%;
    max-height: min(84vh, 100%);
    border-radius: 18px 18px 0 0;
  }
  .review-tab,
  .accounts-tab,
  .settings-tab { white-space: nowrap; }
  .data-table { min-width: 720px; }
  .table-wrap { margin: 0 -4px; }
  .document-preview,
  .document-preview iframe,
  .document-preview img { min-height: 360px; height: 360px; }
  .statement-row,
  .account-row,
  .queue-item { align-items: stretch; }
  .statement-row .inline-actions,
  .account-row .inline-actions { width: 100%; }
  .statement-row .inline-actions .button,
  .account-row .inline-actions .button,
  .queue-actions .button { flex: 1 1 auto; min-width: 0; }
  .bulk-review-list { max-height: 34vh; }
  .detail-grid,
  .meta-list { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 13px; }
  .main-column { padding: 12px; }
  .page-root { gap: 14px; }
  .stat-card { min-height: 86px; }
  .stat-card strong { font-size: 22px; }
  .brand-block strong { font-size: 14px; }
  .sidebar { width: min(300px, 90vw); padding: 16px 12px; }
  .row-card, .row-action, .queue-item { padding: 10px 12px; }
  .queue-actions { gap: 6px; }
  .button { padding: 9px 12px; }
  .button-small { padding: 7px 9px; }
  .document-preview,
  .document-preview iframe,
  .document-preview img { min-height: 300px; height: 300px; }
}
