:root {
    /* ZÁKLADNÍ SVĚTLÁ PALETA (Day mode) */
    --bg: #f1f5f9;         
    --card: #ffffff;       
    --card-hover: #f8fafc; /* Pro neaktivní karty a hlavičky */
    --border: #cbd5e1;     
    
    /* MENU A PŘEPÍNAČE */
    --nav-bg: #E1F2Ff;
    --nav-menu-bg: #bfdbf3;
    --switcher-bg: #e2e8f0;

    /* TYPOGRAFIE */
    --text: #1e293b;       
    --muted: #475569;      
    --accent: #0284c7;     
    
    /* BARVY SENZORŮ */
    --outdoor: #0284c7;    
    --room: #16a34a;       
    --attic: #ea580c;      

    /* PODKRESOVÉ BARVY (Aktivní stavy a průhlednosti) */
    --active-bg-outdoor: rgba(2, 132, 199, 0.04);
    --active-bg-room: rgba(22, 163, 74, 0.04);
    --active-bg-attic: rgba(234, 88, 12, 0.04);
    --fade-color: 255, 255, 255; /* Pro stíny kasino kotoučů (RGB) */
}

/* --- TMAVÁ PALETA (Night mode) --- */
[data-theme="dark"] {
    --bg: #0f172a;         /* Tmavá břidlicová */
    --card: #1e293b;       /* Karty o něco světlejší než pozadí */
    --card-hover: #334155; /* Odlišení prvků na kartě */
    --border: #475569;     
    
    --nav-bg: #1e293b;
    --nav-menu-bg: #0f172a;
    --switcher-bg: #0f172a;

    --text: #f8fafc;       /* Bílý text */
    --muted: #94a3b8;      /* Světle šedý doplňkový text */
    --accent: #38bdf8;     /* Zářivější modrá pro tmavý režim */
    
    /* Senzory (zachován odstín, lehce zvýšený jas pro kontrast na černé) */
    --outdoor: #38bdf8;    
    --room: #4ade80;       
    --attic: #f97316;      

    --active-bg-outdoor: rgba(56, 189, 248, 0.1);
    --active-bg-room: rgba(74, 222, 128, 0.1);
    --active-bg-attic: rgba(249, 115, 22, 0.1);
    --fade-color: 30, 41, 59; /* RGB barvy --card pro kasino kotouče */
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    transition: background-color 0.3s, color 0.3s; /* Plynulý přechod den/noc */
}

/* TOP NAVIGATION */
.topnav {
    background: var(--nav-bg);
    border-bottom: 3px solid var(--border);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
    transition: background-color 0.3s, border-color 0.3s;
}

.brand-text {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--text);
    letter-spacing: -0.5px;
}

.topnav-menu {
    display: flex;
    background: var(--nav-menu-bg); 
    padding: 0.15rem;
    border-radius: 0.45rem;
    width: 100%;
    max-width: 700px;
    transition: background-color 0.3s;
}

.nav-item {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.3rem;
    border-radius: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.nav-item:hover { color: var(--text); }

.nav-item.active {
    background: var(--card);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* HLAVNÍ KONTEJNER */
.layout-center { display: flex; justify-content: center; padding: 1rem; }
.main { width: 100%; max-width: 1200px; }

/* GRID SYSTÉM DASHBOARDU */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; width: 100%; }
.card-main { order: 1; grid-column: span 2; width: 100%; }
.panel { order: 2; grid-column: span 2; width: 100%; display: block; }
.card-room { order: 3; grid-column: span 1; width: 100%; }
.card-attic { order: 4; grid-column: span 1; width: 100%; }

/* GRAF PANEL */
.panel {
    background: var(--card);
    border-radius: 1rem;
    border: 1px solid var(--border);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05); 
    overflow: hidden;
    min-width: 100%;
    transition: background-color 0.3s, border-color 0.3s;
}

.panel-header {
    padding: 1rem;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    background: var(--card-hover);
    transition: background-color 0.3s;
}

.panel-body { height: 350px; padding: 0.5rem 1rem 1rem 1rem; width: 100%; position: relative; }
.chart-wrapper { width: 100%; height: 100%; }
canvas#chartHistory, canvas#chartSearch { width: 100% !important; height: 100% !important; }

/* TLAČÍTKA ROZSAHU */
.range-buttons {
    display: flex;
    background: var(--switcher-bg);
    padding: 3px;
    border-radius: 10px;
    gap: 2px;
}

.range-btn {
    border: none;
    background: transparent;
    padding: 4px 15px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s;
}

.range-btn.active {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* DLAŽDICE (CARDS) */
.card {
    background: var(--card);
    border-radius: 1rem;
    padding: 0.85rem 0.75rem; 
    border: 2px solid var(--border);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease, background-color 0.3s, border-color 0.3s;
    cursor: pointer;
    height: 100%;
    display: flex; flex-direction: column; align-items: center; text-align: center;
}

.card:hover { transform: translateY(-2px); box-shadow: 0 12px 25px rgba(0, 0, 0, 0.08); }

.card-title { font-size: 0.75rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 1.9rem; font-weight: 800; margin: 0.35rem 0; letter-spacing: -0.5px; }

.card-main .card-value { color: var(--outdoor); }
.card-room .card-value { color: var(--room); }
.card-attic .card-value { color: var(--attic); }

.card-sub { 
    font-size: 0.75rem; 
    color: var(--muted); 
    display: flex; 
    justify-content: center; 
    gap: 15px; 
    width: 100%; 
    padding-top: 8px; 
    border-top: 1px dashed var(--border);
    margin-top: auto; 
}

/* ZVÝRAZNĚNÍ AKTIVNÍ DLAŽDICE (HLAVNÍ STRÁNKA) */
.card-main[style*="opacity: 1"] { border-color: var(--outdoor) !important; background-color: var(--active-bg-outdoor); }
.card-room[style*="opacity: 1"] { border-color: var(--room) !important; background-color: var(--active-bg-room); }
.card-attic[style*="opacity: 1"] { border-color: var(--attic) !important; background-color: var(--active-bg-attic); }

/* Neaktivní karta */
.card[style*="opacity: 0.5"] { 
    opacity: 1 !important; 
    filter: none; 
    background-color: var(--card-hover); 
    border-color: var(--border) !important; 
    box-shadow: none;
}

/* --- ZVÝRAZNĚNÍ AKTIVNÍ DLAŽDICE (VYHLEDÁVÁNÍ) --- */
.clickable-sensor { 
    opacity: 1 !important; 
    filter: none !important; 
    background-color: var(--card-hover); 
    transition: all 0.3s ease; 
}
.clickable-sensor.active-sensor { background-color: var(--card); transform: translateY(-3px); }

.card-main.active-sensor { border-color: var(--outdoor) !important; background-color: var(--active-bg-outdoor); }
.card-room.active-sensor { border-color: var(--room) !important; background-color: var(--active-bg-room); }
.card-attic.active-sensor { border-color: var(--attic) !important; background-color: var(--active-bg-attic); }

/* DESKTOP ÚPRAVY */
@media (min-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr 1fr 1fr; }
    .panel { order: 1; grid-column: 1 / span 3; }
    .card-main { order: 2; grid-column: span 1; }
    .card-room { order: 3; grid-column: span 1; }
    .card-attic { order: 4; grid-column: span 1; }
}

.section { display: none; scroll-margin-top: 100px; }
.section.visible { display: block; animation: fadeIn 0.3s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* RESPONZIVNÍ MENU */
@media (max-width: 600px) {
    .nav-label { display: none; }
    .nav-item { padding: 0.6rem; font-size: 1.1rem; }
    .topnav-menu { max-width: 100%; }
    .section { scroll-margin-top: 140px; }
}

/* VYHLEDÁVÁNÍ */
.search-controls { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; justify-content: center; width: 100%; }
.search-controls input[type="date"], .search-controls select {
    border: 1px solid var(--border);
    padding: 0.6rem;
    border-radius: 0.5rem;
    font-family: inherit;
    color: var(--text);
    background: var(--card);
    font-weight: 600;
}
/* Inverze ikony kalendáře pro tmavý režim */
[data-theme="dark"] .search-controls input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

.btn-search {
    background: var(--accent);
    color: #fff; /* Tady necháme bílou natvrdo, na tlačítku bude vidět vždy */
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
[data-theme="dark"] .btn-search { color: #0f172a; } /* V noci bude text na svítivém tlačítku tmavý */
.btn-search:hover { opacity: 0.9; transform: translateY(-1px); }

@media (max-width: 600px) {
    .search-controls { flex-direction: column; gap: 0.5rem; }
    .search-controls input, .search-controls select, .btn-search { width: 100%; }
}

/* POČASÍ GRID */
.weather-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; width: 100%; padding: 5px; }
.weather-card {
    text-decoration: none !important;
    background: var(--card) !important;
    border-radius: 12px !important;
    border: 1px solid var(--border) !important;
    border-bottom: 4px solid var(--accent) !important; 
    display: flex; align-items: center; justify-content: center;
    min-height: 70px; padding: 10px;
    transition: all 0.1s;
}
.weather-card:active { transform: scale(0.97); }
.weather-logo { max-width: 80%; max-height: 40px; object-fit: contain; }

/* RADAR & KAMERA */
.radar-panel-container, .kamera-panel-container {
    margin-top: 15px;
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex; flex-direction: column;
    grid-column: span 2;
}
.radar-body { padding: 0 !important; height: 400px !important; }
.radar-body iframe { width: 100%; height: 100%; border: none; }
[data-theme="dark"] .radar-body iframe { filter: invert(0.9) hue-rotate(180deg); } /* Radar v noci potmavne */

.kamera-body { padding: 0 !important; height: auto !important; min-height: 0 !important; background: #000; }
.kamera-body img { width: 100%; height: auto; display: block; opacity: 0.9; }
.kamera-panel-container .panel-header { padding: 10px 15px; background: var(--card-hover); border-bottom: 1px solid var(--border); }
.kamera-panel-container .card-title { font-size: 0.85rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (min-width: 900px) {
    .weather-grid { grid-template-columns: repeat(4, 1fr); }
    .radar-panel-container { grid-column: span 4; }
    .radar-body { height: 600px !important; }
    .kamera-panel-container { grid-column: span 2; } 
}

/* STATISTIKY MINIKARTY */
.stats-records-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 1rem; }
.mini-record-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex; flex-direction: column; align-items: center; text-align: center;
}
.mini-record-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mini-record-label { font-size: 0.7rem; font-weight: 800; color: var(--muted); text-transform: uppercase; margin-bottom: 0.25rem; }
.mini-record-value { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.mini-record-year { font-size: 0.8rem; color: var(--accent); font-weight: 700; margin-top: 4px; }

.text-hot { color: #ef4444; }
.text-cold { color: #3b82f6; }
.text-warm { color: #f59e0b; }
.text-cool { color: #0ea5e9; }

/* MODÁL */
.modal-stats { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-content {
    background-color: var(--card); margin: 10% auto; padding: 1.5rem; border-radius: 1.5rem; width: 90%; max-width: 500px; position: relative; max-height: 85vh; overflow-y: auto; display: flex; flex-direction: column; border: 1px solid var(--border);
}
.close-modal { position: absolute; right: 1.5rem; top: 1rem; font-size: 1.5rem; cursor: pointer; color: var(--muted); }
.close-modal:hover { color: var(--text); }
.modal-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.95rem; }
.modal-table th, .modal-table td { padding: 0.75rem; border-bottom: 1px solid var(--border); }
.modal-table th { text-align: left; border-bottom: 2px solid var(--border); color: var(--muted); font-weight: 700; }
.modal-table tr:hover { background-color: var(--card-hover); }
.modal-value-cell { display: flex; justify-content: flex-end; align-items: center; gap: 10px; text-align: right; }
.time-label { font-size: 0.75rem; color: var(--text); background: var(--switcher-bg); padding: 2px 6px; border-radius: 4px; font-weight: bold; }

@media (min-width: 900px) { .stats-records-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 600px) {
    .modal-table thead { display: none; }
    .modal-table, .modal-table tbody, .modal-table tr, .modal-table td { display: block; width: 100%; }
    .modal-table tr { margin-bottom: 10px; background: var(--card-hover); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
    .modal-table td { border: none; display: flex; justify-content: space-between; align-items: center; padding: 5px; }
    .modal-table td:first-child::before { content: "Rok"; font-weight: 800; color: var(--muted); font-size: 0.75rem; }
}

/* BLIKÁNÍ */
.blink-effect { animation: blink-animation 0.5s ease-in-out; color: var(--accent) !important; font-weight: 800; }
@keyframes blink-animation { 0% { opacity: 1; } 50% { opacity: 0.2; } 100% { opacity: 1; } }

/* --- KASINO KOTOUČE --- */
.stats-scroll-wrapper { display: grid; grid-template-columns: 1fr; gap: 15px; margin-top: 20px; margin-bottom: 20px; }
@media (min-width: 600px) { .stats-scroll-wrapper { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1200px) { .stats-scroll-wrapper { grid-template-columns: 1fr 1fr 1fr 1fr; } }

.scroll-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
}
.scroll-header {
    background: var(--card-hover); padding: 12px; text-align: center;
    border-bottom: 1px solid var(--border); font-size: 0.85rem; font-weight: 800; color: var(--text); text-transform: uppercase;
}
.scroll-viewport { position: relative; height: 200px; background: var(--card); }
.scroll-list { height: 100%; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; scroll-behavior: smooth; padding: 80px 0; }
.scroll-list::-webkit-scrollbar { display: none; }

.reel-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; height: 40px; border-bottom: 1px solid var(--border);
    color: var(--muted); transition: all 0.3s; opacity: 0.6; font-size: 0.95rem; font-weight: 600;
}
.reel-item.active-year {
    background-color: var(--card-hover); opacity: 1; font-weight: 800; color: var(--text);
    border-left: 4px solid var(--accent); transform: scale(1.02);
}

.scroll-overlay-top {
    position: absolute; top: 0; left: 0; right: 0; height: 40px;
    background: linear-gradient(to bottom, rgba(var(--fade-color),1), rgba(var(--fade-color),0)); pointer-events: none;
}
.scroll-overlay-bottom {
    position: absolute; bottom: 0; left: 0; right: 0; height: 40px;
    background: linear-gradient(to top, rgba(var(--fade-color),1), rgba(var(--fade-color),0)); pointer-events: none;
}

/* --- PŘEPÍNAČ SENZORŮ VE STATISTIKÁCH --- */
.sensor-switcher {
    display: inline-flex;
    background: var(--switcher-bg);
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
    margin-bottom: 15px; 
}

.sensor-btn {
    text-decoration: none;
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
    background: transparent;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
}

.sensor-btn:hover { color: var(--text); }
.sensor-btn.active { background: var(--card); color: var(--text); }

/* Srovnání velikosti čísel ve vyhledávání */
.clickable-sensor .card-value,
.clickable-sensor div[id$="-avg"] {
    font-size: 1.9rem !important;
    font-weight: 800;
    margin: 0.35rem 0;
    letter-spacing: -0.5px;
}