/* ── CSS custom properties ──────────────────────────────────────────────── */
:root {
    --bg:              #999;
    --card-bg:         #EEE;
    --card-border:     #000;
    --card-head-border:#ccc;
    --text:            #222;
    --link:            #222;
    --muted:           #666;
    --range-bg:        #EEE;
    --stat-bg:         #f0f0f0;
    --stat-sep:        #bbb;
    --btn-bg:          #ddd;
    --btn-border:      #bbb;
    --btn-hover:       #bbb;
    --btn-active-bg:   #666;
    --btn-active-text: #fff;
    --btn-active-bdr:  #555;
    --input-bg:        #fff;
    --input-border:    #bbb;
    --load-bg:         #555;
    --load-hover:      #333;
    --load-disabled:   #aaa;
    --chart-text:      #444;
    --chart-grid:      rgba(0,0,0,0.1);
    --chart-grid-q:    rgba(0,0,0,0.22);
    --chart-grid-h:    rgba(0,0,0,0.4);
    --chart-line:      rgb(110,94,68);
    --chart-band:      rgba(110,94,68,0.18);
    --social-icon:     #444;
    --social-hover:    #000;
}
html.dark {
    color-scheme: dark;
    --bg:              #1c1c1e;
    --card-bg:         #2c2c2e;
    --card-border:     #48484a;
    --card-head-border:#48484a;
    --text:            #e5e5ea;
    --link:            #e5e5ea;
    --muted:           #8e8e93;
    --range-bg:        #2c2c2e;
    --stat-bg:         #3a3a3c;
    --stat-sep:        #48484a;
    --btn-bg:          #3a3a3c;
    --btn-border:      #636366;
    --btn-hover:       #48484a;
    --btn-active-bg:   #8e8e93;
    --btn-active-text: #fff;
    --btn-active-bdr:  #636366;
    --input-bg:        #3a3a3c;
    --input-border:    #636366;
    --load-bg:         #636366;
    --load-hover:      #8e8e93;
    --load-disabled:   #48484a;
    --chart-text:      #aeaeb2;
    --chart-grid:      rgba(255,255,255,0.1);
    --chart-grid-q:    rgba(255,255,255,0.22);
    --chart-grid-h:    rgba(255,255,255,0.4);
    --chart-line:      rgb(220,185,120);
    --chart-band:      rgba(180,160,120,0.28);
    --social-icon:     #aeaeb2;
    --social-hover:    #fff;
}

/* ── Reset & layout ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; margin: 0; }
body {
    font-family: sans-serif;
    font-size: 100%;
    background-color: var(--bg);
    color: var(--text);
    padding: 8px;
    gap: 6px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    margin: 0;
}

/* ── Card ───────────────────────────────────────────────────────────────── */
.card {
    flex: 1 1 0;
    min-height: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.15);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
h1 {
    margin: 0;
    font-size: 1.25rem;
    text-align: center;
    border-bottom: 1px solid var(--card-head-border);
    padding-bottom: 5px;
    flex-shrink: 0;
}

/* ── Live page: meter bar ───────────────────────────────────────────────── */
.meter-container {
    flex-shrink: 0;
    margin: 0 5%;
    width: 90%;
    height: 1.6em;
    background-color: #ddd;
    border: 1px solid #ccc;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}
.meter-bar {
    height: 100%;
    width: 0;
    transition: background-color 0.3s ease, width 0.3s ease;
}
.meter-optimum-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background-color: #777;
}
.value {
    flex-shrink: 0;
    text-align: center;
    font-size: 0.95em;
    line-height: 1.4;
}

/* ── Chart wrapper (shared) ─────────────────────────────────────────────── */
.chart-wrapper {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
}

/* ── History page: range picker ─────────────────────────────────────────── */
.range-bar {
    flex-shrink: 0;
    background: var(--range-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 7px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.9em;
}
.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.presets button {
    padding: 3px 10px;
    border: 1px solid var(--btn-border);
    border-radius: 14px;
    background: var(--btn-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.88em;
    transition: background 0.15s;
}
.presets button:hover { background: var(--btn-hover); }
.presets button.active {
    background: var(--btn-active-bg);
    color: var(--btn-active-text);
    border-color: var(--btn-active-bdr);
}
.range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto;
}
.range-inputs label { color: var(--muted); white-space: nowrap; }
.dt-part input[type="text"],
.dt-wrap input[type="text"] {
    padding: 3px 6px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9em;
    background: var(--input-bg);
    color: var(--text);
}
.dt-wrap { display: inline-flex; align-items: center; gap: 4px; }
.dt-part { position: relative; display: inline-block; }
.dt-part input[type="text"] { cursor: pointer; }
.dt-part input[type="date"] {
    position: absolute; inset: 0; opacity: 0; pointer-events: none;
    width: 100%; height: 100%;
}
#load-btn {
    padding: 4px 14px;
    background: var(--load-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s;
    white-space: nowrap;
}
#load-btn:hover    { background: var(--load-hover); }
#load-btn:disabled { background: var(--load-disabled); cursor: default; }
#status { font-size: 0.82em; color: var(--muted); white-space: nowrap; }

/* ── History page: statistics bar ──────────────────────────────────────── */
.stats-bar {
    flex-shrink: 0;
    display: none;
    gap: 1px;
    background: var(--stat-sep);
    border: 1px solid var(--stat-sep);
    border-radius: 6px;
    overflow: hidden;
}
.stat-item {
    flex: 1 0 0;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 6px;
    background: var(--stat-bg);
    gap: 1px;
}
.stat-label {
    font-size: 0.7em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.stat-value {
    font-family: monospace;
    font-size: 0.95em;
    font-weight: bold;
    color: var(--text);
    white-space: nowrap;
}

/* History page: drag-to-zoom overlay */
.chart-wrapper { cursor: default; }
.chart-wrapper.zoomable { cursor: crosshair; }
#sel-overlay {
    position: absolute;
    background: rgba(100,149,237,0.2);
    border: 1px solid cornflowerblue;
    pointer-events: none;
    display: none;
}

/* ── About page ─────────────────────────────────────────────────────────── */
.about-content {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 2px;
}
.about-content h2 {
    font-size: 1em;
    margin: 1em 0 0.3em;
    border-bottom: 1px solid var(--card-head-border);
    padding-bottom: 3px;
}
.about-content h2:first-child { margin-top: 0.2em; }
.about-content p, .about-content ul { margin: 0.4em 0; font-size: 0.9em; line-height: 1.5; }
.about-content ul { padding-left: 1.4em; }
.about-content li { margin: 0.3em 0; }
.about-content a { color: var(--link); }
.about-content a:hover { text-decoration: underline; }
.about-content .status-warn { color: var(--muted); font-style: italic; }

/* ── Email / info page ──────────────────────────────────────────────────── */
.subscribe-info {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 20px;
}
.subscribe-info p { margin: 0; }
.subscribe-addr {
    font-size: 1.1em;
    font-weight: bold;
}
.subscribe-addr a { color: var(--link); }
.subscribe-btn {
    display: inline-block;
    padding: 10px 28px;
    background: var(--load-bg);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 1em;
    transition: background 0.15s;
}
.subscribe-btn:hover { background: var(--load-hover); text-decoration: none; }
code {
    background: var(--stat-bg);
    border: 1px solid var(--stat-sep);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.95em;
}
.subscribe-note { font-size: 0.85em; color: var(--muted); max-width: 38em; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.78em;
    color: var(--text);
    flex-wrap: wrap;
}
footer a { color: var(--link); text-decoration: none; }
footer a:hover { text-decoration: underline; }
.footer-nav { display: flex; gap: 10px; align-items: center; }
.footer-nav a { white-space: nowrap; }
.footer-nav .sep { color: var(--muted); }
.social { display: flex; gap: 8px; align-items: center; }
.social a { display: flex; align-items: center; line-height: 1; }
.social svg { width: 18px; height: 18px; fill: var(--social-icon); transition: fill 0.15s; }
.social a:hover svg { fill: var(--social-hover); }

/* ── Theme toggle button ────────────────────────────────────────────────── */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    line-height: 1;
}
.theme-toggle svg { width: 18px; height: 18px; fill: var(--social-icon); transition: fill 0.15s; }
.theme-toggle:hover svg { fill: var(--social-hover); }
.icon-sun { display: none; }
html.dark .icon-moon { display: none; }
html.dark .icon-sun  { display: block; }

/* ── Notification toggle button ─────────────────────────────────────────── */
.notif-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    line-height: 1;
}
.notif-toggle svg { width: 18px; height: 18px; fill: var(--social-icon); transition: fill 0.15s, opacity 0.15s; opacity: 0.3; }
.notif-toggle:hover svg { fill: var(--social-hover); }
.notif-toggle.enabled svg { opacity: 1; }

/* ── Pause toggle button ────────────────────────────────────────────────── */
.pause-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    line-height: 1;
}
.pause-toggle svg { width: 18px; height: 18px; fill: var(--social-icon); transition: fill 0.15s; }
.pause-toggle:hover svg { fill: var(--social-hover); }
.pause-toggle.paused svg { fill: var(--social-hover); }

/* ── Debug/Preview toggle button ────────────────────────────────────────── */
.debug-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    line-height: 1;
}
.debug-toggle svg { width: 18px; height: 18px; fill: var(--social-icon); transition: fill 0.15s, opacity 0.15s; opacity: 0.3; }
.debug-toggle:hover svg { fill: var(--social-hover); opacity: 1; }
.debug-toggle.enabled svg { fill: #e67e00; opacity: 1; }
