:root {
    --primary: #2563eb;
    --primary-dark: #1746b4;
    --primary-soft: #eff6ff;
    --success: #0f9f6e;
    --ink: #14213d;
    --muted: #64748b;
    --line: #e5eaf1;
    --surface: #ffffff;
    --page: #f6f9fc;
    --shadow: 0 18px 55px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, rgba(37, 99, 235, .09), transparent 26%),
        radial-gradient(circle at 92% 12%, rgba(14, 165, 233, .08), transparent 22%),
        var(--page);
}

.page-header { padding-bottom: 1.2rem !important; }
.hero-card,
.calculator-shell,
.funnel-card,
.results-card,
.detail-card,
.table-card {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(226,232,240,.95);
    box-shadow: var(--shadow);
    border-radius: 26px;
}
.hero-card { position: relative; overflow: hidden; }
.hero-card::after {
    content: "";
    position: absolute;
    width: 240px;
    height: 240px;
    right: -90px;
    bottom: -120px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(37,99,235,.12), rgba(14,165,233,.05));
}
.eyebrow,
.section-kicker {
    display: inline-flex;
    align-items: center;
    letter-spacing: .08em;
    text-transform: uppercase;
    font-size: .76rem;
    font-weight: 800;
    color: var(--primary);
}
.hero-mini-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.hero-mini-grid div {
    padding: 16px;
    border-radius: 18px;
    background: var(--primary-soft);
    border: 1px solid #dbeafe;
}
.hero-mini-grid span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: white;
    border-radius: 11px;
    font-weight: 800;
    margin-bottom: 10px;
}
.hero-mini-grid small { color: #42526a; font-weight: 700; }

.calculator-shell { padding: 26px; }
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}
.btn-soft {
    border: 1px solid #dbeafe;
    background: #f8fbff;
    color: var(--primary);
}
.btn-soft:hover { background: var(--primary-soft); color: var(--primary-dark); }

.form-block {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 22px;
    margin-bottom: 18px;
    background: #fff;
}
.form-block-title {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}
.form-block-title h3 { font-size: 1rem; margin: 0 0 3px; font-weight: 800; }
.form-block-title p { margin: 0; color: var(--muted); font-size: .9rem; }
.form-icon,
.metric-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 1.12rem;
    flex: 0 0 auto;
}
.form-label { font-weight: 750; color: #334155; font-size: .91rem; }
.form-label span { color: #dc2626; }
.input-group-text,
.form-control {
    border-color: #dbe2ea;
    min-height: 52px;
}
.input-group-text { background: #f8fafc; color: #475569; font-weight: 750; }
.form-control:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 .25rem rgba(37,99,235,.10);
}
.form-control.is-invalid:focus { box-shadow: 0 0 0 .25rem rgba(220,38,38,.08); }
.calculate-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 6px;
}
.btn-primary {
    border-color: var(--primary);
    background: var(--primary);
    box-shadow: 0 10px 28px rgba(37,99,235,.20);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.results-section { scroll-margin-top: 20px; }
.funnel-card, .results-card, .detail-card { padding: 24px; }
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.card-title-row > i {
    font-size: 1.45rem;
    color: var(--primary);
    background: var(--primary-soft);
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
}
.funnel-flow { display: flex; flex-direction: column; align-items: center; }
.funnel-step {
    width: min(100%, 360px);
    text-align: center;
    padding: 13px 18px;
    border-radius: 16px;
    border: 1px solid #dbeafe;
    background: #f8fbff;
}
.funnel-step small { display: block; color: var(--muted); font-weight: 700; }
.funnel-step strong { display: block; font-size: 1.45rem; margin-top: 2px; }
.funnel-step.spend { background: #eff6ff; }
.funnel-step.revenue { background: #ecfdf5; border-color: #bbf7d0; }
.funnel-step.revenue strong { color: #047857; }
.funnel-arrow { color: #93a3b8; padding: 4px 0; }

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.metric-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    align-items: center;
    background: #fff;
}
.metric-card .metric-icon { grid-row: 1 / span 2; }
.metric-card small { color: var(--muted); font-weight: 700; }
.metric-card strong { font-size: 1.16rem; line-height: 1.15; overflow-wrap: anywhere; }
.metric-card.highlight { background: linear-gradient(135deg, #eff6ff, #eefbf7); border-color: #bfdbfe; }
.metric-card.highlight strong { color: var(--primary-dark); }

.result-breakdown-table th { color: #334155; font-size: .9rem; }
.result-breakdown-table td { font-weight: 800; }
.result-breakdown-table td.formula { color: var(--muted); font-weight: 600; font-size: .84rem; text-align: right; }
.result-breakdown-table > :not(caption) > * > * { border-bottom-color: #edf1f5; padding: .85rem .5rem; }
.input-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.input-summary-grid > div {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fbfdff;
}
.input-summary-grid small { display: block; color: var(--muted); font-weight: 700; }
.input-summary-grid strong { display: block; margin-top: 5px; font-size: 1.05rem; }

.history-section { scroll-margin-top: 20px; }
.table-card { overflow: hidden; }
.history-table { min-width: 1880px; }
.history-table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .045em;
    white-space: nowrap;
    padding: 15px 12px;
    border-bottom: 1px solid var(--line);
}
.history-table tbody td {
    white-space: nowrap;
    font-size: .88rem;
    padding: 14px 12px;
    border-bottom-color: #eef2f7;
}
.history-table tbody tr:hover { background: #fbfdff; }
.delete-row-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: inline-grid;
    place-items: center;
}
.empty-state { padding: 50px 20px; text-align: center; }
.empty-state i { font-size: 2.4rem; color: #94a3b8; }
.empty-state h3 { font-size: 1.05rem; margin: 10px 0 4px; }
.empty-state p { margin: 0; color: var(--muted); }
.modal-icon {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    margin: 0 auto;
    display: grid;
    place-items: center;
    background: #fef2f2;
    color: #dc2626;
    font-size: 1.5rem;
}

@media (max-width: 991.98px) {
    .section-heading { align-items: flex-start; }
    .calculate-bar { align-items: stretch; flex-direction: column; }
    .calculate-bar .btn { width: 100%; }
}
@media (max-width: 767.98px) {
    .hero-card, .calculator-shell, .funnel-card, .results-card, .detail-card, .table-card { border-radius: 20px; }
    .hero-card { padding: 24px !important; }
    .calculator-shell { padding: 18px; }
    .form-block { padding: 17px; }
    .section-heading { flex-direction: column; }
    .section-heading > .d-flex { width: 100%; }
    .section-heading > .d-flex .btn { flex: 1; }
    .metrics-grid, .input-summary-grid { grid-template-columns: 1fr; }
    .metric-card { padding: 14px; }
    .funnel-card, .results-card, .detail-card { padding: 19px; }
}
@media (max-width: 420px) {
    .hero-mini-grid { grid-template-columns: 1fr 1fr; }
    .hero-mini-grid div { padding: 12px; }
    .display-5 { font-size: 2.1rem; }
}

@media print {
    body { background: #fff; }
    .page-header, .calculator-shell, .history-section, #printBtn, #globalAlert { display: none !important; }
    .results-section { display: block !important; }
    .funnel-card, .results-card, .detail-card { box-shadow: none; break-inside: avoid; }
}

/* --------------------------------------------------
   Compact left-aligned calculator layout
   -------------------------------------------------- */
body {
    background: #f7f9fc;
}

.simple-page-header {
    padding: 28px 0 16px;
}

.simple-page-header h1 {
    margin: 0;
    font-size: clamp(1.65rem, 2.5vw, 2.1rem);
    line-height: 1.2;
    font-weight: 700;
    color: #172033;
}

.simple-page-header p {
    margin: 7px 0 0;
    max-width: 650px;
    color: #64748b;
    font-size: .95rem;
}

.compact-calculator {
    width: 100%;
    max-width: 620px;
    margin-left: 0;
    margin-right: auto;
    padding: 18px;
    border-radius: 12px;
    box-shadow: 0 6px 22px rgba(15, 23, 42, .05);
    border: 1px solid #e3e8ef;
    background: #fff;
}

.compact-calculator-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 13px;
    margin-bottom: 14px;
    border-bottom: 1px solid #edf0f4;
}

.compact-calculator-heading h2 {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.3;
    font-weight: 700;
    color: #1e293b;
}

.compact-calculator-heading p {
    margin: 3px 0 0;
    color: #718096;
    font-size: .82rem;
}

.compact-form-group {
    padding: 0 0 13px;
    margin: 0 0 13px;
    border-bottom: 1px solid #edf0f4;
}

.compact-form-group:last-of-type {
    margin-bottom: 14px;
}

.compact-form-group h3 {
    margin: 0 0 9px;
    font-size: .9rem;
    font-weight: 700;
    color: #334155;
}

.compact-calculator .form-label {
    margin-bottom: 5px;
    font-size: .78rem;
    line-height: 1.35;
    font-weight: 650;
}

.compact-calculator .form-control,
.compact-calculator .input-group-text {
    min-height: 40px;
    height: 40px;
    font-size: .88rem;
}

.compact-calculator .input-group-text {
    padding: .375rem .7rem;
}

.compact-calculator .form-control {
    padding: .45rem .7rem;
}

.compact-calculator .invalid-feedback {
    font-size: .72rem;
}

.compact-calculate-bar {
    display: flex;
    justify-content: flex-start;
}

.compact-calculate-bar .btn {
    min-width: 175px;
    padding: .62rem 1rem;
    font-size: .88rem;
    font-weight: 650;
    border-radius: 8px;
    box-shadow: none;
}

@media (max-width: 767.98px) {
    .simple-page-header {
        padding: 20px 0 13px;
    }

    .simple-page-header h1 {
        font-size: 1.55rem;
    }

    .simple-page-header p {
        font-size: .88rem;
    }

    .compact-calculator {
        max-width: 100%;
        padding: 15px;
        border-radius: 10px;
    }

    .compact-calculator-heading {
        align-items: center;
    }

    .compact-calculate-bar .btn {
        width: 100%;
    }
}

@media print {
    .simple-page-header,
    .compact-calculator {
        display: none !important;
    }
}


/* --------------------------------------------------
   Number inputs: typing only
   Browser spinner arrows are hidden. Mouse-wheel value
   changes are blocked by jQuery in app.js.
   -------------------------------------------------- */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}
