/* ═════════════════════════════════════════════════════════════════════════ */
/* HeadLoss — Pipe Friction Loss, Total Dynamic Head & Pump Operating Point   */
/* Theme: pump room — graphite housings, copper pipe, instrument panel        */
/* ═════════════════════════════════════════════════════════════════════════ */

:root {
    --sil-light-ready: 1;

    /* Surfaces — cast housing through machined face */
    --bg-primary: #101418;
    --bg-surface: #1a2129;
    --bg-card: #1a2129;
    --bg-hover: #232c36;
    --bg-input: #1e262e;
    --bg-sunken: #0c1013;

    /* Type */
    --text-primary: #f0f4f8;
    --text-secondary: #c6d1dc;
    --text-muted: #93a1ae;

    /* Structure */
    --border: #2c3742;
    --border-hover: #435364;

    /* Action — copper */
    --accent: #e07a3f;
    --accent-hover: #f0925a;
    --accent-glow: rgba(224, 122, 63, 0.18);
    --on-accent: #180c04;

    /* Semantic */
    --success: #58c07a;
    --warning: #e0b13f;
    --error: #e2604f;

    /* Domain state — velocity bands and flow regime */
    --state-ok: #58c07a;          /* inside the design envelope */
    --state-high: #e0b13f;        /* past the 5 ft/s design limit */
    --state-over: #e2604f;        /* well past it, or no solution */
    --gauge-track: #232c36;

    /* Curve colours — kept apart in hue AND lightness so the two curves stay
       distinguishable in both themes and to a red-green colour-blind reader. */
    --curve-system: #4aa8e0;      /* the pipe's demand */
    --curve-pump: #e07a3f;        /* what the pump supplies */
    --curve-point: #f0f4f8;       /* the intersection */
    --curve-hw: #9a8ec9;          /* Hazen-Williams cross-check */
    --grade-line: #6fd0a8;        /* hydraulic grade line */
    --pipe-fill: #3a4653;
    --water-fill: #2b5a74;
    --ground-fill: #232c36;

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-subtle: 0 4px 22px rgba(0, 0, 0, 0.48);
}

/* ── Light theme — same hues, lightness remapped. ── */
[data-theme="light"] {
    --bg-primary: #f4f6f8;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #e7ecf1;
    --bg-input: #f9fbfc;
    --bg-sunken: #edf1f4;

    --text-primary: #10161c;
    --text-secondary: #33414e;
    --text-muted: #5c6b78;

    --border: #d3dbe3;
    --border-hover: #a6b4c1;

    --accent: #b1541b;
    --accent-hover: #8f4213;
    --accent-glow: rgba(177, 84, 27, 0.12);
    --on-accent: #ffffff;

    --success: #2f7d45;
    --warning: #8a6206;
    --error: #b33526;

    --state-ok: #2f7d45;
    --state-high: #8a6206;
    --state-over: #b33526;
    --gauge-track: #dde4ea;

    --curve-system: #1d6fa5;
    --curve-pump: #b1541b;
    --curve-point: #10161c;
    --curve-hw: #5b4d9c;
    --grade-line: #1d7d5c;
    --pipe-fill: #b8c4ce;
    --water-fill: #8fb8ce;
    --ground-fill: #dde4ea;

    --shadow-subtle: 0 4px 22px rgba(16, 22, 28, 0.10);
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
    font-family: 'Outfit', system-ui, sans-serif;
    color: var(--text-primary);
    margin: 0 0 0.6rem;
}

h1 { font-size: 2.5rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-size: 1.35rem; font-weight: 700; line-height: 1.3; }
h4 { font-size: 1.15rem; font-weight: 600; line-height: 1.4; }

p { margin: 0 0 1rem; }
a { color: var(--accent); }

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
    background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border);
    padding: 2.5rem 1rem 2rem;
    text-align: center;
}

.header-container { max-width: 800px; margin: 0 auto; }

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent-glow);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.badge-icon { font-size: 1rem; }

.app-header p { color: var(--text-muted); font-size: 1.05rem; margin: 0; }

/* width:100% is load-bearing, not cosmetic. shared/global-ui.css makes <body> a
   column flex container and gives main `flex: 1 0 auto` — flex-shrink 0. Without
   an explicit width the flex base size resolves to max-content, so the widest
   descendant (the 900px canvas, the reference tables) drags the whole page wider
   than the viewport and the body scrolls sideways on a phone. */
.app-main {
    width: 100%;
    max-width: 1140px;
    margin: 0 auto;
    padding: 1.75rem 1rem 3rem;
}

.ad-placeholder {
    background: var(--bg-sunken);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 0.75rem;
    margin-bottom: 1.25rem;
}

.answer-block {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.75rem;
    color: var(--text-secondary);
}

.answer-block strong { color: var(--text-primary); }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.calculator-card,
.content-section,
.reference-section,
.seo-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.6rem;
    margin-bottom: 1.75rem;
    box-shadow: var(--shadow-subtle);
}

.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

.card-head h2 { margin: 0; }

/* ── Verdict badge and regime pill ───────────────────────────────────────── */

.verdict {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-sunken);
    color: var(--text-secondary);
}

.verdict-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex: 0 0 auto; }

.verdict-good { color: var(--state-ok); border-color: var(--state-ok); }
.verdict-good .verdict-dot { background: var(--state-ok); }
.verdict-warn { color: var(--state-high); border-color: var(--state-high); }
.verdict-warn .verdict-dot { background: var(--state-high); }
.verdict-bad  { color: var(--state-over); border-color: var(--state-over); }
.verdict-bad  .verdict-dot { background: var(--state-over); }

.regime-pill {
    display: inline-block;
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-secondary);
}

/* ── Controls ────────────────────────────────────────────────────────────── */

.mode-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    padding-bottom: 1.1rem;
    margin-bottom: 1.1rem;
    border-bottom: 1px solid var(--border);
}

.control-group { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }

.control-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.toggle-group {
    display: inline-flex;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 0.45rem 0.85rem;
    cursor: pointer;
    min-height: 38px;
}

.toggle-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.toggle-btn.active { background: var(--accent); color: var(--on-accent); }

.control-select,
.field-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    padding: 0.55rem 0.7rem;
    min-height: 42px;
    width: 100%;
    min-width: 0;
}

.control-select:focus,
.field-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.field-input.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem 1rem;
    margin-bottom: 1.1rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }

.field > label,
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }

.field-hint { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }

.subsection {
    border-top: 1px solid var(--border);
    padding-top: 1.1rem;
    margin-top: 1.1rem;
}

.subsection h3 { font-size: 1.1rem; margin-bottom: 0.2rem; }
.subsection-lead { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.9rem; }

/* ── Fitting rows ────────────────────────────────────────────────────────── */

.fitting-list { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.9rem; }

.fitting-row {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 0.8fr) auto auto;
    gap: 0.6rem;
    align-items: end;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.7rem;
}

.fitting-k {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    padding-bottom: 0.6rem;
}

.row-remove {
    appearance: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    min-width: 42px;
    min-height: 42px;
}

.row-remove:hover { color: var(--error); border-color: var(--error); }

.row-tools { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.1rem; }

.action-btn {
    appearance: none;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0.6rem 1.1rem;
    min-height: 44px;
}

.action-btn:hover { border-color: var(--border-hover); background: var(--bg-surface); }

.action-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.action-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ── Pump curve points ───────────────────────────────────────────────────── */

.pump-points {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.7rem;
}

.pump-point {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.7rem;
}

.pump-point .control-label { margin-bottom: 0.4rem; display: block; }
.pump-point .pair { display: flex; gap: 0.5rem; }
.pump-point .pair label { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.pump-point .pair span { font-size: 0.72rem; color: var(--text-muted); }

/* ── Warnings ────────────────────────────────────────────────────────────── */

.input-warnings {
    background: var(--bg-sunken);
    border: 1px solid var(--warning);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    margin-bottom: 1.1rem;
    font-size: 0.9rem;
}

.input-warnings ul { margin: 0; padding-left: 1.1rem; }
.input-warnings li + li { margin-top: 0.35rem; }

/* ── Results ─────────────────────────────────────────────────────────────── */

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.4rem;
}

.stat-card {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    min-width: 0;
}

.stat-card.is-alert { border-color: var(--state-over); }
.stat-card.is-warn  { border-color: var(--state-high); }
.stat-card.is-good  { border-color: var(--state-ok); }

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.stat-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; line-height: 1.35; }

/* ── Canvas ──────────────────────────────────────────────────────────────── */

.visual-section { margin-bottom: 1.4rem; }
.visual-head h3 { margin-bottom: 0.3rem; }
.visual-head p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.8rem; }

.canvas-wrap {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    overflow-x: auto;
}

#systemCanvas {
    display: block;
    width: 900px;
    max-width: 100%;
    height: auto;
}

.canvas-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    margin-top: 0.7rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid var(--border);
    flex: 0 0 auto;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-sunken);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 520px;
}

.data-table th,
.data-table td {
    padding: 0.55rem 0.7rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.82rem;
    background: var(--bg-hover);
    position: sticky;
    top: 0;
}

.data-table td { color: var(--text-secondary); }
.data-table td.num,
.data-table th.num { text-align: right; font-family: 'JetBrains Mono', ui-monospace, monospace; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table .row-name { color: var(--text-primary); font-weight: 500; white-space: normal; min-width: 150px; }
.data-table tr.is-current td { background: var(--accent-glow); }

.table-note { font-size: 0.82rem; color: var(--text-muted); margin: 0.6rem 0 0; }

/* ── Prose ───────────────────────────────────────────────────────────────── */

.content-section h2 { margin-top: 0; }
.content-section h3 { margin-top: 1.6rem; }
.content-section p { color: var(--text-secondary); }
.content-section strong { color: var(--text-primary); }

.equation-block {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
    margin: 1rem 0 1.2rem;
    overflow-x: auto;
}

.equation-title {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

.equation {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 1rem;
    color: var(--text-primary);
    margin: 0 0 0.9rem;
    white-space: nowrap;
}

.equation:last-child { margin-bottom: 0; }

.caveat {
    color: var(--text-muted);
    font-size: 0.92rem;
    border-left: 3px solid var(--border);
    padding-left: 0.9rem;
}

.callout {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
    margin: 1.2rem 0;
}

.callout h4 { margin-bottom: 0.5rem; }
.callout p:last-child { margin-bottom: 0; }
.callout-note  { border-left-color: var(--accent); }
.callout-fence { border-left-color: var(--error); }

/* ── Reference ───────────────────────────────────────────────────────────── */

.ref-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.ref-head h2 { margin-bottom: 0.3rem; }
.ref-head p { color: var(--text-muted); font-size: 0.9rem; margin: 0; max-width: 60ch; }

.ref-controls { display: flex; flex-wrap: wrap; gap: 0.7rem; }
.ref-controls .control-group { min-width: 170px; }

.ref-count { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 0.6rem; }

.source-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.9rem; line-height: 1.5; }
.source-note strong { color: var(--text-secondary); }

/* ── FAQ ─────────────────────────────────────────────────────────────────── */

.faq-section details {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-sunken);
    padding: 0.85rem 1rem;
    margin-bottom: 0.7rem;
}

.faq-section summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    min-height: 30px;
}

.faq-section details p { margin: 0.7rem 0 0; color: var(--text-secondary); font-size: 0.94rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .fitting-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .fitting-row .fitting-k { grid-column: 1; padding-bottom: 0; }
    .fitting-row .row-remove { grid-column: 2; justify-self: end; }
}

@media (max-width: 640px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.45rem; }
    .app-header { padding: 2rem 1rem 1.5rem; }
    .app-main { padding: 1.25rem 0.75rem 2.5rem; }
    .calculator-card,
    .content-section,
    .reference-section,
    .seo-content { padding: 1.1rem; }
    .mode-bar { flex-direction: column; align-items: stretch; }
    .toggle-group { flex-wrap: wrap; }
    .field-grid { grid-template-columns: 1fr; }
    .fitting-row { grid-template-columns: 1fr; }
    .fitting-row .row-remove { grid-column: 1; justify-self: start; }
    .pump-points { grid-template-columns: 1fr; }
    .equation { white-space: normal; }
    .ref-controls { width: 100%; }
    .ref-controls .control-group { min-width: 0; flex: 1 1 140px; }
    .stat-value { font-size: 1.3rem; }
}
