:root {
    --primary: #2563eb;
    --secondary: #1e293b;
    --success: #16a34a;
    --danger: #ef4444;
    --gold: #d97706;
    --bg: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
}

/* RTL Support - handled at end of file */

body.loading { opacity: 0; }
body { transition: opacity 0.1s; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */
header {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    height: 55px;
    padding: 0 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.version-badge {
    background: #eff6ff;
    color: var(--primary);
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.view-toggles {
    display: flex;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 6px;
    gap: 2px;
}

.util-btns {
    display: flex;
    gap: 4px;
}

.util-btn {
    background: #f1f5f9;
    border: none;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}
.util-btn:hover { background: #e2e8f0; }

button,
.pill,
.scen-btn,
.select-item,
.lock-toggle,
.prepay-header,
.prepay-remove,
.prepay-max-btn {
    -webkit-tap-highlight-color: transparent;
    font: inherit;
}

button:focus-visible,
.pill:focus-visible,
.scen-btn:focus-visible,
.select-item:focus-visible,
.lock-toggle:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.3);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.dir-ltr-inline {
    direction: ltr;
    display: inline-block;
}

.text-success { color: var(--success) !important; }
.text-success-strong { color: #15803d !important; }
.text-primary { color: var(--primary) !important; }
.text-muted-strong { color: #334155 !important; }
.text-danger-strong { color: #dc2626 !important; }

.card-row-control {
    margin-top: 10px;
    gap: 8px;
    align-items: center;
}

.card-row-spaced {
    margin-bottom: 10px;
}

.card-row-offset {
    margin-top: 8px;
}

.push-inline-end {
    margin-inline-start: auto;
}

.nested-control-group {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}

.chk-row-spaced {
    margin-top: 10px;
}

.chk-row-offset {
    margin-top: 8px;
}

.fine-label {
    font-weight: 400;
    font-size: 0.7rem;
}

.fine-value {
    font-size: 0.7rem;
}

.fee-row {
    margin-bottom: 2px;
}

.fee-row-offset {
    margin-top: 6px;
}

/* Print styles */
@media print {
    header, .sidebar, .util-btns { display: none !important; }
    .main { margin: 0; padding: 20px; }
    .kpi-grid { break-inside: avoid; }
}

.toggle-btn {
    border: 0;
    background: transparent;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* LAYOUT */
.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 380px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-content {
    padding: 16px 8px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* CARDS */
.control-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 8px 12px 12px;
}

.control-card-accent {
    border-inline-start-width: 3px;
    margin-top: 15px;
}

.control-card-accent-secondary {
    border-inline-start-color: var(--secondary);
}

.control-card-accent-advanced {
    border-inline-start-color: #8b5cf6;
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-lbl {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
}

.card-val {
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
}

.card-sub {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: -4px;
    margin-bottom: 8px;
}

.control-select {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-weight: 600;
    color: #475569;
    background: #fff;
    max-width: 58%;
}

.equity-label {
    color: #0369a1;
    margin-bottom: 4px;
}

.input-hint {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: 4px;
}

.input-hint.strong {
    font-weight: 600;
}

.section-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: end;
    margin-top: 15px;
    gap: 10px;
}

.section-title-inline {
    margin: 0;
}

.micro-heading {
    font-size: 0.7rem;
    font-weight: 800;
    color: #64748b;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.inline-control-row {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* SCENARIO SELECTOR */
.scenario-box {
    display: none;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
    animation: fadeIn 0.3s ease;
}

.scenario-box.show {
    display: block;
}

.scenario-grid {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.scenario-grid-spaced {
    margin-bottom: 10px;
}

.scenario-grid-stacked {
    margin: 5px 0 15px;
}

.scen-btn {
    flex: 1;
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
}

.scen-btn:hover {
    border-color: #cbd5e1;
    background: #fff;
}

.scen-btn.bear.active {
    background: #fef2f2;
    border-color: #ef4444;
    color: #ef4444;
}

.scen-btn.base.active {
    background: #f8fafc;
    border-color: #64748b;
    color: #0f172a;
    box-shadow: inset 0 0 0 1px #64748b;
}

.scen-btn.bull.active {
    background: #f0fdf4;
    border-color: #16a34a;
    color: #16a34a;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* SPECS CARD */
.specs-card {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 14px;
}

.specs-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.spec-item {
    display: flex;
    flex-direction: column;
}

.spec-lbl {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
}

.spec-val {
    font-size: 1.1rem;
    font-weight: 800;
    color: #1e3a8a;
    font-family: monospace;
}

.lev-bar-bg {
    height: 6px;
    background: #dbeafe;
    border-radius: 3px;
    overflow: hidden;
    width: 100%;
}

.lev-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    width: 0%;
    transition: width 0.4s;
}

.inline-summary {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
    margin: 4px 0 12px;
}

.detail-summary {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin: 0 0 8px;
}

.detail-summary-head {
    flex: 0 0 100%;
}

.inline-spec {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.inline-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.inline-value {
    font-family: monospace;
    font-weight: 800;
    color: #0f172a;
}

.lev-bar-bg.compact {
    width: 120px;
    height: 6px;
    background: #e2e8f0;
}

/* INPUTS */
.range-wrapper {
    position: relative;
    margin-bottom: 5px;
    height: 24px;
    display: flex;
    align-items: center;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--primary);
    height: 5px;
    background: #cbd5e1;
    border-radius: 3px;
    display: block;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    margin-top: -6px;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
}

input[type="range"]:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: monospace;
    font-weight: 700;
    color: #1e293b;
    box-sizing: border-box;
}

.input-box {
    display: none;
    padding-top: 5px;
}

.input-box.show {
    display: block;
}

.equity-box {
    background: #f0f9ff;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #bae6fd;
    margin-bottom: 5px;
}

.fees-box {
    background: #f1f5f9;
    padding: 8px;
    border-radius: 6px;
    margin-top: 10px;
}

/* MORTGAGE MIX */
.mix-visual-bar {
    height: 12px;
    display: flex;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
    background: #e2e8f0;
}

.mix-bar-seg {
    height: 100%;
    transition: width 0.3s ease;
}

.track-prime { background: #3b82f6; }
.track-kalats { background: #a855f7; }
.track-malatz { background: #14b8a6; }
.track-katz { background: #f97316; }
.track-matz { background: #f43f5e; }

.mix-width-0 { width: 0; }
.mix-width-33 { width: 33%; }
.mix-width-34 { width: 34%; }

.mix-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.mix-row-last {
    margin-bottom: 0;
}

.mix-label {
    width: 75px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mix-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
}

.mix-pct-val {
    font-size: 0.75rem;
    font-weight: 700;
    color: #0f172a;
    min-width: 32px;
    text-align: right;
    line-height: 1.1;
    margin-left: 4px;
}

.mix-amount {
    display: inline-block;
    font-size: 0.55rem;
    color: #64748b;
    font-weight: 400;
}

.mix-sum {
    color: var(--success);
}

.mix-sum-invalid {
    color: var(--danger);
}

.mix-rate-box {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    min-width: 70px;
    justify-content: flex-end;
}

.mix-rate-val {
    font-size: 0.6rem;
    color: #64748b;
    font-family: monospace;
    cursor: pointer;
    border-bottom: 1px dashed #cbd5e1;
    white-space: nowrap;
}

.mix-rate-input {
    width: 45px;
    font-size: 0.7rem;
    padding: 2px 4px;
    border: 1px solid var(--primary);
    border-radius: 4px;
    display: none;
}

.mix-rate-input.show {
    display: block;
}

.prepay-section {
    margin-top: 12px;
    border-top: 1px dashed #e2e8f0;
    padding-top: 8px;
}
.prepay-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 0.75rem;
    color: #64748b;
    padding: 4px 0;
    appearance: none;
    background: transparent;
    border: 0;
}
.prepay-header:hover { color: var(--primary); }
.prepay-arrow {
    font-size: 0.85rem;
    font-weight: 300;
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    transition: all 0.2s;
}
.prepay-header:hover .prepay-arrow { border-color: var(--primary); }
.prepay-arrow.open { transform: rotate(45deg); background: var(--primary); color: #fff; border-color: var(--primary); }
.prepay-container { padding: 8px 0; }
.prepay-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #f8fafc;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.7rem;
}
.prepay-item select, .prepay-item input {
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.7rem;
}
.prepay-item select { width: 80px; }
.prepay-item input[type="number"] { width: 70px; }
.prepay-item select:disabled { opacity: 0.5; cursor: not-allowed; }
.prepay-remove { color: #ef4444; cursor: pointer; margin-left: auto; font-weight: bold; }
.prepay-remove:hover { color: #dc2626; }
.prepay-max {
    font-size: 0.6rem;
    color: #94a3b8;
    margin-right: 4px;
}
.prepay-amt-group {
    display: flex;
    align-items: stretch;
}
.prepay-amt-group input {
    border-radius: 4px 0 0 4px;
    border-right: none;
}
.prepay-max-btn {
    font-size: 0.6rem;
    color: var(--primary);
    background: #eff6ff;
    padding: 4px 6px;
    border-radius: 0 4px 4px 0;
    border: 1px solid #e2e8f0;
    border-left: none;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
}
.prepay-max-btn:hover { background: var(--primary); color: #fff; }
.prepay-add-btn {
    background: none;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.7rem;
    color: #64748b;
    cursor: pointer;
    width: 100%;
}
.prepay-add-btn:hover { border-color: var(--primary); color: var(--primary); }
.prepay-label { color: #64748b; white-space: nowrap; }

.track-badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    flex-shrink: 0;
}

.advanced-term-box {
    margin-top: 8px;
}

.term-val {
    width: 60px;
}

.max-tooltip {
    position: fixed;
    background: var(--danger);
    color: #fff;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    z-index: 999;
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transform: translateX(-50%);
    transition: opacity 0.2s;
}

.max-tooltip-caret {
    position: absolute;
    left: 50%;
    bottom: -4px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--danger);
}

.mix-warn {
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 800;
    margin-top: -4px;
    margin-bottom: 10px;
    background: #fef2f2;
    border: 1px solid #fecdd3;
    border-radius: 6px;
    padding: 6px 8px;
}

.card-divider {
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.rate-toggle-btn {
    appearance: none;
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 0.7rem;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    margin-left: auto;
    display: block;
    width: fit-content;
    margin-bottom: 8px;
}

.rate-toggle-btn:hover {
    text-decoration: underline;
}

.mix-alloc-row {
    display: flex;
    justify-content: space-between;
    align-items: end;
}

/* SWEET SPOT */
.sweet-spot {
    position: absolute;
    top: 18px;
    transform: translateX(-50%);
    color: var(--gold);
    font-size: 10px;
    pointer-events: none;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    z-index: 5;
}

.sweet-spot::before {
    content: '▲';
    font-size: 12px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sweet-spot.visible {
    opacity: 1;
}

/* PILLS */
.pills {
    display: flex;
    background: #e2e8f0;
    border-radius: 8px;
    padding: 2px;
    width: fit-content;
}

.pill {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 3px 10px;
    font-size: 0.7rem;
    cursor: pointer;
    border-radius: 6px;
    color: #64748b;
    font-weight: 600;
    transition: 0.1s;
}

.pill.active {
    background: white;
    color: #0f172a;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.opt-star {
    color: #f59e0b;
    font-size: 10px;
    display: none !important;
}

.opt-star.show {
    display: inline !important;
}

.opt-star.show {
    display: inline;
}

.pill.toggle {
    border: 1px solid var(--border);
    background: #fff;
}

.pill.toggle.active {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.15);
}

.pill-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* SELECT LIST */
.select-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.select-item {
    appearance: none;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: 0.1s;
    background: white;
    text-align: start;
}

.select-item.active {
    background: #eff6ff;
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.radio {
    width: 12px;
    height: 12px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
}

.select-item.active .radio {
    border-color: var(--primary);
    background: var(--primary);
}

.item-text {
    font-size: 0.8rem;
}

.lock-toggle {
    appearance: none;
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748b;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    margin-left: 6px;
    cursor: pointer;
    background: #fff;
}

.lock-toggle.locked {
    color: var(--primary);
    border-color: var(--primary);
    background: #eef2ff;
}

/* MAIN */
.main {
    flex: 1;
    padding: 25px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #f1f5f9;
    gap: 12px;
}

.decision-summary {
    display: grid;
    grid-template-columns: minmax(260px, 1.2fr) minmax(420px, 1fr);
    gap: 18px;
    align-items: stretch;
    padding: 22px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.decision-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.decision-copy h2 {
    margin: 8px 0 6px;
    color: #0f172a;
    font-size: clamp(1.4rem, 2.2vw, 2.05rem);
    line-height: 1.08;
    letter-spacing: 0;
}

.decision-reason {
    margin: 0;
    color: #475569;
    font-size: 0.95rem;
    line-height: 1.45;
    max-width: 62ch;
}

.decision-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.decision-metric {
    min-width: 0;
    border: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
}

.decision-metric.highlight {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.metric-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
}

.metric-value {
    display: block;
    margin-top: 6px;
    font-family: monospace;
    font-size: 1.15rem;
    font-weight: 800;
    color: #0f172a;
    direction: ltr;
    overflow-wrap: anywhere;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
}

.kpi-box-primary {
    text-align: start;
    padding: 18px;
}

.kpi-box-primary .kpi-num {
    font-size: 1.45rem;
}

.kpi-box {
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}
.kpi-re { background: #f0fdf4; border-bottom: 4px solid var(--success); }
.kpi-sp { background: #eff6ff; border-bottom: 4px solid var(--primary); }
.kpi-re-border { border-bottom: 4px solid var(--success); }
.kpi-sp-border { border-bottom: 4px solid var(--primary); }
.kpi-bad { background: #fff1f2; border-color: #fecdd3; }
.kpi-good { background: #f0fdf4; border-color: #bbf7d0; }

.kpi-num {
    font-size: 1.2rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-num.wrap {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.1;
    word-break: break-word;
    font-size: 1rem;
}

.kpi-lbl {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
    margin-top: 4px;
}

.charts-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.chart-wrapper {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    min-height: 300px;
}

.chart-wrapper > div:last-child {
    min-height: 260px;
}

.chart-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.charts-warning {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecdd3;
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 800;
    font-size: 0.85rem;
}

.chart-canvas-frame {
    position: relative;
    flex: 1;
    min-height: 260px;
}

.charts-dim .chart-wrapper {
    opacity: 0.35;
    filter: grayscale(1);
    pointer-events: none;
}

.chk-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #475569;
    user-select: none;
}

input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 10px;
    margin-bottom: 5px;
}

.meter {
    height: 6px;
    background: #e2e8f0;
    margin-top: 8px;
    border-radius: 3px;
    display: flex;
    overflow: hidden;
    gap: 2px;
}

.meter-seg {
    flex: 1;
    opacity: 0.2;
    transition: opacity 0.2s;
}

.meter-low { background: #86efac; }
.meter-mid { background: #fcd34d; }
.meter-high { background: #fca5a5; }

.surplus-row {
    margin-top: 12px;
}

.surplus-control {
    display: flex;
    flex-direction: column;
    width: 60%;
}

.pills-full {
    width: 100%;
}

.pill-equal {
    flex: 1;
    text-align: center;
}

.surplus-desc {
    margin-top: 4px;
    text-align: right;
    font-size: 0.65rem;
}

.input-note {
    font-size: 0.65rem;
    color: #64748b;
    margin-top: 4px;
}

/* Credit score slider accent */
.range-wrapper #creditScore {
    accent-color: #0ea5e9;
}

.card-sub.danger {
    color: #b91c1c;
    font-weight: 700;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

@media (max-width: 1000px) {
    .layout {
        flex-direction: column;
        overflow: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .decision-summary {
        grid-template-columns: 1fr;
    }

    .charts-container {
        min-height: 800px;
    }
}

@media (max-width: 720px) {
    body {
        height: auto;
        min-height: 100vh;
    }

    header {
        height: auto;
        min-height: 55px;
        padding: 10px 14px;
        gap: 10px;
        align-items: flex-start;
    }

    .header-controls {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
    }

    .sidebar-content,
    .main {
        padding: 14px;
    }

    .control-card,
    .equity-box,
    .scenario-box,
    .decision-summary,
    .chart-wrapper {
        border-radius: 8px;
    }

    .decision-summary {
        padding: 16px;
    }

    .decision-copy h2 {
        font-size: 1.35rem;
    }

    .decision-metrics,
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .inline-spec {
        width: 100%;
        justify-content: space-between;
        box-sizing: border-box;
    }

    .lev-bar-bg.compact {
        max-width: 38%;
    }

    .mix-row {
        flex-wrap: wrap;
        row-gap: 4px;
    }

    .mix-label {
        width: 82px;
    }

    .mix-slider-container {
        min-width: calc(100% - 96px);
    }

    .mix-rate-box {
        margin-left: auto;
    }

    .scenario-grid {
        flex-wrap: wrap;
    }

    .scen-btn {
        min-width: 30%;
    }

    .chart-wrapper {
        padding: 14px;
        min-height: 320px;
    }

    .chart-wrapper > div:last-child {
        min-height: 260px;
    }
}

@media (max-width: 460px) {
    header {
        flex-direction: column;
    }

    .header-controls,
    .view-toggles,
    .util-btns {
        width: 100%;
    }

    .toggle-btn,
    .util-btn {
        flex: 1;
    }

    .card-row {
        align-items: flex-start;
        gap: 8px;
    }

    .control-select {
        max-width: 100%;
    }

    .pills {
        max-width: 100%;
        overflow-x: auto;
    }
}


/* ========== DARK MODE - MUST BE LAST ========== */
body.dark {
    background: #0f172a !important;
    color-scheme: dark;
}

/* Main containers */
body.dark .sidebar,
body.dark .main,
body.dark .layout,
body.dark .sidebar-content {
    background: #0f172a !important;
}

/* All text */
body.dark * {
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}

/* Header */
body.dark header { background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%) !important; }

/* Cards - primary background #1e293b */
body.dark .control-card,
body.dark .kpi-card,
body.dark .chart-card,
body.dark .chart-wrapper,
body.dark .chart-canvas-frame,
body.dark .decision-summary,
body.dark .decision-metric,
body.dark .equity-box,
body.dark .kpi-box,
body.dark .kpi-re,
body.dark .kpi-sp,
body.dark .kpi-bad,
body.dark .kpi-good,
body.dark .scenario-box,
body.dark .specs-card,
body.dark .inline-spec,
body.dark .detail-summary,
body.dark .scen-btn,
body.dark .scen-btn.active,
body.dark .scen-btn:hover,
body.dark .select-item,
body.dark .nested-control-group,
body.dark .pill.toggle,
body.dark .lock-toggle { 
    background: #1e293b !important; 
}

/* Secondary elements - #334155 */
body.dark .card-row,
body.dark .pills,
body.dark .view-toggles,
body.dark .util-btn,
body.dark .prepay-item,
body.dark .prepay-section,
body.dark .mix-visual-bar,
body.dark .version-badge,
body.dark #infMeter span,
body.dark .prepay-amt-group,
body.dark .header-controls,
body.dark .lev-bar-bg,
body.dark .compact,
body.dark .locked,
body.dark .toggle.active,
body.dark .meter-seg,
body.dark .fees-box { 
    background: #334155 !important; 
}

/* Inputs */
body.dark input,
body.dark select,
body.dark textarea,
body.dark .pill { 
    background: #0f172a !important; 
}
body.dark input[type="range"] { background: #475569 !important; }
body.dark .pill.active { background: var(--primary) !important; }
body.dark .toggle-btn.active { background: #1e293b !important; }
body.dark .prepay-add-btn { background: transparent !important; }
body.dark .prepay-max-btn { background: #475569 !important; }

/* Muted text */
body.dark .card-lbl,
body.dark .section-title,
body.dark .mix-label,
body.dark .prepay-label,
body.dark .lock-toggle,
body.dark .rate-toggle-btn,
body.dark .mix-rate-val,
body.dark .prepay-max,
body.dark .toggle-btn,
body.dark .prepay-header span,
body.dark .kpi-lbl,
body.dark .metric-label,
body.dark .decision-reason { 
    color: #94a3b8 !important; 
}

/* Keep track colors */
body.dark .track-prime { background: #3b82f6 !important; }
body.dark .track-kalats { background: #a855f7 !important; }
body.dark .track-malatz { background: #14b8a6 !important; }
body.dark .track-katz { background: #f97316 !important; }
body.dark .track-matz { background: #f43f5e !important; }

/* Keep meter colors */
body.dark .meter-low { background: #86efac !important; }
body.dark .meter-mid { background: #fcd34d !important; }
body.dark .meter-high { background: #fca5a5 !important; }

/* KPI borders */
body.dark .kpi-re, body.dark .kpi-re-border { border-bottom-color: var(--success) !important; }
body.dark .kpi-sp, body.dark .kpi-sp-border { border-bottom-color: var(--primary) !important; }

/* RTL Override - must be at end */
body.rtl .sidebar { border-right: none; border-left: 1px solid var(--border); }
body.rtl .sidebar-content { padding: 16px 16px 16px 8px; }
body.rtl .section-title { text-align: right; }
body.rtl .card-sub { text-align: right; }
body.rtl .rate-toggle-btn { margin-left: 0; margin-right: auto; }
body.rtl .mix-rate-box { justify-content: flex-start; }
body.rtl .lock-toggle { margin-right: 6px; }
body.rtl [id^="term"][id$="Val"] { white-space: nowrap; width: 60px !important; direction: ltr; text-align: left !important; }
body.rtl .layout { flex-direction: row-reverse; }
body.rtl input[type="range"] { direction: rtl; }

.mix-alloc-row { flex-direction: row-reverse; }
body.rtl .card-lbl { text-align: right; }
body.rtl .mix-label { text-align: right; }
body.rtl .chart-title { text-align: right; }
body.rtl .equity-box { text-align: right; }
body.rtl .inline-spec { text-align: right; }
body.rtl .decision-copy { text-align: right; }
body.rtl .metric-value,
body.rtl .inline-value,
body.rtl .kpi-num { direction: ltr; }
body.rtl header h1 { text-align: right; }
body.rtl .card-row { direction: rtl; }
body.rtl .card-row > * { direction: ltr; }
body.rtl .mix-row { direction: rtl; }
body.rtl .mix-row > * { direction: ltr; }
body.rtl .pills { direction: rtl; }
body.rtl .pills > * { direction: ltr; }
body.rtl .scenario-grid { direction: rtl; }
body.rtl .scenario-grid > * { direction: ltr; }
body.rtl .inline-summary { direction: rtl; }
body.rtl .inline-summary > * { direction: ltr; }
body.rtl .prepay-header { direction: rtl; }
body.rtl .prepay-header > * { direction: ltr; }
body.rtl .select-item { direction: rtl; }
body.rtl .select-item > * { direction: ltr; }
body.rtl .chk-row { direction: rtl; }
body.rtl .chk-row > * { direction: ltr; }
