/* Bond Transfer and Settlement Desk — design system.
   Layout language blended from Artem's two templates (NOT 1:1, re-skinned
   in Erthiox colours): Subly's black vertical icon sidebar, pill top nav,
   white rounded cards and big KPI numbers; Finor's dark-navy page shell,
   ticker strip, donut/distribution charts and asset lists.
   Palette: Erthiox prestige #111622 / #C5A880 / #B89047 / #FCFBF9 / #5A606C
   + plan tokens navy #0F2A44, teal #0E7C7B, amber #E8A317, red #B91C1C.
   Fonts: Inter (base), Outfit (headings/KPIs). Light mode only in v1. */

:root {
  --navy: #111622; --navy-2: #0F2A44; --navy-deep: #0B0F1A;
  --gold: #C5A880; --gold-dark: #B89047;
  --cream: #FCFBF9; --card: #FFFFFF;
  --ink: #1A2433; --muted: #475569; --slate: #5A606C;
  --border: #E8E5DF; --border-2: #CBD5E1; --surface: #F1F5F9;
  --teal: #0E7C7B; --teal-bg: #E3F2F1; --amber: #E8A317; --amber-bg: #FDF3D7;
  --red: #B91C1C; --red-bg: #FDECEC; --blue: #1a73e8; --blue-bg: #E8F0FE;
  --radius: 16px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 22, 34, .06), 0 8px 24px rgba(17, 22, 34, .06);
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Outfit', 'Inter', system-ui, sans-serif;
  --font-mono: 'Liberation Mono', ui-monospace, 'Roboto Mono', monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--navy); color: var(--ink);
  font-family: var(--font-body); font-size: 14px; line-height: 1.5;
}
h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; color: var(--navy); letter-spacing: -.01em; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 14px; }
.mono { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.gold-text { color: var(--gold-dark); }

/* Custom scrollbars — never the browser default */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--surface); border-radius: 8px; }
::-webkit-scrollbar-thumb { background: #C9CDD6; border-radius: 8px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }
* { scrollbar-width: thin; scrollbar-color: #C9CDD6 var(--surface); }

/* ---------- Auth screen ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(26, 115, 232, .35), transparent 60%),
              radial-gradient(900px 500px at 90% 110%, rgba(200, 168, 128, .35), transparent 60%), var(--navy); }
.auth-card { width: 100%; max-width: 460px; background: var(--card); border-radius: 20px; padding: 32px; box-shadow: 0 24px 64px rgba(0, 0, 0, .35); }
.auth-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-card .logo-row img { width: 44px; height: 44px; }
.auth-tabs { display: flex; gap: 6px; background: var(--surface); border-radius: 999px; padding: 4px; margin: 18px 0; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 9px 12px; border-radius: 999px; font-weight: 600; color: var(--muted); }
.auth-tabs button.active { background: var(--navy); color: #fff; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 6px; color: var(--navy); }
.field input, .field textarea { width: 100%; border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px 12px; background: #fff; color: var(--ink); }
.field input:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-error { color: var(--red); font-size: 12.5px; margin-top: 4px; font-weight: 600; }
.btn { border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 13.5px; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold-dark); color: #090d16; }
.btn-gold:hover { background: var(--gold); }
.btn-ghost { background: transparent; border: 1px solid var(--border-2); color: var(--navy); }
.btn-ghost:hover { border-color: var(--navy); }
.btn-danger { background: var(--red); color: #fff; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.auth-error { background: var(--red-bg); color: var(--red); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 12px; font-weight: 600; }
.auth-note { background: var(--amber-bg); border: 1px solid #F0D48A; color: #6B4E00; border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12.5px; margin-top: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 76px 1fr; min-height: 100vh; }
.shell > * { min-width: 0; }
.rail { background: var(--navy-deep); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; position: sticky; top: 0; height: 100vh; z-index: 40; }
.rail .rail-logo { width: 44px; height: 44px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; padding: 5px; }
.rail .rail-logo img { width: 100%; height: 100%; }
.rail a { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #8A93A6; position: relative; }
.rail a svg { width: 22px; height: 22px; }
.rail a:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.rail a.active { background: var(--gold-dark); color: #090d16; }
.rail a.active::after { content: ''; position: absolute; left: -14px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--gold); }
.rail .rail-spacer { flex: 1; }
.rail .rail-badge { font-size: 10px; color: #8A93A6; text-align: center; padding: 0 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--navy); color: #fff; padding: 12px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 30; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-head); font-weight: 700; font-size: 16px; white-space: nowrap; }
.topbar .brand img { width: 30px; height: 30px; }
.pillnav { display: flex; gap: 4px; background: rgba(255, 255, 255, .08); border-radius: 999px; padding: 4px; flex-wrap: wrap; }
.pillnav a { color: #C6CDDA; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.pillnav a:hover { color: #fff; text-decoration: none; }
.pillnav a.active { background: #fff; color: var(--navy); }
.topbar .top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.desk-date { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .08); border-radius: 999px; padding: 6px 6px 6px 14px; font-size: 13px; }
.desk-date input { background: #fff; border: 0; border-radius: 999px; padding: 6px 10px; font-size: 13px; color: var(--navy); }
.user-chip { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .08); border-radius: 999px; padding: 5px 12px 5px 5px; font-size: 13px; font-weight: 600; }
.user-chip .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--gold-dark); color: #090d16; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; }
.mode-badge { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; background: var(--amber); color: #3A2E00; border-radius: 999px; padding: 4px 9px; }
.ticker { background: var(--navy-2); color: #D7DEEA; display: flex; gap: 0; overflow-x: auto; padding: 8px 24px; font-size: 12.5px; white-space: nowrap; min-width: 0; }
.ticker span { padding: 0 18px; border-right: 1px solid rgba(255, 255, 255, .14); }
.ticker span:first-child { padding-left: 0; }
.ticker b { color: #fff; }
.ticker .up { color: #7BD5B8; }
.content { background: var(--cream); flex: 1; padding: 22px 24px 40px; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 26px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; }
.demo-banner { background: var(--amber-bg); border: 1px solid #F0D48A; color: #6B4E00; border-radius: var(--radius-sm); padding: 9px 14px; font-size: 13px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.demo-banner b { font-weight: 800; }

/* ---------- Cards / KPI ---------- */
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.card { min-width: 0; }
.kpi-row { grid-template-columns: repeat(5, 1fr); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card .card-sub { font-size: 12.5px; color: var(--muted); }
.kpi { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.kpi:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(17, 22, 34, .08), 0 14px 32px rgba(17, 22, 34, .10); }
.kpi .kpi-label { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .kpi-value { font-family: var(--font-head); font-size: 34px; font-weight: 700; line-height: 1.1; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .kpi-detail { font-size: 13px; color: var(--muted); }
.delta { display: inline-block; font-size: 12px; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.delta.good { background: var(--teal-bg); color: var(--teal); }
.delta.bad { background: var(--red-bg); color: var(--red); }
.delta.warn { background: var(--amber-bg); color: #8A6100; }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2-1 { grid-template-columns: 1fr 1fr; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { position: sticky; top: 0; background: var(--navy); color: #fff; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; white-space: nowrap; z-index: 2; }
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tbody tr:hover { background: #FAF7F0; }
tbody tr.clickable { cursor: pointer; }
td.wrap, th.wrap { white-space: normal; }
.row-amber { background: #FFF9E6; }
.row-red { background: #FFF5F5; }
.pagination { display: flex; align-items: center; gap: 12px; padding: 12px 4px 0; font-size: 13px; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.settled, .badge.matched { background: var(--teal-bg); color: var(--teal); }
.badge.pending, .badge.entered { background: var(--surface); color: var(--muted); }
.badge.failed { background: var(--red-bg); color: var(--red); }
.badge.unmatched { background: var(--amber-bg); color: #8A6100; }
.badge.settled_late, .badge.partial { background: #EDE9FE; color: #6D28D9; }
.badge.cancelled { background: var(--surface); color: var(--slate); }
.badge.fop { background: var(--blue-bg); color: var(--blue); }
.badge.info { background: var(--blue-bg); color: var(--blue); }

/* ---------- Forms / filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search-box { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--border-2); border-radius: 999px; padding: 8px 14px; min-width: 240px; flex: 1; max-width: 420px; }
.search-box input { border: 0; outline: 0; flex: 1; font-size: 13.5px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .half { grid-column: span 2; }
.computed-box { background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; }
.computed-box .row { display: flex; justify-content: space-between; padding: 3px 0; }
.computed-box .row b { font-variant-numeric: tabular-nums; }
.validation-list { list-style: none; margin: 10px 0 0; padding: 0; }
.validation-list li { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.validation-list li.warn { background: var(--amber-bg); color: #8A6100; }

/* ---------- Custom dropdown (no native <select>) ---------- */
.dd { position: relative; min-width: 150px; }
.dd-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fff; border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.dd-btn:hover { border-color: var(--navy); }
.dd-btn .chev { color: var(--muted); font-size: 11px; }
.dd-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(17, 22, 34, .18); z-index: 60; max-height: 260px; overflow-y: auto; padding: 4px; display: none; }
.dd.open .dd-list { display: block; }
.dd-item { padding: 9px 12px; border-radius: 8px; font-size: 13.5px; cursor: pointer; }
.dd-item:hover, .dd-item.focused { background: var(--surface); }
.dd-item.selected { font-weight: 700; color: var(--navy); background: #F5EFE3; }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11, 15, 26, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 18px; max-width: 520px; width: 100%; padding: 24px; box-shadow: 0 24px 64px rgba(0, 0, 0, .3); max-height: 88vh; overflow-y: auto; }
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: var(--navy); color: #fff; border-radius: 12px; padding: 12px 16px; font-size: 13.5px; box-shadow: 0 12px 32px rgba(0, 0, 0, .3); display: flex; gap: 10px; align-items: flex-start; }
.toast.error { background: var(--red); }
.toast .toast-x { margin-left: auto; background: none; border: 0; color: #fff; font-size: 16px; line-height: 1; padding: 0 0 0 8px; }

/* ---------- Charts (SVG, no library) ---------- */
.chart-bar { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.chart-bar .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart-bar .bar { width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--gold), var(--gold-dark)); }
.chart-bar .bar.teal { background: linear-gradient(180deg, #2AA5A4, var(--teal)); }
.chart-bar .bar.red { background: linear-gradient(180deg, #E05252, var(--red)); }
.chart-bar .bar.blue { background: linear-gradient(180deg, #5B93F0, var(--blue)); }
.chart-bar .bar-label { font-size: 11px; color: var(--muted); }
.dist-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; }
.dist-row .dist-label { width: 140px; flex-shrink: 0; font-weight: 600; }
.dist-row .dist-track { flex: 1; min-width: 0; height: 10px; background: var(--surface); border-radius: 999px; overflow: hidden; }
.dist-row .dist-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold), var(--gold-dark)); }
.dist-row .dist-fill.red { background: linear-gradient(90deg, #E05252, var(--red)); }
.dist-row .dist-fill.teal { background: linear-gradient(90deg, #2AA5A4, var(--teal)); }
.dist-row .dist-val { width: 112px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 12.5px; flex-shrink: 0; }
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut-legend { font-size: 13px; display: grid; gap: 6px; }
.donut-legend .lg { display: flex; align-items: center; gap: 8px; }
.donut-legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.empty-state { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty-state .big { font-size: 34px; margin-bottom: 8px; }
.empty-state h3 { margin-bottom: 6px; }
.legend-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Detail / legs / timeline ---------- */
.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.leg { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.leg .leg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .t-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold-dark); margin-top: 5px; flex-shrink: 0; }
.timeline .t-dot.teal { background: var(--teal); }
.timeline .t-dot.red { background: var(--red); }
.timeline time { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }
.diff-table td.mismatch { background: var(--red-bg); font-weight: 700; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid > * { min-width: 0; }
.cal-day { border: 1px solid var(--border); border-radius: 10px; min-height: 74px; padding: 8px; font-size: 12.5px; background: #fff; min-width: 0; overflow: hidden; }
.cal-day .dnum { font-weight: 800; font-size: 14px; }
.cal-day.holiday { background: var(--red-bg); border-color: #F3C1C1; }
.cal-day.weekend { background: var(--surface); color: var(--muted); }
.cal-day.today { border: 2px solid var(--gold-dark); }
.cal-day .tag { display: block; font-size: 11px; font-weight: 700; margin-top: 4px; }
.cal-day .tag.due { color: var(--amber); color: #8A6100; }
.cal-day .tag.hol { color: var(--red); }

/* ---------- Footer ---------- */
.app-footer { background: var(--navy); color: #9AA3B5; padding: 22px 24px; font-size: 12.5px; display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.app-footer a { color: #D7DEEA; }
.app-footer .foot-right { margin-left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.kofi-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--gold-dark); color: #090d16 !important; font-weight: 800; border-radius: 999px; padding: 8px 16px; font-size: 13px; }
.kofi-btn:hover { background: var(--gold); text-decoration: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1400px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1100px) {
  .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .legs { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: 60px; flex-direction: row; justify-content: space-around; padding: 0 8px; z-index: 50; }
  .rail .rail-logo, .rail .rail-spacer, .rail .rail-badge { display: none; }
  .rail a { width: 44px; height: 44px; }
  .rail a.active::after { left: 12px; right: 12px; top: auto; bottom: -2px; width: auto; height: 3px; }
  .main { padding-bottom: 60px; }
  .content { padding: 16px 14px 32px; }
  .topbar { padding: 10px 14px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .kpi .kpi-value { font-size: 26px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .half { grid-column: 1; }
  .ticker { padding: 8px 14px; }
  .kv { grid-template-columns: 130px 1fr; }
  .page-head h1 { font-size: 21px; }
  .dist-row { flex-wrap: wrap; row-gap: 4px; }
  .dist-row .dist-label { width: 100px; }
  .dist-row .dist-val { width: auto; min-width: 64px; }
  .dist-row .dist-track { flex-basis: 100%; order: 5; }
}
@media (max-width: 420px) {
  .kpi-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px; }
  .pillnav a { padding: 6px 10px; font-size: 12px; }
  .search-box { min-width: 0; }
}

@media print {
  .rail, .topbar, .ticker, .app-footer, .toolbar, .btn { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { background: #fff; }
  .content { background: #fff; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
