/* Fee Position Analyzer — Financial-grade clean styling */
/* Light theme only. Navy headers, white cards, tabular numbers. */

:root {
    --navy: #1a2332;
    --navy-light: #243044;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --green: #059669;
    --red: #dc2626;
    --amber: #d97706;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --sidebar-width: 340px;
    --header-height: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

/* Tabular numbers for financial data */
.metric-value, .currency-input, .badge, table td, table th {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* === HEADER === */
.app-header {
    height: var(--header-height);
    background: var(--navy);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.header-subtitle { font-size: 13px; color: #94a3b8; }
.header-right { display: flex; gap: 8px; }

/* === BUTTONS === */
.btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}
.btn-outline {
    background: transparent;
    color: #cbd5e1;
    border: 1px solid #475569;
}
.btn-outline:hover { background: rgba(255,255,255,0.08); }
.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover { background: var(--accent-light); }
.btn-block { width: 100%; margin-top: 8px; }

/* === LAYOUT === */
.app-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* === INPUT PANEL === */
.input-panel {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--card);
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 24px;
}

/* Accordion */
.accordion { border-bottom: 1px solid var(--border); }
.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    user-select: none;
}
.accordion-header:hover { color: var(--text); }
.chevron { transition: transform 0.2s; }
.accordion.open .chevron { transform: rotate(180deg); }
.accordion-body {
    display: none;
    padding-bottom: 12px;
}
.accordion.open .accordion-body { display: block; }

/* Form elements */
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}
input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* Toggle */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.toggle-row label:first-child {
    margin-bottom: 0;
}
.toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 22px;
    transition: 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Segmented Control */
.segmented-control {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.seg-btn {
    flex: 1;
    padding: 6px 4px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    background: #fff;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--bg); }
.seg-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Badge */
.metric-badge { display: flex; align-items: center; justify-content: space-between; }
.badge {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

/* Conditional fields */
.conditional { display: none; }
.conditional.visible { display: block; }

/* === TOOLTIPS (click-to-show, appended to body via JS) === */
.tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    font-style: normal;
    cursor: pointer;
    margin-left: 5px;
    flex-shrink: 0;
    vertical-align: middle;
    line-height: 1;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}
.tip:hover {
    background: var(--accent);
    color: #fff;
}
.tip.tip-active {
    background: var(--accent);
    color: #fff;
}
/* Tooltip popup (appended to body by JS) */
.tip-popup {
    position: fixed;
    width: 300px;
    padding: 12px 14px;
    background: var(--navy);
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.6;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    z-index: 10000;
    text-transform: none;
    letter-spacing: 0;
    white-space: normal;
    animation: tipFadeIn 0.15s ease-out;
}
.tip-popup-arrow {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
}
.tip-popup-arrow.arrow-down {
    bottom: -12px;
    border-top-color: var(--navy);
}
.tip-popup-arrow.arrow-up {
    top: -12px;
    border-bottom-color: var(--navy);
}
@keyframes tipFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Inline tip next to label text */
.form-group label .tip,
.metric-label .tip,
.toggle-row label .tip {
    display: inline-flex;
}
/* Chart/table header tip */
.chart-card h3 .tip,
.table-card h3 .tip {
    display: inline-flex;
    vertical-align: middle;
}
thead th .tip {
    background: rgba(255,255,255,0.2);
    color: #fff;
}
thead th .tip:hover {
    background: var(--accent-light);
}

.hidden { display: none !important; }

/* === OUTPUT AREA === */
.output-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* Metric Cards */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.metric-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.metric-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--navy);
}
.metric-value.positive { color: var(--green); }
.metric-value.negative { color: var(--red); }
.metric-context {
    font-size: 10px;
    font-weight: 400;
    color: var(--text-light);
    text-transform: none;
    letter-spacing: 0;
}

/* Tabs */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}
.tab-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Charts */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}
.chart-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.chart-card.full-width { margin-bottom: 16px; }
.chart-card h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.chart-container { height: 320px; }

/* Table */
.table-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.table-card h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.table-scroll {
    max-height: 500px;
    overflow: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    position: sticky;
    top: 0;
    background: var(--navy);
    color: #fff;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 10px 12px;
    text-align: right;
    white-space: nowrap;
}
thead th:first-child { text-align: center; border-radius: 6px 0 0 0; }
thead th:last-child { border-radius: 0 6px 0 0; }
tbody td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td:first-child { text-align: center; font-weight: 600; color: var(--text-muted); }
tbody tr:hover { background: #f8fafc; }
tbody tr:nth-child(5n) { border-bottom: 2px solid var(--border); }

.dscr-good { color: var(--green); font-weight: 600; }
.dscr-warn { color: var(--amber); font-weight: 600; }
.dscr-bad { color: var(--red); font-weight: 600; }

/* Callout */
.callout {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}
.callout-warn {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    color: #92400e;
}
.callout-danger {
    background: #fee2e2;
    border: 1px solid #f87171;
    color: #991b1b;
}

/* Info card (86th & Third story) */
.info-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
    box-shadow: var(--shadow);
}
.info-card h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 10px;
}
.info-card p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 8px;
}
.info-card p:last-child { margin-bottom: 0; }

/* === EXIT WATERFALL TABLE === */
.waterfall-table { width: 100%; border-collapse: collapse; }
.waterfall-table td { padding: 10px 12px; font-size: 14px; border-bottom: 1px solid var(--border); }
.waterfall-table .wf-label { text-align: left; color: var(--text); font-weight: 500; }
.waterfall-table .wf-value { text-align: right; font-weight: 600; color: var(--navy); font-variant-numeric: tabular-nums; }
.waterfall-table .wf-total td { border-top: 2px solid var(--navy); border-bottom: none; font-weight: 700; }
.waterfall-table .wf-total .wf-value { font-size: 16px; color: var(--accent); }

/* === LOAN SIZING === */
.sizing-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 8px 0; }
.sizing-box { border: 1px solid var(--border); border-radius: 6px; padding: 16px; text-align: center; }
.sizing-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.sizing-value { font-size: 22px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.sizing-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* === SENSITIVITY TABLE === */
.sensitivity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sensitivity-table th { background: var(--navy); color: #fff; padding: 8px 10px; text-align: center; font-size: 11px; font-weight: 600; }
.sensitivity-table td { padding: 8px 10px; text-align: center; border: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.sensitivity-table .corner-label { background: var(--navy); color: #fff; font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px; }
.sensitivity-table .row-header { background: var(--navy); color: #fff; font-weight: 600; text-align: center; }
.sens-green { background: #dcfce7; color: #166534; font-weight: 600; }
.sens-amber { background: #fef9c3; color: #854d0e; font-weight: 600; }
.sens-red { background: #fee2e2; color: #991b1b; font-weight: 600; }
.sens-base { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 700; }

/* === SCENARIO COMPARISON === */
.scenario-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.scenario-input { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; width: 180px; }
.scenario-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
.scenario-select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: #fff; min-width: 160px; }
.scenario-delete-btn {
    background: none; border: none; color: var(--red); cursor: pointer; font-size: 14px;
    font-weight: 700; margin-left: 4px; padding: 0 4px; vertical-align: middle;
}
.scenario-delete-btn:hover { opacity: 0.7; }

/* === DEAL VERDICT PANEL === */
.verdict-panel {
    display: flex;
    gap: 24px;
    background: var(--navy);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
    align-items: center;
}
.verdict-left { flex: 1; }
.verdict-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    margin-bottom: 4px;
}
.verdict-title {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 6px;
}
.verdict-title.verdict-buy { color: #4ade80; }
.verdict-title.verdict-hold { color: #facc15; }
.verdict-title.verdict-pass { color: #f87171; }
.verdict-insight {
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.5;
}
.verdict-right {
    display: flex;
    gap: 20px;
    flex-shrink: 0;
}
.verdict-metric { text-align: center; min-width: 110px; }
.verdict-metric-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    margin-bottom: 4px;
}
.verdict-metric-value {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
}
.verdict-metric-value.verdict-positive { color: #4ade80; }
.verdict-metric-value.verdict-negative { color: #f87171; }
.verdict-split { font-size: 13px; font-weight: 600; }

/* === REVERSION OPTIONALITY === */
.reversion-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.reversion-card h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.reversion-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.reversion-item {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
    text-align: center;
}
.reversion-item.highlight {
    background: #f0fdf4;
    border-color: var(--green);
}
.reversion-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.reversion-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--navy);
    font-variant-numeric: tabular-nums;
}
.reversion-item.highlight .reversion-value { color: var(--green); }
.reversion-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 10px;
    font-style: italic;
}

/* Responsive */
@media (max-width: 1400px) {
    .metric-cards { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 1200px) {
    .chart-grid { grid-template-columns: 1fr; }
    .metric-cards { grid-template-columns: repeat(2, 1fr); }
    .verdict-panel { flex-direction: column; }
    .verdict-right { flex-wrap: wrap; }
    .reversion-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .input-panel {
        width: 100%;
        min-width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .metric-cards { grid-template-columns: repeat(2, 1fr); }
}
