/* =====================================================================
   Kadimo console (project LoanV1)
   Tokens and base components follow reporting-frontend so the two consoles
   feel like one product. Everything below "Kadimo components" is new.
   ===================================================================== */

/* ===================== Theme tokens ===================== */
:root {
    --page: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --text: #0f172a;
    --muted: #64748b;
    --faint: #94a3b8;
    --border: #e9ebef;
    --border-strong: #dfe3e8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-weak: #eef4ff;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);

    --green: #16a34a; --green-bg: #e7f6ed;
    --amber: #b45309; --amber-bg: #fdf3e2;
    --red: #dc2626;   --red-bg: #fdecec;
    --slate: #475569; --slate-bg: #eef1f5;
    --blue: #2563eb;
}

html.dark {
    --page: #0a0f1a;
    --surface: #0f1626;
    --surface-2: #121a2b;
    --text: #e6eaf2;
    --muted: #93a1b5;
    --faint: #6b7a90;
    --border: #1e2940;
    --border-strong: #263352;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-weak: rgba(59, 130, 246, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);

    --green: #4ade80; --green-bg: rgba(34, 197, 94, .15);
    --amber: #fbbf24; --amber-bg: rgba(245, 158, 11, .15);
    --red: #f87171;   --red-bg: rgba(239, 68, 68, .15);
    --slate: #94a3b8; --slate-bg: rgba(148, 163, 184, .15);
}

* { box-sizing: border-box; }
body {
    margin: 0; background: var(--page); color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }

/* ===================== Login ===================== */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.login-card { width: 100%; max-width: 380px; padding: 34px 32px; }
.subtitle { color: var(--muted); margin: 6px 0 22px; }
form { display: flex; flex-direction: column; }
label { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
#username, #password {
    width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
    padding: 11px 13px; font-size: 14px; color: var(--text); margin-bottom: 16px;
}
#username::placeholder, #password::placeholder { color: var(--faint); }
#username:focus, #password:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 18px 0 0; }
code { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }

/* ===================== Brand / shell ===================== */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-lg { font-size: 18px; margin-bottom: 2px; }
.logo { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; }
.sidebar .brand { padding: 6px 8px 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); padding: 14px 10px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--muted);
    text-decoration: none; font-weight: 500; font-size: 14px; width: 100%; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav-item .ic { width: 19px; height: 19px; }
.nav-item .badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.nav-item .badge.warn { background: var(--red); }

.profile { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-top: 1px solid var(--border); margin-top: 6px; }
.profile-meta { min-width: 0; flex: 1; }
.profile-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn.nav-toggle { display: none; }
.nav-backdrop { display: none; position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, .45); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 62px; display: flex; align-items: center; gap: 16px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
html:not(.dark) .icon-sun { display: none; }
html.dark .icon-moon { display: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 700; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }

/* ===================== Content ===================== */
.content { padding: 26px 28px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; margin: 0; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.page-actions { display: flex; gap: 10px; flex-shrink: 0; }

.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 9px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent; white-space: nowrap; font-family: inherit; }
.btn .ic { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 10px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat-value.warn { color: var(--red); }
.stat-value.ok { color: var(--green); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.blue { background: var(--blue); } .dot.green { background: var(--green); }
.dot.amber { background: #f59e0b; } .dot.red { background: var(--red); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 4px; }
.tab { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; color: var(--muted); padding: 7px 13px; border-radius: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

/* Tables */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.table-card > h2 { padding: 16px 18px 0; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
table.data thead th { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--surface-2); }
table.data th.right, table.data td.right { text-align: right; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.ref { font-weight: 600; font-variant-numeric: tabular-nums; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill .pd { width: 6px; height: 6px; border-radius: 50%; }
.pill.active, .pill.accepted, .pill.pass, .pill.settled { background: var(--green-bg); color: var(--green); }
.pill.active .pd, .pill.accepted .pd, .pill.pass .pd, .pill.settled .pd { background: var(--green); }
.pill.received, .pill.assessing, .pill.quoted { background: var(--amber-bg); color: var(--amber); }
.pill.received .pd, .pill.assessing .pd, .pill.quoted .pd { background: #f59e0b; }
.pill.declined, .pill.fail, .pill.in_default, .pill.expired { background: var(--red-bg); color: var(--red); }
.pill.declined .pd, .pill.fail .pd, .pill.in_default .pd, .pill.expired .pd { background: var(--red); }
.pill.written_off, .pill.withdrawn, .pill.suspended, .pill.under_debt_review { background: var(--slate-bg); color: var(--slate); }
.pill.written_off .pd, .pill.withdrawn .pd, .pill.suspended .pd, .pill.under_debt_review .pd { background: var(--slate); }

/* =====================================================================
   Kadimo components
   ===================================================================== */

/* --- Statutory citation. Used wherever a rule drove what is on screen.
       Deliberately quiet: it should be findable, not shouty. --- */
.cite {
    display: inline-block; font: 600 11px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
    padding: 1px 6px; border-radius: 6px; white-space: nowrap;
}
.cite.on-accent { background: transparent; border-color: currentColor; color: inherit; opacity: .8; }
.note {
    display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 13.5px;
    background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 12px; line-height: 1.55;
}
.note .ic { flex-shrink: 0; margin-top: 1px; }
.note.info { background: var(--accent-weak); border-color: transparent; color: var(--accent); }
.note.warn { background: var(--amber-bg); border-color: transparent; color: var(--amber); }
.note.bad  { background: var(--red-bg);   border-color: transparent; color: var(--red); }
.note.good { background: var(--green-bg); border-color: transparent; color: var(--green); }
.note strong { font-weight: 700; }

/* --- Layout helpers --- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 15px; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin: 18px 0 10px; }
.section-label:first-child { margin-top: 0; }

/* --- Forms --- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; margin: 0; }
.field .help { color: var(--muted); font-size: 12px; margin: 0; }
.field input[type=text], .field input[type=number], .field input[type=date],
.field input[type=email], .field select {
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
    padding: 9px 11px; font-size: 14px; color: var(--text); width: 100%; font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: flex-start; gap: 9px; padding: 9px 0; font-size: 13.5px; cursor: pointer; font-weight: 500; }
.check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin-top: 2px; flex-shrink: 0; }
.check span { line-height: 1.5; }
.check .cite { margin-left: 6px; }

/* --- Wizard --- */
.steps { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.step {
    display: flex; align-items: center; gap: 9px; padding: 9px 14px; border-radius: 10px;
    background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.step .n {
    width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--faint);
    display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.step.current { border-color: var(--accent); color: var(--accent); background: var(--accent-weak); }
.step.current .n { background: var(--accent); color: #fff; }
.step.done { color: var(--green); border-color: transparent; background: var(--green-bg); }
.step.done .n { background: var(--green); color: #fff; }

/* --- Money summary --- */
.money-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.money-cell { background: var(--surface); padding: 14px 16px; }
.money-cell .k { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.money-cell .v { font-size: 20px; font-weight: 700; margin-top: 7px; font-variant-numeric: tabular-nums; }
.money-cell.total { background: var(--accent-weak); }
.money-cell.total .v, .money-cell.total .k { color: var(--accent); }

/* --- Cap reductions (s101 clamps) --- */
.cap-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; flex-wrap: wrap; }
.cap-row:last-child { border-bottom: 0; }
.cap-was { text-decoration: line-through; color: var(--faint); font-variant-numeric: tabular-nums; }
.cap-now { font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.cap-arrow { color: var(--faint); }

/* --- Rule trace (s81 assessment working) --- */
.trace { display: flex; flex-direction: column; gap: 0; }
.trace-row { display: grid; grid-template-columns: 120px 1fr; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; align-items: start; }
.trace-row:last-child { border-bottom: 0; }
.trace-row .t { line-height: 1.6; }

/* --- Blockers (s130 gate) --- */
.blockers { display: flex; flex-direction: column; gap: 8px; }
.blocker { display: flex; gap: 10px; padding: 11px 13px; border-radius: 10px; background: var(--red-bg); color: var(--red); font-size: 13.5px; line-height: 1.5; }
.blocker .ic { flex-shrink: 0; margin-top: 1px; }

/* --- In duplum meter (s103(5)) --- */
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin: 12px 0 8px; }
.meter > span { display: block; height: 100%; background: var(--green); transition: width .3s; }
.meter.high > span { background: #f59e0b; }
.meter.full > span { background: var(--red); }
.meter-legend { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Consumer notices (s64 plain language) --- */
.notices { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 9px; }
.notices li { display: flex; gap: 10px; font-size: 13.5px; line-height: 1.55; color: var(--text); }
.notices li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 8px; }

/* --- Modal --- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
html.dark .modal-backdrop { background: rgba(0, 0, 0, .65); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 560px; max-height: calc(100vh - 48px); overflow: auto; }
.modal-head { padding: 18px 22px 6px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 14px 22px 4px; }
.modal-error { color: var(--red); font-size: 13px; padding: 0 22px; min-height: 18px; }
.modal-foot { padding: 8px 22px 18px; display: flex; justify-content: flex-end; gap: 10px; }

/* --- Toast --- */
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow); font-size: 13.5px; font-weight: 500; z-index: 60; max-width: 380px; line-height: 1.5; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); color: var(--green); }

/* --- Loading --- */
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ===================== Responsive ===================== */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } .stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
    /* The sidebar becomes an off-canvas drawer; it must never simply vanish,
       or the console loses its only means of navigation. */
    .icon-btn.nav-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; z-index: 60; width: 264px;
        transform: translateX(-100%); transition: transform .18s ease;
        box-shadow: 0 10px 30px rgba(0,0,0,.18); overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    .nav-backdrop:not([hidden]) { display: block; }
    .table-card { overflow-x: auto; }
    .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .stats { grid-template-columns: 1fr; } .field-row { grid-template-columns: 1fr; } .page-head { flex-direction: column; } .trace-row { grid-template-columns: 1fr; gap: 4px; } }
