:root {
    --bg-main: #0F111A;
    --bg-card: rgba(26, 29, 39, 0.7);
    --bg-sensor: rgba(0, 0, 0, 0.2);
    --bg-modal: #1A1D27;
    --accent-blue: #00A2FF;
    --accent-green: #00FFCC;
    --accent-red: #FF3366;
    --text-main: #FFFFFF;
    --text-dim: #8B95A5;
    --border-color: rgba(255, 255, 255, 0.05);
    --glass-effect: blur(10px);
}

[data-theme="light"] {
    --bg-main: #E2E8F0;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-sensor: rgba(255, 255, 255, 0.5);
    --bg-modal: #FFFFFF;
    --accent-blue: #2563EB;
    --accent-green: #059669;
    --accent-red: #E11D48;
    --text-main: #1E293B;
    --text-dim: #64748B;
    --border-color: rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
}

header {
    margin-bottom: 30px;
    position: sticky;
    top: 0;
    background: var(--bg-main);
    opacity: 0.95;
    backdrop-filter: blur(10px);
    z-index: 100;
    padding: 10px 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

h1 {
    font-size: 1.5rem;
    letter-spacing: 2px;
    font-weight: 700;
    background: linear-gradient(90deg, #fff, #8B95A5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--accent-blue);
    font-weight: 600;
    letter-spacing: 1px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.pulse-blue {
    background-color: var(--accent-blue);
    box-shadow: 0 0 0 rgba(0, 162, 255, 0.4);
    animation: pulse 2s infinite;
}

.pulse-red {
    background-color: var(--accent-red);
    animation: pulse-red 1s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 162, 255, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(0, 162, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 162, 255, 0); }
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

#status-text {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-dim);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 8px;
    transition: color 0.3s;
}

.icon-btn:hover {
    color: white;
}

/* Dashboard Grid */
#dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 25px;
    padding-bottom: 50px;
}

.main-nav {
    display: flex;
    gap: 10px;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.nav-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
    box-shadow: 0 4px 15px rgba(0, 162, 255, 0.3);
}

.view {
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
}

.history-grid {
    display: grid;
    grid-template-columns: 1fr; /* Single column layout */
    gap: 30px;
    max-width: 900px; /* Center and restrict width for readability */
    margin: 0 auto;
}

.chart-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-effect);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 24px;
    min-height: 380px;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.chart-container {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 10px;
    margin-top: 10px;
    position: relative;
}

.chart-scroll-wrapper {
    overflow-x: auto;
    width: 100%;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-red) transparent;
}

.chart-scroll-wrapper::-webkit-scrollbar {
    height: 4px;
}
.chart-scroll-wrapper::-webkit-scrollbar-thumb {
    background: var(--accent-red);
    border-radius: 10px;
}

.chart-svg {
    width: 100%;
    height: 220px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
}

.chart-svg.zoomed {
    width: 400%; /* Quadruple width */
}

/* Fix thickness while zooming */
.chart-svg path, 
.chart-svg circle {
    vector-effect: non-scaling-stroke;
}

/* Keep text readable */
.chart-svg text {
    user-select: none;
    transition: font-size 0.2s;
}

.chart-svg.zoomed text {
    font-size: 7px; /* Slightly smaller text to fit more detail */
}

.chart-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 25px; /* Space for zoom button */
    justify-content: flex-end;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.zoom-btn {
    /* Same as before but adjusted */
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

/* --- MOBILE OPTIMIZATIONS (SINGLE LINE) --- */
@media (max-width: 768px) {
    header {
        padding: 5px 0;
    }

    .header-content {
        flex-direction: row !important;
        justify-content: space-between;
        align-items: center;
        gap: 5px;
    }

    .brand h1 {
        font-size: 0.85rem;
    }

    .subtitle {
        display: none; /* Hide subtitle on very small screens to save space */
    }

    .main-nav {
        width: auto !important;
        gap: 4px;
    }

    .nav-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .actions {
        width: auto !important;
        padding: 0;
        border-top: none !important;
        gap: 5px;
    }
    
    .status-indicator {
        padding: 2px 6px;
    }

    #status-text {
        font-size: 0.6rem;
    }

    .icon-btn {
        padding: 4px;
    }

    #dashboard {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

.chart-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.1);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.title-set {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.title-set h3 {
    margin: 0;
    font-size: 0.85rem;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    font-weight: 700;
}

.live-badge {
    background: rgba(255, 51, 102, 0.1);
    color: var(--accent-red);
    font-size: 0.6rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 4px;
    width: fit-content;
    border: 1px solid rgba(255, 51, 102, 0.2);
}

.chart-stats {
    display: flex;
    gap: 8px;
}

.stat-pill {
    padding: 5px 12px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.stat-pill.temp {
    background: rgba(255, 51, 102, 0.1);
    color: var(--accent-red);
}
.stat-pill.temp::before { background: var(--accent-red); }

.stat-pill.hum {
    background: rgba(0, 162, 255, 0.1);
    color: var(--accent-blue);
}
.stat-pill.hum::before { background: var(--accent-blue); }

.svg-container {
    flex-grow: 1;
    width: 100%;
    position: relative;
    margin-top: 10px;
}

.filter-bar {
    background: rgba(var(--primary-rgb), 0.05);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
    display: flex;
    gap: 20px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.filter-group input, .filter-group select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
}

.filter-group input:focus, .filter-group select:focus {
    border-color: var(--primary-color);
}

.btn-search {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 11px 25px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.2s, background 0.3s;
}

.btn-search:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* Mobile Filter Adjustments */
@media (max-width: 600px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }
    .btn-search {
        justify-content: center;
        width: 100%;
    }
}

.rack-card {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 20px;
    border: 1px solid var(--border-color);
    backdrop-filter: var(--glass-effect);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.3s;
    position: relative;
    overflow: hidden;
}

.rack-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-blue);
    opacity: 0.5;
}

.rack-card.alarm::before {
    background: var(--accent-red);
    opacity: 1;
}

.rack-card:active {
    transform: scale(0.98);
}

.rack-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.rack-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.sensor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.sensor-box {
    background: var(--bg-sensor);
    border-radius: 16px;
    padding: 15px;
    text-align: center;
    position: relative;
    border: 1px solid var(--border-color);
}

.sensor-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: 5px;
    display: block;
}

.sensor-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    display: block;
}

.unit {
    font-size: 1rem;
    opacity: 0.6;
}

.temp .sensor-value { color: var(--accent-red); }
.hum .sensor-value { color: var(--accent-green); }

.min-max {
    display: flex;
    justify-content: space-around;
    margin-top: 10px;
    font-size: 0.65rem;
    color: var(--text-dim);
}

.value-pair {
    display: flex;
    flex-direction: column;
}

.val {
    color: white;
    font-weight: 600;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-modal);
    width: 90%;
    max-width: 400px;
    border-radius: 24px;
    padding: 30px;
    border: 1px solid var(--border-color);
}

.modal-content h2 {
    margin-bottom: 20px;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.input-group input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 12px;
    color: white;
    font-family: inherit;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

.btn {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

.btn.primary { background: var(--accent-blue); color: white; }
.btn.secondary { background: rgba(255,255,255,0.05); color: white; }

/* Skeleton */
.skeleton-card {
    height: 180px;
    background: var(--bg-card);
    border-radius: 24px;
    animation: pulse-skeleton 1.5s infinite;
}

@keyframes pulse-skeleton {
    0% { opacity: 0.5; }
    50% { opacity: 0.2; }
    100% { opacity: 0.5; }
}
