/* ============================================================
   Prototype design system — accounting workspace demo.
   Plain CSS, no build step. Served as-is by Live Server.
   ============================================================ */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #16233b;
  --muted: #5b6b83;
  --primary: #2f6bed;
  --primary-hover: #2458cc;
  --primary-soft: #e8effd;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --success: #1e9e6a;
  --success-soft: #e5f6ef;
  --warning: #b7791f;
  --warning-soft: #fdf3e2;
  --sidebar-bg: #101a2e;
  --sidebar-text: #93a3bd;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 35, 59, 0.06);
  --shadow-md: 0 6px 24px rgba(22, 35, 59, 0.10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; color: inherit; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Inline SVG icons: outline by default; filled variant shown when active. */
.ico { width: 16px; height: 16px; flex-shrink: 0; }

/* ------------------------------------------------ Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: #c8d2e0; background: #f8fafc; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
.btn.disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--primary); font-weight: 600; padding: 0; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

/* ------------------------------------------------ Inputs & fields */

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.invalid { border-color: var(--danger); }
textarea.input { resize: vertical; min-height: 80px; }
.search { max-width: 320px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-weight: 600; font-size: 13px; }
.field .req { color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; display: none; }
.field-error.show { display: block; }
.field-hint { color: var(--muted); font-size: 12px; }
.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.check-field input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* ------------------------------------------------ Badges & chips */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}
.badge-soft { background: #eef2f7; color: var(--muted); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.chip {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 6px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  margin: 1px 4px 1px 0;
  white-space: nowrap;
}

.doc-badge { padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.doc-invoice { background: #e8effd; color: #2f6bed; }
.doc-receipt { background: #e5f6ef; color: #1e9e6a; }
.doc-bank_statement { background: #f3e8fd; color: #7c3aed; }
.doc-tax_document { background: #fdf3e2; color: #b7791f; }
.doc-payroll { background: #fdecec; color: #d64545; }
.doc-contract { background: #e0f2f4; color: #0e7490; }
.doc-other { background: #eef2f7; color: #5b6b83; }

/* ------------------------------------------------ Topbar (list & form pages) */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------ Page layout */

.page { max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }
.page-narrow { max-width: 760px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-sub { color: var(--muted); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { margin-bottom: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.back-link { color: var(--muted); font-size: 13px; font-weight: 600; display: inline-flex; margin-bottom: 12px; }
.back-link:hover { color: var(--text); }

/* ------------------------------------------------ Company cards */

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.company-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.company-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: #cdd7e4; }
.card-top { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.card-names { min-width: 0; flex: 1; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.status-dot.active { background: var(--success); }
.card-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.card-foot {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}
.card-open { color: var(--primary); font-weight: 600; }
.grid-note { color: var(--muted); padding: 8px 2px; grid-column: 1 / -1; }

/* ------------------------------------------------ Empty state */

.empty-state {
  text-align: center;
  padding: 70px 20px;
  background: var(--surface);
  border: 1px dashed #c3cede;
  border-radius: var(--radius-lg);
}
.empty-icon { margin-bottom: 10px; color: #93a3bd; }
.empty-icon .ico { width: 40px; height: 40px; }
.empty-state h2 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin-bottom: 18px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------ Form page */

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.form-section { padding: 22px 24px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: none; }
.form-section h2 { margin-bottom: 2px; }
.section-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-footer {
  padding: 16px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------ App shell (dashboard) */

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar .brand { padding: 0 10px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 14px; }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-sub { color: var(--sidebar-text); }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 500;
  color: var(--sidebar-text);
}
.side-link:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
.side-link.active { background: rgba(47, 107, 237, 0.28); color: #fff; }
.side-link .ico { width: 17px; height: 17px; }
.side-link .ico-filled { display: none; }
.side-link.active .ico-outline { display: none; }
.side-link.active .ico-filled { display: inline-block; }
.side-link.disabled { opacity: 0.45; cursor: default; }
.side-link.disabled:hover { background: none; color: var(--sidebar-text); }
.side-link .soon {
  margin-left: auto;
  font-size: 10px;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 999px;
}
.sidebar-foot { padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sidebar-foot a { color: var(--sidebar-text); font-size: 13px; font-weight: 600; }
.sidebar-foot a:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.company-switcher { max-width: 300px; font-weight: 600; }
.content { padding: 26px; max-width: 1100px; width: 100%; margin: 0 auto; }
.view-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.view-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------ Stats & panels */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.panel-body { padding: 18px; }
.panel-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: #f8fafc;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.panel-foot .page-actions { margin-left: auto; }
.two-col { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; align-items: start; }

.details { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.detail-item dt {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-item dd { margin-top: 2px; overflow-wrap: break-word; }
.detail-item.span-2 { grid-column: span 2; }

.recent-list { display: flex; flex-direction: column; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.recent-item:last-child { border-bottom: none; padding-bottom: 0; }
.recent-item:first-child { padding-top: 0; }
.file-ico {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #eef2f7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}
.file-ico .ico { width: 16px; height: 16px; }
.recent-text { min-width: 0; flex: 1; }
.recent-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------ Dropzone */

.dropzone {
  border: 2px dashed #c3cede;
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
  margin-bottom: 16px;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { color: var(--text); }
.dz-icon { margin-bottom: 8px; color: var(--muted); }
.dz-icon .ico { width: 26px; height: 26px; }
.dropzone:hover .dz-icon, .dropzone.dragover .dz-icon { color: var(--primary); }
.dz-hint { font-size: 12px; margin-top: 4px; }

/* ------------------------------------------------ Filters & table */

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters .input { width: auto; }
.filters select.input { min-width: 140px; }
.filters .search { min-width: 200px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
.data th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: none; }
.data tbody tr:hover td { background: #f8fafc; }
.doc-name { font-weight: 600; display: flex; align-items: center; gap: 8px; max-width: 280px; }
.doc-name .ico { width: 15px; height: 15px; color: var(--muted); }
.doc-name .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.icon-btn:hover { color: var(--text); border-color: #c8d2e0; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.table-empty { text-align: center; color: var(--muted); padding: 26px !important; }

/* Chart of accounts: sub-accounts are indented under their parent (depth 1). */
.acct-child > td:first-child { padding-left: 34px; }
.acct-branch { color: var(--muted); font-weight: 400; }
.acct-inactive td { opacity: 0.55; }
.td-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.data tfoot td {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-weight: 700;
  background: #f8fafc;
}

/* ------------------------------------------------ Register & editable grid */

/* Two lines per transaction, like a bank register. Each transaction is its own
   <tbody>, so hover and the row separator need no rowspan and no JS. */
table.register { min-width: 900px; table-layout: fixed; }
table.register td { padding: 8px 12px; border-bottom: none; vertical-align: middle; }
tbody.reg-row + tbody.reg-row { border-top: 1px solid var(--border); }
tbody.reg-row:hover td { background: #f8fafc; }
.reg-line-2 td { padding-top: 0; padding-bottom: 10px; color: var(--muted); font-size: 12px; }
.reg-payee { font-weight: 600; }
.reg-account, .reg-memo {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reg-balance { color: var(--muted); font-weight: 500; }
.reg-cleared { text-align: center; }
.cleared-btn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.cleared-btn:hover { border-color: var(--primary); }

.register-totals { display: flex; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.reg-total { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; }
.reg-total strong { font-variant-numeric: tabular-nums; }
.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }
/* The register's single Amount column: the sign carries the direction, so the
   figures have to line up digit for digit to be scannable. */
.amount-signed { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Which bank account a transaction belongs to, on the register's second line. */
.reg-bank {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.editor-bank { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.editor-bank select { width: 200px; }

/* Row checkboxes behind "Delete selected" in the register and the grid. */
.th-pick, .td-pick { text-align: center; padding-left: 8px !important; padding-right: 4px !important; }
.reg-pick, .editor-pick, #reg-select-all, #editor-select-all {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
}
.reg-pick:disabled { cursor: not-allowed; opacity: 0.4; }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { border-color: var(--danger); background: var(--danger-soft); }

/* Document pickers (receipt modal, vendor documents): two columns, with the
   type and period under the name, so a modal never scrolls sideways. */
.doc-picker { table-layout: fixed; }
.doc-picker .doc-name { max-width: none; min-width: 0; }
.doc-picker .doc-name .txt { min-width: 0; }
.doc-meta { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; padding-left: 23px; }
@media (max-width: 480px) {
  .doc-picker .row-actions { flex-direction: column; align-items: flex-end; }
}

/* ---------------------------------------------------------------- Documents: folders */

.docs-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.folder-panel { padding: 8px; }
.folder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.folder-item { display: flex; align-items: center; gap: 2px; border-radius: 8px; }
.folder-item:hover { background: #f1f5f9; }
.folder-item.active { background: var(--primary-soft); }
.folder-item.active .folder-select { color: var(--primary); font-weight: 600; }
.folder-select {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* Rename/delete show on hover and on the active folder, so the list stays quiet. */
.folder-actions { display: none; gap: 4px; padding-right: 6px; }
.folder-item:hover .folder-actions, .folder-item.active .folder-actions { display: flex; }
.folder-empty { padding: 6px 10px; font-size: 12px; }
#docs-table .doc-folder { width: 100%; min-width: 130px; }
#docs-bulk-folder { width: 180px; }
@media (max-width: 860px) {
  .docs-layout { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- Banking */

.bank-list { display: flex; flex-direction: column; gap: 16px; }
.bank-card .panel-head h2 { margin-right: auto; }
.new-accounts { margin: 14px 0; border-color: var(--warning); }
.icon-btn.accent { color: var(--primary); font-weight: 600; }

/* ---------------------------------------------------------------- Bank feed */

#feed-panel { margin-top: 18px; }
#feed-panel .panel-head h2 { margin-right: 10px; }
#feed-panel .panel-head select { width: 240px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 1px solid transparent;
  background: none;
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { background: #f1f5f9; }
.tab.active { background: var(--primary-soft); border-color: #c7d8fb; color: var(--primary); font-weight: 600; }
.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}
.feed-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.feed-bar .page-actions { margin-left: auto; }
.feed-memo { display: block; color: var(--muted); font-size: 12px; }
#feed-table td { vertical-align: middle; }

/* ---------------------------------------------------------------- Rules */

.rule-summary { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.rule-head { display: grid; grid-template-columns: 1fr 150px 1fr; gap: 14px; }
.rule-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.rule-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}
.rule-section h3 select { width: auto; }
.rule-condition {
  display: grid;
  grid-template-columns: 170px 170px 1fr 36px;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}
.rule-action { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.rule-action label { width: 190px; flex: none; font-size: 13px; color: var(--muted); }
.rule-action select { flex: 1; }

/* ---------------------------------------------------------------- Reconciliation */

.recon-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.recon-cell { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.recon-cell strong { font-size: 17px; font-variant-numeric: tabular-nums; }
/* The number the whole screen exists to drive to zero. */
.recon-difference { font-size: 20px; }
#recon-table td { vertical-align: middle; }
.btn.disabled, .btn:disabled { opacity: .5; pointer-events: none; }

/* A receipt chip is a button, but reads as a chip. */
.chip-btn {
  border: none;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
.chip-btn:hover { background: var(--primary-soft); color: var(--primary); }

/* Compact variant of .input for cells: same focus and error states, less bulk. */
.cell {
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 6px;
  width: 100%;
}
.cell-amount { text-align: right; font-variant-numeric: tabular-nums; }
/* A value brought back from a previous transaction, until the user edits it. */
.cell.autofilled { background: var(--primary-soft); border-color: #c7d8fb; }

.register-editor { margin-bottom: 16px; border-color: var(--primary); }
.editor-summary { display: flex; gap: 14px; font-size: 13px; font-weight: 600; flex-wrap: wrap; }
.cell-payee { display: flex; align-items: center; gap: 6px; }
.reg-badge-new {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

tbody.reg-row.row-invalid td { background: var(--danger-soft); }
.row-message td { padding-top: 0 !important; padding-bottom: 8px !important; font-size: 12px; }
.row-message-error { color: var(--danger); font-weight: 600; }
.row-message-warning { color: var(--warning); font-weight: 600; }

/* CSV import wizard */
.map-sample { font-size: 12px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-preview-title { margin: 18px 0 8px; }
#import-step-2 .filters .field { min-width: 180px; }
.row-duplicate td { background: var(--warning-soft); }
.row-skipped td { background: #f8fafc; font-size: 12px; }

/* Recurring templates: collapsed by default so the register stays the focus. */
.recurring-panel { margin-bottom: 16px; }
.recurring-panel > summary {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  list-style: none;
}
.recurring-panel > summary::-webkit-details-marker { display: none; }
.recurring-panel > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 12px;
}
.recurring-panel[open] > summary::before { content: '▾'; }
.recurring-panel[open] > summary { border-bottom: 1px solid var(--border); }
.recurring-panel > summary .page-actions { margin-left: auto; }

/* ------------------------------------------------ Modals */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 26, 46, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal.modal-lg { max-width: 860px; }
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.modal-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Status pill next to the title (e.g. "File 2 of 5") sits beside it, not centered. */
.modal-head .badge { margin-right: auto; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.file-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 13px;
  min-width: 0;
}
.file-summary .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.preview-frame { width: 100%; height: 65vh; border: none; border-radius: 8px; background: #f1f5f9; }
.preview-img { max-width: 100%; max-height: 65vh; display: block; margin: 0 auto; border-radius: 8px; }
.preview-text {
  background: #0f172a;
  color: #d7e1f0;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  max-height: 65vh;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
}

/* ------------------------------------------------ Toasts & footer */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: #16233b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  animation: toast-in 0.2s ease;
  max-width: 340px;
}
.toast-error { background: var(--danger); }
.toast-info { background: #334155; }
.toast-out { opacity: 0; transform: translateY(6px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.proto-footer { margin-top: 40px; text-align: center; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------ Access gate */

/* Above everything, opaque: the page behind has not rendered and must not show. */
.access-gate { background: var(--bg); z-index: 1000; }
.access-gate .modal { max-width: 420px; }

/* ------------------------------------------------ Demo banner */

.demo-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  padding: 10px 14px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 13px;
}
.demo-banner:empty { display: none; }
.demo-banner-text strong { color: var(--text); }
.demo-banner-meta { white-space: nowrap; }
.demo-banner-actions { display: flex; gap: 8px; margin-left: auto; }
.demo-banner-conflict { display: flex; gap: 8px; flex-wrap: wrap; }
.demo-banner-conflict[hidden] { display: none; }
.demo-banner .btn { padding: 4px 10px; font-size: 12px; }
.demo-banner-warn { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.demo-banner-warn .demo-banner-text strong { color: var(--warning); }
@media (max-width: 640px) {
  .demo-banner-actions { margin-left: 0; width: 100%; }
  .demo-banner-meta { white-space: normal; }
}

/* ------------------------------------------------ Responsive */

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { border-top: none; padding-top: 8px; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .details { grid-template-columns: 1fr; }
  .detail-item.span-2 { grid-column: auto; }
}
