:root {
  /* Ground */
  --bg: #eef1f5;
  --card-bg: #ffffff;
  --panel-sunk: #f5f8fb;
  --border: #dfe4ea;
  --border-strong: #c3cad4;

  /* Ink */
  --text: #111c2b;
  --text-muted: #5a6779;
  --text-faint: #8a94a3;

  /* Deep navy — the one accent */
  --accent: #15498c;
  --accent-hover: #0f3670;
  --accent-light: #eaf0f9;
  --accent-soft: #dce7f5;
  --accent-ring: rgba(21, 73, 140, .18);

  /* Status — only ever status, never decoration */
  --green: #15803d;
  --green-light: #f0fdf4;
  --red: #b91c1c;
  --red-light: #fef2f2;
  --amber: #a16207;
  --amber-light: #fffbeb;

  /* Navy sidebar */
  --sidebar-bg: #0e2038;
  --sidebar-text: #93a3b8;
  --sidebar-hover: #1a2f4a;
  --sidebar-active: #ffffff;

  --shadow-xs: 0 1px 1px rgb(17 28 43 / .05);
  --shadow-sm: 0 1px 2px rgb(17 28 43 / .07);
  --shadow: 0 2px 8px -2px rgb(17 28 43 / .10);
  --shadow-lg: 0 8px 20px -6px rgb(17 28 43 / .14);

  --radius: 10px;
  --radius-sm: 6px;
  --transition: 140ms ease;

  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Every figure in the app is tabular, so columns of money and counts line
     up down the page instead of shimmering. */
  font-variant-numeric: tabular-nums;
}

/* ─── Sidebar ────────────────────────────────────────── */

.sidebar {
  width: 240px;
  /* Exactly the viewport, never taller: the list inside scrolls. With
     min-height and no cap the sidebar grew past the bottom of a short window
     and a phone drawer, and Security, Settings and Ask the Books could not be
     reached at all. */
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,.04);
}

.sidebar-brand {
  padding: 24px 22px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
}

.brand-text {
  color: #f1f5f9;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.4px;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;            /* lets the flex child shrink so overflow-y can scroll */
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sidebar-nav .nav-item, .sidebar-nav .nav-group { flex: 0 0 auto; }
.sidebar-brand, .sidebar-footer { flex: 0 0 auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}

.nav-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  opacity: .55;
  transition: opacity var(--transition);
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #cbd5e1;
}
.nav-item:hover .nav-icon { opacity: .8; }

.nav-item.active {
  background: rgba(255, 255, 255, .07);
  color: var(--sidebar-active);
  font-weight: 600;
}
.nav-item.active .nav-icon { opacity: 1; color: var(--accent); }

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.nav-item.disabled {
  color: rgba(148,163,184,.3);
  cursor: not-allowed;
}
.nav-item.disabled:hover { background: transparent; color: rgba(148,163,184,.3); }

.nav-group {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(147,163,184,.6);
  padding: 14px 14px 4px;
}
.nav-group:first-child { padding-top: 4px; }

.nav-item-btn {
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  margin: 0 0 4px;
  font-family: inherit;
}
.nav-item-btn:hover { background: var(--sidebar-hover); box-shadow: none; }

/* ─── Dialogs ────────────────────────────────────────── */

.app-dialog {
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.app-dialog::backdrop { background: rgba(10, 18, 30, .5); }
.app-dialog h2 { font-size: 15px; font-weight: 650; margin: 0 0 14px; }
.app-dialog label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px; }
.app-dialog label input { display: block; width: 100%; margin-top: 6px; font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.06);
  margin: 10px 14px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,.05);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-name {
  color: rgba(255,255,255,.85);
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  margin-bottom: 12px;
  opacity: .65;
}
.logout-link:hover { opacity: 1; }

.conn-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: 8px;
}

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

.conn-unknown { color: var(--sidebar-text); background: rgba(255,255,255,.04); }
.conn-unknown .conn-dot { background: var(--sidebar-text); }

.conn-badge.badge-ok, .conn-badge.conn-ok { color: #6ee7b7; background: rgba(5,150,105,.08); }
.conn-badge.badge-ok .conn-dot, .conn-ok .conn-dot { background: #34d399; }

.conn-badge.badge-fail, .conn-badge.conn-fail { color: #fca5a5; background: rgba(220,38,38,.08); }
.conn-badge.badge-fail .conn-dot, .conn-fail .conn-dot { background: #f87171; }

/* ─── Main content ───────────────────────────────────── */

.main-content {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
  min-height: 100vh;
}

.content {
  max-width: 1160px;
  margin: 0 auto;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── Cards ──────────────────────────────────────────── */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* The accent edge is what stops a page reading as a stack of blank sheets. */
  border-top: 3px solid var(--accent);
  padding: 20px 24px 22px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0 0 18px;
  padding: 9px 14px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--accent);
}

h1 {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.2px;
  margin-bottom: 4px;
  color: var(--text);
}

h3 {
  font-size: 14px;
  font-weight: 650;
  margin: 20px 0 10px;
  color: var(--text);
}

/* ─── Badges ─────────────────────────────────────────── */

.badge {
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge-unknown { background: var(--bg); color: var(--text-muted); }
.badge-ok { background: var(--green-light); color: var(--green); }
.badge-fail { background: var(--red-light); color: var(--red); }

.badge-auto {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
}

.badge-manual {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-sunk);
  color: var(--text-muted);
}

/* ─── Forms ──────────────────────────────────────────── */

select, button, input[type="text"], input[type="date"], input[type="number"], input[type="password"], input[type="file"] {
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.4;
}

select {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  min-width: 280px;
  cursor: pointer;
  appearance: auto;
  transition: border-color var(--transition), box-shadow var(--transition);
  color: var(--text);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input[type="text"], input[type="date"], input[type="number"], input[type="password"] {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus, input[type="date"]:focus, input[type="number"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input[type="file"] {
  padding: 7px 0;
  color: var(--text-muted);
}

input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  margin-right: 10px;
  transition: all var(--transition);
}
input[type="file"]::file-selector-button:hover {
  background: var(--bg);
  border-color: #cbd5e1;
}

/* ─── Buttons ────────────────────────────────────────── */

button, .btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-left: 0;
  font-size: 13.5px;
  line-height: 1.4;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover, .btn:hover {
  background: var(--accent-hover);
  box-shadow: none;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled, .btn:disabled {
  background: var(--border);
  color: var(--text-faint);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent-soft);
  font-weight: 600;
}
.btn-secondary:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: none;
}

.btn-success { background: var(--green); }
.btn-success:hover { background: #166534; }

.btn-confirm {
  background: var(--accent);
  font-size: 14px;
  padding: 10px 22px;
}
.btn-confirm:hover { background: var(--accent-hover); }

.btn-cancel {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent-soft);
  font-weight: 600;
}
.btn-cancel:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: none;
}

/* ─── Form rows ──────────────────────────────────────── */

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.form-row > div { flex: 1; min-width: 200px; }
.form-row label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.form-row input[type="file"],
.form-row input[type="text"] {
  width: 100%;
  font-size: 13.5px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.form-row select { width: 100%; min-width: 0; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ─── Status messages ────────────────────────────────── */

.status-msg { margin-top: 10px; font-size: 13px; font-weight: 500; }
.status-msg.ok { color: var(--green); }
.status-msg.fail { color: var(--red); }

/* ─── Stats grid ─────────────────────────────────────── */

.stats-grid { display: flex; gap: 16px; flex-wrap: wrap; }

.stat {
  padding: 14px 18px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  min-width: 120px;
  border: 1px solid var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ─── Module list (dashboard) ────────────────────────── */

.module-list { margin: 0; padding-left: 0; color: var(--text-muted); font-size: 13.5px; list-style: none; }
.module-list li {
  margin-bottom: 4px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-sunk);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition);
}
.module-list li:hover { border-color: var(--border-strong); }
.module-list li strong { color: var(--text); font-weight: 600; }

#connection-message.ok { color: var(--green); }
#connection-message.fail { color: var(--red); }

/* ─── Info grid ──────────────────────────────────────── */

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}
.info-grid .info-label { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.info-grid .info-value { font-weight: 600; }

/* ─── Tables ─────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 11px 14px;
  background: var(--accent-light);
  font-weight: 650;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid var(--accent-soft);
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  color: var(--text);
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--panel-sunk); }

td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

td select { min-width: 180px; font-size: 13px; padding: 5px 8px; }

.match-high { color: var(--green); font-weight: 600; }
.match-medium { color: var(--amber); font-weight: 600; }
.match-low { color: var(--red); font-weight: 600; }

/* ─── Mapping tables ────────────────────────────────── */

.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.mapping-table th {
  padding: 10px 14px;
  background: var(--accent-light);
  font-weight: 650;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
}
.mapping-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.mapping-table tr:last-child td { border-bottom: none; }
.mapping-table tr:hover td { background: var(--panel-sunk); }

/* ─── Charges grid ───────────────────────────────────── */

.charges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}
.charge-item .charge-label { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.3px; }
.charge-item .charge-value { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ─── Action bar ─────────────────────────────────────── */

.action-bar { margin-top: 16px; display: flex; gap: 10px; align-items: center; }

/* ─── Voucher preview ────────────────────────────────── */

.voucher-preview {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.voucher-header {
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.voucher-lines { padding: 0; }
.voucher-lines table { margin: 0; border: none; }
.voucher-lines th, .voucher-lines td { border-left: none; border-right: none; }
.voucher-lines tr:last-child td { border-bottom: none; }

.vch-dr { color: var(--red); font-weight: 600; }
.vch-cr { color: var(--green); font-weight: 600; }
.vch-total-row { font-weight: 700; background: #f8fafc; }

/* ─── Drop zone ──────────────────────────────────────── */

.drop-zone {
  border: 2px dashed #d1d5db;
  border-radius: var(--radius);
  padding: 52px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: #fafbfd;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .06);
}
.drop-zone-text { color: var(--text-muted); font-size: 14px; }
.drop-zone-text a { color: var(--accent); text-decoration: none; font-weight: 600; }
.drop-zone-text a:hover { text-decoration: underline; }

/* ─── File chips ─────────────────────────────────────── */

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  margin: 4px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12.5px;
  background: #fff;
  font-weight: 500;
  transition: all var(--transition);
}
.file-chip:hover { border-color: #cbd5e1; background: #f8fafc; }
.file-chip .remove-file {
  cursor: pointer;
  color: var(--red);
  font-weight: 700;
  font-size: 14px;
  border: none;
  background: none;
  padding: 0 2px;
  margin: 0;
}

/* ─── Batch company sections ─────────────────────────── */

.company-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: var(--shadow-xs);
}
.company-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-weight: 650;
  font-size: 14px;
}
.company-body { padding: 14px 18px; }
.company-header.unmatched { background: var(--amber-light); color: var(--amber); }

.file-group {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}
.file-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.file-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.file-group-title { font-size: 13px; font-weight: 600; }

.file-type-badge {
  font-size: 10.5px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-cn { background: var(--accent-light); color: var(--accent); }
.badge-ledger { background: var(--amber-light); color: var(--amber); }

.company-select-inline { min-width: 200px; font-size: 13px; padding: 5px 8px; }

.batch-post-result {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}
.batch-post-result.ok { background: var(--green-light); color: var(--green); }
.batch-post-result.fail { background: var(--red-light); color: var(--red); }

.dup-voucher { opacity: 0.4; }
.dup-voucher .voucher-header { background: var(--red-light); }

/* ─── Topbar compat (hidden) ─────────────────────────── */

.topbar { display: none; }

/* ─── Bank statement table ───────────────────────────── */

#bs-txn-table { table-layout: fixed; width: 100%; }
#bs-txn-table th:nth-child(1),
#bs-txn-table td:nth-child(1) { width: 36px; text-align: center; }
#bs-txn-table th:nth-child(2),
#bs-txn-table td:nth-child(2) { width: 88px; }
#bs-txn-table th:nth-child(3),
#bs-txn-table td:nth-child(3) { width: 68px; }
#bs-txn-table th:nth-child(4),
#bs-txn-table td:nth-child(4) { width: auto; white-space: normal; word-break: break-word; overflow-wrap: break-word; }
#bs-txn-table th:nth-child(5),
#bs-txn-table td:nth-child(5) { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
#bs-txn-table th:nth-child(6),
#bs-txn-table td:nth-child(6) { width: 240px; }
#bs-txn-table th:nth-child(7),
#bs-txn-table td:nth-child(7) { width: 58px; text-align: center; }
#bs-txn-table .bs-company-col { width: 120px; }

#bs-txn-table .ledger-search {
  width: 100% !important;
  font-size: 12.5px !important;
  padding: 7px 10px !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#bs-txn-table .ledger-search:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12) !important;
  outline: none;
}

#ledger-picker {
  position: absolute; z-index: 300; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 240px; overflow-y: auto;
  min-width: 300px; width: max-content; max-width: min(520px, calc(100vw - 24px)); display: none;
}
#ledger-picker .ledger-option { padding: 7px 12px; font-size: 12.5px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ledger-picker .ledger-option:hover, #ledger-picker .ledger-option.hi { background: var(--accent-light); color: var(--accent); }
#ledger-picker .ledger-option .grp { color: var(--text-muted); font-size: 10.5px; margin-left: 6px; }
#ledger-picker .none { padding: 8px 12px; font-size: 12px; color: var(--text-muted); }

.ledger-dropdown {
  border-radius: 10px !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--border) !important;
  min-width: 300px !important;
}
.ledger-dropdown .ledger-option {
  padding: 8px 12px !important;
  font-size: 12.5px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 6px;
  margin: 2px 4px;
  transition: all var(--transition);
}
.ledger-dropdown .ledger-option:hover {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
}

/* ─── Tab buttons ────────────────────────────────────── */

.tab-btn {
  background: var(--accent-light);
  border: 1px solid var(--accent-soft);
  padding: 8px 15px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.tab-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: none;
}
.tab-btn.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Checkbox ───────────────────────────────────────── */

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  border-radius: 4px;
}

/* ─── Add form (mappings) ────────────────────────────── */

.add-form {
  display: none;
  padding: 16px;
  margin-bottom: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ─── Scrollbar ──────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Selection ──────────────────────────────────────── */

::selection { background: rgba(37, 99, 235, .12); color: var(--accent-hover); }

/* ─── Pagination ────────────────────────────────────── */

.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}
.pagination button {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
}
.pagination .active {
  background: var(--accent);
  color: #fff;
}

/* ─── Server cards (settings/dashboard) ──────────────── */

.server-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 10px;
  background: #fff;
  transition: all var(--transition);
}
.server-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

/* ─── Bank statement mode tabs ───────────────────────── */

.bs-mode-btn {
  background: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}
.bs-mode-btn.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}
.bs-mode-btn:hover {
  color: var(--text) !important;
  background: none !important;
  box-shadow: none !important;
}

/* ─── Shared page pieces ─────────────────────────────── */

/* A heading with actions on the right; replaces the inline flex rows. */
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-head h2 { margin: 0; }
.page-head > a { flex: 0 0 auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.muted { color: var(--text-muted); font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* A link styled as a quiet button (used for page-to-page navigation). */
a.btn-cancel, a.btn-confirm {
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap; padding: 9px 14px; border-radius: var(--radius-sm); font-size: 13.5px; line-height: 1.4;
}

/* Destructive is an outlined red control, never a solid red button. */
.btn-danger {
  background: #fff; color: var(--red); border: 1px solid var(--red);
}
.btn-danger:hover { background: var(--red-light); box-shadow: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link {
  background: none; border: 0; color: var(--text-muted); cursor: pointer;
  font-size: 12px; font-weight: 600; text-decoration: underline; padding: 0 4px;
}
.btn-link:hover { background: none; color: var(--accent); box-shadow: none; }
.btn-link.danger { color: var(--red); }

/* Sunk form panel used by the add/edit forms on Mappings, Security, Settings. */
.form-panel {
  padding: 16px; margin: 12px 0 16px; background: var(--panel-sunk);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

/* Status pills. */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
  background: var(--panel-sunk); color: var(--text-muted); border: 1px solid var(--border);
}
.pill.ok { background: var(--green-light); color: var(--green); border-color: transparent; }
.pill.warn { background: var(--amber-light); color: var(--amber); border-color: transparent; }
.pill.bad { background: var(--red-light); color: var(--red); border-color: transparent; }
.pill.accent { background: var(--accent-light); color: var(--accent); border-color: transparent; }

/* Stepper: the three stages of a posting screen. */
.stepper { display: flex; gap: 0; margin: 0 0 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.step {
  flex: 1; padding: 10px 14px; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
  background: var(--panel-sunk); border-right: 1px solid var(--border); display: flex; gap: 8px; align-items: center;
}
.step:last-child { border-right: 0; }
.step .n {
  width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; background: var(--border-strong); color: #fff; flex: 0 0 auto;
}
.step.done { color: var(--green); }
.step.done .n { background: var(--green); }
.step.current { color: var(--accent); background: var(--accent-light); }
.step.current .n { background: var(--accent); }

/* Toasts: transient success or error at the bottom of the screen. */
.toast-host { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  background: var(--text); color: #fff; box-shadow: var(--shadow-lg); max-width: min(560px, calc(100vw - 32px));
}
.toast.ok { background: var(--green); }
.toast.fail { background: var(--red); }

/* Visible keyboard focus, everywhere. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Home tiles. */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.home-tile { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; background: #fff; }
.home-tile .t-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.home-tile .t-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin-top: 4px; }
.home-tile .t-value.accent { color: var(--accent); }
.home-tile .t-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.home-tile.link { cursor: pointer; text-decoration: none; color: inherit; display: block; }
.home-tile.link:hover { border-color: var(--accent); }

/* File cards on Share Entry: collapsed by default, the summary line tells the story. */
.file-card { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; background: #fff; }
.file-card > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-card > summary::-webkit-details-marker { display: none; }
.file-card > summary .chev { color: var(--text-faint); transition: transform var(--transition); }
.file-card[open] > summary .chev { transform: rotate(90deg); }
.file-card .file-body { padding: 0 14px 14px; border-top: 1px solid var(--border); }
.file-card.dup { opacity: .55; }

/* Register rows collapse to cards on a phone. */
@media (max-width: 600px) {
  table.cards-on-phone thead { display: none; }
  table.cards-on-phone tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 4px; }
  table.cards-on-phone td { display: block; border: 0; padding: 2px 6px; white-space: normal; text-align: left !important; }
  table.cards-on-phone td[data-label]::before { content: attr(data-label) " "; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
  table.cards-on-phone td:empty { display: none; }
  table.cards-on-phone td.row-actions { padding-top: 8px; }
  table.cards-on-phone td.row-actions button { margin: 0 6px 6px 0; }
  table.cards-on-phone td .btn-sm { min-height: 40px; }
  table.cards-on-phone tfoot td:first-child { font-weight: 700; }
  /* The Bank Statement table is table-layout:fixed for the desktop columns;
     as cards there are no columns to fix. */
  #bs-txn-table { table-layout: auto; }
  #bs-txn-table td[style*="min-width"] { min-width: 0 !important; }
  #bs-txn-table td.bs-pick-col { text-align: left !important; background: transparent; }
  #bs-txn-table td.bs-pick-col::before { content: "Pick for one ledger "; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
  #bs-txn-table td.bs-check-col, #bs-txn-table td[data-label="Date"] { display: inline-block; vertical-align: middle; }
  #bs-txn-table td.bs-check-col { padding-right: 4px; }
  /* Filters and their controls take the full width of a phone. */
  .content .ch-filters > div, .content .sa-filters > div, .content .rm-filters > div, .content .pr-filters > div { flex: 1 1 100%; min-width: 0; }
  .content .ch-filters select, .content .sa-filters select, .content .rm-filters select, .content .pr-filters select,
  .content .ch-filters input, .content .sa-filters input, .content .rm-filters input, .content .pr-filters input { width: 100%; }
  /* Stepper: number above a short label, so three steps fit in 375px. */
  .stepper .step { flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 8px 4px; font-size: 11px; line-height: 1.25; }
  /* A form-row column whose flex-basis is a width on the desktop must not
     become a height when the row stacks. */
  .form-row > div { flex-basis: auto !important; }
}

/* ─── Responsive ─────────────────────────────────────── */

/* The mobile bar and drawer exist only below 860px. */
.topbar-mobile { display: none; }
.nav-scrim { display: none; }
.nav-label { white-space: nowrap; }

@media (max-width: 860px) {
  /*
    A 60px icon rail was the old answer and it did not work: the labels are
    still in the markup, so they rendered over the content and left under
    300px of a 375px screen to actually use. On a phone the sidebar leaves
    the layout entirely and comes back as a drawer.
  */
  .topbar-mobile {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    z-index: 120;
    background: var(--sidebar-bg);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
  }
  .topbar-brand {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.2px;
  }
  .topbar-page {
    margin-left: auto;
    color: var(--sidebar-text);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-mobile .brand-icon { width: 28px; height: 28px; font-size: 13px; }

  .nav-toggle {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: 0; padding: 0; box-shadow: none;
    flex: 0 0 auto;
  }
  .nav-toggle:hover { background: var(--sidebar-hover); box-shadow: none; }
  /* Three bars drawn from one element, so there is no icon font to load. */
  .nav-toggle-bars,
  .nav-toggle-bars::before,
  .nav-toggle-bars::after {
    display: block;
    width: 20px; height: 2px;
    background: #fff;
    border-radius: 2px;
    content: "";
    position: relative;
  }
  .nav-toggle-bars::before { top: -6px; position: absolute; }
  .nav-toggle-bars::after { top: 6px; position: absolute; }

  .sidebar {
    width: 280px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    z-index: 130;
  }
  body.nav-open .sidebar { transform: translateX(0); }

  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 125;
    background: rgba(10, 18, 30, .55);
  }
  .nav-scrim[hidden] { display: none; }

  /* Full width for the page itself — the whole point of the change. */
  .main-content { margin-left: 0; padding-top: 56px; }
  .content { padding: 16px 12px; gap: 16px; }

  .nav-item { padding: 12px 14px; min-height: 48px; font-size: 14px; }
  .sidebar-brand { padding: 18px 16px 14px; }
  .sidebar-footer { padding: 12px; }
  .sidebar-nav { padding: 12px; }

  /* Nothing may be wider than the screen. A select with a 280px floor, or a
     form column with a 200px floor, was enough to push the whole page sideways. */
  .card { padding: 16px 14px; }
  select, .form-control, input[type="text"], input[type="date"],
  input[type="number"], input[type="password"] {
    min-width: 0;
    max-width: 100%;
  }
  .form-row > div { min-width: 0; flex-basis: 100%; }
  .card h2 { font-size: 13px; padding: 8px 12px; }
  h1 { font-size: 18px; }
  img, svg, pre, textarea { max-width: 100%; }

  /* Long words — ledger names, serials, emails — wrap instead of stretching. */
  td, th, p, li, .charge-value { overflow-wrap: anywhere; }

  /* Tab strips wrap. They used to scroll sideways, and on a phone the cut-off
     last tab looked like the end of the strip (Reports hid six of nine tabs).
     Prefixed with .content because each page declares its own strip in a
     page-level <style>, which loads after this file and would otherwise win
     on equal specificity. */
  .content .tabs, .content .pm-tabs, .content .pr-tabs,
  .content .rm-tabs, .content .sa-tabs, .content .bs-mode-tabs { flex-wrap: wrap; }
  .content .tab-btn, .content .pm-tab, .content .pr-tab,
  .content .rm-tab, .content .sa-tab { flex: 0 0 auto; }

  /* A 25px control cannot be hit with a thumb. Inline padding in JS-rendered
     rows sets the height, so this floor has to cover inputs too. */
  button, .btn, .btn-primary, .btn-secondary, .btn-confirm, .btn-cancel,
  select, input[type="text"], input[type="date"], input[type="number"],
  input[type="password"], .form-control {
    min-height: 44px;
  }
  td input[type="text"], td select { min-height: 40px; }
  .nav-toggle { min-height: 44px; }
  /* A 16px tick box is fine under a mouse and awkward under a thumb. */
  input[type="checkbox"] { width: 20px; height: 20px; }

  table { font-size: 12.5px; }
  th, td { padding: 9px 10px; }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

@media (max-width: 600px) {
  .form-row { flex-direction: column; gap: 10px; }
  .stats-grid { gap: 10px; }
  .stats-grid .stat { flex: 1 1 calc(50% - 5px); min-width: 0; padding: 10px 12px; }
  .stat-value { font-size: 22px; }
  .charges-grid, .info-grid { grid-template-columns: 1fr; }
}
