/* Credit Risk Analyzer — styles (main.css)
 * UI reference: Subly (white rounded cards, black vertical icon sidebar,
 * big KPI numbers, gradient bar/donut charts) + Finor (dark navy page
 * background, light cards, ticker strip, line chart, donut, distribution
 * bars, lists) — blended, re-skinned in Erthiox colours, NOT 1:1.
 * Palette: Risk Navy #0B2239, prestige dark #111622, gold #C5A880 / #B89047,
 * cream #FCFBF9, slate #5A606C, blue #1a73e8. Risk colours (green/amber/red)
 * are used ONLY for risk meaning, never for decoration (plan §1.4).
 * No default scrollbars anywhere: custom thin scrollbars throughout.
 */
:root {
  --navy: #0B2239;
  --dark: #111622;
  --gold: #C5A880;
  --gold-dark: #B89047;
  --cream: #FCFBF9;
  --mist: #F1F5F9;
  --slate: #5A606C;
  --border: #E8E5DF;
  --divider: #F1EFEA;
  --blue: #1a73e8;
  --green: #15803D;
  --amber: #D97706;
  --red: #B91C1C;
  --ink: #1E293B;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(11, 34, 57, .08), 0 8px 24px rgba(11, 34, 57, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, 'Liberation Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--navy);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: Outfit, Inter, 'Liberation Sans', system-ui, sans-serif; color: var(--dark); margin: 0 0 8px; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
p { margin: 0 0 10px; }
a { color: var(--blue); }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 15px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

/* custom scrollbars — no default browser scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--mist); }
::-webkit-scrollbar-thumb { background: var(--gold-dark); border-radius: 6px; border: 2px solid var(--mist); }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }
* { scrollbar-width: thin; scrollbar-color: var(--gold-dark) var(--mist); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; height: 64px; background: var(--dark); color: #fff;
  position: sticky; top: 0; z-index: 50; border-bottom: 1px solid rgba(197, 168, 128, .35);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { width: 40px; height: 40px; flex: none; }
.brand-name { font-family: Outfit, Inter, sans-serif; font-weight: 700; font-size: 18px; line-height: 1.1; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--gold); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sync-chip { font-size: 12px; color: #CBD5E1; white-space: nowrap; }

/* ---------- layout: dark navy page, light cards (Finor) ---------- */
.layout { display: flex; align-items: stretch; min-height: calc(100vh - 64px); }
.sidenav {
  width: 216px; flex: none; background: var(--dark); color: #E2E8F0;
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: none; color: #CBD5E1; padding: 10px 12px;
  border-radius: 10px; font-size: 14px; font-weight: 600;
}
.nav-item:hover { background: rgba(197, 168, 128, .15); color: #fff; }
.nav-active { background: var(--gold-dark); color: #fff; }
.nav-ico { font-size: 16px; width: 22px; text-align: center; flex: none; }
.nav-badge { margin-left: auto; background: var(--amber); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid rgba(255, 255, 255, .12); }
.kofi-link { color: var(--gold); font-weight: 700; font-size: 13px; text-decoration: none; }
.kofi-link:hover { text-decoration: underline; }
.nav-note { font-size: 11px; color: #94A3B8; margin-top: 8px; line-height: 1.5; }
.bottombar { display: none; }
.content { flex: 1; min-width: 0; padding: 24px; background: var(--mist); border-radius: 24px 0 0 0; }

/* ---------- page head / KPI cards (Subly) ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-sub { color: var(--slate); margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.borrower-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); font-weight: 700; }
.kpi-value { font-size: 30px; font-weight: 800; color: var(--dark); font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.kpi-value.sm { font-size: 22px; }
.kpi-unit { font-size: 15px; color: var(--slate); font-weight: 600; }
.kpi-sub { font-size: 13px; color: var(--slate); margin-top: 2px; }
.kpi-row { display: flex; gap: 24px; flex-wrap: wrap; }
.delta-good { color: var(--green); font-weight: 700; }
.delta-bad { color: var(--red); font-weight: 700; }
.muted { color: var(--slate); }

/* ---------- ticker strip (Finor) ---------- */
.ticker { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; margin-bottom: 4px; }
.ticker-item { background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 13px; white-space: nowrap; box-shadow: var(--shadow); }

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--divider); }
.list li:first-child { border-top: none; }
.list-row { display: flex; align-items: center; justify-content: flex-start; gap: 12px; width: 100%; text-align: left; background: none; border: none; padding: 12px 2px; font-size: 14px; color: var(--ink); }
.list-row .list-amount, .list-row .chip, .list-row .list-actions { margin-left: auto; flex: none; }
.list-row > span:first-child { min-width: 0; }
button.list-row:hover { background: var(--cream); border-radius: 8px; }
.list-amount { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }
.dot-green { background: var(--green); }

/* distribution bars (Finor) */
.dist-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.dist-label { width: 110px; flex: none; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-bar { flex: 1; height: 10px; background: var(--mist); border-radius: 999px; overflow: hidden; }
.dist-fill { height: 100%; border-radius: 999px; }
.bar-navy { background: linear-gradient(90deg, var(--navy), var(--blue)); }
.bar-gold { background: linear-gradient(90deg, var(--gold-dark), var(--gold)); }
.bar-green { background: var(--green); }
.bar-amber { background: var(--amber); }
.bar-red { background: var(--red); }
.dist-val { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- chips / tags / risk colours (risk meaning ONLY) ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip-lg { padding: 6px 14px; font-size: 13px; }
.chip-ok { background: #E7F6EC; color: var(--green); }
.chip-amber { background: #FEF3C7; color: #92400E; }
.chip-muted { background: var(--mist); color: var(--slate); }
.risk-low { background: #E7F6EC; color: var(--green); }
.risk-mod { background: #FEF9C3; color: #854D0E; }
.risk-watch { background: #FEF3C7; color: #92400E; }
.risk-high { background: #FEE2E2; color: var(--red); }
.risk-severe { background: var(--red); color: #fff; }
.tag { font-size: 11px; font-weight: 800; letter-spacing: .05em; padding: 2px 8px; border-radius: 4px; }
.tag-sample { background: var(--gold); color: var(--dark); }

/* ---------- buttons ---------- */
.btn { border: none; border-radius: 10px; padding: 10px 18px; font-size: 14px; font-weight: 700; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: #12365A; }
.btn-secondary { background: var(--mist); color: var(--dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: #E2E8F0; }
.btn-ghost { background: transparent; color: #E2E8F0; border: 1px solid rgba(255, 255, 255, .35); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--blue); font-weight: 700; font-size: 14px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.row-name { font-size: 15px; }
.icon-btn { background: var(--mist); border: none; border-radius: 8px; width: 32px; height: 32px; font-size: 14px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--slate); padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px; border-bottom: 1px solid var(--divider); vertical-align: top; font-variant-numeric: tabular-nums; }
.data-table tr:hover td { background: var(--cream); }
.row-highlight td { background: #FDF6E3; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--dark); margin-bottom: 5px; }
.field input, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--ink); }
.field input:focus, .field textarea:focus { border-color: var(--blue); outline: 3px solid rgba(26, 115, 232, .25); }
.field-error { background: #FEE2E2; color: #7F1D1D; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.field-error ul { margin: 6px 0 0; padding-left: 18px; }
.notice { background: #FEF3C7; color: #78350F; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.notice-ok { background: #E7F6EC; color: #14532D; }
.notice-amber { background: #FEF3C7; color: #78350F; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.fin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 24px; }
.form-group h3 { border-bottom: 2px solid var(--gold); padding-bottom: 6px; margin-bottom: 12px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.search-box { flex: 1; min-width: 200px; }
.search-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }

/* ---------- custom dropdown (never native <select>) ---------- */
.dd-host { position: relative; min-width: 170px; }
.dd-btn { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px; font-weight: 600; color: var(--ink); text-align: left; }
.dd-caret { color: var(--slate); }
.dd-list { position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(11, 34, 57, .18); max-height: 260px; overflow-y: auto; padding: 4px; }
.dd-opt { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 12px; border-radius: 8px; font-size: 14px; color: var(--ink); }
.dd-opt:hover { background: var(--cream); }
.dd-opt-active { background: #FDF6E3; font-weight: 700; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab { background: none; border: none; padding: 10px 16px; font-size: 14px; font-weight: 700; color: var(--slate); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab:hover { color: var(--dark); }
.tab-active { color: var(--navy); border-bottom-color: var(--gold-dark); }

/* ---------- score view ---------- */
.score-big { display: flex; gap: 18px; align-items: center; }
.score-grade { font-size: 34px; font-weight: 800; padding: 8px 18px; border-radius: 12px; }
.score-line { margin-bottom: 4px; }
.gauge { display: flex; flex-direction: column; align-items: center; padding: 8px 0; }
.gauge-arc { width: 220px; height: 110px; border-radius: 110px 110px 0 0; background: conic-gradient(from 270deg at 50% 100%, var(--green) 0deg 60deg, var(--gold-dark) 60deg 120deg, var(--amber) 120deg 150deg, var(--red) 150deg 180deg); position: relative; overflow: hidden; }
.gauge-arc::after { content: ''; position: absolute; inset: 22px 22px 0; background: #fff; border-radius: 110px 110px 0 0; }
.gauge-needle { position: absolute; left: 50%; bottom: 0; width: 4px; height: 88px; background: var(--dark); transform-origin: 50% 100%; z-index: 2; border-radius: 2px; transition: transform .4s ease; }
.gauge-needle::after { content: ''; position: absolute; left: -6px; bottom: -6px; width: 16px; height: 16px; border-radius: 50%; background: var(--dark); }
.gauge-reading { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.pd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 12px; }
.pd-box { background: var(--cream); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.mini-bar { width: 90px; height: 8px; background: var(--mist); border-radius: 999px; overflow: hidden; }
.mini-bar div { height: 100%; background: linear-gradient(90deg, var(--blue), var(--navy)); }

/* ---------- spreads charts ---------- */
.spread-chart { display: flex; align-items: flex-end; gap: 18px; height: 150px; padding: 12px 4px 0; border-bottom: 2px solid var(--border); margin: 8px 0; }
.spread-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; font-size: 12px; color: var(--slate); text-align: center; }
.spread-bar { width: 46px; max-width: 100%; background: linear-gradient(180deg, var(--blue), var(--navy)); border-radius: 6px 6px 0 0; }
.el-chart { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding: 12px 4px 0; border-bottom: 2px solid var(--border); margin: 12px 0; }
.el-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; font-size: 12px; color: var(--slate); text-align: center; }
.el-bar { width: 52px; max-width: 100%; background: linear-gradient(180deg, var(--gold), var(--gold-dark)); border-radius: 6px 6px 0 0; }

/* ---------- memo ---------- */
.memo { border: 2px solid var(--navy); border-radius: 12px; padding: 20px; margin: 12px 0; background: #fff; position: relative; }
.memo-head { display: flex; gap: 14px; align-items: flex-start; border-bottom: 2px solid var(--gold); padding-bottom: 12px; margin-bottom: 14px; }
.memo-logo { width: 56px; height: 56px; flex: none; }
.memo-title { font-size: 19px; font-weight: 800; color: var(--dark); }
.memo-draft { margin-left: auto; color: var(--red); font-weight: 800; font-size: 12px; border: 2px solid var(--red); border-radius: 6px; padding: 4px 8px; transform: rotate(-4deg); white-space: nowrap; }
.memo-decision { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: var(--cream); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.memo h3 { margin-top: 14px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.memo-signoff { display: flex; justify-content: space-between; gap: 20px; margin-top: 20px; font-size: 13px; color: var(--slate); flex-wrap: wrap; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--navy); }
.auth-card { background: #fff; border-radius: 20px; padding: 32px; max-width: 520px; width: 100%; box-shadow: 0 24px 64px rgba(0, 0, 0, .35); }
.auth-logo { width: 72px; height: 72px; display: block; margin-bottom: 12px; }
.auth-card h1 { font-size: 28px; margin-bottom: 2px; }
.auth-sub { color: var(--gold-dark); font-weight: 700; margin-bottom: 12px; }
.auth-desc { color: var(--slate); }
.auth-tabs { display: flex; gap: 4px; background: var(--mist); border-radius: 10px; padding: 4px; margin: 16px 0; }
.auth-tab { flex: 1; background: none; border: none; padding: 9px; border-radius: 8px; font-weight: 700; color: var(--slate); }
.auth-tab-active { background: #fff; color: var(--dark); box-shadow: var(--shadow); }
.auth-fine { font-size: 12px; color: var(--slate); margin-top: 12px; }

/* ---------- modal / toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(11, 22, 34, .6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 18px; max-width: 640px; width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0, 0, 0, .35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; flex-wrap: wrap; }
#toasts { 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(--dark); color: #fff; border-left: 4px solid var(--gold); padding: 12px 16px; border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .3); opacity: 0; transform: translateY(8px); transition: opacity .3s, transform .3s; font-size: 14px; }
.toast.show { opacity: 1; transform: none; }
.toast-ok { border-left-color: var(--green); }
.toast-warn { border-left-color: var(--amber); }

/* ---------- empty states ---------- */
.empty-panel { background: #fff; border: 2px dashed var(--gold-dark); border-radius: var(--radius); padding: 28px; margin-bottom: 16px; text-align: center; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.empty-note { padding: 16px; color: var(--slate); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
  .fin-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidenav { display: none; }
  .bottombar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: var(--dark); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 2px; }
  .bottombar .nav-item { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 2px; align-items: center; text-align: center; }
  .bottombar .nav-ico { font-size: 18px; }
  .content { padding: 16px 14px 84px; border-radius: 0; }
  .topbar { padding: 0 12px; }
  .brand-sub, .sync-chip, #snapChip { display: none; }
  .brand-name { font-size: 15px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 22px; }
  .form-row, .fin-grid, .pd-grid, .memo-decision { grid-template-columns: 1fr; }
  h1 { font-size: 21px; }
  .modal { max-height: 92vh; }
}

/* ---------- print: memo only ---------- */
@media print {
  body { background: #fff; }
  .topbar, .sidenav, .bottombar, .tabs, .page-head, .row-actions, .modal-overlay, #toasts { display: none !important; }
  .content { padding: 0; background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
  .memo { border: 1px solid #000; }
}
body.printing-memo .topbar, body.printing-memo .sidenav, body.printing-memo .bottombar,
body.printing-memo .tabs, body.printing-memo .page-head { display: none !important; }
