/*
 * smartGH PWA: dark theme.
 *
 * Every color is a token below. Status colors (on, warning, danger) mean state only;
 * the chart series colors live in assets/charts.js (validated for this card surface).
 */
:root {
    color-scheme: dark;
    --bg: #0d1014;
    --surface: #161a21;          /* cards and chart surface */
    --surface-2: #1d222b;        /* inputs, nested rows */
    --border: #262c36;
    --border-strong: #353c48;
    --text: #e7e9ee;
    --muted: #9aa3b0;
    --faint: #6b7380;
    --accent: #338ced;
    --accent-hover: #4a9bf2;
    --on: #2fb344;
    --on-bg: rgba(47, 179, 68, 0.14);
    --warning: #d9a21b;
    --danger: #eb6263;
    --danger-bg: rgba(235, 98, 99, 0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---- Header ---- */
.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    padding-bottom: 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.app-header h1 { font-size: 22px; letter-spacing: -0.01em; }
.app-subtitle { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.board {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.board strong { color: var(--text); font-weight: 500; }

/* Right side of the header: Wi-Fi, board, firmware */
.header-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-left: auto;
    position: relative;
}

.wifi {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    cursor: default;
}
.wifi-bars { width: 20px; height: 16px; }
.wifi-bars rect { fill: var(--border-strong); }
.wifi[data-bars="1"] .wifi-bars rect:nth-child(-n+1),
.wifi[data-bars="2"] .wifi-bars rect:nth-child(-n+2),
.wifi[data-bars="3"] .wifi-bars rect:nth-child(-n+3),
.wifi[data-bars="4"] .wifi-bars rect:nth-child(-n+4) { fill: var(--on); }
.wifi[data-bars="1"] .wifi-bars rect:nth-child(1) { fill: var(--warning); }
.wifi[data-online="1"][data-bars="0"] .wifi-bars rect { fill: var(--muted); }   /* online, signal unknown */
.wifi[data-online="0"] { color: var(--warning); }

.fw { font-size: 14px; color: var(--muted); }
.fw summary {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    list-style: none;
    border-radius: 6px;
    padding: 2px 4px;
    margin-right: -4px;
}
.fw summary::-webkit-details-marker { display: none; }
.fw summary::after {
    content: "";
    width: 6px; height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    margin-left: 2px;
}
.fw[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.fw summary:hover { color: var(--text); }
.fw summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fw summary strong { color: var(--text); font-weight: 500; }

.fw-badge {
    font-size: 12px;
    font-weight: 500;
    color: #0d1014;
    background: var(--accent);
    border-radius: 999px;
    padding: 1px 8px;
}
.fw-badge-busy { background: var(--warning); }

.fw-panel {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 8px;
    z-index: 20;
    width: min(380px, calc(100vw - 32px));
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    color: var(--text);
    text-align: left;
}
.fw-panel > :first-child { margin-top: 0; }
.fw-panel > :last-child { margin-bottom: 0; }
.fw-versions {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
    margin: 0 0 12px;
}
.fw-versions dt { color: var(--muted); }
.fw-new { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.fw-new + .ota-notes { margin-top: 0; }
.fw-versions dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Sections and cards ---- */
.section { margin-top: 32px; }

.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 12px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.card-title { font-size: 15px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); margin: 0; }
.error-text { color: var(--danger); }

/* ---- Current readings ---- */
.readings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 12px;
}

.reading-group h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 10px;
}

.reading-group dl { margin: 0; display: grid; gap: 10px; }

.reading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.reading dt { color: var(--muted); font-size: 14px; }

.reading dd {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.readings-updated { margin: 10px 0 0; color: var(--faint); font-size: 13px; }

/* ---- Outputs ---- */
.outputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 12px;
}

.output-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.output-name { font-weight: 500; }

.control-button {
    min-width: 92px;
    height: 38px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--muted);
    font: 600 13px var(--font);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.control-button:hover { border-color: var(--faint); color: var(--text); }

.control-button.button-on {
    background: var(--on-bg);
    border-color: var(--on);
    color: #7fdc8e;
}

.control-button.button-pending { opacity: 0.65; }
.control-button:disabled, .update-btn:disabled, input:disabled { cursor: progress; }

/* ---- Automatic control ---- */
.automation {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 12px;
    margin-top: 12px;
}

.auto-control { display: grid; gap: 12px; }

.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.switch input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.temp-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.temp-control label { margin-right: auto; }

input[type="number"] {
    width: 72px;
    height: 34px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font: 500 15px var(--font);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

input[type="number"]:focus-visible,
select:focus-visible,
button:focus-visible,
input[type="submit"]:focus-visible,
input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.control-status { min-height: 1.5em; margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.control-status[data-kind="error"] { color: var(--danger); }
.control-status[data-kind="ok"] { color: var(--on); }

/* ---- Temperature alerts (with the controls) ---- */
.alerts-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 24px;
    margin-top: 4px;
}

.alerts-text { flex: 1 1 260px; }
.alerts-text .card-title { margin-bottom: 2px; }
.alerts-text p { margin: 0; font-size: 14px; }

.alerts-range {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.alerts-range label:not(:first-child) { margin-left: 10px; }
.alerts-card .notification-status { flex-basis: 100%; margin: 0; }
.alerts-card .notification-status:empty { display: none; }

/* ---- Buttons ---- */
.update-btn, .notification-btn, .btn-secondary {
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font: 600 14px var(--font);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.update-btn {
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
}

.update-btn:hover { border-color: var(--faint); }

.notification-btn {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    height: 38px;
    padding: 0 18px;
}

.notification-btn:hover { background: var(--accent-hover); }
.notification-btn:disabled { background: var(--surface-2); border-color: var(--border-strong); color: var(--faint); cursor: not-allowed; }
.notification-btn.enabled { background: var(--on-bg); border-color: var(--on); color: #7fdc8e; }

.btn-secondary { border: 1px solid var(--border-strong); background: transparent; color: var(--text); height: 38px; }

/* ---- Settings rows (firmware) ---- */
.notification-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.notification-row:last-of-type { border-bottom: none; }
.notification-row label { color: var(--muted); }
.notification-row > div { font-weight: 500; }
.notification-status { color: var(--muted); font-size: 14px; margin: 10px 0 0; }

#lastUpdate { color: var(--faint); font-size: 13px; margin-top: 24px; }

/* ---- Firmware update ---- */

.ota-progress {
    height: 8px;
    margin: 10px 0 4px;
    border-radius: 4px;
    background: var(--surface-2);
    overflow: hidden;
}

.ota-progress > div { height: 100%; background: var(--accent); transition: width 0.5s; }
.ota-warning { color: var(--warning); font-size: 14px; }
.ota-error { color: var(--danger); font-weight: 600; }
.ota-notes { white-space: pre-line; color: var(--muted); }

.ota-dialog {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0;
    max-width: 440px;
    width: calc(100% - 32px);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.ota-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.ota-dialog header { padding: 16px 20px 0; font-size: 17px; font-weight: 600; }
.ota-dialog .ota-dialog-body { padding: 8px 20px 4px; line-height: 1.5; }
.ota-dialog .ota-dialog-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 20px; }

/* ---- Board selector ---- */
select {
    height: 34px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font: 14px var(--font);
}

/* ---- History charts (assets/charts.js) ---- */
.history-ranges { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }

.history-ranges button {
    height: 32px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--muted);
    font: 500 13px var(--font);
    cursor: pointer;
}

.history-ranges button:hover { color: var(--text); }
.history-ranges button[aria-pressed="true"] { background: var(--surface-2); border-color: var(--faint); color: var(--text); }

.history-grid {
    display: grid;
    align-items: start;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
    gap: 12px;
    transition: opacity 0.2s;
}

.history-grid.loading { opacity: 0.5; }

.history-note {
    grid-column: 1 / -1;
    margin: 0;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 14px;
}

.chart-card {
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 14px 10px;
    color: var(--text);
    min-width: 0;
}

.chart-title { display: flex; align-items: baseline; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.chart-unit { font-size: 13px; font-weight: 400; color: var(--muted); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; flex: none; }
.chart-plot { position: relative; width: 100%; }

.chart-tip {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
}

.chart-tip-time { color: var(--muted); margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip-name { color: var(--muted); }
.chart-empty { color: var(--muted); font-size: 14px; margin: 24px 0; text-align: center; }

table.chart-summary {
    width: 100%;
    margin: 8px 0 0;
    border-collapse: collapse;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

table.chart-summary th {
    color: var(--faint);
    font-weight: 600;
    padding: 4px 6px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

table.chart-summary td { white-space: nowrap; padding: 4px 6px; text-align: right; color: var(--text); }
table.chart-summary td.chart-summary-name { text-align: left; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.history-status { font-size: 13px; color: var(--faint); margin-top: 10px; }

@media (max-width: 600px) {
    .container { padding: 16px 12px 40px; }
    .reading dd { font-size: 18px; }
}

/* ---- Accounts: sign-in and account pages, header link ---- */
.account-link {
    display: inline-block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
}
.account-link::before {
    content: "";
    display: inline-block;
    width: 8px; height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--on);
    vertical-align: 1px;
}
.account-link:hover { color: var(--text); text-decoration: underline; }
.account-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.auth-stack { width: min(400px, 100%); display: grid; gap: 16px; }
.auth-card { width: min(400px, 100%); display: grid; gap: 6px; padding: 24px; }
.auth-card h1 { font-size: 22px; margin: 0; }
.auth-card h2 { font-size: 17px; margin: 0 0 6px; }
.auth-card > p { margin: 0 0 10px; }
.auth-card label { margin-top: 8px; font-size: 14px; color: var(--muted); }
.auth-card input[type="text"],
.auth-card input[type="password"] {
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font: 15px var(--font);
}
.auth-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-card button { margin-top: 16px; justify-self: start; }
.auth-card form button { margin-top: 4px; }
.auth-error, .auth-note {
    margin: 4px 0 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}
.auth-error { color: var(--danger); background: var(--danger-bg); }
.auth-note { color: #7fdc8e; background: var(--on-bg); }
.field-hint { margin: 2px 0 0; font-size: 13px; color: var(--faint); }
.back-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--text); }
