/* styles.css — AUTOMAX PRO Configurator: the MPPT's Dashboard cards and the
   Solar Simulator's PV Curve page (at the end of this file).
   Colour tokens come from ../assets/tokens.css, the app chrome from
   ../assets/base.css; ../assets/modern.css is loaded AFTER this file and
   layers on top (translucent panels, HUD brackets, mono type), exactly as it
   does for the xFOC Configurator. The Telemetry table and the instrument rows
   below are copied from ../quadfoc/styles.css so the two tools look
   identical; the host-control rules (slider, presets, STOP, arm toggle) are
   left out — this device has none. The Plot card is copied from
   ../commsbox/styles.css so it matches the plot in that app. */

/* ------------------------------ */
/* Layout grid (Telemetry | MPPT) */
/* ------------------------------ */

.grid
{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: stretch;
}

#page-dashboard .grid,
#page-panel .grid { margin-bottom: 10px; }

/* Text and tabs of one mode only (data-kind): hidden while the tool shows the other (app.js) */
body[data-kind="mppt"]     [data-kind="solarsim"],
body[data-kind="solarsim"] [data-kind="mppt"] { display: none !important; }

/* Right card: the instrument rows fill the card */
.right-card
{
    display: flex;
    flex-direction: column;
}

@media (max-width: 900px)
{
    .grid { grid-template-columns: 1fr; }
}

.section-head
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.section-head .section-title
{
    margin-bottom: 0;
}

.mono
{
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ------------------------------ */
/* Catalog rows / groups with a showIf that is not met */
.form-row.form-row--hidden,
.form-group.form-group--hidden
{
    display: none !important;
}

/* Telemetry table (compact)      */
/* ------------------------------ */

.telem-table
{
    width: 100%;
    border-collapse: collapse;
    margin-top: 2px;
    font-size: 13px;
    table-layout: fixed;
}

.telem-table thead th
{
    padding: 3px 6px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted2);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.telem-table thead th:first-child
{
    width: 30%;
}

.telem-table td
{
    padding: 3px 6px;
    border-bottom: 1px solid #333333;
}

.telem-table tr:last-child td
{
    border-bottom: none;
}

.telem-table td:first-child
{
    color: var(--muted);
    width: 30%;
}

.telem-table td.mono
{
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.6px;
}

.telem-table td.muted-val
{
    font-size: 12px;
    color: var(--muted2);
    letter-spacing: 0.3px;
    transition: color 0.9s ease;
}

/* A 5 s min / max that is being pushed right now snaps to the accent colour, then fades back */
.telem-table td.muted-val.telem-hot
{
    color: var(--accent);
    transition: none;
}

/* Value | 5 s min | 5 s max columns beside the 30 % label column */
.telem-board th:nth-child(2),
.telem-board td:nth-child(2)
{
    width: 35%;
}

.telem-board th:nth-child(3),
.telem-board td:nth-child(3),
.telem-board th:nth-child(4),
.telem-board td:nth-child(4)
{
    width: 17.5%;
}

/* Flag pills: compact versions of the shared .status chip in the MPPT card header */
.telem-flags
{
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}

.telem-flags .status,
.section-head .status
{
    padding: 3px 8px;
    font-size: 10px;
}

.status.idle           { color: var(--muted2); }
.status.idle::before   { box-shadow: none; opacity: .5; }
.status.info           { color: var(--info); }
.status.accent         { color: var(--accent); }

:root                  { --info: #4aa3df; }
[data-theme="light"]   { --info: #1f6fb2; }

/* ------------------------------ */
/* MPPT card: stacked instrument rows */
/* ------------------------------ */

.control-panel
{
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-top: 4px;
    border: 1px solid var(--border);
    background: #222222;
    overflow: hidden;
}

.ctrl-row
{
    display: flex;
    flex: 1;
    max-height: 35px;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    min-height: 28px;
    transition: background 0.12s ease;
}

.ctrl-row:last-child
{
    border-bottom: none;
}

.ctrl-row--highlight
{
    background: rgba(245,184,46,0.04);
    max-height: 40px;
}

.ctrl-label
{
    font-size: 11px;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    color: var(--muted2);
    flex-shrink: 0;
}

.ctrl-value
{
    font-size: 13px;
    color: var(--text);
    letter-spacing: 0.5px;
    text-align: right;
}

.ctrl-value--large
{
    font-size: 22px;
    font-weight: 300;
    letter-spacing: -0.5px;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(245,184,46,0.12);
}

/* MPPT state: one colour per kind of state (set by telem.js) */
.mppt-state            { color: var(--muted2); text-shadow: none; }
.mppt-state.is-idle    { color: var(--muted); }
.mppt-state.is-blocked { color: var(--warn); }
.mppt-state.is-active  { color: var(--ok); }
.mppt-state.is-limit   { color: var(--info); }
.mppt-state.is-fault   { color: var(--err); }

/* Simulator state (PV Curve page), the same colours */
.sim-state            { color: var(--muted2); text-shadow: none; }
.sim-state.is-idle    { color: var(--muted); }
.sim-state.is-blocked { color: var(--warn); }
.sim-state.is-active  { color: var(--ok); }
.sim-state.is-fault   { color: var(--err); }

/* ------------------------------ */
/* Plot (plot.js, same card as ../commsbox) */
/* ------------------------------ */

.plot-card { margin-bottom: 10px; }

/* Series visibility chips (same look as plot.html) - clickable legend
   on the left of the plot card header. */

.series-checks
{
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-right: auto;
}

.series-check
{
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 2px 6px;
    border: 1px solid #333;
    background: #252525;
    transition: background 0.12s ease, border-color 0.12s ease, opacity 0.15s ease;
    user-select: none;
}

.series-check:hover
{
    background: #303030;
    border-color: #4a4a4a;
}

.series-check.unchecked
{
    opacity: 0.40;
}

.series-dot
{
    width: 8px;
    height: 8px;
    flex-shrink: 0;
}

.series-check input[type="checkbox"]
{
    display: none;
}

.series-label
{
    font-size: 10px;
    letter-spacing: 0.3px;
    color: var(--text);
    white-space: nowrap;
}

/* Actions live in the card header (.section-head) to give the chart
   the full card height. */
.plot-actions
{
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.plot-actions-right
{
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-compact
{
    padding: 2px 9px;
    height: 22px;
    font-size: 10px;
}

.plot-wrap
{
    padding: 4px;
    border: 1px solid var(--border);
    background: #1e1e1e;
    position: relative;
}

.plot-scroll
{
    overflow-x: auto;
    overflow-y: hidden;
}

/* Explicit height, matching the canvas height attribute (plot.js reads it as
   cssH). Left to auto, the height follows the canvas's intrinsic aspect ratio
   until the plot worker sizes the bitmap. The eight axis strips take 330 px,
   so the canvas keeps a minimum width and .plot-scroll scrolls sideways on a
   narrow screen. */
#telemPlot
{
    width: 100%;
    min-width: 720px;
    height: 330px;
    display: block;
    cursor: crosshair;
    background: #1e1e1e;
}

.plot-hint
{
    font-size: 10px;
    letter-spacing: 0.4px;
}

.subtle
{
    color: var(--muted2);
}

/* Overlays in the empty bottom corners of the canvas
   (under the left / right axis strips) */

.plot-overlay-left,
.plot-overlay-right
{
    position: absolute;
    bottom: 5px;
    z-index: 5;
}

.plot-overlay-left  { left: 20px; }
.plot-overlay-right { right: 20px; gap: 6px; }

.plot-overlay-right .toggle-label { font-size: 10px; }

/* Toggle switch (Full history) */
.ctrl-toggle
{
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.ctrl-toggle input[type="checkbox"]
{
    display: none;
}

.ctrl-toggle-track
{
    display: inline-block;
    width: 36px;
    height: 18px;
    background: #3a3a3a;
    border: 1px solid #4a4a4a;
    position: relative;
    transition: background 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
}

.ctrl-toggle-track::after
{
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: #777;
    transition: left 0.2s ease, background 0.2s ease;
}

.ctrl-toggle input[type="checkbox"]:checked ~ .ctrl-toggle-track
{
    background: rgba(92, 184, 92, 0.20);
    border-color: rgba(92, 184, 92, 0.50);
}

.ctrl-toggle input[type="checkbox"]:checked ~ .ctrl-toggle-track::after
{
    left: 20px;
    background: var(--ok);
}

/* Pill variant: smaller, rounded like the theme toggle */
.ctrl-toggle--pill .ctrl-toggle-track
{
    width: 30px;
    height: 16px;
    border-radius: 100px;
}

.ctrl-toggle--pill .ctrl-toggle-track::after
{
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.ctrl-toggle--pill input[type="checkbox"]:checked ~ .ctrl-toggle-track::after
{
    left: 16px;
}

.ctrl-toggle .toggle-label
{
    color: var(--muted);
    font-size: 11px;
}

/* Narrow screen: the header stacks (chips, then buttons) and the canvas
   scrolls sideways, so the overlays move out of its bottom corners - the
   mouse hint goes, the Full history toggle sits under the plot. */
@media (max-width: 900px)
{
    .plot-card .section-head { flex-wrap: wrap; }
    .plot-actions-right      { flex-wrap: wrap; }
    .plot-overlay-left       { display: none; }

    .plot-overlay-right
    {
        position: static;
        justify-content: flex-end;
        padding: 6px 4px 2px;
    }
}

/* ═══════════════════════════════════════════════
   Light Theme Overrides
   ═══════════════════════════════════════════════ */

[data-theme="light"] .control-panel { background: #f5f5f5; }
[data-theme="light"] .ctrl-row--highlight { background: rgba(154,98,0,0.04); }
[data-theme="light"] .telem-table td { border-bottom-color: #e6e6e6; }
[data-theme="light"] .plot-wrap { background: #e4e4e4; }
[data-theme="light"] #telemPlot { background: #e4e4e4; }
[data-theme="light"] .series-check { background: #e4e4e4; border-color: #d0d0d0; }
[data-theme="light"] .series-check:hover { background: #dedede; border-color: #bebebe; }
[data-theme="light"] .ctrl-toggle-track { background: #d0d0d0; border-color: #bebebe; }
[data-theme="light"] .ctrl-toggle-track::after { background: #f5f5f5; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
[data-theme="light"] .ctrl-toggle input[type="checkbox"]:checked ~ .ctrl-toggle-track { background: #1a9e3f; border-color: #1a9e3f; }
[data-theme="light"] .ctrl-toggle input[type="checkbox"]:checked ~ .ctrl-toggle-track::after { background: #f5f5f5; }

/* Dashboard tab sits on its own at the right end of the nav strip */
.nav-tab--end
{
    margin-left: auto;
    border-left: 1px solid var(--border);
}
[data-theme="light"] .nav-tab--end { border-left-color: #d0d0d0; }

/* Firmware page: the status lines carry whole sentences (a failed update says
   what to do next), so they wrap instead of being cut; on a narrow screen the
   step's button drops below its text. */
#page-firmware .step-sub
{
    white-space: normal;
    overflow-wrap: anywhere;
}
@media (max-width: 600px)
{
    #page-firmware .step-row { grid-template-columns: auto minmax(0, 1fr); }
    #page-firmware .step-row button
    {
        grid-column: 1 / -1;
        width: 100%;
    }
}

/* ═══════════════════════════════════════════════
   PV Curve page (panel.js)
   ═══════════════════════════════════════════════ */

/* Panel inputs | live readouts, the curve card full width below */
#page-panel .grid
{
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
}

@media (max-width: 900px)
{
    #page-panel .grid { grid-template-columns: 1fr; }
}

/* Input rows: label | range hint | control, same rhythm as the instrument rows */
.pv-form
{
    display: flex;
    flex-direction: column;
    margin-top: 4px;
    border: 1px solid var(--border);
    background: #222222;
}

.pv-row
{
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    padding: 4px 12px;
    border-bottom: 1px solid var(--border);
}

.pv-row:last-child { border-bottom: none; }

.pv-row .ctrl-label { flex: 0 0 132px; }

.pv-row .pv-hint
{
    flex: 1;
    font-size: 11px;
    color: var(--muted2);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv-row input[type="number"] { width: 110px; flex-shrink: 0; }
.pv-row select               { flex: 1; min-width: 0; }

.pv-row input[type="range"]
{
    flex: 1;
    min-width: 0;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #444;
    outline: none;
}

.pv-row input[type="range"]::-webkit-slider-thumb
{
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.pv-row input[type="range"]::-moz-range-thumb
{
    width: 14px;
    height: 14px;
    background: var(--accent);
    border: none;
    border-radius: 0;
    cursor: pointer;
}

.pv-row .pv-slider-val
{
    flex: 0 0 62px;
    text-align: right;
    font-size: 13px;
    color: var(--text);
}

/* Model figures under the inputs */
.pv-figures
{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin-top: 6px;
    border: 1px solid var(--border);
    background: #222222;
}

.pv-figure
{
    padding: 6px 12px;
    border-right: 1px solid var(--border);
    min-width: 0;
}

.pv-figure:last-child { border-right: none; }

.pv-figure--wide
{
    grid-column: 1 / -1;
    border-right: none;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.pv-figure .ctrl-label { display: block; }

.pv-figure .pv-figure-val
{
    font-size: 16px;
    color: var(--text);
    white-space: nowrap;
}

.pv-figure--wide .pv-figure-val { font-size: 13px; }

.pv-note
{
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted2);
}

.pv-note--offline { color: var(--warn); }

/* Output card: state, the min / max table, the derived figures and the flags as one
   stack. Only the table takes up spare height */
#page-panel .right-card .control-panel { flex: 0 0 auto; }
#page-panel .right-card .telem-table { margin: 8px 0; }
#page-panel .pv-flags { margin-top: 8px; justify-content: flex-start; flex-wrap: wrap; }
#page-panel .pv-derived-panel .ctrl-row:nth-last-child(-n+2) { border-bottom: none; }

/* Live readouts: two instrument columns under the state row */
.pv-readouts
{
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.pv-readouts .ctrl-row
{
    max-height: none;
    border-bottom: 1px solid var(--border);
}

.pv-readouts .ctrl-row:nth-child(odd) { border-right: 1px solid var(--border); }
.pv-readouts .ctrl-row:nth-last-child(-n+2) { border-bottom: none; }

/* Warnings: what the flags mean, in words */
.pv-warnings
{
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.pv-warnings:empty { display: none; }

.pv-warning
{
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.45;
    border: 1px solid var(--border);
    border-left: 3px solid var(--muted2);
    background: #222222;
    color: var(--text);
}

.pv-warning--err  { border-left-color: var(--err); }
.pv-warning--warn { border-left-color: var(--warn); }
.pv-warning--info { border-left-color: var(--info); }

/* Curve card */
.pv-curve-wrap
{
    border: 1px solid var(--border);
    background: #1b1b1b;
}

#pvCanvas
{
    display: block;
    width: 100%;
    height: 340px;
}

.pv-legend
{
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    font-size: 11px;
    color: var(--muted);
}

.pv-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.pv-legend i    { display: inline-block; width: 12px; height: 3px; }
.pv-legend i.pv-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Simulated-device controls (?sim=1) */
.pv-sim-box { margin-top: 6px; }
.pv-sim-box .pv-form { border-style: dashed; }

[data-theme="light"] .pv-form,
[data-theme="light"] .pv-figures,
[data-theme="light"] .pv-warning { background: #f5f5f5; }
[data-theme="light"] .pv-curve-wrap { background: #ffffff; }
[data-theme="light"] .pv-row input[type="range"] { background: #d0d0d0; }

/* ── PV Curve page layout: telemetry | controls, then the two plots ── */
#page-panel .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }

/* Controls card: panel settings | flags | irradiance */
.pv-controls
{
    display: flex;
    align-items: stretch;
    gap: 6px;
    margin-top: 4px;
}

.pv-controls-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pv-controls-main .pv-form { margin-top: 0; }
.pv-controls-main .pv-figures { flex: 1; }
.pv-controls .pv-row .ctrl-label { flex: 0 0 64px; }
.pv-controls .pv-row input[type="number"] { width: 96px; }

/* Flags, one under the other, left of the irradiance slider */
.pv-flag-col
{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--border);
    background: #222222;
}

.pv-flag-col .status
{
    padding: 3px 8px;
    font-size: 10px;
    white-space: nowrap;
    justify-content: flex-start;
}

/* Irradiance: vertical slider, 100 % at the top */
.pv-irr
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px 6px;
    min-width: 76px;
    border: 1px solid var(--border);
    background: #222222;
}

.pv-irr input[type="range"]
{
    flex: 1;
    min-height: 120px;
    width: 4px;
    writing-mode: vertical-lr;
    direction: rtl;
    -webkit-appearance: none;
    appearance: none;
    background: #444;
    outline: none;
    cursor: pointer;
}

.pv-irr input[type="range"]::-webkit-slider-thumb
{
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 12px;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.pv-irr input[type="range"]::-moz-range-thumb
{
    width: 22px;
    height: 12px;
    background: var(--accent);
    border: none;
    border-radius: 0;
    cursor: pointer;
}

.pv-irr-val { font-size: 13px; color: var(--text); white-space: nowrap; }

/* The two plots share a row when there is room for both */
.pv-plots
{
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    gap: 10px;
    align-items: stretch;
}

.pv-plots .plot-card { display: flex; flex-direction: column; }
.pv-plots .plot-card .section-head { flex-wrap: wrap; row-gap: 6px; }
.pv-plots .pv-curve-wrap { flex: 1; position: relative; min-height: 300px; }
.pv-plots #pvCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Beside the curve the time plot is narrower than its usual minimum: let it shrink
   instead of scrolling sideways (it still does on a phone, see .plot-scroll) */
@media (min-width: 1101px)
{
    .pv-plots #telemPlot { min-width: 0; }
}

@media (max-width: 1100px)
{
    .pv-plots { grid-template-columns: 1fr; }
}

@media (max-width: 900px)
{
    #page-panel .grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px)
{
    .pv-controls { flex-wrap: wrap; }
    .pv-controls-main { flex-basis: 100%; }
    .pv-flag-col { flex: 1; }
}

[data-theme="light"] .pv-flag-col,
[data-theme="light"] .pv-irr { background: #f5f5f5; }
[data-theme="light"] .pv-irr input[type="range"] { background: #d0d0d0; }

/* Plot buttons in a row of their own under the time plot */
.plot-actions--under { margin-top: 8px; display: flex; justify-content: flex-end; }
.plot-actions--under .plot-actions-right { flex-wrap: wrap; justify-content: flex-end; }
.pv-controls .pv-row .ctrl-label { flex: 0 0 auto; min-width: 64px; white-space: nowrap; }
