:root {
  /* Blue theme: dark navy for the frame and headings, light blues for surfaces and highlights. */
  --navy: #0b2545;
  --navy-2: #13315c;
  --bg: #eef4fb;
  --panel: #ffffff;
  --border: #d3e0f0;
  --text: #0f1e33;
  --muted: #5b6b82;
  --brand: #1d5fbf;
  --brand-dark: #13315c;
  --light-blue: #8db8ec;
  --green: #157a4a;
  --green-bg: #e6f5ec;
  --amber: #a35b00;
  --amber-bg: #fdf0dd;
  --blue: #1d5fbf;
  --blue-bg: #e1ecfa;
  --red: #b3261e;
  --red-bg: #fbe9e7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  background: var(--brand);
  color: white;
  font-weight: 700;
  font-size: 14px;
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12.5px; color: var(--muted); }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--blue-bg); color: var(--brand); }

main#app { max-width: 1180px; margin: 0 auto; padding: 24px; }
/* Anything marked hidden stays hidden, even when a class gives it a display style (e.g. the login screen). */
[hidden] { display: none !important; }
.view[hidden] { display: none; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.card .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.card .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.card .value.pos { color: var(--green); }
.card .value.neg { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; }
@media (max-width: 900px) { .grid-2, .cards { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.panel-header h2 { margin: 0; font-size: 18px; }

.prose h3 { font-size: 14.5px; margin: 20px 0 6px; }
.prose p { line-height: 1.55; color: #333; font-size: 14px; }

table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}
table.table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.table th.num, table.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table tbody tr:hover { background: #fafbfc; }
table.table tbody tr.clickable { cursor: pointer; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge.open { background: var(--amber-bg); color: var(--amber); }
.badge.partial { background: var(--blue-bg); color: var(--blue); }
.badge.paid { background: var(--green-bg); color: var(--green); }
.badge.bad { background: var(--red-bg); color: var(--red); }

.btn {
  border: 1px solid var(--border);
  background: white;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(480px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 20, 30, .45); }
.form { padding: 26px 28px 6px; display: flex; flex-direction: column; gap: 12px; }
.form h2 { margin: 0 0 6px; font-size: 17px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form input, .form select {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
}
.form .row { display: flex; gap: 12px; }
.form .row label { flex: 1; }
.hint { font-size: 12.5px; color: var(--muted); margin: -4px 0 0; }
.error { color: var(--red); font-size: 13px; min-height: 16px; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 28px 24px; }

.tb-status { font-weight: 700; padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.tb-status.ok { background: var(--green-bg); color: var(--green); }
.tb-status.bad { background: var(--red-bg); color: var(--red); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; font-size: 13.5px; margin-bottom: 8px; }
.detail-grid .k { color: var(--muted); }
.section-title { font-weight: 700; margin: 14px 0 6px; font-size: 13.5px; }


/* ---------- Additions: multi-line forms, bank, financials, setup ---------- */

.tabs { flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.ok-msg { color: var(--green); font-size: 13px; font-weight: 600; margin: 0; min-height: 16px; }
.rates-line { margin: -8px 0 16px; }

.grid-2.even { grid-template-columns: 1fr 1fr; }
.panel-header.wrap { flex-wrap: wrap; gap: 12px; }
.panel-header .btn-small { flex-shrink: 0; }

table.table tbody tr.selected { background: var(--blue-bg); }
table.table tr.total td { font-weight: 700; border-top: 2px solid var(--border); }

dialog.wide { width: min(900px, 96vw); }
dialog .dialog-actions.inline { padding: 16px 0 0; }
.form .row { flex-wrap: wrap; }
.form .row label { min-width: 140px; }
.form .totals { margin: 0; font-size: 13.5px; color: var(--text); }

.lines-table td { padding: 5px 6px; vertical-align: middle; }
.lines-table input, .lines-table select {
  width: 100%;
  font-size: 13.5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}
.lines-table input.num { text-align: right; min-width: 90px; }
.lines-table input.narrow { min-width: 60px; max-width: 80px; }
.btn-icon { padding: 3px 9px; font-size: 15px; line-height: 1; }

/* Bank */
.upload-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.upload-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.upload-row select, .upload-row input[type=file] { font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.post-cell { display: flex; flex-direction: column; gap: 6px; min-width: 260px; }
.post-cell select, .post-cell input { font-size: 13px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
.post-cell .p-settle { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.post-cell .p-settle input { width: 110px; text-align: right; }
.post-cell [hidden] { display: none; }

/* Journal source badges */
.badge.src-manual { background: var(--blue-bg); color: var(--blue); }
.badge.src-invoice { background: #f1ecfb; color: #5b3aa6; }
.badge.src-payment { background: var(--green-bg); color: var(--green); }
.badge.src-bank { background: var(--amber-bg); color: var(--amber); }
.badge.src-opening { background: #eceff3; color: #475467; }

/* Financial statements */
.period-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.period-row label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.period-row input[type=date] { font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.fin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.fin-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 900px) { .fin-grid, .grid-2.even { grid-template-columns: 1fr; } }
table.fin td { padding: 6px 10px; border-bottom: 1px solid #f0f2f5; }
table.fin tr.section td { font-weight: 700; text-transform: uppercase; font-size: 11.5px; letter-spacing: .04em; color: var(--muted); padding-top: 16px; border-bottom: 2px solid var(--border); }
table.fin tr.cat td { font-weight: 600; }
table.fin tr.acct td { color: var(--muted); font-size: 12.5px; }
table.fin tr.acct td:first-child { padding-left: 26px; }
table.fin tr.sub td { font-weight: 700; border-top: 1px solid var(--text); background: #fafbfc; }
table.fin tr.grand td { font-weight: 800; border-top: 2px solid var(--text); border-bottom: 3px double var(--text); background: var(--blue-bg); }
.hide-detail table.fin tr.acct { display: none; }

/* Setup */
#accounts-table select { font-size: 13px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; max-width: 100%; }
.fx-rates { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 8px; }
.check { cursor: pointer; }
#bs-check, #cf-check { margin-top: 10px; }

/* ---------- KPIs, charts, fixed assets, periods, pay ---------- */

.badge.closed { background: #eceff3; color: #475467; }
.badge.src-asset { background: #e6f5ec; color: var(--green); }
.badge.src-depreciation { background: #f1ecfb; color: #5b3aa6; }
.lines-table select:disabled { background: #f5f6f8; color: var(--muted); }
.post-cell .p-cc { max-width: 100%; }

.kpi-group { margin-bottom: 18px; }
.kpi-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.kpi-group .cards { margin-bottom: 0; }
.card.kpi .value { font-size: 22px; }
.kpi-charts { align-items: start; }
.kpi-charts .span-2 { grid-column: 1 / -1; }

.chart { min-height: 60px; }
.chart-wrap { position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: #eceef1; stroke-width: 1; }
.chart .axis-zero { stroke: #c4c9d2; stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .end-label, .chart .bar-label { font-size: 12px; fill: var(--text); }
.chart .bar-value { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .crosshair { stroke: #98a2b3; stroke-width: 1; }
.chart .bar { transition: opacity .1s; }
.chart .bar.hover { opacity: .8; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line, .tip-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.chart-tip {
  position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(16, 24, 40, .12);
  min-width: 150px; z-index: 5;
}
.chart-tip .tip-title { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tip strong { font-variant-numeric: tabular-nums; }
.table-view { margin-top: 8px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { border: none; background: #fff; padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--blue-bg); color: var(--brand); }

.period-row select { font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.periods-wrap { max-height: 360px; overflow-y: auto; }
.upload-row input:not([type=file]) { font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.form .radio { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--text); font-weight: 500; }
.form .radio select { font-size: 13px; padding: 5px 7px; }

.pay-amount { font-size: 26px; font-weight: 800; margin: 2px 0 10px; }
.pay-amount .muted { font-size: 13px; font-weight: 500; }
.pay-fields { display: grid; gap: 6px; }
.pay-field { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 10px; padding: 6px 10px; background: var(--bg); border-radius: 8px; font-size: 13.5px; }
.pay-field .k { color: var(--muted); }
.pay-field strong { font-variant-numeric: tabular-nums; word-break: break-all; }
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.bank-btn { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; text-align: left; color: var(--text); }
.bank-btn:hover { background: var(--bg); }
.bank-btn.selected { border-color: var(--brand); background: var(--blue-bg); color: var(--brand); }
.bank-mark { flex-shrink: 0; width: 30px; height: 30px; border-radius: 6px; background: #eceff3; color: #475467; font-size: 10.5px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.bank-btn.selected .bank-mark { background: var(--brand); color: #fff; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
@media (max-width: 600px) { .pay-field { grid-template-columns: 1fr auto; } .pay-field .k { grid-column: 1 / -1; } }
#assets-table td:nth-child(1), #assets-table td:nth-child(5), #assets-table td:nth-child(11), #journals-table td:nth-child(1), #journals-table td:nth-child(2) { white-space: nowrap; }
#periods-table td:first-child .muted { white-space: nowrap; }

/* Simulated bank pay window */
.pay-dialog .form { padding-bottom: 0; }
.bank-btn:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
.sim-bank { margin: 0; }
.sim-bank-bar { display: flex; align-items: center; gap: 12px; background: #1f2937; color: #fff; padding: 16px 24px; border-radius: 12px 12px 0 0; flex-wrap: wrap; }
.sim-bank-bar .bank-mark { background: #fff; color: #1f2937; }
.sim-bank-name { font-weight: 700; font-size: 15px; }
.sim-bank-sub { font-size: 12px; opacity: .75; }
.sim-badge { margin-left: auto; background: #fbbf24; color: #1f2937; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em; }
.sim-bank-body { padding: 20px 28px 8px; display: flex; flex-direction: column; gap: 12px; }
.sim-bank-body h2 { margin: 0; font-size: 17px; }
.sim-bank-body.center { align-items: center; text-align: center; padding: 32px 28px 16px; }
.sim-bank-body p { margin: 0; }
.done-mark { width: 52px; height: 52px; border-radius: 50%; background: var(--green-bg); color: var(--green); font-size: 28px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Entities, account links, editing */
.brand { flex-wrap: wrap; }
.entity-picker { display: flex; align-items: center; gap: 8px; margin-left: 16px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.entity-picker select { font-size: 13.5px; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--blue-bg); color: var(--brand); font-family: inherit; }
.entity-tag { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .03em; padding: 1px 6px; border-radius: 5px; background: #eceff3; color: #475467; }
.entity-note { margin: -4px 0 12px; }
.entity-note:empty { display: none; }
a.acct-link { color: var(--brand); text-decoration: none; }
a.acct-link:hover { text-decoration: underline; }
table.fin tr.acct a.acct-link { color: inherit; }
table.fin tr.acct a.acct-link:hover { color: var(--brand); }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; }
.back-link:hover { color: var(--brand); }
.badge.edited { background: var(--amber-bg); color: var(--amber); font-size: 10.5px; }
.history { margin: 0; padding-left: 18px; font-size: 13px; }
.history li { margin: 2px 0; }
select:disabled { opacity: .7; }

.demo-banner { background: #fef3c7; color: #92400e; text-align: center; font-size: 13px; font-weight: 600; padding: 8px 16px; border-bottom: 1px solid #fde68a; }
.btn-edit-entry { padding: 3px 10px; font-size: 12px; }

/* Login & users */
.login-screen { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(16, 24, 40, .08); }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-card input { font-size: 14px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.logged-out .topbar, .logged-out main, .logged-out .demo-banner { visibility: hidden; }
.user-menu { display: flex; align-items: center; gap: 8px; margin-left: 12px; font-size: 13px; }
.user-name { font-weight: 600; }
#users-table input, #users-table select { font-size: 13px; padding: 4px 7px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }

/* Viewers can look but not change: hide every create / edit / pay / post control (the server refuses them anyway). */
.role-viewer .admin-only,
.role-viewer [data-new-invoice], .role-viewer #btn-new-journal, .role-viewer #btn-import-ledger,.role-viewer .btn-edit-entry, .role-viewer #btn-edit-journal,
.role-viewer .btn-pay, .role-viewer #btn-record-payment, .role-viewer #btn-pay-invoice,
.role-viewer #form-upload, .role-viewer .post-cell, .role-viewer .p-post, .role-viewer #btn-auto-settle,
.role-viewer #btn-new-asset, .role-viewer #form-depr,
.role-viewer #btn-new-account, .role-viewer .edit-account, .role-viewer [data-new-party], .role-viewer [data-edit-party],
.role-viewer #form-cc, .role-viewer [data-cc-toggle], .role-viewer [data-period], .role-viewer #btn-refresh-rates { display: none !important; }
.role-viewer .cat-select { pointer-events: none; background: transparent; border-color: transparent; }

.problem-banner { position: sticky; top: 0; z-index: 50; background: var(--red-bg); color: var(--red); text-align: center; font-size: 13.5px; font-weight: 600; padding: 8px 16px; border-bottom: 1px solid #f5c2bd; }
.problem-banner .btn { margin-left: 10px; }

/* Invoice recognition */
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.drop-target { outline: 3px dashed var(--brand); outline-offset: 6px; border-radius: 8px; }
dialog.with-preview { width: min(1400px, 98vw); }
.invoice-layout { display: grid; grid-template-columns: 1fr; }
dialog.with-preview .invoice-layout { grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.1fr); }
.invoice-preview { background: #eceff3; border-right: 1px solid var(--border); min-height: 70vh; }
.invoice-preview iframe { width: 100%; height: 100%; min-height: 70vh; border: 0; display: block; }
@media (max-width: 900px) { dialog.with-preview .invoice-layout { grid-template-columns: 1fr; } .invoice-preview, .invoice-preview iframe { min-height: 50vh; } }
.recognition-banner { background: var(--blue-bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.recognition-banner .legend { font-size: 12px; color: var(--muted); }
.recognition-banner .legend span { padding: 1px 6px; border-radius: 4px; border: 2px solid transparent; }
.rec-learned { border-color: #16a34a !important; box-shadow: 0 0 0 1px #16a34a33; }
.rec-generic { border-color: #2a78d6 !important; }
.rec-guess { border-color: #d97706 !important; background: #fffbeb; }
.rec-missing { border-color: #dc2626 !important; background: #fef2f2; }
.legend .rec-learned { border-color: #16a34a; } .legend .rec-generic { border-color: #2a78d6; } .legend .rec-guess { border-color: #d97706; } .legend .rec-missing { border-color: #dc2626; }
.notice-banner { position: sticky; top: 0; z-index: 51; text-align: center; font-size: 13.5px; font-weight: 600; padding: 9px 16px; }
.notice-banner.ok { background: var(--green-bg); color: var(--green); border-bottom: 1px solid #bbe5cc; }
.notice-banner.bad { background: var(--red-bg); color: var(--red); border-bottom: 1px solid #f5c2bd; }
.role-viewer #btn-upload-invoice { display: none !important; }


/* ---------- Blue theme ---------- */
body { background: linear-gradient(180deg, #e3edf9 0, var(--bg) 260px) no-repeat, var(--bg); }
.topbar { background: linear-gradient(90deg, var(--navy) 0%, var(--navy-2) 60%, #1b4a86 100%); border-bottom: 3px solid var(--light-blue); box-shadow: 0 2px 10px rgba(11, 37, 69, .25); }
.brand-mark { background: var(--light-blue); color: var(--navy); }
.brand-name { color: #fff; }
.brand-sub, .brand-sub strong { color: #b9d1f0; }
.tabs .tab { color: #c9dcf5; }
.tabs .tab:hover { background: rgba(141, 184, 236, .18); color: #fff; }
.tabs .tab.active { background: var(--light-blue); color: var(--navy); }
.entity-picker { color: #b9d1f0; }
.entity-picker select { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(141, 184, 236, .5); }
.entity-picker select option { color: var(--text); background: #fff; }
.user-menu .user-name { color: #fff; }
.user-menu .btn { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(141, 184, 236, .45); }
.user-menu .btn:hover { background: rgba(255, 255, 255, .2); }

/* "Other" dropdown */
.tab-more { position: relative; }
.tab-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 190px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 30px rgba(11, 37, 69, .22); padding: 6px; display: flex; flex-direction: column; }
.tab-menu[hidden] { display: none; }
.tabs .tab-menu .tab { color: var(--text); text-align: left; border-radius: 7px; padding: 8px 12px; }
.tabs .tab-menu .tab:hover { background: var(--blue-bg); color: var(--brand-dark); }
.tabs .tab-menu .tab.active { background: var(--blue-bg); color: var(--brand); }

/* Surfaces */
.panel, .card { border-color: var(--border); box-shadow: 0 1px 2px rgba(11, 37, 69, .05); }
.card { border-top: 3px solid var(--light-blue); }
.panel h2, .panel-header h2, .card .value { color: var(--navy); }
table.table th { background: #f1f6fd; color: #3f5a80; border-bottom-color: var(--border); }
table.table tbody tr:hover { background: #f5f9ff; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn { border-color: var(--border); }
.btn:hover { background: var(--blue-bg); }
.login-screen { background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 55%, #2f6fbf 100%); }
.login-card { border-top: 4px solid var(--light-blue); }
.tb-status.ok { background: var(--green-bg); }
table.fin tr.grand td { background: var(--blue-bg); }
.login-card .brand-name { color: var(--navy); }
.login-card .brand-sub { color: var(--muted); }

/* Delete buttons (admin only) */
.btn-delete { color: var(--red); border-color: #f1c7c3; }
.btn-delete:hover { background: var(--red-bg); }
.btn-delete.confirm { background: var(--red); color: #fff; border-color: var(--red); }
td.nowrap { white-space: nowrap; }
.role-viewer .btn-delete { display: none !important; }

/* Invoice recognition: PDF drawn next to the form, with boxes to teach positions */
.invoice-preview { display: flex; flex-direction: column; }
.teach-bar { position: sticky; top: 0; z-index: 3; background: var(--navy); color: #fff; font-size: 13px; padding: 9px 12px; line-height: 1.4; }
.teach-bar.warn { background: #b45309; }
.pdf-pages { overflow: auto; max-height: 82vh; padding: 10px; }
.pdf-page { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 2px 10px rgba(11, 37, 69, .18); }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-overlay { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.zone { position: absolute; border: 2px solid; border-radius: 3px; pointer-events: none; }
.zone span { position: absolute; left: -2px; bottom: 100%; margin-bottom: 1px; font-size: 10.5px; font-weight: 700; color: #fff; padding: 1px 5px; border-radius: 4px 4px 4px 0; white-space: nowrap; }
.zone.drawing { border-color: #2a78d6; background: rgba(42, 120, 214, .14); }
.zone.learned { border-style: dashed; border-color: #16a34a; background: rgba(22, 163, 74, .07); }
.zone.learned span { background: #16a34a; }
.zone.taught { border-color: #7c3aed; background: rgba(124, 58, 237, .1); }
.zone.taught span { background: #7c3aed; }
.teach-active { outline: 3px solid #7c3aed; outline-offset: 1px; }
.rec-taught { border-color: #7c3aed !important; background: #f5f3ff; }
.legend .rec-taught { border-color: #7c3aed; }
.lines-footer { align-items: flex-end; justify-content: space-between; }
.pdf-total { max-width: 220px; }
.lines-table .l-vat-code { min-width: 96px; }
.lines-table .l-desc { min-width: 150px; }
.lines-table .l-account { min-width: 150px; }

.inbox-panel { margin-bottom: 16px; border-left: 4px solid var(--light-blue); }
.inbox-address { font-size: 13px; font-weight: 500; }

/* Sortable lists: click a heading to sort, again to reverse */
table.table:not(.fin):not(.lines-table) thead th { cursor: pointer; user-select: none; }
table.table:not(.fin):not(.lines-table) thead th:empty { cursor: default; }
table.table:not(.fin):not(.lines-table) thead th:not(:empty):hover { color: var(--brand); }
table.table thead th.sorted-asc::after { content: ' B2'; font-size: 9px; color: var(--brand); }
table.table thead th.sorted-desc::after { content: ' BC'; font-size: 9px; color: var(--brand); }

/* ---------- Reimbursements ---------- */
.claim-panel { scroll-margin-top: 140px; margin-bottom: 18px; border-left: 4px solid var(--light-blue); padding: 0; overflow: hidden; }
.claim-layout { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; }
.claim-layout .receipt-preview[hidden] + .claim-form { grid-column: 1 / -1; }
.receipt-preview { background: var(--bg); padding: 16px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.receipt-preview img { max-width: 100%; max-height: 70vh; border-radius: 6px; box-shadow: 0 2px 10px rgba(11, 37, 69, .15); background: white; }
.receipt-progress { width: 100%; }
.receipt-progress .bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.receipt-progress .bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.receipt-progress p { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.claim-form { padding: 20px 22px 16px; }
.claim-form .dialog-actions { padding: 0; }
.src-tag { align-self: flex-start; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 10px; padding: 0 6px; margin-left: 4px; }
.src-tag:empty { display: none; }
.src-tag.src-learned { background: var(--green-bg); color: var(--green); }
.src-tag.src-generic, .src-tag.src-calculated { background: var(--blue-bg); color: var(--blue); }
.src-tag.src-guess { background: var(--amber-bg); color: var(--amber); }
.claim-cards { margin-top: 4px; }
.badge.rejected { background: var(--red-bg); color: var(--red); }
.muted.small { font-size: 12px; }
.scan-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Phones: a stacked form with big touch targets, the list as cards. */
@media (max-width: 700px) {
  main#app { padding: 14px 12px; }
  /* The header scrolls away on a phone instead of covering a third of the screen. */
  .topbar { position: static; }
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .brand { flex-wrap: wrap; gap: 8px 12px; }
  .brand-sub { display: none; }
  .tabs { flex-wrap: wrap; }
  .tab { padding: 7px 10px; }
  .claim-layout { grid-template-columns: 1fr; }
  .receipt-preview { border-right: none; border-bottom: 1px solid var(--border); }
  .receipt-preview img { max-height: 40vh; }
  .claim-form { padding: 16px 14px; }
  .claim-form .row { flex-direction: column; gap: 12px; }
  .claim-form .row label { min-width: 0; }
  .claim-form input, .claim-form select { font-size: 16px; min-height: 42px; } /* 16px stops iOS zooming in */
  .claim-form .dialog-actions .btn { flex: 1; min-height: 44px; }
  .scan-actions { width: 100%; }
  .scan-actions .btn { flex: 1 1 auto; min-height: 46px; }
  #btn-scan-receipt { flex-basis: 100%; font-size: 16px; }
  .claim-cards { grid-template-columns: 1fr 1fr; }
  .claim-cards .card { padding: 12px; }
  .claim-cards .card .value { font-size: 18px; }
  table.claims-table thead { display: none; }
  table.claims-table, table.claims-table tbody, table.claims-table tr { display: block; width: 100%; }
  table.claims-table tr { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; }
  table.claims-table td { border: none; padding: 4px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; }
  table.claims-table td[data-label]::before { content: attr(data-label); font-size: 11.5px; font-weight: 700; text-transform: uppercase; color: var(--muted); text-align: left; flex-shrink: 0; }
  table.claims-table td.claim-actions { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; }
  table.claims-table td.claim-actions:empty { display: none; }
  table.claims-table td.claim-actions .btn { min-height: 40px; }
}
@media (max-width: 700px) { .entity-picker, .user-menu { margin-left: 0; } .user-menu { flex-wrap: wrap; } }

/* Camera scanner (Reimbursements) */
.camera-dialog { width: min(560px, 96vw); max-width: none; background: #000; overflow: hidden; }
.camera-view { position: relative; aspect-ratio: 3 / 4; max-height: 75vh; overflow: hidden; background: #000; }
.camera-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-frame { position: absolute; inset: 7% 12% 14%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); pointer-events: none; }
.camera-tip { position: absolute; left: 0; right: 0; bottom: 3%; margin: 0; padding: 0 16px; text-align: center; color: #fff; font-size: 13.5px; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.camera-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px)); background: #000; }
.camera-actions .btn { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .35); min-width: 96px; min-height: 44px; }
.camera-shutter { width: 70px; height: 70px; border-radius: 50%; border: 4px solid #fff; background: #fff; box-shadow: inset 0 0 0 3px #000; cursor: pointer; flex-shrink: 0; }
.camera-shutter:active { transform: scale(.94); }
@media (max-width: 700px) {
  .camera-dialog { width: 100vw; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .camera-dialog[open] { display: flex; flex-direction: column; }
  .camera-view { flex: 1; aspect-ratio: auto; max-height: none; }
}

/* Intercompany */
#ic-pl-table td, #ic-bs-table td { vertical-align: middle; }
#ic-pl-table tr.sub td, #ic-bs-table tr.sub td { font-weight: 700; }
#ic-checks-table td:nth-child(3) .muted { font-size: 12.5px; font-weight: 400; margin-top: 2px; }
#ic-invoices-table td.muted { font-size: 12.5px; max-width: 320px; }

/* Export bar above tables */
.export-bar { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin: 4px 0 6px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.export-bar .btn-small { padding: 2px 8px; font-size: 12px; }
@media print { .export-bar { display: none; } }

/* HMRC connection */
.hmrc-output { background: #f6f8fb; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; margin: 10px 0 0; }
#hmrc-panel code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Filter bar above lists */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 6px 0 10px; padding: 10px 12px; background: #f6f8fb; border: 1px solid var(--border); border-radius: 8px; }
.filter-bar label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.filter-bar label.grow { flex: 1; min-width: 180px; }
.filter-bar select, .filter-bar input { font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; font-family: inherit; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }
.filter-bar .filter-count { margin-left: auto; font-size: 12.5px; align-self: center; }

/* Group overview: ownership chart */
.org-wrap { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; align-items: flex-start; }
.org-group { border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px 18px; background: #fbfcfe; max-width: 100%; overflow-x: auto; }
.org-group.consolidated { border: 2px dashed #8aa6c8; background: #f4f8fd; }
.org-group-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 12px; text-align: center; }
.org-link { border: 0; cursor: pointer; font-family: inherit; }
.org-tree, .org-tree ul, .org-flat { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; gap: 0; }
.org-flat { gap: 14px; flex-wrap: wrap; }
.org-tree ul { padding-top: 24px; position: relative; }
.org-tree li { position: relative; padding: 24px 8px 0; display: flex; flex-direction: column; align-items: center; }
.org-tree li.org-root { padding-top: 0; }
.org-tree li::before, .org-tree li::after { content: ''; position: absolute; top: 0; width: 50%; height: 24px; border-top: 2px solid #b8c2d0; }
.org-tree li::before { right: 50%; border-right: 2px solid #b8c2d0; }
.org-tree li::after { left: 50%; border-left: 2px solid #b8c2d0; }
.org-tree li.org-root::before, .org-tree li.org-root::after, .org-tree li:only-child::before, .org-tree li:only-child::after { display: none; }
.org-tree li:only-child { padding-top: 24px; }
.org-tree li:first-child::before, .org-tree li:last-child::after { border: 0 none; }
.org-tree li:last-child::before { border-right: 2px solid #b8c2d0; border-radius: 0 8px 0 0; }
.org-tree li:first-child::after { border-radius: 8px 0 0 0; }
.org-tree ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 2px solid #b8c2d0; height: 24px; }
.org-tree li:only-child::after { display: block; left: 50%; width: 0; border-top: 0; border-left: 2px solid #b8c2d0; border-radius: 0; }
.org-card { display: flex; flex-direction: column; gap: 2px; width: 190px; text-align: left; padding: 9px 11px; border: 1px solid var(--border); border-left: 5px solid #98a2b3; border-radius: 9px; background: #fff; font-family: inherit; cursor: pointer; position: relative; box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
.org-card:hover { border-color: var(--blue); box-shadow: 0 2px 8px rgba(42, 120, 214, .18); }
.org-card.type-holding { border-left-color: #2a78d6; }
.org-card.type-gambling { border-left-color: #eb6834; }
.org-card.type-services { border-left-color: #1baf7a; }
.org-card.type-tech_services { border-left-color: #7c5cd6; }
.org-card.type-admin_services { border-left-color: #c9a227; }
.org-code { font-size: 11px; font-weight: 800; letter-spacing: .04em; color: #475467; }
.org-pct { position: absolute; top: 8px; right: 9px; font-size: 11px; font-weight: 700; background: var(--blue-bg); color: var(--blue); padding: 1px 7px; border-radius: 10px; }
.org-name { font-size: 13.5px; font-weight: 700; line-height: 1.25; color: var(--text); }
.org-type { font-size: 12px; font-weight: 600; color: var(--muted); }
.org-meta { font-size: 11.5px; color: var(--muted); }

/* Company detail page */
.back-link { font-size: 12.5px; font-weight: 600; color: var(--blue); text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 28px; margin-top: 10px; }
.kv-section .section-title { margin-top: 10px; }
dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 8px 0 0; font-size: 13.5px; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; }
dl.kv a { color: var(--blue); text-decoration: none; }
dl.kv a:hover { text-decoration: underline; }
.form textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; resize: vertical; }

/* Filter that sits in a panel header */
.inline-filter { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.inline-filter select { font-size: 13.5px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; font-family: inherit; color: var(--text); }

/* Sub-tabs inside the Setup page */
.subtabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.subtab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; cursor: pointer; color: inherit; opacity: .7; }
.subtab:hover { opacity: 1; }
.subtab.active { opacity: 1; font-weight: 600; border-bottom-color: var(--brand); }
.setup-pane[hidden] { display: none; }
.role-viewer .subtab.admin-only { display: none !important; }
