/* ═══════════════════════════════════════════════════════════════════
   AION RE-cast × GRIDQCA — frontend stylesheet
   Preserves GRIDQCA dark aesthetic; typography bumped up for accessibility.
   Base font: 15px (was 13px) → roughly 15% larger across the board.
   ═══════════════════════════════════════════════════════════════════ */

:root,
:root[data-theme="dark"] {
    --bg:  #0c0e12;
    --bg2: #13161c;
    --bg3: #1a1e26;
    --bg4: #222830;
    --tx:  #e0e4ea;
    --tx2: #8892a0;
    --tx3: #555e6e;
    --ac:  #00cc88;
    --bl:  #3080e0;
    --or:  #e89020;
    --rd:  #e04040;
    --cy:  #20b0d0;
    --vi:  #8866cc;
    --yl:  #d0b020;
    --mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    --sans: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --r: 6px;
    --brd: 1px solid rgba(255,255,255,.06);
    --focus: 2px solid #00cc88;
    --reg-tx: #00995e;
    --reg-bg: rgba(0,204,136,.05);
}

/* §39 — light-mode palette (WCAG AA against dark accents preserved) */
:root[data-theme="light"] {
    --bg:  #f4f6f8;
    --bg2: #ffffff;
    --bg3: #eef1f4;
    --bg4: #dde2e8;
    --tx:  #1a1f29;          /* AA on white */
    --tx2: #4a5360;
    --tx3: #6d7785;
    --ac:  #00754f;          /* darker green for contrast on light */
    --bl:  #1e5fad;
    --or:  #a55d0c;
    --rd:  #b81e1e;
    --cy:  #156c87;
    --vi:  #5a3f99;
    --yl:  #806800;
    --brd: 1px solid rgba(0,0,0,.10);
    --focus: 2px solid #00754f;
    --reg-tx: #006b3f;
    --reg-bg: rgba(0,117,79,.06);
}
:root[data-theme="light"] .ph .reg { color: var(--reg-tx); background: var(--reg-bg); border-color: rgba(0,117,79,.18); }
:root[data-theme="light"] code { background: #eef1f4; border-color: rgba(0,0,0,.08); }
:root[data-theme="light"] .bp { color: #fff; }
:root[data-theme="light"] .bo { color: #fff; }
:root[data-theme="light"] .toast { color: #fff; }
:root[data-theme="light"] .sb a.on { background: rgba(0,117,79,.10); border-left-color: var(--ac); color: var(--ac); }
:root[data-theme="light"] .modal { background: rgba(0,0,0,.45); }
:root[data-theme="light"] .sg { background: rgba(0,117,79,.18); color: #00754f; }
:root[data-theme="light"] .so { background: rgba(165,93,12,.18); color: #a55d0c; }
:root[data-theme="light"] .sr { background: rgba(184,30,30,.18); color: #b81e1e; }
:root[data-theme="light"] .s2 { background: rgba(30,95,173,.18); color: #1e5fad; }
:root[data-theme="light"] .sm { background: rgba(90,63,153,.18); color: #5a3f99; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    /* Accessibility: was 13px/1.5, now 15px/1.6 */
    font: 15px/1.6 var(--sans);
    color: var(--tx);
    background: var(--bg);
}

::-webkit-scrollbar       { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }

.app { display: flex; height: 100vh; }

/* ────────── Sidebar ────────── */
.sb {
    width: 250px; min-width: 250px;
    background: var(--bg2);
    border-right: var(--brd);
    overflow-y: auto;
    display: flex; flex-direction: column;
}
.sb-h { padding: 16px 18px; border-bottom: var(--brd); }
.sb-h h1 {
    font-size: 1rem;
    color: var(--ac);
    font-weight: 700;
    letter-spacing: .3px;
    line-height: 1.3;
}
.sb-h .brand-sep { color: var(--tx3); font-weight: 300; margin: 0 4px; }
.sb-h p { font-size: .72rem; color: var(--tx3); margin-top: 4px; }

.sb-s {
    font-size: .68rem;
    color: var(--tx3);
    padding: 14px 18px 6px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
}

.sb a {
    display: flex; align-items: center;
    gap: 9px;
    padding: 9px 18px;
    font-size: .92rem;        /* bumped */
    color: var(--tx2);
    text-decoration: none;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background .15s;
}
.sb a:hover { background: rgba(255,255,255,.03); color: var(--tx); }
.sb a.on {
    background: rgba(0,204,136,.06);
    color: var(--ac);
    border-left-color: var(--ac);
    font-weight: 600;
}
.sb a .n {
    font-size: .7rem;
    font-family: var(--mono);
    background: var(--bg4);
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: auto;
    color: var(--tx3);
}

.sb-foot {
    margin-top: auto;
    padding: 12px 18px 14px;
    border-top: var(--brd);
}
.sb-foot .clock {
    font-family: var(--mono);
    font-size: .82rem;
    color: var(--ac);
}
.sb-foot .sb-copy {
    font-size: .68rem; color: var(--tx3); margin-top: 3px;
}
.sb-foot .sb-user {
    font-size: .72rem; color: var(--tx2); margin-top: 8px;
}

/* ────────── Main content ────────── */
.mn { flex: 1; overflow-y: auto; }
.pg { display: none; padding: 24px 28px 48px; }
.pg.on { display: block; }

.ph { margin-bottom: 20px; padding-bottom: 14px; border-bottom: var(--brd); }
.ph h2 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.2px; }
.ph .sub { font-size: .88rem; color: var(--tx2); margin-top: 4px; }
.ph .reg {
    font-size: .76rem; color: #00995e;
    font-family: var(--mono);
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(0,204,136,.05);
    border-radius: var(--r);
    border: 1px solid rgba(0,204,136,.12);
    line-height: 1.6;
}

/* ────────── Form controls ────────── */
.fg { display: flex; flex-direction: column; gap: 3px; }
.fg label {
    font-size: .74rem;
    color: var(--tx2);
    font-weight: 600;
    letter-spacing: .3px;
}
.fg input, .fg select {
    background: var(--bg3);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--r);
    padding: 8px 10px;           /* bigger padding for accessibility */
    color: var(--tx);
    font-size: .88rem;            /* bumped */
    outline: none;
    font-family: inherit;
}
.fg input:focus, .fg select:focus { border-color: var(--ac); }
.fg input[type=number] { font-family: var(--mono); text-align: right; }

/* ────────── Buttons ────────── */
.btn {
    display: inline-flex; align-items: center;
    gap: 5px;
    padding: 8px 14px;           /* bigger for accessibility */
    border: none;
    border-radius: var(--r);
    font-size: .86rem;            /* bumped */
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: filter .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.bp  { background: var(--ac); color: #000; }
.bs  { background: var(--bg4); color: var(--tx); }
.bd  { background: var(--rd); color: #fff; }
.bb  { background: var(--bl); color: #fff; }
.bo  { background: var(--or); color: #000; }
.bsm { padding: 5px 10px; font-size: .78rem; }

.big-btn {
    padding: 11px 22px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: var(--r);
    cursor: pointer;
}
.fc-big-go { background: var(--ac); color: #000; }

.bar {
    display: flex; gap: 8px; margin-bottom: 14px;
    flex-wrap: wrap; align-items: flex-end;
}

/* ────────── Tables ────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }  /* bumped */
.tbl th {
    background: var(--bg3);
    font-size: .74rem;              /* bumped */
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--tx2);
    padding: 9px 12px;              /* bigger padding */
    text-align: left;
    border-bottom: var(--brd);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 1;
    font-weight: 700;
}
.tbl td {
    padding: 7px 12px;              /* bigger padding */
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.tbl tr:hover { background: rgba(255,255,255,.02); }
.tbl .m { font-family: var(--mono); font-size: .82rem; }
.tbl .r { text-align: right; }

.tw { overflow-x: auto; border: 1px solid rgba(255,255,255,.06); border-radius: var(--r); }
.th { max-height: 560px; overflow-y: auto; }

/* ────────── Status badges ────────── */
.st {
    display: inline-flex;
    font-size: .74rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
}
.sg { background: rgba(0,204,136,.14); color: #00cc88; }
.so { background: rgba(232,144,32,.14); color: #e89020; }
.sr { background: rgba(224,64,64,.14); color: #e04040; }
.s2 { background: rgba(48,128,224,.14); color: #3080e0; }
.sm { background: rgba(136,102,204,.14); color: #8866cc; }

/* ────────── KPI cards ────────── */
.kpi { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.kp {
    background: var(--bg2);
    border: var(--brd);
    border-radius: var(--r);
    padding: 14px 18px;
    min-width: 140px;
    flex: 1;
}
.kp .kl {
    font-size: .72rem;
    color: var(--tx3);
    text-transform: uppercase;
    letter-spacing: .6px;
    font-weight: 600;
}
.kp .kv {
    font-size: 1.55rem;
    font-weight: 700;
    font-family: var(--mono);
    margin: 4px 0;
}
.kp .kd { font-size: .74rem; color: var(--tx2); }

/* ────────── Panels ────────── */
.pn {
    background: var(--bg2);
    border: var(--brd);
    border-radius: var(--r);
    margin-bottom: 14px;
}
.pn-h {
    display: flex; justify-content: space-between; align-items: center;
    padding: 11px 16px;
    border-bottom: var(--brd);
}
.pn-t { font-size: .92rem; font-weight: 700; }       /* bumped */
.pn-h-meta { font-size: .78rem; color: var(--tx2); font-family: var(--mono); }
.pn-b { padding: 14px; }

/* ────────── Layout helpers ────────── */
.g2  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.g23 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }

.fc-hero {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 18px;
    background: var(--bg2);
    border: 1px solid rgba(0,204,136,.15);
    border-radius: var(--r);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.fc-hero-status {
    font-size: .82rem;
    color: var(--tx2);
    margin-left: 4px;
    max-width: 280px;
    line-height: 1.4;
}

/* ────────── Toast ────────── */
.toast {
    position: fixed;
    bottom: 24px; right: 24px;
    background: var(--ac);
    color: #000;
    padding: 12px 22px;
    border-radius: var(--r);
    font-size: .92rem;
    font-weight: 700;
    z-index: 999;
    opacity: 0;
    transition: opacity .25s;
    box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; }

/* ────────── Login modal ────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.82);
    z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(6px);
}
.modal-body {
    background: var(--bg2);
    padding: 32px 36px;
    border-radius: 10px;
    min-width: 340px;
    max-width: 420px;
    border: 1px solid rgba(0,204,136,.15);
    box-shadow: 0 14px 60px rgba(0,0,0,.6);
}
.modal-body h2 { font-size: 1.2rem; margin-bottom: 4px; }
.modal-body .muted { font-size: .86rem; color: var(--tx2); margin-bottom: 20px; }
.modal-body .fg { margin-bottom: 14px; }
.modal-body .btn { width: 100%; justify-content: center; padding: 11px; font-size: .95rem; }
.modal-body .err {
    color: var(--rd);
    font-size: .84rem;
    min-height: 20px;
    margin-bottom: 10px;
}

/* ────────── Utility ────────── */
.muted   { color: var(--tx2); }
.small   { font-size: .82rem; }
code {
    font-family: var(--mono);
    font-size: .88em;
    background: var(--bg3);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,.05);
}

/* ────────── Responsive ────────── */
@media (max-width: 880px) {
    .sb { width: 200px; min-width: 200px; }
    .g2, .g23 { grid-template-columns: 1fr; }
    .fc-hero { flex-direction: column; align-items: stretch; }
    .pg { padding: 16px 18px 36px; }
    .ph h2 { font-size: 1.2rem; }
}

/* ────────── Smart Import ────────── */
.drop-zone {
    border: 2px dashed rgba(255,255,255,.15);
    border-radius: 10px;
    padding: 44px 24px;
    text-align: center;
    cursor: pointer;
    background: var(--bg2);
    transition: all .18s;
}
.drop-zone:hover,
.drop-zone-active {
    border-color: var(--ac);
    background: rgba(0,204,136,.04);
}
.dz-icon {
    font-size: 48px;
    margin-bottom: 8px;
    opacity: .82;
}
.dz-headline {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tx);
}
.dz-subtext {
    font-size: .82rem;
    color: var(--tx2);
    margin-top: 4px;
}

.log-pane {
    font-family: var(--mono);
    font-size: .82rem;
    max-height: 320px;
    overflow-y: auto;
    white-space: pre-wrap;
    background: var(--bg3);
    padding: 12px 14px;
    border-radius: var(--r);
    border: 1px solid rgba(255,255,255,.05);
    color: var(--tx2);
    line-height: 1.55;
}
.log-pane div {
    padding: 1px 0;
}
.log-pane .log-ok { color: var(--ac); }
.log-pane .log-warn { color: var(--or); }
.log-pane .log-err { color: var(--rd); }
.log-pane strong { color: var(--tx); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════
   v1.0.6 additions: sidebar toolbar, theme toggle, a11y
   ═══════════════════════════════════════════════════════════════════ */

/* §38 — keyboard focus rings (visible-only) */
*:focus { outline: none; }
*:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}
.btn:focus-visible { outline-offset: 3px; }

/* §38 — skip-to-main link, only visible on focus */
.a11y-skip {
    position: absolute;
    left: -9999px;
    top: 6px;
    background: var(--ac); color: #000;
    padding: 8px 14px; border-radius: 4px;
    font-weight: 700; font-size: .9rem;
    z-index: 10001;
}
.a11y-skip:focus { left: 6px; }

/* §38 — reduced-motion respect */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* Sidebar footer toolbar (theme + language + signout) */
.sb-toolbar {
    display: flex; align-items: center; gap: 6px;
    margin-top: 10px; flex-wrap: wrap;
}
.sb-toolbar select {
    background: var(--bg3);
    color: var(--tx);
    border: 1px solid rgba(128,128,128,.2);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: .78rem;
    font-family: inherit;
}
.theme-toggle { font-size: 1rem; padding: 4px 10px; }

/* §31 — plant detail tweaks */
#pg-plant_detail .kp .kv { font-size: 1.4rem; }

/* §40 — schedule editor */
#schedTb input[type=text],
#schedTb .sched-cron {
    background: var(--bg3); color: var(--tx);
    border: 1px solid rgba(128,128,128,.2);
    padding: 5px 8px; border-radius: 4px;
    font-size: .85rem;
}

/* §32 — backtest chart layout helpers (chart already responsive) */

/* §6 — config-page grid spacing */
#pg-config .pn-b .fg { margin-bottom: 0; }


/* ============================================================================
   3D Map page (Cesium)
   ========================================================================= */
#pg-map3d.on { padding: 0; }                  /* full-bleed */
#map3dContainer {
    position: relative;
    width: 100%;
    height: calc(100vh - 84px);
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}
#map3dContainer .cesium-viewer { width: 100%; height: 100%; }
/* hide Cesium's default chrome we don't need */
#map3dContainer .cesium-viewer-fullscreenContainer,
#map3dContainer .cesium-viewer-vrContainer,
#map3dContainer .cesium-viewer-animationContainer,
#map3dContainer .cesium-viewer-timelineContainer,
#map3dContainer .cesium-viewer-bottom { display: none !important; }
#map3dContainer .cesium-viewer-toolbar { top: 8px; right: 8px; }
#map3dContainer .cesium-viewer .cesium-widget-credits { display: none !important; }

#map3dOverlay {
    position: absolute; top: 12px; left: 12px;
    background: rgba(8,14,24,0.78);
    border: 1px solid rgba(0,204,136,0.28);
    color: #e6f5ec;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: .85rem;
    z-index: 10;
    backdrop-filter: blur(6px);
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#map3dOverlay .m3-h { font-weight: 600; letter-spacing: .04em; margin-bottom: 4px; }
#map3dOverlay .m3-sub { font-size: .72rem; color: var(--tx2); letter-spacing: .06em; text-transform: uppercase; }

#map3dLoading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #00cc88; font-size: .9rem; letter-spacing: .12em;
    text-transform: uppercase;
    z-index: 5;
    background: radial-gradient(closest-side, rgba(0,0,0,0.6), rgba(0,0,0,0.9));
}
