/* ============================================================
   Pool Controller Dashboard
   Aesthetic: Deep aquatic instrument panel — luminous readouts
   against ocean-dark surfaces. Calm, precise, glanceable.
   ============================================================ */

:root {
    --bg-deep: #0a0e17;
    --bg-surface: #111827;
    --bg-card: #161d2e;
    --bg-card-hover: #1a2236;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-accent: rgba(255, 255, 255, 0.1);

    --text-primary: #e8ecf4;
    --text-secondary: rgba(200, 210, 228, 0.6);
    --text-muted: rgba(200, 210, 228, 0.35);

    --pool-hue: 195;
    --pool-color: hsl(var(--pool-hue), 80%, 55%);
    --pool-glow: hsla(var(--pool-hue), 90%, 50%, 0.15);
    --pool-glow-strong: hsla(var(--pool-hue), 90%, 50%, 0.3);

    --spa-hue: 25;
    --spa-color: hsl(var(--spa-hue), 85%, 58%);
    --spa-glow: hsla(var(--spa-hue), 90%, 50%, 0.15);
    --spa-glow-strong: hsla(var(--spa-hue), 90%, 50%, 0.3);

    --air-hue: 160;
    --air-color: hsl(var(--air-hue), 45%, 55%);
    --air-glow: hsla(var(--air-hue), 50%, 50%, 0.12);

    --toggle-on: #22c55e;
    --toggle-on-glow: rgba(34, 197, 94, 0.25);
    --toggle-off: #2a3244;
    --toggle-knob: #ffffff;

    --status-online: #22c55e;
    --status-offline: #ef4444;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 100px;

    --font-display: 'DM Mono', 'SF Mono', 'Fira Code', monospace;
    --font-ui: 'Outfit', -apple-system, sans-serif;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Subtle noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    pointer-events: none;
    z-index: 0;
}

/* ---- Layout ---- */

.dashboard {
    position: relative;
    z-index: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    min-height: 100dvh;
}

/* ---- Header ---- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.logo-accent {
    color: var(--pool-color);
    opacity: 0.8;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out);
}

.status-dot.online {
    background: var(--status-online);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-dot.offline {
    background: var(--status-offline);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
    animation: pulse-offline 2s ease-in-out infinite;
}

@keyframes pulse-offline {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---- Temperature Cards ---- */

.temps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.temp-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 28px 24px 24px;
    overflow: hidden;
    transition: border-color 0.3s var(--ease-out);
    animation: card-in 0.6s var(--ease-out) both;
}

.temp-card:nth-child(1) { animation-delay: 0.05s; }
.temp-card:nth-child(2) { animation-delay: 0.12s; }
.temp-card:nth-child(3) { animation-delay: 0.19s; }

@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.temp-card-inner {
    position: relative;
    z-index: 1;
}

.temp-glow {
    position: absolute;
    bottom: -40%;
    left: -20%;
    width: 140%;
    height: 100%;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.6s var(--ease-out);
    pointer-events: none;
}

.pool-glow { background: radial-gradient(ellipse, var(--pool-glow-strong), transparent 70%); }
.spa-glow { background: radial-gradient(ellipse, var(--spa-glow-strong), transparent 70%); }
.air-glow { background: radial-gradient(ellipse, var(--air-glow), transparent 70%); }

.temp-card.has-data .temp-glow {
    opacity: 1;
}

.temp-card.has-data.pool-card { border-color: hsla(var(--pool-hue), 60%, 40%, 0.25); }
.temp-card.has-data.spa-card { border-color: hsla(var(--spa-hue), 60%, 40%, 0.25); }
.temp-card.has-data.air-card { border-color: hsla(var(--air-hue), 40%, 40%, 0.2); }

.temp-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.pool-card .temp-label { color: var(--pool-color); }
.spa-card .temp-label { color: var(--spa-color); }
.air-card .temp-label { color: var(--air-color); }

.temp-reading {
    display: flex;
    align-items: baseline;
    gap: 2px;
    line-height: 1;
}

.temp-value {
    font-family: var(--font-display);
    font-size: 4.2rem;
    font-weight: 400;
    letter-spacing: -0.04em;
    color: var(--text-primary);
    transition: color 0.3s;
}

.temp-unit {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 2px;
    align-self: flex-start;
    margin-top: 0.5rem;
}

.temp-setpoint {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.setpoint-label {
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.setpoint-value {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-secondary);
}

/* ---- Controls Section ---- */

.section-title {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    animation: card-in 0.6s var(--ease-out) 0.25s both;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card);
    transition: background 0.2s;
}

.control-row:hover {
    background: var(--bg-card-hover);
}

.control-row + .control-row {
    border-top: 1px solid var(--border-subtle);
}

.control-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.control-name {
    font-size: 0.92rem;
    font-weight: 400;
    color: var(--text-primary);
}

/* ---- Toggle Switch ---- */

.toggle {
    position: relative;
    width: 52px;
    height: 30px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--toggle-off);
    cursor: pointer;
    transition: background 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
    flex-shrink: 0;
    outline: none;
}

.toggle:focus-visible {
    box-shadow: 0 0 0 2px var(--bg-deep), 0 0 0 4px var(--pool-color);
}

.toggle.on {
    background: var(--toggle-on);
    box-shadow: 0 0 16px var(--toggle-on-glow);
}

.toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: var(--toggle-knob);
    border-radius: 50%;
    transition: transform 0.3s var(--ease-spring);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle.on .toggle-knob {
    transform: translateX(22px);
}

.toggle.pending {
    opacity: 0.6;
    cursor: wait;
}

/* ---- Footer ---- */

.footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
    text-align: center;
}

.last-updated {
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

/* ---- Offline State ---- */

.dashboard.offline .temp-card {
    opacity: 0.5;
}

.dashboard.offline .toggle {
    pointer-events: none;
    opacity: 0.4;
}

/* ---- Responsive ---- */

@media (max-width: 680px) {
    .dashboard {
        padding: 16px 14px 32px;
        gap: 24px;
    }

    .temps-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .temp-card {
        padding: 22px 20px 20px;
    }

    .temp-value {
        font-size: 3.4rem;
    }

    .temp-unit {
        font-size: 1.1rem;
    }
}

@media (min-width: 681px) and (max-width: 860px) {
    .temps-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .temp-card:last-child {
        grid-column: 1 / -1;
    }
}
