:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --dark: #0c1a2e;
    --dark2: #112240;
    --blue: #1d4ed8;
    --blue-lt: #3b82f6;
    --blue-hl: #60a5fa;
    --amber: #d97706;
    --amber-lt: #fbbf24;
    --leak: #dc2626;
    --profit: #16a34a;
    --muted: #6b7280;
    --border: #e5e7eb;
    --r-sm: 8px;
    --r-md: 16px;
    --r-lg: 24px;
    --sh-sm: 0 1px 3px rgba(0,0,0,.08);
    --sh-md: 0 4px 16px rgba(0,0,0,.10);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", system-ui, sans-serif;
    color: var(--dark);
    background: linear-gradient(160deg, #f4f6fb 0%, #eef1f8 100%);
    min-height: 100vh;
}

.page {
    width: min(1140px, 96vw);
    margin: 2rem auto 4rem;
}

/* Hero */
.hero { margin-bottom: 2rem; }

.hero-top {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.back-link {
    font-size: .87rem;
    font-weight: 600;
    color: var(--blue);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity .2s;
}
.back-link:hover { opacity: .7; }

.live-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .75rem;
    font-weight: 700;
    color: #16a34a;
    background: rgba(22,163,74,.1);
    padding: 4px 12px;
    border-radius: 50px;
}
.live-badge .dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(74,222,128,.6); }
    50%      { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--blue-lt);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: .78rem;
}

.hero h1 {
    margin: 0 0 12px;
    font-family: "Fraunces", serif;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    line-height: 1.1;
    color: var(--dark);
}

.subhead {
    max-width: 68ch;
    color: var(--muted);
    font-size: .97rem;
    line-height: 1.65;
    margin: 0;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 28px;
    box-shadow: var(--sh-sm);
}

.card h2 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 20px;
    color: var(--dark);
}

/* Scenario Panel */
.scenario-panel { margin-bottom: 24px; }

.scenario-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.preset {
    padding: 9px 18px;
    border-radius: 50px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-family: inherit;
    font-size: .88rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all .2s;
}
.preset:hover { border-color: var(--blue); color: var(--blue); background: rgba(29,78,216,.05); }
.preset.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* Layout */
.controls-and-results {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    align-items: start;
}

/* Controls */
.controls { position: sticky; top: 20px; }

.grid-two {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--dark);
}

input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    height: 5px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--blue);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(29,78,216,.3);
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb:hover { background: var(--blue-lt); }

.value-chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 50px;
    font-size: .8rem;
    font-weight: 700;
    background: rgba(29,78,216,.08);
    color: var(--blue);
    align-self: flex-start;
}

.targets-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.targets-label { font-size: .8rem; font-weight: 600; color: var(--muted); }

.target-chip {
    font-size: .75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 50px;
    background: rgba(22,163,74,.08);
    color: var(--profit);
    border: 1px solid rgba(22,163,74,.2);
}

/* Results */
.results { display: flex; flex-direction: column; gap: 20px; }

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 22px 24px;
    box-shadow: var(--sh-sm);
    transition: box-shadow .2s;
}
.kpi-card:hover { box-shadow: var(--sh-md); }

.kpi-card.alert-red   { border-color: var(--leak); background: rgba(220,38,38,.02); }
.kpi-card.alert-amber { border-color: var(--amber); background: rgba(217,119,6,.02); }
.kpi-card.alert-green { border-color: var(--profit); background: rgba(22,163,74,.02); }

.kpi-label {
    font-size: .76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 8px;
}

.kpi-value {
    font-family: "Fraunces", serif;
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
    color: var(--dark);
}
.kpi-value.red    { color: var(--leak); }
.kpi-value.amber  { color: var(--amber); }
.kpi-value.green  { color: var(--profit); }

.kpi-sub {
    font-size: .76rem;
    color: var(--muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kpi-sub.warn  { color: var(--amber); font-weight: 600; }
.kpi-sub.ok    { color: var(--profit); font-weight: 600; }
.kpi-sub.bad   { color: var(--leak); font-weight: 600; }

/* P&L Breakdown */
.pl-card {}
.pl-card h2 { margin-bottom: 16px; }

.pl-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}
.pl-row:last-child { border-bottom: none; font-weight: 700; font-size: .95rem; }
.pl-row .pl-label { color: var(--muted); }
.pl-row .pl-val.pos    { color: var(--profit); font-weight: 600; }
.pl-row .pl-val.neg    { color: var(--leak); font-weight: 600; }
.pl-row .pl-val.warn   { color: var(--amber); font-weight: 600; }
.pl-row .pl-val.neutral { color: var(--dark); }

.pl-bar-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-top: 4px;
    overflow: hidden;
    flex-basis: 120px;
    flex-shrink: 0;
}
.pl-bar { height: 100%; border-radius: 3px; transition: width .4s; }
.pl-bar.blue   { background: var(--blue); }
.pl-bar.red    { background: var(--leak); }
.pl-bar.amber  { background: var(--amber); }
.pl-bar.green  { background: var(--profit); }

/* Leak Alerts */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h2 { margin: 0; }

.leak-count-badge {
    font-size: .78rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 50px;
    background: rgba(220,38,38,.1);
    color: var(--leak);
}
.leak-count-badge.zero { background: rgba(22,163,74,.1); color: var(--profit); }

.leak-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    background: rgba(220,38,38,.04);
    border: 1px solid rgba(220,38,38,.18);
    border-radius: var(--r-md);
    margin-bottom: 10px;
    transition: background .2s;
}
.leak-alert:last-child { margin-bottom: 0; }
.leak-alert:hover { background: rgba(220,38,38,.07); }

.leak-icon {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: rgba(220,38,38,.12);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: .95rem;
}

.leak-text strong { display: block; font-size: .88rem; font-weight: 700; margin-bottom: 3px; }
.leak-text span { font-size: .8rem; color: var(--muted); }
.leak-text .leak-cost { font-size: .78rem; font-weight: 700; color: var(--leak); margin-top: 4px; display: block; }

.no-leaks {
    text-align: center;
    padding: 24px;
    color: var(--profit);
    font-weight: 600;
    font-size: .9rem;
}
.no-leaks .icon { display: flex; justify-content: center; margin-bottom: 8px; }

/* Recommendations */
.reco-card {}
.reco-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}
.reco-item:last-child { border-bottom: none; }
.reco-num {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), var(--blue-lt));
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.reco-text strong { display: block; font-weight: 700; margin-bottom: 2px; }
.reco-text span { color: var(--muted); }

/* Channel Matrix */
.channel-matrix { margin-top: 12px; }
.ch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: .86rem;
}
.ch-row:last-child { border-bottom: none; }
.ch-name { font-weight: 600; }
.ch-margin { font-weight: 700; }
.ch-margin.good { color: var(--profit); }
.ch-margin.warn { color: var(--amber); }
.ch-margin.bad  { color: var(--leak); }
.ch-badge { font-size: .72rem; padding: 2px 8px; border-radius: 50px; font-weight: 600; }
.ch-keep  { background: rgba(22,163,74,.1); color: var(--profit); }
.ch-watch { background: rgba(217,119,6,.1); color: var(--amber); }
.ch-drop  { background: rgba(220,38,38,.1); color: var(--leak); }

/* Responsive */
@media(max-width:900px) {
    .controls-and-results { grid-template-columns: 1fr; }
    .controls { position: static; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media(max-width:500px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .scenario-buttons { flex-direction: column; }
}
