/* --- ZMIENNE I KONFIGURACJA --- */
:root {
    --bg-color: #05070a;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-color: #00d4ff;
    --error-color: #ff4d4d;
    --success-color: #00ff88;
    --header-height: calc(70px + env(safe-area-inset-top));
    --nav-height: calc(75px + env(safe-area-inset-bottom));
}

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

body {
    margin: 0; 
    background-color: var(--bg-color); 
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden; /* Zapobiega "pływaniu" całej strony */
}

/* --- NAGŁÓWEK (Aplikacyjny) --- */
.app-header {
    position: fixed; 
    top: 0; left: 0; right: 0; 
    height: var(--header-height);
    background: rgba(10, 15, 20, 0.8); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px);
    display: flex; 
    align-items: flex-end; 
    justify-content: space-between;
    padding: 0 20px 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08); 
    z-index: 1000;
}

.logo {
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 1px;
    background: linear-gradient(to right, #fff, var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#v-batt {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--accent-color);
    background: rgba(0, 212, 255, 0.1);
    padding: 4px 8px;
    border-radius: 8px;
}

.logout-btn {
    background: rgba(255, 77, 77, 0.15);
    border: 1px solid rgba(255, 77, 77, 0.2);
    color: #ff9f9f;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
}

.settings-trigger {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 5px;
}

/* --- GŁÓWNA TREŚĆ (Przewijana) --- */
main {
    position: fixed; 
    top: var(--header-height); 
    bottom: var(--nav-height);
    left: 0; right: 0; 
    overflow-y: auto; 
    padding: 20px; 
    -webkit-overflow-scrolling: touch;
}

.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --- KARTY CZUJNIKÓW --- */
.sensor-card {
    background: var(--card-bg); 
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px; 
    padding: 20px; 
    display: flex; 
    justify-content: space-between;
    align-items: center;
}

.sensor-info h2 {
    margin: 0; 
    font-size: 1.1rem; 
    font-weight: 600;
}

.sensor-meta {
    font-size: 0.8rem; 
    opacity: 0.5; 
    margin-top: 4px;
}

.temp-big { 
    font-size: 2.4rem; 
    font-weight: 700; 
    color: var(--accent-color); 
}

.unit { font-size: 1rem; margin-left: 2px; opacity: 0.7; }

/* --- DOLNA NAWIGACJA --- */
.bottom-nav {
    position: fixed; 
    bottom: 0; left: 0; right: 0; 
    height: var(--nav-height);
    background: rgba(10, 15, 20, 0.9); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px);
    display: flex; 
    justify-content: space-around; 
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid rgba(255, 255, 255, 0.1); 
    z-index: 1000;
}

.nav-item {
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center;
    opacity: 0.5; 
    flex: 1;
}

.nav-item.active { opacity: 1; color: var(--accent-color); }

.nav-item .icon { font-size: 1.4rem; margin-bottom: 4px; }
.nav-item .label { font-size: 0.65rem; font-weight: 500; }

/* --- EKRAN LOGOWANIA --- */
.full-screen-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-color); z-index: 5000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--card-bg); 
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(30px); 
    border-radius: 35px; 
    padding: 40px 30px; 
    width: 100%; 
    max-width: 380px;
    text-align: center;
}

.brand-logo { font-size: 3.5rem; margin-bottom: 15px; }
.login-card h1 { margin: 0; font-size: 1.6rem; font-weight: 800; }
.login-card p { opacity: 0.4; font-size: 0.85rem; margin-bottom: 30px; }

.input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.input-group input {
    width: 100%; 
    background: rgba(255, 255, 255, 0.05); 
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px; 
    border-radius: 18px; 
    color: white; 
    font-size: 1rem;
    outline: none;
}

.password-wrapper { position: relative; width: 100%; }
.password-wrapper input { padding-right: 50px !important; }

#toggle-password {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; font-size: 1.2rem; cursor: pointer; opacity: 0.5;
}

.login-btn {
    width: 100%; padding: 16px; background: var(--accent-color); color: #000;
    border: none; border-radius: 18px; font-weight: 800; font-size: 1rem; cursor: pointer;
}

.error-msg { color: var(--error-color); font-size: 0.8rem; margin-top: 15px; min-height: 1em; }

/* --- PANEL USTAWIEŃ (Bottom Sheet) --- */
.bottom-sheet {
    position: fixed; bottom: -100%; left: 0; right: 0; 
    background: #0d1218;
    border-radius: 30px 30px 0 0; z-index: 2000; padding: 25px;
    padding-bottom: calc(25px + env(safe-area-inset-bottom));
    transition: bottom 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    border-top: 1px solid rgba(255,255,255,0.1);
}
.bottom-sheet.open { bottom: 0; }
.sheet-handle { width: 40px; height: 5px; background: rgba(255,255,255,0.2); border-radius: 10px; margin: 0 auto 20px auto; }

.setting-group { margin-bottom: 20px; }
.setting-group label { display: block; font-size: 0.8rem; opacity: 0.5; margin-bottom: 8px; }
.setting-group input { 
    width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
    padding: 12px; border-radius: 12px; color: white;
}

.toggle-group { display: flex; gap: 10px; }
.channel-btn { flex: 1; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); color: white; border-radius: 12px; }
.channel-btn.active { background: var(--accent-color); color: #000; font-weight: bold; }

.save-btn { width: 100%; padding: 16px; background: var(--success-color); color: #000; border: none; border-radius: 15px; font-weight: bold; }

/* --- STYLIZACJA MULTI-RANGE SLIDER --- */
.range-slider-container {
    position: relative;
    width: 100%;
    height: 50px;
    margin-top: 20px;
}

.range-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    z-index: 1;
}

.range-slider-container input[type="range"] {
    position: absolute;
    width: 100%;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
}

/* Stylizujemy uchwyty (knoby) */
input[type="range"]::-webkit-slider-thumb {
    height: 24px; width: 24px; border-radius: 50%;
    background: white; pointer-events: auto;
    -webkit-appearance: none; cursor: pointer;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

#slider-critical::-webkit-slider-thumb { background: var(--error-color); border: 3px solid white; }
#slider-warning::-webkit-slider-thumb { background: #ff9f00; border: 3px solid white; }

.range-labels {
    display: flex; justify-content: space-between;
    font-size: 0.8rem; margin-top: 10px;
}
/* --- ELEGANCKIE WSKAŹNIKI STANU --- */
.sensor-card {
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}

/* Pasek boczny (Accent Bar) */
.sensor-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 5px;
    background: transparent;
    transition: background 0.3s;
}

.state-safe::before { background: var(--success-color); }
.state-warning::before { background: #ff9f00; }
.state-critical::before { background: var(--error-color); }

/* Pulsująca kropka (Status Dot) */
.status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

.state-safe .status-dot { background: var(--success-color); box-shadow: 0 0 5px var(--success-color); }
.state-warning .status-dot { background: #ff9f00; box-shadow: 0 0 5px #ff9f00; }
.state-critical .status-dot { 
    background: var(--error-color); 
    box-shadow: 0 0 8px var(--error-color);
    animation: pulse 1.5s infinite; 
}

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

/* --- STYLE DLA NAPIĘCIA BATERII --- */
#v-batt {
    transition: all 0.3s ease;
}

.vbatt-warning {
    background: rgba(255, 159, 0, 0.2) !important;
    color: #ff9f00 !important;
    border: 1px solid rgba(255, 159, 0, 0.3);
}

.vbatt-critical {
    background: rgba(255, 77, 77, 0.2) !important;
    color: var(--error-color) !important;
    border: 1px solid rgba(255, 77, 77, 0.5);
    animation: pulse-border 1.5s infinite;
}

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