:root {
    --bg-dark: #050608;
    --card-bg: rgba(20, 25, 30, 0.4);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-border-hover: rgba(255, 255, 255, 0.2);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.5);

    --accent-green: #00ff9d;
    --accent-red: #ff3366;
    --accent-blue: #00d2ff;

    --glass-blur: blur(20px);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);

    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;

    --padding-outer: 2vh 2vw;
    --gap-grid: 1.5vh;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    /* Kiosk feel */
}

body {
    background-color: var(--bg-dark);
    font-family: var(--font-main);
    color: var(--text-primary);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    /* ZERO SCROLL ENFORCER */

    /* Live Background (Noise + Gradient) */
    background:
        radial-gradient(circle at 15% 15%, rgba(0, 210, 255, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(0, 255, 157, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(20, 20, 30, 1) 0%, #000 100%);
    background-size: cover;
}

/* Optional Noise overlay */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

.dashboard-container {
    position: relative;
    z-index: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: var(--padding-outer);
}

/* Header Compact */
.header {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2vh;
    padding-bottom: 0;
    border-bottom: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo h1 {
    font-size: 2.5vh;
    font-weight: 700;
    letter-spacing: -0.5px;
    text-transform: uppercase;
}

.accent {
    color: var(--accent-blue);
}

.pulse-indicator {
    width: 1.2vh;
    height: 1.2vh;
    background-color: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 15px var(--accent-green);
    animation: pulse 3s infinite ease-in-out;
}

.header-stats {
    display: flex;
    gap: 3vw;
}

.stat-item {
    display: flex;
    align-items: center;
    /* Inline stats for compact header */
    gap: 0.8rem;
}

.stat-item .label {
    font-size: 1.5vh;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-item .value {
    font-size: 2vh;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

/* Main Grid - The Magic of Zero Scroll */
.grid-container {
    flex: 1;
    display: grid;
    /* Auto-fit columns, min 250px */
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    /* Rows stretch to fill available height */
    grid-auto-rows: 1fr;
    gap: var(--gap-grid);
    min-height: 0;
    /* Crucial for flex child scrolling/sizing */
}

/* Card Styling Glassmorphism 2.0 */
.device-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--glass-shadow);
    border-radius: 20px;
    padding: 2.5vh 2vw;

    display: flex;
    flex-direction: column;
    justify-content: space-between;

    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.device-card:hover {
    background: rgba(30, 35, 45, 0.6);
    border-color: var(--card-border-hover);
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    z-index: 10;
    /* Bring to front */
}

/* Status Colors & Glow */
.status-indicator {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 4px;
    background: var(--text-secondary);
    opacity: 0.5;
    transition: all 0.5s ease;
}

.device-card.status-on .status-indicator {
    background: var(--accent-green);
    box-shadow: 0 0 20px var(--accent-green);
    opacity: 1;
}

.device-card.status-off .status-indicator {
    background: var(--accent-red);
    box-shadow: 0 0 20px var(--accent-red);
    opacity: 1;
}

/* Card Content layout */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.device-name {
    font-size: 2.2vh;
    /* Responsive font based on height */
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5vh;
}

.device-meta {
    font-size: 1.4vh;
    color: var(--text-secondary);
    font-family: 'Outfit', monospace;
}

.status-badge {
    font-size: 1.2vh;
    font-weight: 800;
    padding: 0.5vh 1vh;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-on .status-badge {
    background: rgba(0, 255, 157, 0.15);
    color: var(--accent-green);
}

.status-off .status-badge {
    background: rgba(255, 51, 102, 0.15);
    color: var(--accent-red);
}

.card-metrics {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: auto;
    /* Push to bottom */
}

.metric-group {
    display: flex;
    flex-direction: column;
}

.metric-label {
    font-size: 1.1vh;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5vh;
}

.metric-value {
    font-size: 2vh;
    font-weight: 500;
    color: var(--text-primary);
}

.rssi-value {
    font-variant-numeric: tabular-nums;
}

/* Footer Compact */
.footer {
    flex: 0 0 auto;
    margin-top: 1vh;
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 1.2vh;
    opacity: 0.6;
}

/* Animations */
@keyframes pulse {
    0% {
        transform: scale(0.9);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
}

/* Responsive adjustments for very small screens or phones */
@media (max-width: 600px) {
    .dashboard-container {
        padding: 1rem;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        /* Allow scroll on phones logic */
    }

    body {
        overflow-y: auto;
        /* Phone needs scroll often */
    }

    .grid-container {
        grid-template-columns: 1fr;
        /* Single column */
        grid-auto-rows: min-content;
        /* Auto height */
    }

    .device-card {
        min-height: 120px;
    }
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-dark);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 2vh 2vw;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 2.5vh;
    font-weight: 700;
}

.modal-close {
    font-size: 3vh;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.modal-close:hover {
    opacity: 1;
    color: var(--accent-red);
}

.modal-body {
    padding: 2vh 2vw;
    overflow-y: auto;
}

.modal-section {
    margin-bottom: 3vh;
}

.modal-section h3 {
    font-size: 1.5vh;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 1vh;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0.5vh;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5vh;
    max-height: 20vh;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    font-size: 1.4vh;
    padding: 0.5vh;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.history-item span.ts {
    font-family: monospace;
    opacity: 0.7;
}

.history-item span.val {
    font-weight: 600;
}

#modal-raw {
    background: #000;
    padding: 1vh;
    border-radius: 8px;
    font-family: monospace;
    font-size: 1.2vh;
    color: var(--accent-green);
    white-space: pre-wrap;
    max-height: 15vh;
    overflow-y: auto;
}

/* DEBUG CONSOLE */
.debug-console {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30vh;
    background: rgba(10, 10, 10, 0.95);
    border-top: 2px solid var(--accent-green);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 200;
    display: flex;
    flex-direction: column;
    font-family: 'Courier New', monospace;
}

.debug-console.active {
    transform: translateY(0);
}

.debug-header {
    background: #000;
    color: var(--accent-green);
    padding: 0.5vh 2vw;
    font-size: 1.2vh;
    display: flex;
    justify-content: space-between;
    font-weight: bold;
}

.close-console {
    cursor: pointer;
}

.debug-output {
    flex: 1;
    overflow-y: auto;
    padding: 1vh 2vw;
    color: #ccc;
    font-size: 1.2vh;
}

.log-line {
    margin-bottom: 2px;
}

.log-line.system {
    color: var(--accent-blue);
}

.log-line.error {
    color: var(--accent-red);
}

.log-line.success {
    color: var(--accent-green);
}

/* Card Graph Area */
.card-graph {
    flex: 1;
    width: 100%;
    position: relative;
    overflow: hidden;
    margin: 1vh 0;
    opacity: 0.5;
    transition: opacity 0.3s;
}

.device-card:hover .card-graph {
    opacity: 0.8;
}

/* Enhancing sparkline stroke */
.sparkline polyline {
    vector-effect: non-scaling-stroke;
    stroke-width: 2px;
}

/* Absolute Graph Styling (Premium Look) */
.card-graph {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60%;
    /* Occupy bottom 60% */
    margin: 0;
    opacity: 0.4;
    /* Subtle background */
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.device-card:hover .card-graph {
    opacity: 0.6;
}

/* Ensure text stays on top */
.card-header-row,
.card-metrics,
.status-indicator {
    position: relative;
    z-index: 2;
}

/* LOGIN CUSTOMIZATION */

.login-subtitle {
    margin-top: 0.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 2px;
    opacity: 0.8;
    text-transform: uppercase;
    font-weight: 300;
    border-top: 1px solid var(--card-border);
    padding-top: 0.5rem;
    width: 80%;
    /* underline effect */
}

/* Power On Animation */
@keyframes flicker {
    0% {
        opacity: 0.1;
    }

    5% {
        opacity: 0.5;
    }

    10% {
        opacity: 0.1;
    }

    15% {
        opacity: 0.8;
    }

    20% {
        opacity: 0.1;
    }

    25% {
        opacity: 0.3;
    }

    30% {
        opacity: 0.1;
    }

    40% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }

    60% {
        opacity: 1;
    }

    70% {
        opacity: 0.9;
    }

    100% {
        opacity: 1;
        text-shadow: 0 0 30px rgba(0, 255, 157, 0.8);
    }
}

@keyframes bg-power-up {
    0% {
        filter: brightness(0.5) grayscale(1);
    }

    30% {
        filter: brightness(0.6) grayscale(0.8);
    }

    35% {
        filter: brightness(1.2) grayscale(0);
    }

    /* FLASH */
    40% {
        filter: brightness(1) grayscale(0);
    }

    100% {
        filter: brightness(1) grayscale(0);
    }
}

body.powering-on {
    animation: bg-power-up 1.5s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

body.powering-on .login-card {
    border-color: var(--accent-green);
    box-shadow: 0 0 50px rgba(0, 255, 157, 0.3);
    transition: all 0.5s;
}

body.powering-on .btn-login {
    background: var(--accent-green) !important;
    color: black !important;
    box-shadow: 0 0 30px var(--accent-green);
    transform: scale(1.05);
}

/* Glitch text effect for title on success */
body.powering-on h1 {
    animation: flicker 1s infinite alternate;
    color: white;
}

/* --- MIGRATED LOGIN STYLES --- */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    /* Changed from height to min-height */
    height: auto;
    padding: 1rem;
    /* Ensure padding on small screens */
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 3rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group input {
    width: 100%;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: white;
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.input-group input:focus {
    border-color: var(--accent-blue);
}

.btn-login {
    width: 100%;
    padding: 1rem;
    background: var(--accent-blue);
    color: #000;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.3s;
}

.btn-login:hover {
    opacity: 0.9;
}

.error-msg {
    color: var(--accent-red);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    text-align: center;
    display: none;
}

@media (max-width: 600px) {
    .login-container {
        align-items: flex-start;
        /* Allow top scrolling */
        padding-top: 10vh;
    }
}