/* ═════════════════════════════════════════════════════════════════════════ */
/* ZoneSoak — Sprinkler Precipitation Rate, Run Time & Cycle-Soak Calculator  */
/* Theme: pre-dawn watering window — wet slate, standing water, turf green    */
/* ═════════════════════════════════════════════════════════════════════════ */

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

    /* Surfaces — 4am sky through to wet soil */
    --bg-primary: #0b141a;
    --bg-surface: #14212a;
    --bg-card: #14212a;
    --bg-hover: #1d2f3a;
    --bg-input: #182833;
    --bg-sunken: #0e1a21;

    /* Type */
    --text-primary: #eaf4f8;
    --text-secondary: #c2d6de;
    --text-muted: #93aab5;

    /* Structure */
    --border: #263b47;
    --border-hover: #3a5566;

    /* Action — water */
    --accent: #4fc3dd;
    --accent-hover: #6fd6ec;
    --accent-glow: rgba(79, 195, 221, 0.20);
    --on-accent: #06171d;

    /* Semantic */
    --success: #63c46a;
    --warning: #e2a63c;
    --error: #e4695a;

    /* Domain state — how the applied depth compares to what the soil takes */
    --state-ok: #63c46a;          /* inside the window */
    --state-runoff: #e4695a;      /* PR above intake — water leaves the zone */
    --state-dry: #d8b24a;         /* under-applied */
    --gauge-track: #22343f;

    /* Canvas ramp — application depth, dry corner through hot spot.
       Chosen to stay ordered by lightness in BOTH themes so the plan view
       still reads as a heat map when the page is inverted. */
    --depth-1: #35566b;   /* driest */
    --depth-2: #3f8496;
    --depth-3: #4fc3dd;
    --depth-4: #7fdcb4;
    --depth-5: #d5cf62;
    --depth-6: #e08a4a;   /* wettest */
    --on-depth: #071219;

    /* Timeline */
    --run-block: #4fc3dd;
    --soak-block: #2b4351;

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

/* ── Light theme — same hues, lightness remapped. ── */
[data-theme="light"] {
    --bg-primary: #f1f6f8;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #e3eef2;
    --bg-input: #f7fbfc;
    --bg-sunken: #eaf2f5;

    --text-primary: #0d1c24;
    --text-secondary: #2e4a56;
    --text-muted: #55707c;

    --border: #cbdde4;
    --border-hover: #9fbecb;

    --accent: #0e7490;
    --accent-hover: #095b72;
    --accent-glow: rgba(14, 116, 144, 0.13);
    --on-accent: #ffffff;

    --success: #2f7d38;
    --warning: #8a5b06;
    --error: #b23726;

    --state-ok: #2f7d38;
    --state-runoff: #b23726;
    --state-dry: #8a6a06;
    --gauge-track: #dbe8ed;

    --depth-1: #9db8c4;
    --depth-2: #5c96a8;
    --depth-3: #0e7490;
    --depth-4: #2f8f6a;
    --depth-5: #8a7a10;
    --depth-6: #a8541c;
    --on-depth: #ffffff;

    --run-block: #0e7490;
    --soak-block: #b7ccd5;

    --shadow-subtle: 0 4px 22px rgba(13, 28, 36, 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: 780px; 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: 1120px;
    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 ───────────────────────────────────────────────────────── */

.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(--warning); border-color: var(--warning); }
.verdict-warn  .verdict-dot { background: var(--warning); }
.verdict-bad   { color: var(--state-runoff); border-color: var(--state-runoff); }
.verdict-bad   .verdict-dot { background: var(--state-runoff); }

/* ── Mode + 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; }

/* ── Input grids ─────────────────────────────────────────────────────────── */

.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;
}

.field-row {
    display: flex;
    gap: 0.5rem;
    min-width: 0;
}

.field-row .field-input { flex: 1 1 0; }

.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;
}

/* ── Nozzle group rows (matched precipitation check) ─────────────────────── */

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

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

.group-row.is-off { border-color: var(--warning); }

.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); }

/* ── Catch-can grid ──────────────────────────────────────────────────────── */

.can-grid-wrap { overflow-x: auto; padding-bottom: 0.35rem; }

.can-grid {
    display: grid;
    gap: 4px;
    min-width: max-content;
}

.can-cell {
    width: 62px;
    padding: 0.4rem 0.25rem;
    text-align: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.9rem;
    min-height: 44px;
}

.can-cell:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.can-cell.is-low { border-color: var(--state-dry); background: var(--bg-hover); }
.can-cell.is-empty { color: var(--text-muted); }

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

/* ── 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; }

/* ── Result stats ────────────────────────────────────────────────────────── */

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 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-runoff); }
.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;
}

#zoneCanvas {
    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;
    letter-spacing: 0.02em;
    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: 160px; }
.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); }

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

.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) {
    .group-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .group-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; }
    .group-row { grid-template-columns: 1fr; }
    .group-row .row-remove { grid-column: 1; }
    .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; }
}
