/* Greenhouse Roof Control – Kulturgewächshaus Fürth Style
   Black & white minimalist, GT Pressura-inspired (Space Grotesk).
   Desktop: 1280x720 base, scaled via JS (max 2x).
   Mobile (<768px): native responsive, no JS scaling. */

:root {
    --bg: #ffffff;
    --bg-rose: #f8e0e0;         /* Misty rose – subtle accent bg */
    --bg-sage: #e0ece4;         /* Sage green – tab bar accent */
    --surface: #ffffff;
    --surface-2: #f7f7f7;
    --text: #000000;
    --text-dim: #666666;
    --primary: #000000;          /* Black as primary */
    --safe: #3a8a3e;
    --warn: #d4900a;
    --danger: #ea384c;
    --slider-track: #ddd;
    --border: rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-pill: 100px;
    --font: 'Space Grotesk', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
@media (pointer: coarse) { * { cursor: none !important; } }

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* ========== App Layout ========== */
#app {
    display: flex;
    flex-direction: column;
    width: 1280px;
    height: 720px;
    background: var(--bg);
    transform-origin: top left;
}

/* ========== Top Bar ========== */
/* "Kulturgewächshaus Fürth - Dachsteuerung" | NORMAL | 20.6°C | 54% | 0.0 km/h | ☀ | 74°C */
#topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    background: #000;
    color: #fff;
    flex-shrink: 0;
    height: 44px;
}

#topbar-title {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.3px;
    white-space: nowrap;
    margin-right: 8px;
}

/* "Auto" / "Manuell" toggle + "STOPP" button bar */
#dashboard-action-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.btn-camera-toggle {
    padding: 6px 16px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1px;
    background: var(--primary);
    color: #fff;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}

.btn-camera-toggle:active {
    opacity: 0.7;
}

.btn-camera-toggle.streaming {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

#mode-toggle {
    display: flex;
    gap: 2px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 3px;
}

.mode-label input { display: none; }

.mode-btn {
    display: inline-block;
    padding: 5px 20px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    color: var(--text-dim);
    letter-spacing: -0.2px;
}

.mode-label input:checked + .mode-btn {
    background: #000;
    color: #fff;
}

.mode-label input:disabled + .mode-btn {
    opacity: 0.3;
    cursor: not-allowed;
}

#mode-disabled-info {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
}

/* "NORMAL" / "WIND" / "REGEN" / "STURM" / "OVERRIDE" / "EMERGENCY" badge */
#safety-indicator {
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.status-normal { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.7); }
.status-rain { background: #2196F3; color: #fff; }
.status-wind { background: var(--warn); color: #000; }
.status-storm { background: var(--danger); color: #fff; }
.status-override { background: #ff8c00; color: #fff; }
.status-emergency { background: var(--danger); color: #fff; }
.status-sensor-failure { background: #9c27b0; color: #fff; }
.status-warning { background: var(--warn); color: #000; }
.status-danger { background: var(--danger); color: #fff; }


/* "20.6°C" | "54%" | "0.0 km/h" | sun/rain | "74°C" sensor pills */
#sensor-summary {
    display: flex;
    gap: 8px;
    margin-left: auto;
    font-size: 17px;
}

.sensor-val {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-pill);
    white-space: nowrap;
    color: rgba(255,255,255,0.8);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.sensor-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
}

.sensor-icon-lg {
    width: 22px;
    height: 22px;
}

.sensor-icon-wifi {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    opacity: 0.85;
}

/* ========== PIN Numpad ========== */
#settings-pin-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    min-height: 100%;
    position: relative;
    z-index: 1;
}

.pin-container, .pin-modal-box {
    text-align: center;
    width: 340px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.pin-dots {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: 20px 0 12px;
}

.pin-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: background 0.1s, border-color 0.1s;
}

.pin-dot.filled {
    background: var(--text);
    border-color: var(--text);
}

.pin-error {
    color: var(--danger);
    font-size: 14px;
    min-height: 24px;
    margin-bottom: 6px;
}

.pin-numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0 auto;
}

.pin-key {
    padding: 16px 0;
    font-size: 26px;
    font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
}

.pin-key:active {
    background: var(--bg-sage);
}

.pin-key-fn {
    font-size: 22px;
    color: var(--text-dim);
}

.pin-key-enter {
    background: rgba(58,138,62,0.1);
    border-color: rgba(58,138,62,0.3);
}

.pin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* pin-modal-box inherits from shared .pin-container/.pin-modal-box rule */

/* ========== Tab Navigation ========== */
/* "Dashboard" | "Rekorde" | "Einstellungen" | "Log" */
#tab-nav {
    display: flex;
    background: var(--bg-sage);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 46px;
}

.tab {
    flex: 1;
    padding: 0 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    line-height: 38px;
    letter-spacing: -0.2px;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--text);
    border-bottom-color: #000;
    background: rgba(255,255,255,0.6);
}

/* ========== Tab Content ========== */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px;
    max-height: 630px; /* 720 - 44 topbar - 46 tabs */
}

.tab-content.active { display: flex; flex-direction: column; }

/* ========== Dashboard: Two-Column Layout ========== */
#tab-dashboard { padding: 10px 14px; gap: 0; position: relative; overflow: hidden; }

#dashboard-columns {
    display: flex;
    flex: 1;
    gap: 12px;
    min-height: 0;
    z-index: 1;
    position: relative;
}

#left-column {
    width: 50%;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    overflow-y: auto;
}

#right-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

/* ========== Chart Series Toggles ========== */
#chart-series-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-bottom: 6px;
}

.chart-toggle {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.chart-toggle input { display: none; }

.ct-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
    opacity: 0.35;
    transition: opacity 0.15s;
}

.chart-toggle input:checked ~ .ct-swatch {
    opacity: 1;
}

.chart-toggle input:checked ~ .ct-swatch + .ct-label,
.chart-toggle:has(input:checked) {
    color: var(--text);
}

/* ========== Custom Sliders ========== */
#sliders-area {
    display: flex;
    gap: 0;
    height: 230px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

#roof-controls {
    display: flex;
    flex: 1;
    gap: 0;
}

.cslider-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 4px 4px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    min-width: 62px;
    transition: opacity 0.3s;
}

.cslider-col:last-child { border-right: none; }

/* "ALLE" column with 0/25/50/75/100 buttons */
.cslider-all {
    background: #eef6ee;
    border-right: none;
    min-width: 44px;
    max-width: 60px;
}

/* "100" "75" "50" "25" "0" button stack in ALLE column */
.alle-buttons {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    justify-content: space-between;
    width: 100%;
    padding: 2px 0;
}

.alle-btn {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    padding: 1px 0;
    min-height: 0;
    transition: background 0.1s;
}

.alle-btn:hover {
    background: #e8e8e8;
}

.alle-btn:active {
    background: #000;
    color: #fff;
}

#sliders-area.sliders-disabled .alle-btn {
    color: #bbb;
    border-color: #e0e0e0;
    cursor: not-allowed;
    background: #f2f2f2;
}

.cslider-divider {
    width: 2px;
    background: #000;
    flex-shrink: 0;
}

/* "DACH 1" "DACH 2" ... "DACH 6" labels above sliders */
.cslider-label {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    margin-bottom: 1px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* "25%" current position + arrow indicator per slider */
.cslider-status {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 2px;
    height: 18px;
}

.cslider-pct {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.cslider-arrow {
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.cslider-col.state-opening .cslider-arrow {
    opacity: 1;
    color: var(--safe);
}

.cslider-col.state-closing .cslider-arrow {
    opacity: 1;
    color: var(--warn);
}

.cslider-col.state-error .cslider-arrow {
    opacity: 1;
    color: var(--danger);
}

/* Track: the vertical bar area, with padding for thumb overflow */
.cslider-track {
    flex: 1;
    position: relative;
    width: 100%;
    margin: 10px 0;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Thermometer fill: actual position, rises from bottom */
.cslider-fill {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 0%;
    background: #4caf50;
    border-radius: 4px;
    z-index: 1;
}

/* Draggable thumb: target position */
.cslider-thumb {
    position: absolute;
    left: 50%;
    bottom: 0%;
    transform: translate(-50%, 50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #000;
    border: 3px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2);
    z-index: 3;
    cursor: grab;
}

.cslider-thumb:active,
.dragging .cslider-thumb {
    cursor: grabbing;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.4), 0 3px 8px rgba(0,0,0,0.3);
}

/* Track background line */
.cslider-track::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 4px;
    transform: translateX(-50%);
    background: var(--slider-track);
    border-radius: 2px;
    z-index: 0;
}

/* "0" "25" "50" "75" "100" tick labels next to each slider */
.cslider-ticks {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 2px;
    width: auto;
    z-index: 0;
    pointer-events: all;
}

.cslider-ticks span {
    position: absolute;
    right: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    line-height: 1;
    cursor: pointer;
    transform: translateY(50%);
}

.cslider-ticks span[data-val="0"] { bottom: 0; transform: translateY(50%); }
.cslider-ticks span[data-val="25"] { bottom: 25%; transform: translateY(50%); }
.cslider-ticks span[data-val="50"] { bottom: 50%; transform: translateY(50%); }
.cslider-ticks span[data-val="75"] { bottom: 75%; transform: translateY(50%); }
.cslider-ticks span[data-val="100"] { bottom: 100%; transform: translateY(50%); }

/* Tick lines */
.cslider-ticks span::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    width: 6px;
    height: 1px;
    background: var(--text-dim);
    margin-right: 2px;
}

/* Disabled state – everything muted gray */
#sliders-area.sliders-disabled {
    background: #f2f2f2;
}

#sliders-area.sliders-disabled .cslider-col {
    background: #f2f2f2;
}

#sliders-area.sliders-disabled .cslider-all {
    background: #ececec;
}

#sliders-area.sliders-disabled .cslider-track {
    cursor: not-allowed;
}

#sliders-area.sliders-disabled .cslider-thumb {
    background: #bbb;
    border-color: #f2f2f2;
    cursor: not-allowed;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

#sliders-area.sliders-disabled .cslider-fill {
    background: #c8c8c8;
}

#sliders-area.sliders-disabled .cslider-arrow {
    color: #bbb;
}

#sliders-area.sliders-disabled .cslider-ticks span {
    color: #ccc;
    cursor: not-allowed;
}

#sliders-area.sliders-disabled .cslider-ticks span::before {
    background: #ccc;
}

#sliders-area.sliders-disabled .cslider-track::before {
    background: #e0e0e0;
}

#sliders-area.sliders-disabled .cslider-divider {
    background: #ccc;
}

/* State indicators handled by .cslider-arrow visibility */

/* ========== "STOPP" button (in mode bar, right-aligned) ========== */
.btn-estop {
    margin-left: auto;
    padding: 6px 16px;
    border: 2px solid var(--danger);
    background: var(--danger);
    color: #fff;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    white-space: nowrap;
    transition: opacity 0.15s;
}

.btn-estop:active {
    transform: scale(0.97);
}

.btn-estop:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* ========== Camera preview (left column, below sliders) ========== */
#camera-inline {
    flex-shrink: 0;
    margin-top: -5px;
    width: 100%;
}

.btn-camera {
    width: 100%;
    font-size: 13px;
    padding: 8px 12px;
    min-height: 36px;
}

#camera-inline #camera-wrapper {
    margin-top: 14px;
    background: #111;
    border-radius: var(--radius);
    overflow: hidden;
    width: 100%;
    border: 1px solid var(--border);
    position: relative;
    height: 310px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 2px;
}

#camera-inline #camera-wrapper.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cam-spin 0.8s linear infinite;
    z-index: 2;
}

@keyframes cam-spin {
    to { transform: rotate(360deg); }
}

#camera-inline #camera-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: relative;
    z-index: 1;
    min-width: 0;
    min-height: 0;
    background: #000;
}

/* Hidden slot on the dashboard preview (physical cam not connected). */
#camera-inline #camera-wrapper img.camera-stream.kamera-img-hidden {
    display: none;
}

/* With 3 connected cameras, put the 3rd preview centered in the bottom
 * row instead of left-aligned (matches the Kamera tab layout). */
#camera-inline #camera-wrapper.cams-3 img.camera-stream:nth-child(3) {
    grid-column: 1 / span 2;
    justify-self: center;
    width: calc(50% - 1px);
}

/* ========== Kamera Tab (fullscreen 2x2 grid) ========== */
#tab-kamera {
    padding: 10px 14px;
    overflow: hidden;
    position: relative;
}

#tab-kamera.active {
    display: flex;
    flex-direction: column;
}

#kamera-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
    min-height: 0;
    position: relative;
    z-index: 1;
}

/* Hidden when the physical camera isn't connected (set by JS). */
.kamera-tile.kamera-tile-hidden { display: none; }

/* With 3 connected cameras on desktop, center the 3rd tile in the bottom
 * row (otherwise it'd sit left-aligned under tile 1). Uses a 2-column span
 * with an inner width of one column so the tile keeps the same size. */
#kamera-grid.cams-3 .kamera-tile:nth-child(3) {
    grid-column: 1 / span 2;
}

#kamera-grid.cams-2 {
    grid-template-rows: 1fr;
}

#kamera-grid.cams-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.kamera-tile {
    position: relative;
    background: #111;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    /* Tiles match the 4:3 webcam feed so we don't get black letterbox bars
     * inside a wider cell. Height leads; width is derived and capped so
     * narrow cells shrink the tile instead of overflowing. */
    aspect-ratio: 4 / 3;
    height: 100%;
    width: auto;
    max-width: 100%;
    justify-self: center;
    align-self: center;
}

.kamera-tile img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: block;
}

.kamera-label {
    position: absolute;
    top: 6px;
    left: 8px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
}

/* ========== Chart Area (right column) ========== */
#chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.period-buttons { display: flex; gap: 4px; }

.period-btn {
    padding: 5px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    min-height: 28px;
    transition: all 0.15s;
}

.period-btn:hover { border-color: #000; color: #000; }

.period-btn.active {
    background: #000;
    color: #fff;
    border-color: #000;
}

.chart-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s;
}

.nav-btn:hover { border-color: #000; }

#chart-period-label {
    font-size: 12px;
    color: var(--text-dim);
    min-width: 80px;
    text-align: center;
    font-weight: 500;
}

.chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

#chart-no-data {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #bbb;
    pointer-events: none;
    z-index: 2;
}

/* ========== Log Window ========== */
/* "[29.03. 18:40] INFO: Motor 2 open: 0% -> 50%" log entries */
#tab-log {
    padding: 8px 14px;
    position: relative;
    overflow: hidden;
}
#tab-dashboard::before,
#tab-log::before,
#tab-webcam::before,
#tab-kamera::before,
#tab-about::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../img/kulturgewaechshaus.svg') center/cover no-repeat;
    filter: grayscale(1);
    opacity: 0.08;
    pointer-events: none;
    z-index: 0;
}
.log-scroll {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: auto;
}
.log-scroll::-webkit-scrollbar {
    width: 20px;
}
.log-scroll::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
}
.log-scroll::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.25);
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: padding-box;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    background: transparent;
    position: relative;
    z-index: 1;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    line-height: 1.5;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
    color: var(--text);
}

.log-entry { padding: 2px 0; }
.log-entry.WARNING { color: var(--warn); }
.log-entry.ERROR, .log-entry.CRITICAL { color: var(--danger); font-weight: 700; }
.log-entry.INFO { color: var(--text); }
.log-entry.DEBUG { color: var(--text-dim); }

/* ========== Rekorde ========== */
/* "Temperatur" / "Luftfeuchte" / "Wind" / "Niederschlag" records grid */
#tab-rekorde {
    padding: 8px 14px;
    position: relative;
    overflow: hidden;
}
#tab-rekorde::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../img/kulturgewaechshaus.svg') center/cover no-repeat;
    filter: grayscale(1);
    opacity: 0.08;
    pointer-events: none;
    z-index: 0;
}

#rekorde-grid {
    display: flex;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

#tab-rekorde h2 {
    font-size: 14px;
    margin: 0 0 4px;
    color: var(--text);
    letter-spacing: -0.3px;
}

.record-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

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

.record-label {
    font-size: 12px;
    color: var(--text);
    flex: 1;
    min-width: 0;
}

.record-value {
    font-size: 13px;
    font-weight: 700;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--text);
    text-align: right;
    white-space: nowrap;
}

.record-sub {
    width: 100%;
    font-size: 10px;
    color: var(--text-dim);
    text-align: right;
    line-height: 1.3;
}

.rekorde-footer {
    font-size: 10px;
    color: var(--text-dim);
    text-align: center;
    padding: 6px 0;
    position: relative;
    z-index: 1;
}

/* ========== Settings ========== */
/* "Klimasteuerung" / "Sicherheit" / "Motorkalibrierung" / "Datenbank" / "Passwort" */
#tab-settings {
    padding: 8px 14px;
    position: relative;
    overflow: hidden;
}
#tab-settings::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../img/kulturgewaechshaus.svg') center/cover no-repeat;
    filter: grayscale(1);
    opacity: 0.08;
    pointer-events: none;
    z-index: 0;
}

#settings-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
    background: var(--surface-2);
    padding: 8px 12px;
    border-radius: var(--radius);
    transition: background 0.3s;
    position: relative;
    z-index: 1;
}

#settings-actions.has-changes {
    background: var(--bg-rose);
}

#settings-grid {
    display: flex;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.settings-col {
    flex: 1;
    min-width: 0;
}

.settings-card {
    background: var(--surface);
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

#tab-settings h2 {
    font-size: 14px;
    margin: 8px 0 4px;
    color: var(--text);
    letter-spacing: -0.3px;
}

.settings-col:first-child > h2:first-child { margin-top: 0; }

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
}

.form-row:last-of-type { border-bottom: none; }

.form-row label { font-size: 12px; flex: 1; }

/* Number input with arrow buttons */
.num-input {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
}

.num-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.num-btn:hover { background: #e8e8e8; }
.num-btn:active { background: #000; color: #fff; }

.num-display {
    width: 60px;
    padding: 4px 2px;
    background: var(--surface-2);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    text-align: center;
    line-height: 24px;
    white-space: nowrap;
}

.num-input input[type="number"] {
    width: 60px;
    padding: 4px 2px;
    background: var(--surface-2);
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    text-align: center;
    -moz-appearance: textfield;
}

.num-input input[type="number"]::-webkit-inner-spin-button,
.num-input input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.num-input input[type="number"]:focus {
    outline: none;
    background: #fff;
}

.form-row input[type="password"],
.form-row select {
    width: 140px;
    padding: 6px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 13px;
}

.form-row input[type="password"]:focus,
.form-row select:focus {
    outline: none;
    border-color: #000;
}

.form-row input[type="password"] {
    text-align: left;
}

.settings-footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 11px;
    margin-top: 16px;
    padding: 8px 0;
}

/* ========== Buttons ========== */
.btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    min-height: 36px;
    transition: all 0.15s;
    letter-spacing: -0.2px;
}

.btn:hover { border-color: #000; }
.btn:active { transform: scale(0.97); }

.btn-primary { background: #000; color: #fff; border-color: #000; }
.btn-primary:hover { background: #222; }

.btn-warn { background: var(--warn); color: #000; border-color: var(--warn); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* ========== Calibration ========== */

.cal-motor-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
    padding: 4px 0 1px;
    border-top: 1px solid var(--border);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.cal-motor-header:first-child {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

/* (maintenance section removed - replaced by OVERRIDE + E-STOP) */

/* ========== Camera (full tab) ========== */
.camera-container { text-align: center; }

#camera-wrapper-full {
    margin: 12px 0;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

#camera-stream-full {
    width: 100%;
    max-height: 560px;
    object-fit: contain;
}

.camera-note { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

/* ========== Custom Modal Dialog ========== */
/* Replaces browser-native confirm()/alert() */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
#modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
#modal-text {
    font-size: 15px;
    color: var(--text);
    margin-bottom: 20px;
    line-height: 1.5;
}
#modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
#modal-buttons .btn {
    min-width: 100px;
    padding: 8px 16px;
    font-size: 14px;
}

/* ========== Login ========== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1280px;
    height: 720px;
    background: var(--bg-rose);
    transform-origin: top left;
}

.login-box {
    background: rgba(248,224,224,0.93);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    padding: 40px;
    border-radius: var(--radius);
    width: 380px;
    text-align: center;
    box-shadow: 0 4px 30px rgba(0,0,0,0.9);
}

.login-box h1 {
    font-size: 26px;
    margin-bottom: 4px;
    color: #000000;
    letter-spacing: -0.5px;
}

.login-subtitle { color: #000000; margin-bottom: 28px; font-size: 14px; }

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: #000;
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255,255,255,0.7);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 16px;
}

.form-group input:-webkit-autofill,
.form-group input:-webkit-autofill:hover,
.form-group input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 40px rgba(255,255,255,0.7) inset;
    -webkit-text-fill-color: var(--text);
}

.form-group input:focus {
    outline: none;
    border-color: #000;
}

.error-msg {
    background: #fef2f2;
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 13px;
}

.success-msg {
    background: #f0fdf4;
    color: var(--safe);
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 13px;
}

.login-box .btn { width: 100%; }

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
    html, body { overflow: auto; }

    #app {
        width: 100%;
        height: auto;
        min-height: 100vh;
        transform: none !important;
    }

    #topbar {
        flex-wrap: wrap;
        height: auto;
        padding: 6px 10px;
        gap: 6px;
    }

    #topbar-title { font-size: 13px; }

    #sensor-summary {
        gap: 6px;
        font-size: 11px;
        margin-left: 0;
        flex-wrap: wrap;
    }

    .sensor-val { padding: 2px 6px; font-size: 11px; }

    .tab-content { max-height: none; flex: none; }

    .tab {
        font-size: 12px;
        padding: 0 4px;
        letter-spacing: -0.3px;
    }

    /* Webcam gallery: let page scroll instead of internal scroll on mobile */
    #tab-webcam { overflow: visible; }
    #webcam-gallery { overflow: visible; flex: none; }

    /* Kamera tab: stack all cams vertically on mobile */
    #tab-kamera { overflow: visible; }
    #kamera-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, auto);
    }
    /* Override the desktop "center the 3rd tile" rule on mobile so tile 3
     * remains a single full-width row in the stack. */
    #kamera-grid.cams-3 .kamera-tile:nth-child(3) {
        grid-column: auto;
    }
    /* On mobile the grid has auto rows, so `height: 100%` would collapse.
     * Fall back to width-driven sizing (aspect-ratio still applies). */
    .kamera-tile {
        aspect-ratio: 4 / 3;
        height: auto;
        width: 100%;
        max-width: none;
    }

    #dashboard-columns {
        flex-direction: column;
        gap: 10px;
    }

    #left-column { width: 100%; max-width: none; min-width: 0; }
    #right-column { width: 100%; }

    #sliders-area { height: 180px; }

    .cslider-label { font-size: 9px; }
    .cslider-pct { font-size: 11px; }
    .cslider-col { min-width: 42px; padding: 4px 2px; }
    .cslider-thumb { width: 16px; height: 16px; }

    .chart-wrapper { height: 300px; flex: none; }
    #chart-controls { flex-wrap: wrap; }

    #settings-grid, #rekorde-grid { flex-direction: column; }

    .login-container {
        width: 100%;
        height: auto;
        min-height: 100vh;
        transform: none !important;
        padding: 20px;
    }

    .login-box { width: 100%; max-width: 380px; }
    .log-scroll { min-height: 400px; }
}

@media (max-width: 480px) {
    #topbar-title { font-size: 13px; }
}

/* --- Mock Debug Panel --- */
#mock-debug-panel {
    margin-top: 10px;
    border: 2px dashed var(--warn);
    border-radius: var(--radius);
    padding: 8px;
    background: #fffbe6;
    font-size: 12px;
}
.mock-debug-header {
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 1px;
    color: var(--warn);
    margin-bottom: 6px;
    text-align: center;
}
.mock-section-label {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-dim);
    margin: 6px 0 3px;
}
#mock-pos-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.mock-pos-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 6px;
    min-width: 48px;
}
.mock-pos-label { font-size: 10px; color: var(--text-dim); }
.mock-pos-value { font-weight: 700; font-size: 13px; }
.mock-pos-diff {
    font-size: 9px;
    color: var(--text-dim);
}
.mock-pos-diff.drift { color: var(--danger); font-weight: 600; }
.mock-sensor-toggles {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.mock-sensor-btn {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    background: #fff;
    color: var(--text);
    transition: background 0.15s, color 0.15s;
}
.mock-sensor-btn:hover { background: #f0f0f0; }
.mock-sensor-btn.disabled {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

/* Mock sensor override sliders */
.mock-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}
.mock-row label:first-child {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-dim);
    min-width: 50px;
}
.mock-row input[type="range"] {
    flex: 1;
    height: 16px;
    -webkit-appearance: none;
    appearance: none;
    background: #f0e6c0;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
}
.mock-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--warn);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.mock-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--warn);
    cursor: pointer;
    border: 2px solid #fff;
}
.mock-row span:last-child {
    font-family: monospace;
    font-weight: 700;
    font-size: 11px;
    min-width: 55px;
    text-align: right;
    color: var(--text);
}
#mock-rain-btn.active {
    background: #4488ff;
    color: #fff;
    border-color: #4488ff;
}

/* Three-dot menu */
#tab-menu-wrapper {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
}
#tab-menu-btn {
    padding: 0 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
#tab-menu-btn svg { opacity: 0.45; transition: opacity 0.15s; }
#tab-menu-btn:hover svg { opacity: 0.8; }
#tab-menu-dropdown {
    position: absolute;
    right: 0;
    bottom: 0;
    transform: translateY(100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 500;
    min-width: 170px;
    overflow: hidden;
}
.tab-menu-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: background 0.1s;
}
.tab-menu-item:hover { background: var(--surface-2); }
.tab-menu-item[data-action="logout"] { color: var(--danger); }
.tab-menu-item[data-action="logout"]:hover { background: #fef2f2; }

/* ========== About Page ========== */
#tab-about {
    position: relative;
    overflow: hidden;
}
#about-content {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 24px;
}
#about-content h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 2px;
}
#about-content .about-subtitle {
    font-size: 16px;
    color: var(--text-dim);
    margin-bottom: 16px;
}
#about-content h2 {
    font-size: 17px;
    font-weight: 700;
    margin-top: 14px;
    margin-bottom: 4px;
}
#about-content p, #about-content li {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
}
#about-content ol {
    padding-left: 18px;
    margin: 4px 0;
}
#about-content li { margin-bottom: 2px; }
.about-footer {
    margin-top: 24px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    text-align: center;
}
.about-footer p {
    color: var(--text-dim) !important;
    font-size: 14px !important;
    margin-bottom: 2px;
}

/* ========== Webcam Gallery ========== */
#tab-webcam {
    padding: 8px 10px;
    overflow: hidden;
    position: relative;
}

#webcam-gallery {
    flex: 1;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}
#webcam-gallery::-webkit-scrollbar { width: 6px; }
#webcam-gallery::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

.day-header {
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 6px 4px 4px;
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    z-index: 2;
    border-bottom: 1px solid var(--border);
    margin-top: 2px;
}
.day-header:first-child { margin-top: 0; }

.day-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 3px;
    padding: 3px 0;
}

.snapshot-thumb-wrap {
    position: relative;
    cursor: pointer;
    transition: opacity 0.1s;
}
.snapshot-thumb-wrap:active { opacity: 0.7; }

.snapshot-thumb {
    aspect-ratio: 1 / 1;
    object-fit: cover;
    width: 100%;
    display: block;
    background: #f0f0f0;
    border-radius: 2px;
}

.snapshot-cam-badge {
    position: absolute;
    top: 3px;
    left: 3px;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 3px;
    pointer-events: none;
}

/* Fullscreen overlay */
#webcam-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 2000;
}
#webcam-overlay-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
#webcam-overlay-caption {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.9);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    z-index: 2001;
    padding: 6px 16px;
    background: rgba(0,0,0,0.45);
    border-radius: 6px;
}
#webcam-overlay-caption:empty { display: none; }
.webcam-overlay-btn {
    position: absolute;
    top: 12px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: rgba(255,255,255,0.9);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 6px;
    z-index: 2001;
    display: flex;
    align-items: center;
    justify-content: center;
}
.webcam-overlay-btn:hover { background: rgba(0,0,0,0.7); }
#webcam-overlay-delete { left: 16px; }
#webcam-overlay-delete:hover { color: var(--danger); }
#webcam-overlay-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 32px;
    color: rgba(255,255,255,0.9);
    background: rgba(0,0,0,0.5);
    border: none;
    cursor: pointer;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 6px;
    z-index: 2001;
}
#webcam-overlay-close:hover { background: rgba(0,0,0,0.7); }

.webcam-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    border: none;
    color: rgba(255,255,255,0.9);
    font-size: 28px;
    padding: 16px 12px;
    cursor: pointer;
    border-radius: 6px;
    z-index: 2001;
    transition: background 0.15s;
}
.webcam-nav-btn:hover { background: rgba(0,0,0,0.7); }
.webcam-nav-prev { left: 12px; }
.webcam-nav-next { right: 12px; }
