/* Bank Statement Analyser — styles. Plain CSS, light theme, dense tables. */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #7b8794;
  --border: #d9e0e7;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --green: #047857;
  --green-bg: #ecfdf5;
  --red: #b91c1c;
  --red-bg: #fef2f2;
  --amber-bg: #fff7ed;
  --amber-border: #fdba74;
  --small-upi: #fffbeb;
  --drill-bg: #f8faff;
  --drill-border: #bfdbfe;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 18px; margin: 0; }
header .sub { color: var(--muted); font-weight: 400; }
.client-bar { display: flex; align-items: center; gap: 8px; }
.client-bar select { min-width: 200px; }
.user-greeting { margin-left: 8px; padding-left: 12px; border-left: 1px solid var(--border);
  color: var(--muted); font-size: 13px; }
.session-notice { background: var(--amber-bg); border-bottom: 1px solid var(--amber-border);
  color: #92400e; font-size: 12.5px; padding: 7px 20px; text-align: center; }
.credit-note { color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--panel);
  border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 10px 16px; cursor: pointer;
  border-bottom: 2px solid transparent; color: var(--muted); font-size: 14px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Full-width so the transactions table fits without a horizontal scrollbar. */
main { padding: 20px 28px; max-width: none; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Branding/credit line — sits below all content (normal flow, never overlaps) */
.app-credit {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 20px 24px;
}
.app-disclaimer {
  max-width: 760px;
  margin: 0 auto 10px;
  font-size: 12px;
  font-style: italic;
  line-height: 1.4;
  color: var(--muted);
}
.app-disclaimer:empty { display: none; }

h2 { font-size: 18px; margin-top: 0; }
h3 { font-size: 15px; margin: 20px 0 8px; }
.hint, .muted { color: var(--muted); }
.hint { font-size: 13px; }
.green { color: var(--green); font-weight: 600; }
.red   { color: var(--red);   font-weight: 600; }

/* ---- Forms ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; margin-bottom: 16px; display: flex; flex-wrap: wrap;
  gap: 12px; align-items: center; }
.card h3 { width: 100%; margin: 0 0 4px; }

label { display: inline-flex; align-items: center; gap: 6px; }
input, select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: #fff; }
input[type="checkbox"] { width: auto; }

button { padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 14px; }
button:hover { background: #f0f4f8; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { background: #1d4ed8; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost.danger { color: #dc2626; }
button.ghost.danger:hover { background: #fef2f2; border-color: #fca5a5; }

/* Link to the redesigned (v2) UI — subtle pill on the classic header */
.version-switch {
  text-decoration: none; color: var(--accent); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; margin-right: 4px;
}
.version-switch:hover { background: #eef4ff; }

.mapping-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
.mapping-grid label { display: flex; justify-content: space-between; }
.mapping-grid select { flex: 1; margin-left: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px; }
.toolbar-sep { width: 1px; align-self: stretch; min-height: 24px;
  background: var(--border); margin: 0 2px; }
/* Push the element (and everything after it) to the far right of a flex row */
.push-right { margin-left: auto; }
/* Excel export lives at the right end of the tabs bar, on every tab */
.tabs .tabs-export { align-self: center; margin: 2px 0; }
.tabs .status-msg  { align-self: center; }
/* Small numeric threshold inputs (UPI limit, audit limits) */
.upi-limit   { width: 70px;  padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; }
.limit-input { width: 100px; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; }
/* Inline progress spinner (audit re-run acknowledgement) */
.spinner { width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; display: inline-block;
  animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Filter toggle buttons: greyed when OFF, coloured (filled) when ON */
.toggle-btn { background: #eef2f7; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 14px; font-size: 14px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s; }
.toggle-btn:hover { color: var(--ink); border-color: #cbd5e1; background: #e7edf4; }
.toggle-btn.on-blue  { background: var(--accent); color: #fff; border-color: var(--accent); }
.toggle-btn.on-green { background: var(--green);  color: #fff; border-color: var(--green); }
.toggle-btn.on-red   { background: var(--red);    color: #fff; border-color: var(--red); }
.toggle-btn.on-blue:hover  { background: #1d4ed8; color: #fff; }
.toggle-btn.on-green:hover { background: #036c4e; color: #fff; }
.toggle-btn.on-red:hover   { background: #a01a1a; color: #fff; }

.txn-search-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.txn-search { flex: 1; max-width: 360px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.txn-count { font-size: 12px; }

.txn-hint { font-size: 12px; }

/* Two-way UPI parties section on the Audit Flags tab (between flag cards) */
.twoway-section { margin: 20px 0; }
.twoway-section h3 { margin: 0 0 4px; }

/* Sortable column headers in the Transactions table */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #e4ebf3; }
.sort-ind { font-size: 10px; color: var(--accent); margin-left: 2px; }

/* Row-select checkbox column */
th.chk-col, td.chk-col { width: 34px; text-align: center; padding: 7px 6px; }
th.chk-col input, td.chk-col input { cursor: pointer; }

/* Balance greyed out when the table is not in date order (running total is only
   meaningful chronologically — same failure mode as the multi-account export). */
td.bal-muted { color: var(--muted); font-style: italic; text-align: right; }

/* Batch action bar (shown when ≥1 row is checked) */
.batch-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 8px 0 12px; padding: 10px 14px;
  background: var(--drill-bg); border: 1px solid var(--drill-border);
  border-radius: 8px; }
.batch-count { font-weight: 600; color: var(--accent); }
.batch-bar select { min-width: 190px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.scrollable { max-height: 480px; overflow-y: auto; }
.txn-load-more-row { display: flex; justify-content: center; padding: 12px 0; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; }
th { background: #f0f4f8; font-weight: 600; position: sticky; top: 0; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.center { text-align: center; }
td.narr { white-space: normal; min-width: 280px; max-width: 500px; word-break: break-word; }
tr.small-upi-row { background: var(--small-upi); }
table select { padding: 3px 6px; font-size: 13px; }
/* Category combo: select + hidden custom input share the same cell */
td.cat-cell { white-space: nowrap; }
select.cat-select {
  min-width: 170px; max-width: 260px;
  padding: 3px 6px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 4px;
  background: #fff;
}
select.cat-select:focus { outline: 2px solid var(--accent); }
input.cat-custom {
  min-width: 170px; max-width: 260px;
  padding: 3px 6px; font-size: 13px;
  border: 1px solid var(--accent); border-radius: 4px;
  background: #fffbeb;
}
input.cat-custom:focus { outline: 2px solid var(--accent); }

select.itr-select {
  min-width: 140px; max-width: 220px;
  padding: 3px 6px; font-size: 12px;
  border: 1px solid #c7d8f0; border-radius: 4px;
  background: #f0f7ff; color: var(--accent);
}
select.itr-select:focus { outline: 2px solid var(--accent); }

.banner { background: var(--amber-bg); border: 1px solid var(--amber-border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.result { background: var(--green-bg); border: 1px solid #6ee7b7; color: var(--green);
  border-radius: 8px; padding: 10px 14px; }

/* ---- Dashboard cards ---- */
.card-section-label {
  width: 100%; grid-column: 1 / -1;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  margin-top: 10px; padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.itr-form-suggestion {
  width: 100%; grid-column: 1 / -1;
  background: var(--panel); border: 1px solid var(--border);
  border-left: 4px solid #2563EB; border-radius: 8px;
  padding: 10px 14px; font-size: 15px; margin-bottom: 6px;
}
.itr-form-suggestion strong { color: #2563EB; }
.itr-form-suggestion .muted { color: var(--muted); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px; margin-bottom: 20px;
  align-items: start;
}
.metric {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px;
  transition: box-shadow .15s, border-color .15s;
}
.metric[data-drill]:hover {
  border-color: var(--accent); box-shadow: 0 0 0 2px #dbeafe;
}
.metric-label { color: var(--muted); font-size: 12px; line-height: 1.3; }
.metric-value { font-size: 22px; font-weight: 700; margin-top: 5px;
  font-variant-numeric: tabular-nums; }
.metric-hint { font-size: 11px; color: var(--accent); margin-top: 4px; }

.card-green { border-left: 3px solid var(--green); }
.card-green .metric-value { color: var(--green); }
.card-red   { border-left: 3px solid var(--red); }
.card-red   .metric-value { color: var(--red); }
.card-amber { border-left: 3px solid #f59e0b; background: var(--amber-bg); }

/* Income-head cards: each statutory head expands to the categories beneath it */
.head-group { display: flex; flex-direction: column; gap: 6px; }
.head-card { cursor: pointer; }
.head-card:hover,
.head-card.head-card-open {
  border-color: var(--accent); box-shadow: 0 0 0 2px #dbeafe;
}
.head-cats { display: flex; flex-direction: column; gap: 4px; }
.head-cat-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--panel); cursor: pointer;
  font-size: 12.5px;
}
.head-cat-row:hover { border-color: var(--accent); background: #f0f7ff; }
.head-cat-name { flex: 1; }
.head-cat-amt {
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--green);
}
.head-cat-go { font-size: 10.5px; color: var(--accent); white-space: nowrap; }

/* ---- Category table with drill-down ---- */
.cat-row { cursor: pointer; }
.cat-row:hover { background: #f0f7ff; }
.cat-row-active { background: #dbeafe !important; }
.drill-toggle { color: var(--accent); font-size: 12px; white-space: nowrap; }

.drill-panel {
  background: var(--drill-bg);
  border-top: 2px solid var(--drill-border);
  padding: 12px 16px;
}
.drill-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px; font-size: 13px;
}
.drill-close {
  margin-left: auto; font-size: 12px; padding: 3px 10px;
  border: 1px solid var(--border);
}
.drill-loading { padding: 12px; color: var(--muted); }
.drill-table-wrap {
  max-height: 400px; overflow-y: auto;
  border: 1px solid var(--drill-border); border-radius: 6px;
}
.drill-table-wrap table th { background: #e0ecff; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: #fff; border-radius: 10px; padding: 20px; width: 360px;
  display: flex; flex-direction: column; gap: 10px; }
.modal-box label { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Two-way UPI parties: net column colours */
.num.pos { color: var(--green, #047857); font-weight: 600; }
.num.neg { color: var(--red,   #b91c1c); font-weight: 600; }
.twoway-row { cursor: pointer; }

.hidden { display: none !important; }

/* Boot-failure banner: shown only if the startup API calls fail. */
.boot-error {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: #fef2f2; color: #dc2626;
  border-bottom: 1px solid #fca5a5;
  font-size: 14px;
}
.boot-error button { color: #dc2626; border-color: #fca5a5; }

#pdfPasswordRow {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 6px; padding: 10px 12px;
  background: var(--amber-bg); border: 1px solid var(--amber-border);
  border-radius: 6px;
}
#pdfPasswordRow label { font-weight: 500; }
#pdfPasswordRow input[type="password"] { width: 220px; margin-top: 2px; }
#pdfPasswordRow .hint { margin: 0; font-size: 12px; color: var(--muted); }

/* Upload action row: button + status message side by side */
.upload-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

.status-msg {
  font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.status-msg::before {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Client-switch feedback (header): a small pill next to the dropdown that
   shows "Loading <client>…" while the active tab refetches, then briefly
   flips to a checkmark "Loaded <client>" before fading. Paired with a fade
   on <main> (below) so the screen visibly refreshes even when the new
   client's tab happens to render a similar shape (e.g. an empty table). */
.client-switch-indicator {
  font-size: 12px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  background: var(--drill-bg); border: 1px solid var(--drill-border);
  opacity: 0; transform: translateY(-3px);
  transition: opacity .18s ease, transform .18s ease;
}
.client-switch-indicator.show { opacity: 1; transform: translateY(0); }
.client-switch-indicator.done {
  background: var(--green-bg); border-color: #a7e3c5; color: var(--green);
}
.client-switch-indicator::before {
  content: ''; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite; flex-shrink: 0;
}
.client-switch-indicator.done::before {
  content: '✓'; width: auto; height: auto; border: none; animation: none;
  color: var(--green); font-size: 12px; font-weight: 700; line-height: 1;
}

@keyframes clientSwitchFade { 0% { opacity: .35; } 100% { opacity: 1; } }
main.client-switch-anim { animation: clientSwitchFade .35s ease; }

/* Disable button while processing without hiding its text */
button:disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

/* ---- Tab badge (Audit Flags count) ---- */
.tab-badge {
  display: inline-block; margin-left: 5px;
  background: var(--red); color: #fff;
  border-radius: 10px; padding: 1px 6px;
  font-size: 11px; font-weight: 700; vertical-align: middle;
  line-height: 16px;
}

/* ---- Audit Flags ---- */
.audit-flag {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 12px; overflow: hidden;
}
.audit-flag-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; cursor: pointer; user-select: none;
}
.audit-flag-header:hover { background: #f5f7fa; }
.audit-flag-header strong { flex: 1; font-size: 14px; }
.audit-chevron { color: var(--muted); font-size: 13px; transition: transform .2s; }
.audit-flag.open .audit-chevron { transform: rotate(180deg); }

.audit-badge {
  min-width: 24px; height: 24px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; padding: 0 7px; flex-shrink: 0;
}
.audit-badge-high   { background: #fef2f2; color: var(--red);   border: 1px solid #fca5a5; }
.audit-badge-medium { background: var(--amber-bg); color: #92400e; border: 1px solid var(--amber-border); }
.audit-badge-ok     { background: var(--green-bg); color: var(--green); border: 1px solid #6ee7b7; }

.audit-desc {
  padding: 0 16px 10px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.audit-body { display: none; padding: 0; }
.audit-flag.open .audit-body { display: block; }

.audit-totals {
  display: flex; gap: 24px; padding: 10px 16px;
  font-size: 13px; border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.audit-totals span { color: var(--muted); }
.audit-totals .green { color: var(--green); font-weight: 600; }
.audit-totals .red   { color: var(--red);   font-weight: 600; }

/* Pairs table for round-trip section */
.audit-pairs { padding: 10px 16px 14px; }
.audit-pairs-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.audit-pairs-table th {
  background: #f0f4f8; padding: 6px 10px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.audit-pairs-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.audit-pairs-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.audit-pairs-table th.narr-sm,
.audit-pairs-table td.narr-sm { max-width: 220px; white-space: normal; word-break: break-word; font-size: 12px; }
.audit-pair-arrow { text-align: center; color: var(--muted); font-size: 16px; }
.audit-pairs-table tr:last-child td { border-bottom: none; }

.audit-empty {
  padding: 14px 16px; color: var(--green); font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}

/* OCR balance-reconciliation warning box (shown on scanned-PDF preview) */
.ocr-warn {
  margin-top: 8px; padding: 10px 12px;
  background: var(--red-bg); border: 1px solid #fca5a5;
  border-radius: 6px; font-size: 12.5px; color: #7f1d1d;
  line-height: 1.5;
}

/* Pre-import validation report (advisory checks shown above Confirm & import) */
.validation-report:empty { display: none; }
.validation-report {
  margin-top: 12px; padding: 10px 14px;
  background: var(--drill-bg); border: 1px solid var(--drill-border);
  border-radius: 6px;
}
.vr-title { margin: 0 0 6px; font-size: 13.5px; }
.vr-list { list-style: none; margin: 0; padding: 0; }
.vr-list li {
  padding: 4px 0; font-size: 12.5px; line-height: 1.5;
  border-top: 1px solid var(--border);
}
.vr-list li:first-child { border-top: none; }
.vr-badge {
  display: inline-block; min-width: 52px; text-align: center;
  padding: 1px 6px; margin-right: 6px; border-radius: 4px;
  font-size: 11px; font-weight: 700; vertical-align: baseline;
}
.vr-pass   { background: var(--green-bg); color: var(--green); }
.vr-fail   { background: var(--red-bg);   color: var(--red); }
.vr-review { background: var(--amber-bg); color: #9a3412; border: 1px solid var(--amber-border); }
.vr-na     { background: #eef2f7;          color: var(--muted); }
