/* ─── Design tokens (themed) ───────────────────────────────────────────
 * Theme is selected via `<html data-theme="...">`. The pre-paint script
 * in each HTML file's <head> reads localStorage["fs25.dash.v1.theme"]
 * and sets the attribute before first paint to avoid a flash.
 *
 * Available themes: dark-green (default), dark-blue, light, high-contrast, fs25-native.
 * `:root` (no attribute) is a safety fallback — same values as dark-green.
 */

/* Geometry tokens (theme-independent) */
:root {
    --radius: 8px;
    --nav-h:  52px;
}

/* Default + dark-green */
:root,
:root[data-theme="dark-green"] {
    --bg:        #0d1610;
    --surface:   #172220;
    --surface2:  #1f2c28;
    --border:    #2e3a34;
    --accent:    #7fb069;       /* tlumený list */
    --accent2:   #e8a838;       /* zralé obilí */
    --accent3:   #c08552;       /* hlína (pro budoucí použití) */
    --text:      #e6ecdf;
    --muted:     #8a9a82;
    --red:       #e05252;
    --orange:    #e07a30;
    --teal:      #4caf9a;
}

/* Dark blue (cooler night palette) */
:root[data-theme="dark-blue"] {
    --bg:        #0e1422;
    --surface:   #162236;
    --surface2:  #1c2c46;
    --border:    #2a3654;
    --accent:    #5a8fad;
    --accent2:   #f0b429;
    --text:      #dde7f0;
    --muted:     #7a8aa0;
    --red:       #e05252;
    --orange:    #e07a30;
    --teal:      #4cc4af;
}

/* Light (office monitor friendly) */
:root[data-theme="light"] {
    --bg:        #f4f6f1;
    --surface:   #ffffff;
    --surface2:  #eef1e7;
    --border:    #d6dcc6;
    --accent:    #3a8a22;
    --accent2:   #b07a00;
    --text:      #1c2a18;
    --muted:     #5d7355;
    --red:       #c43a3a;
    --orange:    #c45a18;
    --teal:      #1f8a76;
}

/* High contrast (accessibility) */
:root[data-theme="high-contrast"] {
    --bg:        #000000;
    --surface:   #101010;
    --surface2:  #181818;
    --border:    #ffffff;
    --accent:    #ffd400;
    --accent2:   #ffd400;
    --text:      #ffffff;
    --muted:     #bbbbbb;
    --red:       #ff5555;
    --orange:    #ff9900;
    --teal:      #66e0c4;
}

/* FS25-native (echoes the in-game HUD: GIANTS green + steel HUD + wheat gold) */
:root[data-theme="fs25-native"] {
    --bg:        #0a0d0a;
    --surface:   #141811;
    --surface2:  #1d2419;
    --border:    #2f3b2a;
    --accent:    #a0c213;       /* GIANTS FS25 brand green */
    --accent2:   #d4a836;       /* wheat gold */
    --accent3:   #8b6f47;       /* aged steel-brown */
    --text:      #f0f2e8;
    --muted:     #92a08a;       /* lifted from #8a9580 for AA contrast on surface2 */
    --red:       #d04545;
    --orange:    #e08838;
    --teal:      #4caf9a;
}

:root[data-theme="fs25-native"] body {
    font-family: 'Nunito Sans', 'Segoe UI', system-ui, sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Nav ────────────────────────────────────────────────────────────── */
nav {
    position: sticky; top: 0; z-index: 100;
    height: var(--nav-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 0;
}
.nav-brand {
    font-size: 16px; font-weight: 700; color: var(--accent);
    margin-right: 12px; white-space: nowrap;
}
.nav-save {
    font-size: 11px; color: var(--muted);
    margin-right: 18px; white-space: nowrap;
    padding: 2px 8px;
    background: var(--surface2);
    border-radius: 4px;
    max-width: 240px;
    overflow: hidden; text-overflow: ellipsis;
}
.nav-version {
    font-size: 11px; color: var(--accent);
    margin-right: 10px; white-space: nowrap;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-burger {
    display: none;          /* desktop: hidden; mobile media query shows it */
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px; height: 32px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-right: 8px;
    flex-shrink: 0;
}
.nav-burger:hover { background: var(--surface2); border-color: var(--accent); }
.nav-links a {
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--muted);
    transition: background .15s, color .15s;
}
.nav-links a:hover,
.nav-links a.active {
    background: var(--surface2);
    color: var(--text);
    text-decoration: none;
}
.nav-links a.active { color: var(--accent); }

.nav-status {
    margin-left: auto;
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--muted);
}
.dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--muted); flex-shrink: 0;
}
.dot.live  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.error { background: var(--red); }

/* ─── Notification bell ──────────────────────────────────────────────── */
.bell-slot { position: relative; display: inline-flex; }
.bell {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    border-radius: 6px;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 16px;
    line-height: 1;
    display: inline-flex; align-items: center; gap: 4px;
    position: relative;
}
.bell:hover { background: var(--surface2); color: var(--text); }
.bell.has-alerts { color: var(--accent2); }
.bell-icon { display: inline-block; }
.bell-count {
    background: var(--red);
    color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 1px 5px;
    border-radius: 9px;
    min-width: 16px; text-align: center;
    line-height: 1.2;
}
.bell-panel {
    position: absolute;
    right: 0; top: calc(100% + 6px);
    width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    z-index: 100;
    overflow: hidden;
    color: var(--text);
}
.bell-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.bell-panel-head h3 {
    margin: 0; font-size: 13px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted);
}
.bell-close {
    background: transparent; border: none;
    color: var(--muted); cursor: pointer;
    font-size: 18px; line-height: 1;
    padding: 0 4px;
}
.bell-close:hover { color: var(--text); }
.bell-list {
    list-style: none; padding: 0; margin: 0;
    max-height: 50vh; overflow-y: auto;
}
.bell-item {
    display: grid;
    grid-template-columns: 28px 1fr 16px;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    align-items: center;
    transition: background .15s;
}
.bell-item:last-child { border-bottom: 0; }
.bell-item:hover { background: var(--surface2); }
.bell-item-icon { font-size: 18px; line-height: 1; text-align: center; }
.bell-item-text { min-width: 0; }
.bell-item-title {
    font-size: 12px; font-weight: 600;
    color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bell-item-detail {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.bell-item-arrow { color: var(--muted); font-size: 14px; }
.bell-item.bell-urgent  .bell-item-icon { color: var(--red); }
.bell-item.bell-warning .bell-item-icon { color: var(--orange); }

/* Per-row dismiss button — invisible until row hover. Hides the alert
   from the bell badge until the underlying condition changes (different
   items in detail) or the page reloads. */
.bell-item-dismiss {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .12s, color .12s, background-color .12s;
    flex-shrink: 0;
}
.bell-item:hover .bell-item-dismiss { opacity: 1; }
.bell-item-dismiss:hover { color: var(--red); background: rgba(255,255,255,.05); }

.bell-empty {
    padding: 20px 14px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}
.bell-panel-actions {
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end;
}
.bell-dismiss-all {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: color .12s, border-color .12s;
}
.bell-dismiss-all:hover { color: var(--text); border-color: var(--accent); }

/* Card flash on bell-item click — short pulse to direct user's eye */
@keyframes card-flash {
    0%   { box-shadow: 0 0 0 2px var(--accent2); }
    50%  { box-shadow: 0 0 0 3px var(--accent2); }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.card-flash { animation: card-flash 1s ease-out; }

/* ─── Main content ───────────────────────────────────────────────────── */
main {
    padding: 12px;
    max-width: 1920px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Bento content grid — auto-fit columns. Cards keep their natural height
   (`align-items:start`) so a tall card doesn't stretch its row neighbours. */
/* Section layout — 4-column CSS grid with sec-fields spanning 2 cells.
 * At a wide viewport the field table is the visual anchor (2 of 4 cols,
 * left side), the four smaller sections fill the remaining 2 cols and the
 * row below. At 1300 px we collapse to 2 cols (sec-fields then = both =
 * full width); below 700 px every section stacks in a single column.
 *
 * grid-auto-flow:row dense lets shorter sections back-fill gaps created
 * by sec-fields' span, so the layout stays compact instead of leaving
 * empty cells next to the field table.
 */
.masonry {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    /* Sections are placed explicitly by applyMasonrySpans() (greedy shortest-
       column packer), so auto-flow only matters as a fallback for not-yet-
       measured sections. */
    grid-auto-flow: row dense;
    /* 2 px row unit — fine enough that the `grid-row: span N` inline value
       written by applyMasonrySpans() lands within a couple of pixels of
       each section's true height. Larger row units (8 px, 4 px) leave
       noticeable trailing whitespace below shorter sections; 2 px keeps the
       excess below 14 px (≈ one row gap). */
    grid-auto-rows: 2px;
    gap: 5px;
    align-items: start;
}
.masonry > .section {
    margin: 0;
    min-width: 0;
    /* Default span — JS overrides per-section after measuring. */
    grid-row: span 100;
}
.masonry > .sec-fields {
    grid-column: span 2;
}
@media (max-width: 1300px) {
    .masonry { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    /* sec-fields stays at span:2 — that's the whole row at 2-col viewport. */
}
@media (max-width: 700px) {
    .masonry { grid-template-columns: 1fr; }
    .masonry > .sec-fields { grid-column: auto; }
}

/* ─── KPI hero row ───────────────────────────────────────────────────── */
.kpi-row {
    display: grid;
    /* auto-fit so the row gracefully shrinks when KPIs are hidden — the
       remaining cards fill the row instead of leaving a 75 %-wide layout. */
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }
@media (max-width: 480px) { .kpi-row { grid-template-columns: 1fr; } }

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex; flex-direction: column;
    gap: 4px;
    min-height: 92px;
    justify-content: center;
}
/* Status accents — light left-border tint so the eye picks up the card's
   state before reading the number (balance dropped, fields ready, ...). */
.kpi-card.kpi-alert { border-left: 3px solid var(--red);    padding-left: 13px; }
.kpi-card.kpi-ok    { border-left: 3px solid var(--accent); padding-left: 13px; }

/* Forecast advice — pulls the seasonal headline out of an 11px muted
   chart-header span and into a real callout box above the chart. */
.forecast-advice {
    margin: 8px 16px 4px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--accent2) 12%, transparent);
    border-left: 3px solid var(--accent2);
    border-radius: 4px;
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
}
.forecast-advice b { color: var(--accent2); }
.forecast-advice .forecast-advice-text { margin-left: 4px; }
.kpi-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    font-weight: 600;
}
.kpi-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex; align-items: baseline; gap: 8px;
}
.kpi-value .kpi-icon {
    font-size: 24px;
    line-height: 1;
}
.kpi-sub {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.2;
    min-height: 14px;
}
.kpi-sub.delta-up   { color: var(--accent); }
.kpi-sub.delta-down { color: var(--red); }

/* Weather KPI — split into "current" (left) + "forecast strip" (right) with
   a vertical divider. Overrides the default column flex on .kpi-card. */
.kpi-card.kpi-weather-card {
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding-right: 12px;
}
.kpi-weather-card .kpi-weather-current {
    display: flex; flex-direction: column;
    gap: 4px;
    justify-content: center;
    flex: 1; min-width: 0;
}
.kpi-weather-card .kpi-weather-forecast {
    display: flex; flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding-left: 14px;
    margin-left: 14px;
    border-left: 2px solid var(--border);
    min-width: 96px;
}
.kpi-weather-card .kpi-weather-forecast:empty { display: none; }
.forecast-day {
    display: flex; align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1;
}
.forecast-day .forecast-when { font-weight: 600; color: var(--text); opacity: .75; }
.forecast-day .forecast-icon { font-size: 14px; }
.forecast-day .forecast-temp { margin-left: auto; opacity: .8; }

/* Balance KPI — same split as weather: current (left) + 3-day history (right) */
.kpi-card.kpi-balance-card {
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding-right: 12px;
}
.kpi-balance-card .kpi-balance-current {
    display: flex; flex-direction: column;
    gap: 4px;
    justify-content: center;
    flex: 1; min-width: 0;
}
.kpi-balance-card .kpi-balance-history {
    display: flex; flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding-left: 14px;
    margin-left: 14px;
    border-left: 2px solid var(--border);
    min-width: 96px;
}
.kpi-balance-card .kpi-balance-history:empty { display: none; }
.history-day {
    display: flex; align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1;
}
.history-day .history-when  { font-weight: 600; color: var(--text); opacity: .75; }
.history-day .history-arrow { font-size: 12px; }
.history-day .history-delta { margin-left: auto; opacity: .85; }
.history-day.delta-up    .history-arrow,
.history-day.delta-up    .history-delta { color: var(--accent); opacity: 1; }
.history-day.delta-down  .history-arrow,
.history-day.delta-down  .history-delta { color: var(--red); opacity: 1; }

/* Updated timestamp in nav */
.nav-updated {
    font-size: 11px; color: var(--muted);
    margin-right: 8px;
    font-variant-numeric: tabular-nums;
}

/* ─── Section card ───────────────────────────────────────────────────── */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.section-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted);
}
.section-header .count {
    background: var(--surface2);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 10px; color: var(--text);
}
:root[data-theme="fs25-native"] .section-header .count {
    background: color-mix(in srgb, var(--accent2) 25%, transparent);
    color: var(--accent2);
}
.section-header .section-jump {
    margin-left: auto;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--accent);
    text-decoration: none;
}
.section-header .section-jump:hover { text-decoration: underline; }
.section-body { padding: 12px 16px; }

/* ─── Table ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    background: var(--surface2);
    padding: 7px 10px;
    text-align: left;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .07em;
    color: var(--muted); white-space: nowrap;
}
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tbody td { padding: 7px 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Collapsible group rows (storage / prices) */
tr.collapsible { cursor: pointer; user-select: none; }
tr.collapsible:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.group-toggle { display: inline-block; width: 12px; color: var(--accent); font-size: 11px; }
.group-meta   { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 8px; }
.hidden-row { display: none; }

/* Inline donut for silo headers */
.silo-donut {
    vertical-align: -2px;
    color: var(--accent);
    margin-right: 2px;
}
.silo-donut.donut-warn { color: var(--accent2); }
.silo-donut.donut-full { color: var(--red); }
.silo-pct {
    margin-left: auto;
    color: var(--muted);
    font-size: 11px; font-variant-numeric: tabular-nums;
    float: right;
}

/* Sortable column headers (sortable.js) */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sortable::after {
    content: ' \2195';
    opacity: .35;
    font-size: 9px;
    margin-left: 3px;
}
th.sort-asc::after  { content: ' \2191'; opacity: 1; color: var(--accent); }
th.sort-desc::after { content: ' \2193'; opacity: 1; color: var(--accent); }

/* ─── Progress bar ───────────────────────────────────────────────────── */
.bar-wrap  { display: flex; align-items: center; gap: 8px; min-width: 100px; }
.bar-bg    { flex: 1; height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 3px; background: var(--accent); transition: width .5s; }
.bar-fill.warn  { background: var(--accent2); }
.bar-fill.danger { background: var(--red); }
.bar-fill.full  { background: var(--teal); }
.bar-pct   { font-size: 11px; color: var(--muted); width: 32px; text-align: right; flex-shrink: 0; }

/* ─── Storage change flash ─────────────────────────────────────────────
   Applied for ~10 s when an item's amount changes (timing is JS-side via
   scheduled re-render that removes the class). Static colour, no animation
   — keyframes had a subtle bug (!important inside @keyframes is ignored
   per CSS spec, so red animation didn't always win against .st-row td's
   own background). Applied to <td> (not <tr>) because .st-row td sets
   its own background. */
/* Table rows — must override .st-row td's own background (var(--surface2)) */
tr.flash-up   > td,
tr.flash-down > td { transition: background-color .3s ease-out; }
tr.flash-up   > td { background-color: color-mix(in srgb, var(--accent) 35%, transparent) !important; }
tr.flash-down > td { background-color: rgba(224, 82, 82, .35)                              !important; }
/* Div-based rows (vehicles, animals) */
.vehicle-row.flash-up,
.animal-row.flash-up   { background-color: color-mix(in srgb, var(--accent) 35%, transparent) !important; transition: background-color .3s ease-out; }
.vehicle-row.flash-down,
.animal-row.flash-down { background-color: rgba(224, 82, 82, .35) !important; transition: background-color .3s ease-out; }

/* Per-bar flash for animal parameter changes (food, straw, milk, manure, …) */
.ac-bar-lbl.flash-up   { background-color: color-mix(in srgb, var(--accent) 60%, transparent); border-radius: 3px; transition: background-color .3s ease-out; }
.ac-bar-lbl.flash-down { background-color: rgba(224, 82, 82, .6); border-radius: 3px; transition: background-color .3s ease-out; }
/* Sub-line values (zdraví, reprodukce) */
.ac-sub-val.flash-up   { color: var(--accent); transition: color .3s ease-out; }
.ac-sub-val.flash-down { color: var(--red);    transition: color .3s ease-out; }

/* Per-section toggle (right-aligned in section-header) to enable/disable
   the change-flash effect. State persisted in DashState.flashEnabled keyed
   by section name. iOS-style switch — native checkbox is visually hidden
   (still keyboard/click-accessible inside the <label>), the `.switch-knob`
   sibling renders the track + sliding knob via `:checked` cascade. The knob
   element is injected at init by JS so the HTML stays simple. */
.section-header .flash-toggle {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 10px; font-weight: 600;
    text-transform: none; letter-spacing: 0;
    color: var(--muted);
    cursor: pointer; user-select: none;
}
.section-header .flash-toggle:hover { color: var(--text); }
.section-header .flash-toggle input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
    margin: 0;
}
.section-header .flash-toggle .switch-knob {
    width: 28px;
    height: 16px;
    background: var(--surface2);
    border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
    border-radius: 9px;
    position: relative;
    transition: background-color .2s, border-color .2s;
    flex-shrink: 0;
}
.section-header .flash-toggle .switch-knob::before {
    content: '';
    position: absolute;
    left: 1px; top: 1px;
    width: 12px; height: 12px;
    background: var(--muted);
    border-radius: 50%;
    transition: transform .2s ease-out, background-color .2s;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.section-header .flash-toggle input:checked + .switch-knob {
    background-color: color-mix(in srgb, var(--accent) 35%, transparent);
    border-color: var(--accent);
}
.section-header .flash-toggle input:checked + .switch-knob::before {
    transform: translateX(12px);
    background: var(--accent);
}
.section-header .flash-toggle input:focus-visible + .switch-knob {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ─── Per-section settings button ───────────────────────────────────── */
.sec-cfg-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 5px;
    border-radius: 4px;
    color: var(--muted);
    line-height: 1;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}
.sec-cfg-btn:hover  { color: var(--text); background: var(--surface2); }
.sec-cfg-btn.active { color: var(--accent); }
/* Non-default-settings indicator — small accent dot on the ⚙ button (V-2) */
.sec-cfg-btn.has-custom { position: relative; }
.sec-cfg-btn.has-custom::after {
    content: '';
    position: absolute;
    top: 1px; right: 1px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px var(--surface);
}

/* ─── Per-section settings panel (dropdown) ─────────────────────────── */
#sec-cfg-panel {
    position: fixed;
    z-index: 9999;
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    font-size: 13px;
    color: var(--text);
}
.sec-cfg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px 7px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}
.sec-cfg-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
    padding: 0 2px;
}
.sec-cfg-close:hover { color: var(--text); }
.sec-cfg-body { padding: 4px 0; }
#sec-cfg-panel .section-row {
    padding: 5px 12px;
    background: none;
    border: none;
    border-radius: 0;
}
#sec-cfg-panel .section-row:hover { background: var(--surface2); border-color: transparent; }
.sec-cfg-adv-toggle, .sec-cfg-flash-toggle {
    display: block;
    width: 100%;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    cursor: pointer;
    padding: 7px 12px;
    text-align: left;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.sec-cfg-adv-toggle:hover, .sec-cfg-flash-toggle:hover { color: var(--text); background: var(--surface2); }
.sec-cfg-adv, .sec-cfg-flash { padding: 2px 0; }
.sec-cfg-group { padding: 2px 0 4px; }
.sec-cfg-group + .sec-cfg-group { border-top: 1px solid var(--border); }
.sec-cfg-group-label {
    padding: 6px 12px 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}
.sec-cfg-group-note {
    padding: 2px 12px 4px;
    font-size: 10px;
    line-height: 1.3;
    color: var(--muted);
    opacity: .8;
    font-style: italic;
}
.sec-cfg-select {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
}
.sec-cfg-select:hover { border-color: var(--accent); }

/* Reset footer (V-1) */
.sec-cfg-footer {
    border-top: 1px solid var(--border);
    padding: 7px 12px;
    text-align: right;
}
.sec-cfg-reset {
    background: none;
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    padding: 4px 10px;
    font-size: 11px;
    color: var(--muted);
}
.sec-cfg-reset:hover { color: var(--text); border-color: var(--accent); }

/* Mobile: stretch to full viewport width */
@media (max-width: 600px) {
    #sec-cfg-panel {
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        border-radius: 0 0 8px 8px;
        border-left: none;
        border-right: none;
    }
}

/* ─── Expanded sections (2-column masonry span) ──────────────────────── */
.masonry > .section.expanded-animals,
.masonry > .section.expanded-storage,
.masonry > .section.expanded-productions {
    grid-column: span 2;
}

/* ─── Expanded ANIMALS — unstuck bars + inline litres + richer sub ─────── */
.expanded-animals .animal-row {
    grid-template-columns: 24px minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
}
/* Bars become an inner grid (label | bar | litres) so litres line up vertically. */
.expanded-animals .ac-bars { display: grid; grid-template-columns: 14px 1fr auto; row-gap: 3px; column-gap: 6px; align-items: center; }
.expanded-animals .ac-barpair { display: contents; }
.expanded-animals .ac-barpair .bar-wrap { width: auto; min-width: 0; flex: 1 1 auto; }
.ac-bar-liters { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; white-space: nowrap; }
.ac-herd-value { color: color-mix(in srgb, var(--muted) 60%, var(--accent)); white-space: nowrap; }

@media (max-width: 700px) {
    .expanded-animals .animal-row { grid-template-columns: 24px minmax(0, 1fr) 88px 88px; }
    .expanded-animals .ac-bars { display: flex; }
    .expanded-animals .ac-barpair { display: inline-flex; }
    .ac-bar-liters { min-width: 0; }
}

/* ─── Fields — wider zoned growth bar (uses the always-2col width) ─────── */
/* The growth column is where the field table has the most free width.
   Give it a longer bar with a ripening gradient (green → wheat gold). */
.field-growth { width: 40%; }
.field-growth .bar-wrap { min-width: 160px; width: 100%; }
.bar-zoned .bar-fill {
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent2) 100%) !important;
}
@media (max-width: 700px) {
    .field-growth { width: auto; }
    .field-growth .bar-wrap { min-width: 90px; }
}

/* ─── Expanded STORAGE — stacked overview bar + 2-column body ──────────── */
.st-stack {
    display: inline-flex; height: 10px; border-radius: 5px; overflow: hidden;
    flex: 1 1 auto; min-width: 120px; max-width: 420px; margin: 0 10px;
    vertical-align: middle;
}
.st-stack > span { display: block; box-shadow: 0 0 0 1px var(--bg) inset; }
.st-stack .st-seg-free { background: color-mix(in srgb, var(--text) 12%, transparent); box-shadow: none; }
.st-free { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.expanded-storage .st-items {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; row-gap: 2px;
    padding: 2px 0 4px 22px;
}
.st-item { display: flex; align-items: center; gap: 7px; font-size: 12px; font-variant-numeric: tabular-nums; padding: 1px 0; }
.st-item.flash-up   { background-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.st-item.flash-down { background-color: rgba(224, 82, 82, .30); }
.st-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 1px var(--border); }
.st-item-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-item-amt { color: var(--muted); white-space: nowrap; }
.st-item-pct { min-width: 36px; text-align: right; }
@media (max-width: 700px) {
    .expanded-storage .st-items { grid-template-columns: 1fr; }
    .st-stack { max-width: 180px; }
}

/* ─── Expanded PRODUCTIONS (B) — stocks left · recipes right ───────────── */
.prod-split > td { padding: 2px 0 6px; }
.ps-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; align-items: start; padding-left: 22px; }
.ps-grid > .ps-col-recipes { border-left: 1px solid var(--border); padding-left: 14px; }
.ps-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 2px 0; }
.ps-stock-row, .ps-recipe-row {
    display: flex; align-items: center; gap: 8px; font-size: 11px;
    font-variant-numeric: tabular-nums; padding: 1px 0; min-width: 0;
}
.ps-stock-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-stock-row .bar-wrap { width: 64px; min-width: 64px; flex: 0 0 64px; }
.ps-stock-amt { color: var(--muted); white-space: nowrap; }
.ps-stock-row.flash-up   { background-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.ps-stock-row.flash-down { background-color: rgba(224, 82, 82, .30); }
.ps-recipe-row { border-left: 3px solid transparent; padding-left: 6px; }
.ps-recipe-row.is-running { border-left-color: var(--accent); }
.ps-recipe-row.is-missing { border-left-color: var(--red); }
.ps-recipe-row.is-full    { border-left-color: var(--accent2); }
.ps-recipe-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-recipe-io { color: var(--muted); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-throughput, .ps-cost { color: var(--muted); white-space: nowrap; }
.ps-sum { font-size: 10px; margin-top: 3px; padding-left: 6px; }
.ps-empty { font-size: 11px; padding: 2px 0; }
@media (max-width: 700px) {
    .ps-grid { grid-template-columns: 1fr; }
    .ps-grid > .ps-col-recipes { border-left: none; padding-left: 0; }
    .ps-recipe-io { display: none; }
}

/* Field-need chips — used by the calendar Gantt (fixed grid) AND the main
   dashboard Pole–přehled table (inline wrapping flex). */
.need-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    line-height: 1.5;
    white-space: nowrap;
    background: color-mix(in srgb, var(--accent2) 22%, transparent);
    color: var(--accent2);
}
.need-chip.bad {
    background: rgba(224, 82, 82, .20);
    color: var(--red);
}
.field-needs-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 4px;
}

/* Section visibility list inside Settings → Sekce — re-uses the same
   iOS-style switch styling as the flash toggles but scoped to a row layout. */
.section-list {
    display: flex; flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}
.section-row {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color .12s;
    font-size: 13px;
    color: var(--text);
}
.section-row:hover { border-color: var(--accent); }
.section-row-label { flex: 1; }
.section-row-toggle {
    position: relative;
    display: inline-flex; align-items: center;
}
.section-row input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
    margin: 0;
}
.section-row .switch-knob {
    width: 28px; height: 16px;
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
    border-radius: 9px;
    position: relative;
    transition: background-color .2s, border-color .2s;
    flex-shrink: 0;
}
.section-row .switch-knob::before {
    content: '';
    position: absolute;
    left: 1px; top: 1px;
    width: 12px; height: 12px;
    background: var(--muted);
    border-radius: 50%;
    transition: transform .2s ease-out, background-color .2s;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.section-row input:checked + .switch-knob {
    background-color: color-mix(in srgb, var(--accent) 35%, transparent);
    border-color: var(--accent);
}
.section-row input:checked + .switch-knob::before {
    transform: translateX(12px);
    background: var(--accent);
}
.section-row input:focus-visible + .switch-knob {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Settings hint — small muted explainer under a panel label. */
.settings-hint {
    font-size: 11px;
    color: var(--muted);
    margin: 0 0 10px 0;
    line-height: 1.4;
}

/* Reset row inside Settings → Sekce: one tertiary (just order) + one
   destructive (everything). */
.section-reset-row {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.section-reset-row .secondary,
.section-reset-row .danger {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    transition: border-color .12s, color .12s, background .12s;
}
.section-reset-row .secondary:hover { border-color: var(--accent); color: var(--accent); }
.section-reset-row .danger {
    color: var(--red);
    border-color: color-mix(in srgb, var(--red) 35%, var(--border));
    margin-left: auto;
}
.section-reset-row .danger:hover {
    background: color-mix(in srgb, var(--red) 12%, transparent);
    border-color: var(--red);
}

/* ─── Productions table (slightly tighter) ───────────────────────────── */
#sec-productions table { table-layout: fixed; }
#sec-productions thead th { white-space: normal; padding: 6px 6px; }
#productions-body td, #productions-hidden-body td { padding: 6px 6px; }
#productions-body td, #productions-hidden-body td {
    overflow-wrap: anywhere;
    word-break: break-word;
}
#productions-body .tag, #productions-hidden-body .tag { white-space: normal; }

/* ─── Vehicle rows (compact) ─────────────────────────────────────────── */
#vehicles-body, #vehicles-hidden-body { padding: 4px 12px 8px; }
.vehicle-row {
    display: grid;
    /* dot · name(flex) · fuel block · right cluster (condition·speed·mh).
       The full vehicle type name is in the row's title attribute (tooltip).
       Content-sized side columns keep the row inside the narrowest masonry
       track (~340 px); wider tracks let the 1fr name column absorb the slack. */
    grid-template-columns: 10px minmax(50px, 1fr) minmax(60px, max-content) max-content;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 7px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    border-left: 3px solid transparent;
}
.vehicle-row:last-child { border-bottom: 0; }
.vehicle-row.in-use {
    background: color-mix(in srgb, var(--accent) 7%, transparent);
    border-left-color: var(--accent);
    padding-left: 4px;
}
.dot-active, .dot-idle {
    width: 8px; height: 8px; border-radius: 50%;
    display: inline-block;
}
.dot-active { background: var(--accent); box-shadow: 0 0 4px var(--accent); }
.dot-idle   { background: var(--muted); opacity: .35; }
.vc-name {
    font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vc-type {
    color: var(--muted); font-size: 11px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vc-fuel { display: flex; align-items: center; gap: 8px; min-width: 0; }
.vc-fuel .bar-wrap { width: 60px; min-width: 60px; flex: 0 0 60px; }
.vc-fuel-num { font-size: 11px; color: var(--muted); white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* Right-aligned info cluster: condition · speed · motor-hours (mh at the very
   right edge, speed just left of it when moving). */
.vc-right {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
    white-space: nowrap;
}
.vc-cond { font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.vc-speed { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.vc-mh {
    font-size: 11px;
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.vc-ai {
    /* Sit on a dedicated second row of the row's grid, spanning from the
       name column to the end (no dot offset) so the badge has room and
       reads as a sub-line of the same vehicle. */
    grid-column: 2 / -1;
    grid-row: 2;
    justify-self: start;
    margin-top: 1px;
    font-size: 11px;
    color: var(--accent);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: help;
}

/* Compact implement fill summary — visible in basic view so the user can
   see a wagon filling up without enabling the expanded layout. Hidden
   when .expanded-vehicles is on (the full sub-rows take over there).
   Sits on row 3 so it stacks below the AI badge when both are present;
   row 2 collapses to zero height when no AI badge is rendered. */
.vc-impl-summary {
    grid-column: 2 / -1;
    grid-row: 3;
    justify-self: stretch;
    margin-top: 1px;
    font-size: 11px;
    color: var(--muted);
    max-width: 100%;
    display: flex;
    flex-direction: column;
    cursor: help;
}
.vc-impl-line {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.vc-impl-summary .c-green { color: #4ade80; }
.expanded-vehicles .vc-impl-summary { display: none; }

/* Implements sub-block — one line per fillUnit, indented under the vehicle.
   Hidden by default; the user enables it via Settings → 🚜 Vozidla →
   "Rozšířené zobrazení". When enabled, the parent .section gets the
   .expanded-vehicles class which both reveals these sub-rows and lets
   the section span two masonry columns (room for the wider info).

   Spans ALL grid columns (1/-1) — the vehicle-row's grid-template-columns
   add up to ~324 px; pinning the sub-row to columns 2..-1 made it inherit
   that min-width and pushed numbers off the right edge. With 1/-1 plus
   a small padding-left, we get the visual "indent under name" without
   stealing room from .vi-num. */
.v-implements {
    display: none;
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 2px;
    padding-left: 18px;            /* dot 10 + gap 8 → aligns under .vc-name */
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.expanded-vehicles {
    /* Take two masonry columns so the dense row breathes. */
    grid-column: span 2;
}

/* ─── Expanded VEHICLES — dense row: fuel+litres · cond · speed · mh ── */
/* 4 stable columns (vc-right stays one cell → robust to hidden cond/speed). */
.expanded-vehicles .vehicle-row {
    grid-template-columns: 10px minmax(120px, 1fr) max-content max-content;
}
.expanded-vehicles .vc-fuel .bar-wrap { width: 100px; min-width: 100px; flex: 0 0 auto; }
.expanded-vehicles .vc-fuel-num { font-variant-numeric: tabular-nums; }
/* Expanded view (desktop) shows the full per-fillUnit stack below the row —
   the single source of truth for attached-implement fill. Each row carries
   the implement name, crop name (right before the bar), the bar, and the
   tonnage/litres value. */
.expanded-vehicles .v-implements { display: flex; }

/* AdBlue: thin gold strip under the fuel bar (colour only, no number).
   Expanded-only so the compact default row stays unchanged. */
.expanded-vehicles .vc-fuel.has-adblue .bar-wrap { position: relative; }
.expanded-vehicles .vc-fuel.has-adblue .bar-wrap::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: -3px; height: 2px;
    background: var(--accent2); opacity: .7; border-radius: 1px;
}

@media (max-width: 700px) {
    .expanded-vehicles .vehicle-row { grid-template-columns: 10px 1fr max-content; }
    .expanded-vehicles .v-implements { display: flex; }   /* back to vertical stack */
}
.vi-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--muted);
    min-width: 0;
}
.vi-row .bar-wrap { width: 70px; min-width: 70px; flex: 0 0 70px; }
.vi-label {
    flex: 1 1 auto;
    min-width: 0;            /* lets the ellipsis kick in when truly narrow */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.vi-bar  { flex: 0 0 70px; }
.vi-num  { flex: 0 0 auto; }
.vi-impl { color: var(--muted); }
/* Crop name, sits right before the bar (mirrors the old top-right chip).
   Empty when the unit carries no fill. */
.vi-fill { flex: 0 0 auto; white-space: nowrap; color: var(--text); }
.vi-num {
    /* `flex: 0 0 max-content` forces the box to its natural content width,
       even inside a constrained flex track. The label is the one that
       shrinks (it has flex:1 + min-width:0). Without this `.vi-num` would
       collapse and its text would overflow the parent .v-implements
       which has overflow:hidden, making the value invisible. */
    flex: 0 0 max-content;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Vehicle drag-and-drop zone highlight */
.vehicle-row { cursor: grab; }
.vehicle-row:active { cursor: grabbing; }
#vehicles-body.vc-drop-active,
#vehicles-hidden-wrap.vc-drop-active {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-radius: 6px;
}
.vc-drop-hint { font-style: italic; opacity: .7; padding: 10px; }
.vc-hide {
    background: transparent; border: 1px solid var(--border);
    color: var(--muted); border-radius: 4px;
    width: 22px; height: 22px; line-height: 1;
    cursor: pointer; font-size: 12px;
}
.vc-hide:hover { color: var(--text); border-color: var(--accent); }

/* ─── Animal rows (compact) ──────────────────────────────────────────── */
#animals-body, #animals-hidden-body { padding: 4px 12px 8px; }
.animal-row {
    display: grid;
    /* icon · meta(flex, shrinkable) · inputs column · outputs column.
       The two bar columns are fixed-width so K/P always sit in the same
       slot across rows. minmax(0, …) on the meta column lets it shrink
       past its content's natural width, so on narrow sections (430-ish
       px) the outputs column doesn't overflow off the right edge. */
    grid-template-columns: 24px minmax(0, 1fr) 88px 88px;
    align-items: center;
    column-gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
/* Truncate the husbandry name + sub-text instead of overflowing — without
   this, a long name forces the row wider than the section. */
.ac-name, .ac-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.animal-row:last-child { border-bottom: 0; }
.animal-row.alert { background: rgba(224,82,82,.07); }
.ac-icon { font-size: 22px; line-height: 1; text-align: center; }
.ac-meta { min-width: 0; }
.ac-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.ac-sub  { font-size: 11px; color: var(--muted); }
.ac-bars {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    min-width: 0;
}
.ac-bars:empty { display: none; }
.ac-bars-outputs {
    border-left: 1px solid var(--border);
    padding-left: 10px;
}
/* When outputs are empty (e.g. Králičí výběh has no produce), drop the
   divider so the row doesn't show an orphan border. */
.ac-bars-outputs:empty { border-left: 0; padding-left: 0; }
.ac-barpair {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;          /* fixed-size — bars don't stretch */
}
.ac-barpair .bar-wrap {
    width: 56px;             /* compact — fits 88 px column with label + value */
    min-width: 56px;
    flex: none;
    gap: 2px;                /* tight gap between the bar and the % text */
}
.ac-barpair .bar-pct {
    width: 26px;             /* 2-3 digit values — narrower than the 32 px default */
}
.ac-barpair { gap: 2px; }    /* tight gap between the label and the bar */
.ac-bar-lbl {
    color: var(--muted); font-size: 10px;
    min-width: 12px; text-align: right;
    flex-shrink: 0; font-weight: 600;
}
.alert-badge {
    background: var(--red); color: #fff;
    border-radius: 4px; padding: 1px 6px;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase;
}

/* ─── Section toggle (active-only checkbox) ──────────────────────────── */
.section-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    cursor: pointer; user-select: none;
    font-size: 11px; font-weight: 400; color: var(--muted);
    text-transform: none; letter-spacing: 0;
}
.section-toggle input { margin: 0; cursor: pointer; }

/* ─── Hidden / collapsed subgroup header ─────────────────────────────── */
.subgroup-header {
    cursor: pointer; user-select: none;
    padding: 6px 16px;
    background: var(--surface2);
    color: var(--muted);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em;
    border-top: 1px solid var(--border);
}
.subgroup-header:hover { color: var(--text); }
.subgroup-header .count {
    margin-left: 4px; padding: 1px 6px;
    background: var(--surface); color: var(--muted);
    border-radius: 10px; font-size: 10px;
    text-transform: none; letter-spacing: 0;
}

/* ─── Field table coloring ───────────────────────────────────────────── */
.tag {
    display: inline-block;
    border-radius: 3px; padding: 1px 6px;
    font-size: 10px; font-weight: 600;
    text-transform: uppercase;
}
.tag-ready   { background: color-mix(in srgb, var(--accent) 22%, transparent);  color: var(--accent); }
.tag-growing { background: rgba(76,175,154,.15); color: var(--teal); }
.tag-sow     { background: color-mix(in srgb, var(--accent2) 18%, transparent); color: var(--accent2); }
.tag-empty   { background: rgba(255,255,255,.06); color: var(--muted); }

/* ─── Sell-point sub-header row ──────────────────────────────────────── */
.sp-row td {
    background: var(--surface2); color: var(--muted);
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; padding: 5px 10px;
}

/* ─── Storage sub-header ─────────────────────────────────────────────── */
.st-row td {
    background: var(--surface2); color: var(--muted);
    font-size: 10px; font-weight: 700;
    padding: 5px 10px;
}

/* ─── Empty state ────────────────────────────────────────────────────── */
.empty {
    padding: 24px; text-align: center; color: var(--muted); font-size: 13px;
}

/* ─── Colours ────────────────────────────────────────────────────────── */
.c-green  { color: var(--accent); }
.c-yellow { color: var(--accent2); }
.c-orange { color: var(--orange); }
.c-red    { color: var(--red); }
.c-muted  { color: var(--muted); }

/* ─── Notification settings (gear icon in nav) ──────────────────────── */
.notif-btn,
.theme-btn {
    background: transparent; border: 1px solid var(--border);
    color: var(--muted); border-radius: 4px; padding: 4px 8px;
    font-size: 14px; cursor: pointer;
    margin-left: 6px;
}
.notif-btn.on  { color: var(--accent); border-color: var(--accent); }
.notif-btn:hover, .theme-btn:hover { background: var(--surface2); color: var(--text); }

#notif-modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.6); z-index: 200;
    align-items: center; justify-content: center;
}
#notif-modal-overlay.open { display: flex; }

/* ── Relay viewer fallback overlay — source (publisher) offline / ended ─────── */
/* Opaque full-page cover so a viewer never sees stale/blank data unexplained. */
#source-overlay {
    position: fixed; inset: 0; z-index: 1500;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 24px; text-align: center;
}
#source-overlay[hidden] { display: none; }
#source-overlay .so-card {
    max-width: 420px; display: flex; flex-direction: column; gap: 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 32px 28px;
}
#source-overlay .so-icon  { font-size: 48px; line-height: 1; }
#source-overlay .so-title { font-size: 20px; font-weight: 700; color: var(--text); }
#source-overlay .so-msg   { font-size: 14px; color: var(--muted); }

/* Relay viewer serves only index.html — hide nav/section links to pages that
   would 404 there (Kalendář, Historie). Read-only class is on <html> pre-paint. */
html.read-only a[href$="calendar.html"],
html.read-only a[href$="history.html"] { display: none; }
#notif-modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; width: 500px; max-width: 92%;
    position: relative;
}
#notif-modal h3 { margin-bottom: 12px; font-size: 16px; }

/* Close button — top-right corner of the modal. */
.settings-close {
    position: absolute;
    top: 10px; right: 12px;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    transition: color .12s, background-color .12s;
}
.settings-close:hover { color: var(--red); background: var(--surface2); }

/* Action row — sits at the bottom of the modal. Save right-aligned via
   margin-left:auto on the button, Test (if visible) stays left. */
.settings-actions {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
/* Form-field labels (e.g. "Krmivo zvířat — varovat pod %") stack on top
   of their input. `:not([class])` keeps this rule from clobbering the
   switch-toggle labels in Sekce / Vozidla / Sync panels, which need
   inline-flex to render the iOS-style pill + knob — without the guard
   the broad rule collapsed .switch-knob to zero width and only the
   ::before dot was visible (looked like `|●` instead of a track). */
#notif-modal label:not([class]) { display: block; margin: 12px 0 4px; font-size: 12px; color: var(--muted); }
#notif-modal input[type=number] {
    width: 80px; background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 13px;
}
.lang-select {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); padding: 6px 10px; border-radius: 4px; font-size: 13px;
    min-width: 160px; cursor: pointer;
}
#notif-modal .row { display: flex; align-items: center; gap: 10px; }
#notif-modal .switch { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
#notif-modal button.primary {
    background: var(--accent); color: var(--bg); border: none;
    padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: 700;
    font-size: 13px;
}
#notif-modal button.primary:hover { filter: brightness(1.1); }
#notif-modal button.secondary {
    background: var(--surface2); border: 1px solid var(--border); color: var(--text);
    padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px;
}

/* Settings tabs — sit at the top of the modal, switch panels below. */
.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin: 0 -24px 14px;
    padding: 0 24px;
}
.settings-tabs button {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .12s, border-color .12s;
}
.settings-tabs button:hover { color: var(--text); }
.settings-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
/* Stack all panels in the same grid cell so the modal sizes to the tallest
   panel and doesn't reflow when the user switches tabs. Hidden panels are
   layout-present (visibility: hidden) so they still contribute to sizing. */
.settings-panels {
    display: grid;
    grid-template-areas: 'stack';
    grid-template-columns: 1fr;
}
.settings-panels > .settings-panel {
    grid-area: stack;
    min-width: 0;
}
.settings-panel[hidden] {
    /* Override the UA `[hidden] { display: none }` so the panel keeps
       contributing to the grid sizing — visibility:hidden takes care of
       not showing it, pointer-events:none keeps the inputs untabbable. */
    display: block;
    visibility: hidden;
    pointer-events: none;
}

/* Theme picker — 2-col grid of cards inside the Vzhled tab. */
.theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}
.theme-card {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: border-color .12s, background-color .12s;
}
.theme-card:hover { border-color: var(--accent); }
.theme-card.active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, var(--surface2));
    color: var(--accent);
}
.theme-card-icon { font-size: 18px; line-height: 1; }

/* ─── Field condition badges (in detail modal) ─────────────────────── */
.cond-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-top: 8px;
}
.cond-badge {
    background: var(--surface2);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cond-badge .v { font-weight: 600; }
.cond-badge.warn { background: color-mix(in srgb, var(--accent2) 18%, transparent); color: var(--accent2); }
.cond-badge.ok   { background: color-mix(in srgb, var(--accent) 18%, transparent);  color: var(--accent); }
.cond-badge.bad  { background: rgba(224,82,82,.15);  color: var(--red); }

/* ─── Animal detail modal ─────────────────────────────────────────────── */
.animal-row { cursor: pointer; transition: background .12s; }
.animal-row:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(2px);
}
.modal-panel {
    position: relative;
    background: var(--bg-card, #1e2128);
    color: var(--fg, #e6e6e6);
    border-radius: 10px;
    border: 1px solid var(--border, rgba(255,255,255,.08));
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    max-width: 640px; width: calc(100% - 32px);
    max-height: calc(100vh - 60px);
    overflow: auto;
    padding: 22px 26px 26px;
}
.modal-close {
    position: absolute; top: 10px; right: 10px;
    background: transparent; border: 0; cursor: pointer;
    color: var(--muted, #9aa);
    width: 30px; height: 30px; font-size: 16px;
    border-radius: 6px;
}
.modal-close:hover { background: rgba(255,255,255,.08); color: var(--fg); }
.modal-panel h3 { margin: 0 0 14px; font-size: 18px; }
.modal-panel h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.amodal-meta {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
    font-size: 13px; padding: 10px 12px;
    background: rgba(255,255,255,.03); border-radius: 6px;
    margin-bottom: 12px;
}
.amodal-meta > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amodal-lbl { color: var(--muted); margin-right: 4px; }

.amodal-fills, .amodal-clusters {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.amodal-fills td, .amodal-clusters td, .amodal-clusters th {
    padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.05);
}
.amodal-fills tr:last-child td, .amodal-clusters tr:last-child td { border-bottom: 0; }
.amodal-clusters th { font-weight: 600; color: var(--muted); text-align: left; }
.amodal-fills .num, .amodal-clusters .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ─── tabletools.js — hide button + drag & drop reorder ──────────────── */
.tt-hide {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}
.tt-hide:hover { color: var(--red); background: rgba(255,255,255,.05); }
[data-tt-dnd][data-tt-key] { cursor: grab; }
[data-tt-dnd][data-tt-key]:active { cursor: grabbing; }
/* Sortable's forceFallback drag doesn't suppress text selection on its own
   — mid-drag pointer moves sweep through table cells, turning everything
   blue. Disable selection globally while a drag is in progress (body gets
   .tt-drag-active in tabletools.js onStart/onEnd). */
body.tt-drag-active,
body.tt-drag-active * {
    user-select: none !important;
    -webkit-user-select: none !important;
}
/* Sortable.js classes — applied during drag:
   .tt-ghost    = the placeholder element shown at the drop position (where
                  the dragged item will land if released now). Acts as the
                  insertion indicator — the user sees the actual destination,
                  not just a 2px line.
   .tt-chosen   = the original element while it's being picked up (subtle
                  scale + outline).
   .tt-dragging = the floating element following the cursor (fallback drag
                  image since we set forceFallback: true). */
/* Insertion-point placeholder — has to be the loudest element on the page
   during a drag, since this is the only feedback the user has for "where
   will it land?". A bold dashed accent outline + a halo and a faint stripe
   pattern make it pop against any background; content of the placeholder is
   hidden so the user reads the SHAPE (size + position) instead of being
   distracted by the duplicated table contents. */
.tt-ghost {
    opacity: 0.55;
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}
/* Bigger placeholder (section/chart card) — Sortable shows the SHAPE of
   where the item will land, so blank it out and overlay a clear hint.
   Skipped on small rows (table TRs, KPI cards) where the hint wouldn't fit
   and the outline alone reads fine. */
.section.tt-ghost,
.chart-card.tt-ghost {
    position: relative;
    opacity: 1;
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    outline: 3px dashed var(--accent);
    outline-offset: -3px;
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent);
    border-radius: 6px;
}
.section.tt-ghost > *,
.chart-card.tt-ghost > * { visibility: hidden; }
.section.tt-ghost::after,
.chart-card.tt-ghost::after {
    content: '↓ Sem se umístí';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: .04em;
    text-shadow: 0 1px 2px rgba(0,0,0,.5);
    visibility: visible;
    pointer-events: none;
}
/* .tt-chosen — the originating row while Sortable is still deciding whether
   to drag (touch long-press window). Strong visual signal that the item is
   "armed" — accent outline + a slight grow so the user knows they can now
   move it. Without this, mobile users couldn't tell whether their long-press
   registered. */
.tt-chosen {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    transform: scale(1.01);
    transition: transform .12s, background .12s, outline-color .12s;
}
/* Fallback element (the floating clone that follows the cursor with
   forceFallback). Show the WHOLE source so the user sees exactly what
   they're moving; lower opacity + accent halo + heavy shadow signals "I'm
   being carried" without hiding the drop target underneath. The 1:1 cursor
   tracking is handled by tabletools.js (attachFallbackTracking) — Sortable's
   own positioning math is broken for items inside absolutely-positioned
   parents and was leaving the clone stuck near the source. */
.tt-dragging {
    opacity: 0.85 !important;
    border-radius: 8px !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 0 2px var(--accent) !important;
    cursor: grabbing !important;
    transition: none !important;
}

/* Dim the rest of the page slightly during a drag so the bright .tt-ghost
   insertion indicator dominates the user's visual focus. The masonry and
   KPI row stay readable but recede; the active drop zone (lit by the
   existing .tt-hidden-zone rule) and the .tt-ghost placeholder stand out. */
body.tt-drag-active main { filter: brightness(0.85) saturate(0.85); }
body.tt-drag-active .tt-ghost,
body.tt-drag-active .tt-hidden-zone [data-tt-hidden] { filter: none; }

/* Shared "Skryté …" drop zone styling used by every section that supports
   drag-to-hide. The zone is always rendered so it's a valid drop target —
   when no items are hidden it shows a dashed hint, otherwise the hidden
   items live inside at lower opacity. */
.tt-hidden-zone {
    margin-top: 4px;
    border-top: 1px dashed color-mix(in srgb, var(--border) 80%, var(--accent2));
}
.tt-hidden-zone .subgroup-header {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 6px 14px 2px;
    display: flex; align-items: center; gap: 6px;
    cursor: pointer;
    user-select: none;
}
.tt-hidden-zone .subgroup-header:hover { color: var(--text); }
.tt-hidden-zone .subgroup-header .group-toggle {
    font-size: 10px;
    transition: transform .15s;
    display: inline-block;
}
/* Collapsed: hide everything in the zone except the header so the user
   can still see + click the toggle. Tables (tbody children) and divs
   alike get hidden via display:none. During a Sortable drag we restore
   visibility so the zone stays a valid drop target — `display: revert`
   falls back to the UA default (block for div, table-row-group for tbody). */
.tt-hidden-zone.collapsed > :not(.subgroup-header) {
    display: none;
}
.tt-hidden-zone.collapsed .subgroup-header .group-toggle {
    transform: rotate(-90deg);
}
body.tt-drag-active .tt-hidden-zone.collapsed > :not(.subgroup-header) {
    display: revert;
}
.tt-hidden-zone .tt-hidden-icon { font-size: 13px; opacity: .8; }
.tt-hidden-zone [data-tt-hidden] {
    min-height: 36px;
    padding: 6px 10px 8px;
}
.tt-hidden-zone [data-tt-hidden] > *:not(.tt-hidden-empty) {
    opacity: 0.55;
    filter: grayscale(0.25);
    transition: opacity .15s;
}
.tt-hidden-zone [data-tt-hidden] > *:not(.tt-hidden-empty):hover {
    opacity: 0.85;
}
.tt-hidden-empty {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    padding: 10px;
    border: 1px dashed color-mix(in srgb, var(--border) 70%, var(--accent2));
    border-radius: 6px;
    background: color-mix(in srgb, var(--accent2) 4%, transparent);
}
/* Highlight the hidden zone while a drag is in progress so the drop target
   is obvious. Sortable doesn't add a class to the over-container directly,
   but it does mark `body` with .tt-drag-active when forceFallback is on. */
body.tt-drag-active .tt-hidden-zone [data-tt-hidden]:empty,
body.tt-drag-active .tt-hidden-zone [data-tt-hidden] {
    background: color-mix(in srgb, var(--accent) 6%, transparent);
}

/* Divider between the KPI hero row and the dashboard masonry. The KPI
   cards no longer support drag-to-hide (only drag-to-reorder), so a
   simple line carries the visual separation that the hide drop zone
   used to provide. */
.kpi-divider {
    margin: 10px 0 12px;
    border: 0;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent,
        var(--border) 8%,
        var(--border) 92%,
        transparent
    );
}
.tt-hidden-sep td {
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    font-size: 12px;
}
.tt-hidden-sep:hover td { color: var(--text); }

.section-btn {
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--text) 15%, transparent);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}
.section-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Drag handle — a dedicated element inside section-header (and any other
   reorderable container) that serves as the grab target. Visible at low
   opacity in idle state so touch users see the affordance; lights up on
   hover. The flash-toggle + count badge + section-jump links inside the
   header all stay clickable because drag is restricted to this element. */
.drag-handle {
    display: inline-flex;
    align-items: center;
    cursor: grab;
    color: var(--muted);
    opacity: 0.55;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
    margin-right: 4px;
    border-radius: 3px;
    user-select: none;
    transition: opacity .15s, color .15s, background .15s;
}
.drag-handle:hover {
    opacity: 1;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.drag-handle:active { cursor: grabbing; }
.drag-handle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    opacity: 1;
}
/* On touch devices (hover: none) the handle is always at full opacity so
   the user knows it's there — no hover hint to discover. */
@media (hover: none) {
    .drag-handle { opacity: 1; }
}
/* Keyboard-driven reorder mode: handle stays lit + accent-tinted while the
   user is moving with arrow keys. Distinct from :focus-visible so a casual
   Tab-through doesn't look like an active move. */
.drag-handle.kb-moving {
    opacity: 1;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Screen-reader-only — used by the #tt-announcer live region. */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
    margin: -1px !important;
}

/* ─── Help page ──────────────────────────────────────────────────────── */
.help-main {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 80px;
    align-items: start;
}
.help-toc {
    position: sticky;
    top: calc(var(--nav-h) + 16px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 13px;
    max-height: calc(100vh - var(--nav-h) - 32px);
    overflow-y: auto;
}
.help-toc h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 8px;
}
.help-toc ol {
    list-style: none;
    padding: 0;
    margin: 0;
}
.help-toc ol ol {
    padding-left: 14px;
    margin-top: 4px;
    font-size: 12px;
}
.help-toc li { margin: 4px 0; }
.help-toc a {
    color: var(--muted);
    display: block;
    padding: 3px 6px;
    border-radius: 4px;
    transition: background .15s, color .15s;
}
.help-toc a:hover {
    background: var(--surface2);
    color: var(--text);
    text-decoration: none;
}
.help-toc a.toc-active {
    background: var(--surface2);
    color: var(--accent);
    font-weight: 600;
}

.help-article {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 36px 40px;
    line-height: 1.55;
}
.help-hero h1 {
    font-size: 28px;
    color: var(--accent);
    margin-bottom: 8px;
}
.help-lead {
    font-size: 15px;
    color: var(--muted);
    margin-bottom: 24px;
}

.help-section {
    margin-top: 36px;
    scroll-margin-top: calc(var(--nav-h) + 16px);
}
.help-section h2 {
    font-size: 22px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
    margin-bottom: 14px;
}
.help-section h3 {
    font-size: 16px;
    color: var(--accent);
    margin: 22px 0 8px;
    scroll-margin-top: calc(var(--nav-h) + 16px);
}
.help-section p,
.help-section ul,
.help-section ol,
.help-section dl { margin-bottom: 12px; }
.help-section ul,
.help-section ol { padding-left: 22px; }
.help-section li { margin: 4px 0; }
.help-section code {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12.5px;
    color: var(--accent);
}
.help-section strong { color: var(--text); }
.help-section a { color: var(--accent); }

/* Help-specific table (slimmer than dashboard tables) */
.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 16px;
    font-size: 13px;
}
.help-table th,
.help-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.help-table th {
    color: var(--muted);
    font-weight: 600;
    background: var(--surface2);
}
.help-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

/* Callout boxes */
.help-callout {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 10px 14px;
    margin: 12px 0;
    font-size: 13px;
}
.help-callout--warn {
    background: color-mix(in srgb, var(--orange) 12%, transparent);
    border-left-color: var(--orange);
}

/* Figures with images */
.help-figure {
    margin: 16px 0 20px;
    text-align: center;
}
.help-figure img {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: block;
    margin: 0 auto;
}
.help-figure figcaption {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}
.help-figure--missing img { display: none; }
.help-figure--missing::before {
    content: "📷 (screenshot bude přidán později)";
    display: block;
    background: var(--surface2);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px 16px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

/* Inline color swatches for legend */
.help-swatch {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 4px;
    border: 1px solid var(--border);
}
.help-swatch--ready    { background: #7fb069; }
.help-swatch--growing  { background: #4caf9a; }
.help-swatch--tosow    { background: #e8a838; }
.help-swatch--cut      { background: #888; }
.help-swatch--withered { background: #e05252; }

/* Theme preview cards */
.help-theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 12px 0 20px;
}
.help-theme-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}
.help-theme-card strong { display: block; margin: 8px 0 4px; color: var(--text); }
.help-theme-card p { font-size: 12px; color: var(--muted); margin: 0; }
.help-theme-swatch {
    height: 48px;
    border-radius: 4px;
    border: 1px solid var(--border);
}
.help-theme-swatch--dark-green    { background: linear-gradient(135deg, #0d1610 0%, #172220 50%, #7fb069 100%); }
.help-theme-swatch--dark-blue     { background: linear-gradient(135deg, #0e1422 0%, #162236 50%, #5a8fad 100%); }
.help-theme-swatch--light         { background: linear-gradient(135deg, #f4f6f1 0%, #ffffff 50%, #3a8a22 100%); }
.help-theme-swatch--high-contrast { background: linear-gradient(135deg, #000 0%, #181818 50%, #ffd400 100%); }
.help-theme-swatch--fs25-native   { background: linear-gradient(135deg, #0a0d0a 0%, #141811 50%, #a0c213 100%); }

/* FAQ definition list */
.help-faq dt {
    font-weight: 600;
    color: var(--text);
    margin-top: 12px;
}
.help-faq dd {
    margin: 4px 0 0 0;
    padding-left: 14px;
    border-left: 2px solid var(--border);
    color: var(--muted);
    font-size: 13.5px;
}

.help-footer {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

/* Responsive — sidebar above content on narrow screens */
@media (max-width: 900px) {
    .help-main {
        grid-template-columns: 1fr;
    }
    /* Grid items default to min-content width; on a single column this
       lets the content (long URL in <code>, etc.) push the column past
       the viewport. min-width:0 lets the column shrink, then long-word
       wrapping inside code/pre absorbs any leftover overflow. */
    .help-toc, .help-article {
        position: static;
        max-height: none;
        min-width: 0;
    }
    .help-article { padding: 20px 18px 32px; }
    .help-article code, .help-article pre {
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    .help-article pre { overflow-x: auto; }
}

/* ─── Mobile / narrow viewports ───────────────────────────────────────────
   The dashboard is desktop-first but should remain usable on tablets and
   phones (a player checking status from the couch). Tighten paddings, allow
   the nav to wrap, scale KPI numbers down, and let the masonry's JS layout
   take care of dropping to 1 column (containerW < 360 + gap). */
@media (max-width: 700px) {
    main { padding: 8px; }
    .section-body { padding: 10px 12px; }
    .section-header { padding: 8px 12px; }
    .kpi-card { padding: 10px 12px; min-height: 76px; }
    .kpi-value { font-size: 22px; }
    .kpi-card.kpi-balance-card,
    .kpi-card.kpi-weather-card {
        flex-direction: column;
        align-items: stretch;
        padding-right: 12px;
    }
    .kpi-balance-card .kpi-balance-history,
    .kpi-weather-card .kpi-weather-forecast {
        border-left: 0;
        border-top: 1px solid var(--border);
        margin-left: 0; margin-top: 8px;
        padding-left: 0; padding-top: 6px;
        min-width: 0;
    }
    /* Mobile nav: hide the inline link strip and surface a hamburger ☰
       button instead. The links drop down as an absolute panel below the
       nav when toggled, so they no longer fight for space with the save
       chip + version + status. */
    .nav-burger { display: inline-flex; align-items: center; justify-content: center; }
    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-h); left: 0; right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 6px 16px rgba(0,0,0,.25);
        flex-direction: column;
        gap: 0;
        padding: 8px 0;
        z-index: 99;
    }
    .nav-links.open { display: flex; }
    .nav-links a {
        padding: 10px 20px;
        font-size: 14px;
        border-radius: 0;
        border-bottom: 1px solid transparent;
    }
    .nav-links a.active { border-left: 3px solid var(--accent); padding-left: 17px; }
    nav { padding: 0 10px; gap: 4px; }
    .nav-brand { font-size: 13px; margin-right: 6px; }
    /* Save chip + version chip eat space on mobile; trim them aggressively
       so the bell + time + status dot still fit. */
    .nav-save { max-width: 130px; font-size: 10px; margin-right: 6px; padding: 1px 6px; }
    .nav-version { font-size: 10px; margin-right: 4px; padding: 1px 4px; }
    .nav-status { gap: 4px; font-size: 11px; }
    .nav-updated { display: none; }   /* time is in the bell tooltip too */
}
@media (max-width: 480px) {
    .kpi-value { font-size: 18px; }
    .kpi-card { padding: 8px 10px; min-height: 64px; }
    .section-header { font-size: 10px; padding: 7px 10px; }
    table { font-size: 12px; }
    thead th, tbody td { padding: 5px 6px; }
    .nav-brand { display: none; }
    /* Help-page table wrappers — keep the table's normal table layout but
       give it its own horizontal scroll so a 4-column row of long Czech
       labels doesn't force the entire page to scroll. */
    .help-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    /* Fields table has 7 columns; on a 375 px viewport hide the two least-
       critical ones (ZP = parcel-number, identifiable via id; "Dní do
       sklizně" = visible in the per-field modal). */
    .sec-fields table thead th:nth-child(2),
    .sec-fields table tbody td:nth-child(2),
    .sec-fields table thead th:nth-child(7),
    .sec-fields table tbody td:nth-child(7) { display: none; }
    /* Vehicle names truncated mid-word on narrow screens — allow wrap to
       a 2nd line; the card grows but the user can read the full name. */
    .vc-name {
        white-space: normal;
        overflow-wrap: anywhere;
        line-height: 1.2;
    }
    /* Settings modal tab strip — let the row scroll horizontally so the
       last tab ("Sync") isn't clipped off the right edge. */
    .settings-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .settings-tabs::-webkit-scrollbar { display: none; }
    .settings-tabs button { flex-shrink: 0; }
}

/* ── Settings → Diagnostics panel ──────────────────────────────────────────── */
.diag-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}
.diag-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.diag-row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.diag-row-when { font-size: 12px; color: var(--text); }
.diag-note-txt {
    font-size: 11px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.diag-row-meta { font-size: 10px; color: var(--muted); }
.diag-rec-dot { color: #e5484d; }
.diag-err { color: #e5a23d; font-weight: 600; }
.diag-dl, .diag-del {
    flex: 0 0 auto;
    text-decoration: none;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
}
.diag-dl {
    display: inline-flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}
.diag-dl:hover { border-color: var(--accent); }

/* ── Mockup mode (hidden replay controls, revealed by the brand gesture) ───── */
#diag-mockup-tools { display: none; }
body.mockup-mode #diag-mockup-tools { display: block; }
.diag-play {
    flex: 0 0 auto;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
    display: none;
}
body.mockup-mode .diag-play { display: inline-flex; align-items: center; }
.diag-upload-btn { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.diag-upload-btn input[type="file"] { display: none; }

/* ── Replay banner — fixed bar while a recording plays as live data ────────── */
#replay-banner {
    position: fixed;
    left: 0; right: 0; top: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #b45309;
    color: #fff;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
#replay-banner[hidden] { display: none; }
.replay-banner-txt {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.replay-banner-stop {
    flex: 0 0 auto;
    background: rgba(0, 0, 0, .25);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-weight: 600;
}
.replay-banner-stop:hover { background: rgba(0, 0, 0, .4); }
body.replaying { padding-top: 34px; }

/* Playback transport in the banner */
#replay-banner { overflow-x: auto; }
.replay-ctl { display: flex; align-items: center; gap: 6px; flex: 2; min-width: 0; }
.replay-ctl button {
    flex: 0 0 auto;
    background: rgba(0, 0, 0, .22);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: 5px;
    padding: 2px 7px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.2;
}
.replay-ctl button:hover { background: rgba(0, 0, 0, .42); }
#rp-seek { flex: 1; min-width: 90px; accent-color: #fff; cursor: pointer; }
.replay-count { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-size: 12px; min-width: 52px; text-align: center; }

/* Frame inspector overlay */
#replay-inspector {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 2100;
    width: min(440px, 92vw);
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
#replay-inspector[hidden] { display: none; }
#replay-inspector .ri-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
}
#replay-inspector #ri-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
#replay-inspector #ri-body {
    margin: 0;
    padding: 10px;
    overflow: auto;
    font-size: 11px;
    line-height: 1.4;
    white-space: pre;
    font-family: ui-monospace, Consolas, "Courier New", monospace;
}

/* ─── Read-only viewer mode (relay) ──────────────────────────────────────────
   Set on <html>/<body> when GET /api/mode reports readOnly. Hide every control
   that would mutate state: hide/drag handles, per-section ⚙, replay controls,
   nav links to non-served pages, all settings tabs, the notification bell. The
   only thing a viewer can change is the colour theme. Layout (hidden items +
   order) is mirrored from the publisher; theme/language stay the viewer's own. */
.read-only .tt-hide,
.read-only .drag-handle,
.read-only .sec-cfg-btn,
.read-only .replay-ctl,
.read-only .nav-links,
.read-only #bell-slot,
.read-only [data-tab="diag"],
.read-only [data-panel="diag"],
.read-only [data-tab="sync"],
.read-only [data-panel="sync"],
.read-only [data-tab="relay"],
.read-only [data-panel="relay"] { display: none !important; }

/* Settings modal becomes theme-only: hide the tab bar, language block, and the
   notification action/status row. The theme panel is made the active one in
   openNotifModal() (the [hidden] mechanism handles visibility). */
.read-only #settings-tabs,
.read-only #lang-block,
.read-only #notif-modal .settings-actions,
.read-only #nt-status { display: none !important; }
