/* ============================================================
   FlowPro stylesheet
   Aesthetic: hydraulic engineering notebook. Warm paper-white,
   near-black text, hydraulic-teal single accent. Mono numerics.
   Numbered tabs, thin rules, no shadows.
   ============================================================ */

:root {
    --paper:        #fbfdfe;   /* near-white with a faint cool tint */
    --paper-2:      #eef6f9;   /* section bg — soft aqua wash */
    --ink:          #0a1822;   /* deep slate — near-black */
    --ink-soft:     #2a3846;
    --ink-dim:      #5f7384;
    --rule:         #d7e5ee;   /* thin rule — pale aqua-gray */
    --rule-2:       #b3c8d6;
    --accent:       #0891b2;   /* bright aqua */
    --accent-weak:  #e0f4f8;
    --accent-ink:   #075a6d;
    --alert:        #d1492f;
    --ok:           #1f8a4c;

    --fs-body: 14px;
    --fs-mini: 11px;
    --ff-body: "Instrument Sans", ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
    --ff-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

    --topbar-h: 62px;
    --footbar-h: 28px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--ff-body);
    font-size: var(--fs-body);
    line-height: 1.5;
    color: var(--ink);
    background-color: #d9ebf2;
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 200' preserveAspectRatio='none'><path d='M0,100 C200,150 400,50 600,100 C800,150 1000,50 1200,100 L1200,200 L0,200 Z' fill='%237dc4dd' opacity='0.45'/></svg>"),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 200' preserveAspectRatio='none'><path d='M0,120 C250,60 450,170 700,110 C950,60 1100,150 1200,120 L1200,200 L0,200 Z' fill='%234ea9c9' opacity='0.38'/></svg>"),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 240' preserveAspectRatio='none'><path d='M0,80 C300,200 500,20 800,120 C1000,180 1100,60 1200,100 L1200,240 L0,240 Z' fill='%232a8bb0' opacity='0.28'/></svg>"),
        linear-gradient(180deg, #dceff5 0%, #bcdbe7 50%, #8cb8cd 100%);
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
    background-size: 100% 300px, 100% 380px, 100% 420px, 100% 100%;
    background-position: 0 top, 0 240px, 0 bottom, 0 0;
    background-attachment: fixed, fixed, fixed, fixed;
}
body::before {
    content: "";
    position: fixed; inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0.55) 50%, rgba(255,255,255,0.45) 100%);
    pointer-events: none;
    z-index: 0;
}

.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
a:hover { border-bottom-color: var(--accent); }

/* ---------- brand ---------- */
.brand, .auth-brand {
    display: flex; align-items: baseline; gap: 8px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.brand .mark, .auth-brand .mark {
    font-family: var(--ff-mono);
    font-size: 20px;
    color: var(--accent);
    transform: translateY(2px);
}
.wordmark { font-size: 20px; color: var(--ink); }

/* ============================================================
   AUTH SHELL
   ============================================================ */
.auth-shell {
    position: relative; z-index: 1;
    min-height: 100vh;
    padding: 32px 24px 40px 24px;
    display: grid;
    /* `auto` on the landing row lets content grow past the viewport with
       normal page scroll, preventing focus-triggered jumps inside a
       bounded scroll container. */
    grid-template-rows: auto auto;
}

/* Auth landing layout
 *
 * DESKTOP (≥ 961px): two columns
 *   row 1: hero (left)            | sign-in card (right, spans both rows)
 *   row 2: info (features etc.)   |
 *
 * MOBILE (≤ 960px): single column, with the sign-in card pulled UP between
 * the hero and the rest of the informational content.
 */
.auth-landing {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 32px 56px;
    align-items: start;
}
.auth-hero      { grid-column: 1; grid-row: 1; }
.auth-info      { grid-column: 1; grid-row: 2; }
.auth-card-col  { grid-column: 2; grid-row: 1 / span 2; }

@media (max-width: 960px) {
    .auth-landing {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 28px;
    }
    /* Mobile order: hero, then sign-in card, then info */
    .auth-hero     { grid-column: 1; grid-row: 1; }
    .auth-card-col { grid-column: 1; grid-row: 2; }
    .auth-info     { grid-column: 1; grid-row: 3; }
}

.auth-info > section {
    margin-bottom: 44px;
}
.auth-info > section:last-child { margin-bottom: 0; }

/* Hero */
.auth-kicker {
    font-family: var(--ff-mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent-ink);
    margin: 16px 0 10px 0;
}
.auth-h1 {
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 400;
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin: 0 0 20px 0;
    color: var(--ink);
}
.auth-h1 em {
    font-style: italic;
    color: var(--accent-ink);
    font-weight: 500;
}
.auth-lead {
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink-soft);
    max-width: 56ch;
    margin: 0;
}

/* Section headings */
.auth-h2 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-ink);
    margin: 0 0 18px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--rule);
}

/* Feature grid */
.auth-feature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
@media (max-width: 600px) {
    .auth-feature-grid { grid-template-columns: 1fr; }
}
.auth-feature {
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 10px;
    padding: 18px 20px;
}
.auth-feature-ico {
    color: var(--accent);
    margin-bottom: 8px;
}
.auth-feature h3 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
    margin: 0 0 6px 0;
    color: var(--ink);
}
.auth-feature p {
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink-soft);
    margin: 0;
}

/* Audience list */
.auth-audience-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.auth-audience-list li {
    padding: 10px 0;
    border-bottom: 1px dotted var(--rule);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-soft);
}
.auth-audience-list li:last-child { border-bottom: none; }
.auth-audience-list li b { color: var(--ink); font-weight: 600; }

/* CTA block */
.auth-cta p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--ink-soft);
    margin: 0 0 12px 0;
}
.auth-prov {
    font-size: 12px;
    color: var(--ink-dim);
    font-style: italic;
}

/* Right-side sign-in card wrapper; sticky on desktop so the card
   stays in view while the informational content scrolls past. */
.auth-card-col {
    position: sticky;
    top: 24px;
}
@media (max-width: 960px) {
    .auth-card-col { position: static; }
}

.auth-card {
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 10px 40px -10px rgba(10, 24, 34, 0.15),
                0 2px 8px -2px rgba(10, 24, 34, 0.05);
}
.auth-brand { margin-bottom: 4px; }
.auth-tag {
    margin: 0 0 28px 0;
    color: var(--ink-dim);
    font-size: 13px;
    line-height: 1.5;
}
.auth-form h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 20px 0;
    letter-spacing: -0.01em;
}
.auth-form label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--ink-soft); letter-spacing: 0.04em; text-transform: uppercase; }
.auth-form input { margin-top: 6px; }
.auth-form .btn { width: 100%; margin-top: 6px; }
.muted-row {
    display: flex; gap: 10px; justify-content: center;
    margin: 20px 0 0 0;
    font-size: 13px; color: var(--ink-dim);
}
.muted { color: var(--ink-dim); font-size: 13px; margin: 0 0 16px 0; }
.auth-err {
    min-height: 18px;
    margin-top: 12px;
    color: var(--alert);
    font-size: 13px;
}
.auth-footer {
    font-size: 11px;
    color: var(--ink-dim);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: center;
    margin-top: 40px;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
    position: relative; z-index: 1;
    min-height: 100vh;
    min-height: 100dvh;   /* accounts for dynamic mobile browser chrome */
    display: grid;
    /* workbench is `auto` (not 1fr) so the page scrolls naturally when
       content overflows rather than creating a nested scrollable region.
       This prevents browsers from scroll-jumping inputs into the middle
       of a scroll container on focus. */
    grid-template-rows: var(--topbar-h) auto var(--footbar-h);
}

/* ---------- top bar ---------- */
.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    padding: 0 28px;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    /* Stay put when the workbench scrolls on mobile (defense-in-depth; the
       grid layout also keeps it anchored on desktop). */
    position: sticky;
    top: 0;
    z-index: 40;
}
.tabs { display: flex; gap: 2px; height: 100%; }
.tab {
    display: flex; align-items: center; gap: 8px;
    padding: 0 16px; height: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--ff-body);
    font-size: 13px;
    color: var(--ink-dim);
    cursor: pointer;
    letter-spacing: 0.01em;
}
.tab .tab-num {
    font-family: var(--ff-mono);
    font-size: 10px;
    color: var(--ink-dim);
    letter-spacing: 0;
}
.tab:hover { color: var(--ink); }
.tab.active {
    color: var(--ink);
    border-bottom-color: var(--accent);
}
.tab.active .tab-num { color: var(--accent); }

.topbar-right { display: flex; align-items: center; gap: 20px; }
.units-toggle {
    display: flex;
    border: 1px solid var(--rule);
    height: 28px;
}
.units-toggle button {
    border: none; background: transparent;
    padding: 0 14px;
    font-family: var(--ff-mono); font-size: 11px;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--ink-dim);
    cursor: pointer;
}
.units-toggle button.active {
    background: var(--ink);
    color: var(--paper);
}

.userchip {
    display: flex; align-items: center; gap: 10px;
    font-size: 12px;
    color: var(--ink-soft);
}
#userchip-name { font-family: var(--ff-mono); font-size: 12px; }
#btn-settings {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    cursor: pointer;
}
#btn-settings:hover { color: var(--ink); border-color: var(--ink); }
#btn-logout {
    background: transparent;
    border: 1px solid var(--rule);
    padding: 5px 10px;
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    cursor: pointer;
}
#btn-logout:hover { color: var(--ink); border-color: var(--ink); }

/* ---------- workbench ---------- */
.workbench {
    padding: 28px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    /* Hard cap to prevent any wide child (data tables, charts, etc.)
       from forcing the page wider than the viewport. Children with their
       own scroll containers (.scroll-x) handle their own overflow. */
    min-width: 0;
    overflow-x: hidden;
}

.panel { }

.panel-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--ink);
    margin-bottom: 24px;
}
.panel-head .eyebrow {
    font-family: var(--ff-mono);
    font-size: var(--fs-mini);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-ink);
    margin-bottom: 4px;
}
.panel-head h2 {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0;
}
.panel-actions { display: flex; gap: 8px; }

/* ---------- two-column layout ---------- */
.twocol {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 32px;
    margin-bottom: 28px;
}
@media (max-width: 900px) {
    .twocol { grid-template-columns: 1fr; }
}

/* Profile tab uses three equal-height columns: inputs, diagram, results.
   `align-items: stretch` (grid default) + the cards' own flex column
   layout gives us rows that start at identical heights. */
.threecol {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
    margin-bottom: 28px;
}
@media (max-width: 1100px) {
    .threecol {
        grid-template-columns: 1fr 1fr;
    }
    .threecol > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
    .threecol { grid-template-columns: 1fr; }
    .threecol > :last-child { grid-column: auto; }
}

/* ---------- inputs ---------- */
.inputs {
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 26px 28px;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
}
.inputs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
}
.inputs-grid label {
    display: block;
    font-size: var(--fs-mini);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
}
.inputs-grid label.span-2,
.inputs-grid .span-2 { grid-column: span 2; }

/*
 * The Compute button sits in the last cell of the inputs-grid, paired with
 * Integration steps on its left. The cell stretches to the grid row's full
 * height; flex-end pushes the button to the bottom so its baseline matches
 * the input field next to it rather than floating at the top.
 */
.inputs-grid .compute-cell {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-self: stretch;
}
.inputs-grid .compute-cell .btn {
    width: 100%;
}
input, select {
    width: 100%;
    height: 36px;
    padding: 0 12px;
    margin-top: 6px;
    font-family: var(--ff-mono);
    font-size: 14px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule-2);
    border-radius: 8px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
/* iOS Safari zooms into any input whose font-size is under 16px when you
   tap it, and doesn't zoom back out. Bump inputs to 16px on mobile-width
   viewports so the page stays at the user's chosen zoom level. */
@media (max-width: 1024px) {
    input, select, textarea {
        font-size: 16px;
    }
}
select {
    background: var(--paper);
    background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
                      linear-gradient(135deg, var(--ink) 50%, transparent 50%);
    background-position: calc(100% - 14px) 50%, calc(100% - 10px) 50%;
    background-size: 4px 4px;
    background-repeat: no-repeat;
    padding-right: 28px;
}
input[type=file] { display: none; }
input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-weak);
}
input:disabled { background: var(--paper-2); color: var(--ink-dim); }
sub { font-size: 0.7em; }

.submit-row { margin-top: 20px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 18px;
    font-family: var(--ff-body);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    border: 1px solid var(--ink);
    border-radius: 8px;
    background: var(--ink);
    color: var(--paper);
    cursor: pointer;
    transition: background 120ms ease;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost {
    background: transparent;
    color: var(--ink);
    border-color: var(--rule-2);
}
.btn.ghost:hover {
    border-color: var(--ink);
}
.btn:disabled {
    opacity: 0.4; cursor: not-allowed;
}

/* ---------- summary card ---------- */
.summary {
    border: 1px solid var(--rule);
    background: #ffffff;
    border-radius: 14px;
    padding: 24px 26px;
    min-height: 180px;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
}
.summary-empty {
    color: var(--ink-dim);
    font-style: italic;
    font-size: 13px;
}
.summary h3 {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-ink);
    margin: 0 0 16px 0;
}
.kv {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 14px;
    align-items: baseline;
    padding: 6px 0;
    border-top: 1px dotted var(--rule-2);
    font-size: 13px;
}
.kv:first-of-type { border-top: none; }
.kv .k { color: var(--ink-soft); letter-spacing: 0.02em; }
.kv .v {
    font-family: var(--ff-mono);
    color: var(--ink);
    text-align: right;
}
.kv.strong .v { font-weight: 500; color: var(--accent-ink); }
.pill {
    display: inline-block;
    padding: 2px 8px;
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--paper);
    background: var(--accent-ink);
}
.pill.warn { background: var(--alert); }

.warn-block { margin: -4px 0 18px 0; }
.warn {
    border-left: 3px solid var(--alert);
    background: rgba(162, 58, 31, 0.06);
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.45;
    color: var(--ink);
    margin-bottom: 6px;
}
.hint {
    font-family: var(--ff-body);
    font-size: 10px;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink-dim);
    font-weight: 400;
}

/* ---------- chart ---------- */
.chart-wrap {
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 22px 24px;
    margin-bottom: 28px;
    background: #ffffff;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
    /* Prevent the chart canvas (which Chart.js resizes responsively to its
       parent) from overflowing the page width on mobile. */
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.saved-wrap {
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 8px 0;
    overflow: hidden;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
}

.viz-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.viz-heading {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: 0;
}
.viz-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 24px;
    align-items: start;
}
@media (max-width: 900px) {
    .viz-split { grid-template-columns: 1fr; }
}
.viz-chart-col {
    min-width: 0;
    height: 360px;
    position: relative;
}
.viz-xs-col {
    border-left: 1px solid var(--rule);
    padding-left: 20px;
}
@media (max-width: 900px) {
    .viz-xs-col { border-left: none; border-top: 1px solid var(--rule); padding: 16px 0 0 0; }
}

/* cross-section panel */
.xs-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 10px;
}
.xs-station {
    font-family: var(--ff-mono);
    font-size: 11px;
    color: var(--accent-ink);
    letter-spacing: 0.04em;
}
.xs-svg-wrap {
    border: 1px solid var(--rule);
    border-radius: 8px;
    background:
        linear-gradient(var(--rule) 1px, transparent 1px),
        linear-gradient(90deg, var(--rule) 1px, transparent 1px),
        var(--paper);
    background-size: 20px 20px;
    background-position: -1px -1px;
    aspect-ratio: 1 / 1;
    width: 100%;
    margin-bottom: 12px;
}
.xs-svg-wrap svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* SVG styling for cross-section */
.xs-svg-wrap .channel-earth {
    fill: rgba(95, 115, 132, 0.20);
    stroke: none;
}
.xs-svg-wrap .channel-outline {
    fill: none;
    stroke: var(--ink);
    stroke-width: 0.5;
    vector-effect: non-scaling-stroke;
}
.xs-svg-wrap .water-fill {
    fill: rgba(8,145,178, 0.35);
    stroke: var(--accent);
    stroke-width: 0.5;
    vector-effect: non-scaling-stroke;
}
.xs-svg-wrap .water-hatch {
    fill: url(#water-hatch);
}
.xs-svg-wrap .dim-line {
    stroke: var(--ink-soft);
    stroke-width: 0.5;
    vector-effect: non-scaling-stroke;
}
.xs-svg-wrap .dim-tick {
    stroke: var(--ink-soft);
    stroke-width: 0.5;
    vector-effect: non-scaling-stroke;
}
.xs-svg-wrap .top-callout {
    stroke: var(--alert);
    stroke-width: 0.7;
    vector-effect: non-scaling-stroke;
    stroke-dasharray: 3 2;
    fill: none;
}
.xs-svg-wrap .label {
    font-family: var(--ff-mono);
    font-size: 10px;
    fill: var(--ink-soft);
}
.xs-svg-wrap .label-val {
    fill: var(--accent-ink);
}

.xs-readout {
    font-size: 12px;
}
.xs-readout .kv {
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    padding: 4px 0;
    font-size: 12px;
}
.xs-readout .kv .v { font-size: 12px; }

/* ---------- toggle switches ---------- */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: var(--ink-soft);
}
.toggle-switch input { display: none; }
.toggle-track {
    display: inline-block;
    width: 32px; height: 18px;
    background: var(--rule-2);
    border-radius: 9px;
    position: relative;
    transition: background 150ms ease;
}
.toggle-thumb {
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    background: var(--paper);
    border-radius: 50%;
    transition: transform 150ms ease;
}
.toggle-switch input:checked + .toggle-track {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb {
    transform: translateX(14px);
}
.toggle-label {
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.toggle-switch.compact { gap: 6px; }
.toggle-switch.compact .toggle-track { width: 26px; height: 14px; }
.toggle-switch.compact .toggle-thumb { width: 10px; height: 10px; }
.toggle-switch.compact input:checked + .toggle-track .toggle-thumb {
    transform: translateX(12px);
}

/* ---------- range sliders ---------- */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    margin: 8px 0 0 0;
    padding: 0;
    background: var(--rule-2);
    border: none;
    outline: none;
    cursor: ew-resize;
}
input[type=range]:focus { box-shadow: none; }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--paper);
    cursor: ew-resize;
    transition: transform 100ms ease;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type=range]::-moz-range-thumb {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--paper);
    cursor: ew-resize;
}

/* ---------- data grid ---------- */
.grid-wrap {
    margin-bottom: 24px;
    min-width: 0;
    max-width: 100%;
}
.grid-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}
.grid-heading {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: 0;
}
/*
 * Compact icon-button for per-table Excel export. Used inline in data-table
 * headings and in the Saved tab's panel-head. Sized to sit neatly next to
 * existing .btn elements without dominating them.
 */
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--rule-2);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink-soft);
    font-family: var(--ff-body);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.icon-btn:hover:not(:disabled) {
    color: var(--accent-ink);
    border-color: var(--accent-ink);
}
.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.icon-btn svg {
    flex: 0 0 auto;
}
.viz-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.scroll-x {
    overflow-x: auto;
    border: 1px solid var(--rule);
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
.data-grid {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--ff-mono);
    font-size: 12px;
    background: var(--paper);
}
.data-grid thead th {
    background: var(--paper-2);
    padding: 8px 12px;
    font-family: var(--ff-body);
    font-weight: 500;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--rule-2);
    white-space: nowrap;
    text-align: left;
}
.data-grid td {
    padding: 6px 12px;
    border-bottom: 1px dotted var(--rule);
    white-space: nowrap;
}
.data-grid tr:last-child td { border-bottom: none; }
.data-grid tr:hover td { background: rgba(8,145,178, 0.04); }
.c-right { text-align: right; }

/* ---------- saved grid ---------- */
.saved-grid td { padding: 10px 12px; font-family: var(--ff-body); font-size: 13px; }
.saved-grid .saved-actions { display: flex; gap: 6px; justify-content: flex-end; }
.saved-grid .mini-btn {
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--rule-2);
    color: var(--ink-soft);
    cursor: pointer;
}
.saved-grid .mini-btn:hover { color: var(--ink); border-color: var(--ink); }
.saved-grid .mini-btn.danger:hover { color: var(--alert); border-color: var(--alert); }

/* ---------- modal ---------- */
.modal {
    position: fixed; inset: 0;
    background: rgba(15, 20, 25, 0.5);
    display: grid; place-items: center;
    z-index: 100;
}
.modal-card {
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    width: 100%; max-width: 420px;
    padding: 28px;
    box-shadow: 0 20px 60px -20px rgba(10, 24, 34, 0.3),
                0 4px 12px -4px rgba(10, 24, 34, 0.1);
}
.modal-card h2 { margin: 0 0 20px 0; font-size: 18px; font-weight: 600; }
.modal-card label {
    display: block;
    font-size: var(--fs-mini);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin-bottom: 16px;
}
.modal-actions {
    display: flex; justify-content: flex-end; gap: 8px;
    margin-top: 20px;
}

/* ---------- footer ---------- */
.footbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 28px;
    background: var(--paper);
    border-top: 1px solid var(--rule);
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.status.ok { color: var(--ok); }
.status.err { color: var(--alert); }

/* ---------- toast ---------- */
.toast {
    position: fixed; bottom: 48px; left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--paper);
    padding: 10px 18px;
    font-size: 13px;
    z-index: 200;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
    animation: toast-in 200ms ease;
}
.toast.err { background: var(--alert); }
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   HELP TAB
   ============================================================ */

/* Help-dot icon on input labels */
.help-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    padding: 0;
    border: 1px solid var(--rule-2);
    border-radius: 50%;
    background: transparent;
    color: var(--ink-dim);
    font-family: var(--ff-mono);
    font-size: 9px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
    transition: all 120ms ease;
}
.help-dot:hover {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}

/* Layout: sticky TOC + content, wrapped in a white card over the water */
.help-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 36px;
    align-items: start;
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 36px 44px;
    box-shadow: 0 10px 40px -12px rgba(10, 24, 34, 0.14),
                0 2px 8px -2px rgba(10, 24, 34, 0.05);
}
@media (max-width: 880px) {
    .help-layout { grid-template-columns: 1fr; padding: 24px 22px; }
    .help-toc { position: static !important; }
}
.help-toc {
    position: sticky;
    top: 80px;
    padding: 0;
}
.help-toc nav {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--rule);
}
.help-toc a {
    padding: 8px 0 8px 14px;
    margin-left: -1px;
    font-size: 12px;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    border-bottom: none;
    border-left: 2px solid transparent;
    transition: all 120ms ease;
}
.help-toc a:hover {
    color: var(--ink);
    border-left-color: var(--rule-2);
}
.help-toc a.active {
    color: var(--accent-ink);
    border-left-color: var(--accent);
    font-weight: 500;
}

.help-content { max-width: 820px; line-height: 1.6; color: var(--ink); }
.help-content section { margin-bottom: 56px; }
.help-content section:last-child { margin-bottom: 20px; }
.help-content h3 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin: 0 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--ink);
}
.help-content h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 28px 0 10px 0;
    letter-spacing: -0.005em;
}
.help-content p { margin: 0 0 14px 0; font-size: 14px; }
.help-content p.lead { font-size: 15px; color: var(--ink-soft); }
.help-content p.muted { color: var(--ink-dim); font-size: 13px; }
.help-content ul, .help-content ol { margin: 0 0 14px 0; padding-left: 22px; font-size: 14px; }
.help-content li { margin-bottom: 6px; }

.eq-display {
    margin: 14px 0 20px 0;
    padding: 10px 14px;
    background: var(--paper-2);
    border-left: 2px solid var(--accent);
    overflow-x: auto;
}

.callout {
    background: var(--accent-weak);
    border-left: 3px solid var(--accent);
    padding: 12px 16px;
    margin: 20px 0;
    font-size: 13px;
    line-height: 1.5;
}

.worked {
    background: var(--paper-2);
    border: 1px dotted var(--rule-2);
    padding: 14px 18px;
    border-radius: 8px;
    margin: 14px 0;
}
.worked p { margin-bottom: 8px; font-size: 13px; }

/* Formula table inside shape card */
.formula-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.formula-table td {
    padding: 6px 8px;
    border-top: 1px dotted var(--rule-2);
    vertical-align: top;
}
.formula-table tr:first-child td { border-top: none; }
.formula-table td:first-child {
    width: 24%;
    color: var(--accent-ink);
    font-weight: 500;
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 10px 0 16px 0;
}
.ref-table th {
    background: var(--paper-2);
    padding: 8px 12px;
    text-align: left;
    font-weight: 500;
    letter-spacing: 0.04em;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--rule-2);
}
.ref-table td {
    padding: 7px 12px;
    border-bottom: 1px dotted var(--rule);
}
.ref-table tr:hover td { background: rgba(8,145,178,0.03); }

.profile-types-table td:first-child {
    font-family: var(--ff-mono);
    color: var(--accent-ink);
    font-weight: 500;
    white-space: nowrap;
}

/* Grid of shape cards */
.shape-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 20px;
}
@media (max-width: 620px) {
    .shape-grid { grid-template-columns: 1fr; }
}
.shape-card {
    border: 1px solid var(--rule);
    padding: 18px;
    border-radius: 10px;
    background: var(--paper);
}
.shape-card h4 {
    margin: 0 0 10px 0;
    font-size: 15px;
    color: var(--accent-ink);
}
.shape-diagram {
    width: 100%;
    height: 200px;
    margin-bottom: 16px;
    border: 1px dotted var(--rule-2);
    overflow: hidden;
    background:
        linear-gradient(var(--rule) 1px, transparent 1px),
        linear-gradient(90deg, var(--rule) 1px, transparent 1px),
        var(--paper);
    background-size: 16px 16px;
    background-position: -1px -1px;
}
.shape-diagram svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Assumptions grid */
.assume-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 16px 0;
}
@media (max-width: 620px) {
    .assume-grid { grid-template-columns: 1fr; }
}
.assume-item {
    border: 1px solid var(--rule);
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--paper);
}
.assume-item h4 {
    margin: 0 0 6px 0;
    font-size: 13px;
    color: var(--accent-ink);
}
.assume-item p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink-soft);
}

/* References */
.refs { padding-left: 20px; font-size: 13px; color: var(--ink-soft); }
.refs li { margin-bottom: 8px; }

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
.settings-modal-card {
    max-width: 480px;
    width: calc(100vw - 32px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 10px; right: 12px;
    width: 28px; height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: var(--ink-soft);
    cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

.settings-section {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px dotted var(--rule);
}
.settings-section:first-of-type {
    margin-top: 10px;
    padding-top: 0;
    border-top: none;
}
.settings-section h3 {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: 0 0 10px 0;
}
.settings-section label {
    display: block;
    margin-bottom: 10px;
    font-size: 12px;
}
.settings-section input[type=text],
.settings-section input[type=password] {
    width: 100%;
    font-size: 13px;
}
.settings-section input:disabled {
    background: var(--paper-2);
    color: var(--ink-dim);
    cursor: not-allowed;
}
.field-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.field-row > label { flex: 1; margin-bottom: 0; }
.field-row-readonly { margin-top: 10px; }
.field-row-inline { justify-content: flex-end; margin-top: 6px; }

.settings-feedback {
    margin-top: 8px;
    font-size: 12px;
    min-height: 16px;
}
.settings-feedback.ok  { color: var(--ok); }
.settings-feedback.err { color: var(--alert); }

.settings-danger h3 { color: var(--alert); }
.settings-danger .muted { font-size: 12px; margin-bottom: 10px; }

.btn.danger {
    background: var(--alert);
    color: var(--paper);
    border-color: var(--alert);
}
.btn.danger:hover {
    background: #a93a26;
    border-color: #a93a26;
}

/* Resend-verification button styling in auth err area */
.link-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}
.link-btn:hover { background: var(--paper-2); }
.link-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Safety disclaimer callout variant */
.callout.important {
    background: #fbefe8;
    border-left-color: var(--alert);
}

/* ============================================================
   CHANNEL CROSS-SECTION PREVIEW (Profile tab, right column)
   ============================================================ */

/* The right column holds preview + summary stacked. */
.summary-col {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.channel-preview {
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 22px 24px 18px 24px;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
    overflow: auto;   /* formula table can be tall; scroll if needed */
}
.channel-preview-body {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.channel-preview-body > .shape-heading {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: -0.01em;
    margin: 0 0 12px 0;
}
.channel-preview-body > .shape-diagram {
    height: 180px;
    margin-bottom: 14px;
}
.channel-preview-body > .muted {
    font-size: 12px;
    line-height: 1.5;
    margin: 0 0 14px 0;
}
.channel-preview-body > .formula-table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}
.channel-preview-body > .formula-table td {
    padding: 6px 8px;
    border-top: 1px dotted var(--rule);
    vertical-align: baseline;
}
.channel-preview-body > .formula-table tr:first-child td {
    border-top: none;
}
.channel-preview-body > .formula-table td:first-child {
    width: 60px;
    color: var(--ink-soft);
}
.channel-preview-body > .formula-table tr.formula-section td {
    border-top: none;
    padding-top: 10px;
    padding-bottom: 2px;
    color: var(--ink-soft);
    font-size: 11px;
}

/* Profile-types master figure (reference diagram in Help tab) */
.profile-types-figure {
    border: 1px solid var(--rule);
    background: var(--paper);
    padding: 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    min-height: 220px;
}
.profile-types-figure svg {
    display: block;
    width: 100%;
    height: auto;
}

/* ============================================================
   EXPORTS / PRINT / RATING CURVE
   ============================================================ */

/* Export button group: keeps CSV/XLSX/FLO/Print together */
.export-group {
    display: inline-flex;
    border: 1px solid var(--rule-2);
}
.export-group .btn {
    border: none;
    border-left: 1px solid var(--rule-2);
    height: 36px;
    padding: 0 12px;
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.export-group .btn:first-child { border-left: none; }
.export-group .btn:hover { background: var(--paper-2); }

/* Rating curve layout */
.rating-wrap {
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 22px 24px;
    margin-top: 20px;
    background: #ffffff;
    box-shadow: 0 8px 28px -12px rgba(10, 24, 34, 0.12),
                0 2px 6px -2px rgba(10, 24, 34, 0.04);
}
.rating-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 24px;
    align-items: start;
}
@media (max-width: 900px) {
    .rating-split { grid-template-columns: 1fr; }
}
.rating-chart-col {
    height: 320px;
    position: relative;
}
.rating-table-col {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--rule);
}
.rating-table { font-size: 11px; }
.rating-table td { padding: 4px 10px; }
.rating-table tr.current td {
    background: rgba(8,145,178,0.10);
    font-weight: 500;
}

/* Calc-sheet header shown only when printing */
.print-only { display: none; }
.calc-sheet-header { padding: 0 0 12px 0; border-bottom: 2px solid var(--ink); margin-bottom: 20px; }
.calc-sheet-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.calc-brand {
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-dim);
    margin-bottom: 4px;
}
.calc-sheet-title h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}
.calc-meta { font-size: 11px; text-align: right; }
.calc-meta > div { margin-bottom: 2px; }
.calc-meta-k {
    display: inline-block;
    min-width: 60px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-dim);
    font-family: var(--ff-mono);
    font-size: 9px;
    margin-right: 8px;
}
.calc-meta-v { font-family: var(--ff-mono); color: var(--ink); }

/* =======================================================
   PRINT STYLES
   ======================================================= */
@media print {
    @page {
        size: letter portrait;
        margin: 0.6in;
    }
    html, body {
        background: white !important;
        background-image: none !important;
        color: black !important;
        font-size: 10pt;
    }
    body::before { display: none !important; }

    /* Hide everything except the Profile panel content */
    .topbar, .footbar, .auth-shell, .toggle-switch, .help-dot, .modal, .toast,
    input[type=range], input[type=file], select, .submit-row,
    .export-group, #btn-save-profile, #flo-import,
    #live-preview-toggle, .units-toggle, .userchip,
    .panel[data-panel=mannings], .panel[data-panel=critical],
    .panel[data-panel=orifice],  .panel[data-panel=saved],
    .panel[data-panel=help],
    .tabs, .viz-head .toggle-switch,
    .panel-actions, .panel-head .eyebrow {
        display: none !important;
    }

    /* Show the calc-sheet header */
    .print-only { display: block !important; }

    /* Reset workbench layout for print */
    .app-shell {
        display: block !important;
        min-height: 0 !important;
        grid-template-rows: none !important;
    }
    .workbench {
        padding: 0 !important;
        max-width: none !important;
        overflow: visible !important;
    }
    .panel[data-panel=profile] {
        display: block !important;
    }
    .panel-head { display: none; }

    /* Collapse the two-column input/summary to one-column summary only */
    .twocol {
        display: block !important;
    }
    .inputs { display: none !important; }
    .summary {
        border: 1px solid #333 !important;
        background: white !important;
        margin: 0 0 16px 0 !important;
        padding: 10px 14px !important;
        page-break-inside: avoid;
    }
    .summary h3 { color: #333 !important; border: none; margin: 0 0 8px 0; font-size: 10pt; }
    .summary .kv { border-color: #ccc !important; font-size: 9pt; }
    .summary .kv .v { color: black !important; }
    .summary .pill {
        background: white !important; color: black !important;
        border: 1px solid #333;
    }

    /* Chart + cross-section side by side */
    .chart-wrap {
        border: 1px solid #333 !important;
        padding: 10px !important;
        margin-bottom: 16px !important;
        page-break-inside: avoid;
        background: white !important;
    }
    .viz-head { margin-bottom: 6px; }
    .viz-heading { color: #333 !important; }
    .viz-split {
        grid-template-columns: 2fr 1fr !important;
        gap: 16px !important;
    }
    .viz-chart-col { height: 2.4in !important; }
    .viz-xs-col { border-left-color: #ccc !important; padding-left: 12px !important; }
    .xs-svg-wrap {
        background: white !important;
        background-image: none !important;
        border-color: #ccc !important;
        aspect-ratio: 1 / 1;
    }
    .xs-svg-wrap .channel-outline { stroke: black !important; }
    .xs-svg-wrap .water-fill { fill: rgba(0,0,0,0.08) !important; stroke: #333 !important; }
    .xs-svg-wrap .top-callout { stroke: #333 !important; }
    .xs-svg-wrap .label { fill: #333 !important; }
    .xs-svg-wrap .label-val { fill: black !important; }

    /* Data grid: use compact table */
    .grid-wrap { page-break-before: auto; }
    .grid-heading { color: #333 !important; margin-bottom: 6px; }
    .data-grid {
        font-size: 8.5pt !important;
        border-collapse: collapse !important;
    }
    .data-grid thead th {
        background: #eee !important;
        color: #333 !important;
        font-size: 8pt !important;
        padding: 4px 6px !important;
        border-bottom: 1px solid #333 !important;
    }
    .data-grid td {
        padding: 3px 6px !important;
        border-bottom: 1px solid #ddd !important;
    }
    .scroll-x { overflow: visible !important; border: 1px solid #ccc !important; }
    thead { display: table-header-group; } /* repeat header across page breaks */

    /* Warnings still visible */
    .warn-block { page-break-inside: avoid; }
    .warn {
        border-left-color: #333 !important;
        background: #f5f5f5 !important;
        color: black !important;
    }

    /* Legend/titles need ink color */
    .pill { color: black !important; background: white !important; border: 1px solid #333; }
}

/* ============================================================
   FEEDBACK WIDGET  (per-panel thumbs up/down + comment)
   ============================================================ */
.feedback-widget {
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: flex-end;
    margin: 0 16px 4px auto;
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.feedback-widget.sent { color: var(--ok); }
.feedback-widget .fb-prompt { margin-right: 4px; }
.feedback-widget .fb-thumb {
    width: 26px; height: 26px;
    padding: 0;
    border: 1px solid var(--rule-2);
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 100ms ease;
}
.feedback-widget .fb-thumb:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.feedback-widget .fb-thumb svg { width: 13px; height: 13px; }
.feedback-widget .fb-thumb.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--paper);
}
.feedback-widget .fb-comment {
    display: none;
    margin-left: 6px;
    gap: 4px;
    align-items: center;
}
.feedback-widget.show-comment .fb-comment { display: inline-flex; }
.feedback-widget .fb-comment input {
    width: 180px;
    height: 26px;
    margin: 0;
    padding: 0 8px;
    font-family: var(--ff-body);
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
    border: 1px solid var(--rule-2);
}
.feedback-widget .fb-comment button {
    height: 26px;
    padding: 0 10px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    cursor: pointer;
}

/* ============================================================
   BOTTOM NAV (tablet and mobile)
   ============================================================ */
.bottom-nav {
    display: none;           /* hidden on desktop; shown via media query */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 50;
    background: var(--paper);
    border-top: 1px solid var(--rule);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    justify-content: space-between;
    box-shadow: 0 -2px 12px -6px rgba(10, 24, 34, 0.1);
}
/* hide when not signed in */
body:has(#auth-shell:not(.hidden)) .bottom-nav { display: none !important; }
.bn-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--ink-dim);
    font-family: var(--ff-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    min-height: 56px;
    transition: color 150ms ease, background 150ms ease;
}
.bn-tab svg { width: 22px; height: 22px; }
.bn-tab.active { color: var(--accent); }
.bn-tab.active svg { color: var(--accent); }
.bn-tab:hover { color: var(--ink); }
.bn-tab:active { background: var(--paper-2); }

/* Phone sizes — tighter spacing, smaller label */
@media (max-width: 640px) {
    .bn-tab {
        font-size: 9px;
        min-height: 52px;
        padding: 6px 2px;
        gap: 2px;
    }
    .bn-tab svg { width: 20px; height: 20px; }
}

/* ============================================================
   MOBILE MEDIA QUERIES (≤ 640px)
   ============================================================ */
/* ============================================================
   TABLET AND BELOW (≤ 1024px) — bottom nav replaces top tabs
   ============================================================ */
@media (max-width: 1024px) {
    /* Hide desktop top tabs; show bottom-nav */
    .topbar .tabs { display: none; }
    .bottom-nav { display: flex; }

    /* Leave room at the bottom for the fixed nav so content doesn't
       disappear behind it when scrolled to the end. */
    .workbench {
        padding-bottom: calc(68px + env(safe-area-inset-bottom));
    }

    /* Free up topbar horizontal space now that tabs are gone */
    .topbar {
        grid-template-columns: auto 1fr;
        gap: 16px;
        padding: 0 18px;
    }

    /* Hide the desktop footer — not useful on tablet either */
    .footbar { display: none; }
}

/* ============================================================
   MOBILE ONLY (≤ 640px) — condensed text, single-column forms
   ============================================================ */
@media (max-width: 640px) {
    :root {
        --topbar-h: 52px;
        --footbar-h: 0px;
    }
    body { font-size: 13px; }

    /* Further tighten topbar contents */
    .topbar {
        gap: 12px;
        padding: 0 12px;
    }
    .topbar-right {
        gap: 10px;
        justify-content: flex-end;
    }
    .units-toggle button {
        padding: 0 10px;
        font-size: 10px;
    }
    .userchip #userchip-name { display: none; } /* save width */

    .workbench {
        padding: 16px 14px 100px 14px;
    }

    /* Panel heads: stack the actions below the title */
    .panel-head {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding-bottom: 12px;
        margin-bottom: 16px;
    }
    .panel-head h2 { font-size: 20px; }
    .panel-actions {
        flex-wrap: wrap;
        gap: 6px;
    }
    .export-group {
        width: 100%;
    }
    .export-group .btn {
        flex: 1;
        padding: 0 6px;
    }
    .feedback-widget {
        margin: 0 0 0 0;
        align-self: flex-start;
        flex-wrap: wrap;
    }
    .feedback-widget .fb-comment input { width: 120px; }

    /* Two-column form collapses to one */
    .twocol {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .inputs-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .inputs-grid label.span-2 {
        grid-column: span 1;
    }

    /* Chart + cross-section: stack */
    .viz-split {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .viz-chart-col { height: 260px; }
    .viz-xs-col {
        border-left: none;
        border-top: 1px solid var(--rule);
        padding: 14px 0 0 0;
    }
    .xs-svg-wrap { max-width: 240px; margin: 0 auto 12px; }

    /* Rating curve split on Mannings: stack */
    .rating-split { grid-template-columns: 1fr; }
    .rating-chart-col { height: 240px; }

    /* Help TOC becomes horizontal scroll strip */
    .help-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .help-toc {
        position: static;
        margin: -4px 0 8px 0;
        overflow-x: auto;
    }
    .help-toc nav {
        flex-direction: row;
        border-left: none;
        border-bottom: 1px solid var(--rule);
        padding-bottom: 4px;
    }
    .help-toc a {
        padding: 6px 12px;
        border-left: none;
        border-bottom: 2px solid transparent;
        margin: 0;
        white-space: nowrap;
    }
    .help-toc a.active {
        border-left: none;
        border-bottom-color: var(--accent);
    }

    /* Shape cards: one column on phone */
    .shape-grid { grid-template-columns: 1fr; }
    .assume-grid { grid-template-columns: 1fr; }

    /* Auth card and shell padding on mobile. The auth landing now has
       substantial prose content above the sign-in card, so horizontal
       breathing room matters. */
    .auth-card { border: none; padding: 24px 20px; }
    .auth-shell { padding: 24px 20px 32px 20px; }

    /* Modal: full-width */
    .modal-card { width: 92%; }

    /* Hide the background grid paper on small screens to reduce visual noise */
    html, body { background-image: none; }

    /* Data grid: smaller */
    .data-grid { font-size: 11px; }
    .data-grid td, .data-grid thead th { padding: 5px 8px; }
}

/* Very small / narrow phones */
@media (max-width: 380px) {
    .bn-tab { font-size: 8px; gap: 1px; }
    .bn-tab svg { width: 18px; height: 18px; }
    .panel-head h2 { font-size: 18px; }
    .export-group .btn { font-size: 9px; padding: 0 4px; }
}
