/* --- ZMIENNE I BAZA --- */
:root {
    --bg-main: #f4f7f6; --bg-dark: #2c3e50; --color-primary: #3498db;
    --color-danger: #c0392b; --color-success: #2ecc71; --color-warning: #f1c40f;
    --border-color: #ddd;
}
body { margin: 0; font-family: 'Segoe UI', Tahoma, sans-serif; display: flex; height: 100vh; flex-direction: column; background: var(--bg-main); overflow: hidden; }
* { box-sizing: border-box; }
.hidden { display: none !important; }
.text-highlight { color: var(--color-warning); font-weight: bold; }

/* --- LOGOWANIE --- */
#login-overlay { position: fixed; inset: 0; background: rgba(44,62,80,0.95); z-index: 9999; display: flex; justify-content: center; align-items: center; }
.login-box { background: white; padding: 40px; border-radius: 8px; text-align: center; max-width: 350px; width: 90%; }
.login-box h1 { color: var(--color-danger); margin-top: 0; }
.login-box input { width: 100%; padding: 12px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; text-align: center; }
.login-box button { width: 100%; padding: 12px; background: var(--color-success); color: white; border: none; border-radius: 4px; font-weight: bold; cursor: pointer; }
.error-msg { color: var(--color-danger); font-size: 13px; margin-top: 10px; }

/* --- HEADER & STATUS BAR --- */
#header, #status-bar { background: var(--bg-dark); color: white; padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; z-index: 1001; }
#header h2 { margin: 0; font-size: 20px; }
#btn-logout { background: var(--color-danger); color: white; border: none; padding: 5px 10px; border-radius: 4px; margin-left: 15px; cursor: pointer; }
.ws-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.ws-dot.connected { background: var(--color-success); box-shadow: 0 0 8px var(--color-success); }
.ws-dot.disconnected { background: var(--color-danger); }
.ws-dot.connecting { background: var(--color-warning); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* --- OBSZAR GŁÓWNY --- */
#main { display: flex; flex: 1; overflow: hidden; position: relative; }
#map-container { flex: 3; position: relative; display: flex; flex-direction: column; }
#map { flex: 1; z-index: 1; }
#map-controls { position: absolute; top: 10px; left: 50px; z-index: 1000; background: rgba(255,255,255,0.95); padding: 12px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); width: 250px; }
#map-controls label { font-size: 11px; font-weight: bold; display: block; margin-bottom: 6px; text-transform: uppercase; }
#map-controls select { width: 100%; padding: 8px; border-radius: 4px; border: 1px solid #ccc; font-size: 13px; }

/* --- NOWOCZESNA LEGENDA MAPY --- */
.custom-map-legend {
    /* Pozycjonowanie nad mapą */
    position: absolute;
    bottom: 25px;
    right: 25px;
    z-index: 1000;
    
    /* Nowoczesny wygląd "szkła" */
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    
    /* Kształt i cień */
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    
    /* Wewnętrzne odstępy */
    padding: 12px 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-width: 140px;
}

.custom-map-legend .legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7f8c8d;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #bdc3c7;
    text-align: center;
}

.custom-map-legend .legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
    color: #34495e;
    font-weight: 500;
}

.custom-map-legend .legend-item:last-child {
    margin-bottom: 0;
}

/* Kropki przypominające ikony z mapy (z białą obwódką) */
.custom-map-legend .legend-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid #ffffff; 
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Kontrastowe kolory */
.legend-dot.red { background-color: #e74c3c; }
.legend-dot.orange { background-color: #e67e22; } /* Zmiana na ciemniejszy pomarańcz (Carrot) */
.legend-dot.yellow { background-color: #f1c40f; } /* Jaskrawy żółty (Sunflower) */
.legend-dot.green { background-color: #2ecc71; }

/* --- SIDEBAR / BOTTOM SHEET --- */
#sidebar { flex: 1; background: #fff; border-left: 1px solid var(--border-color); display: flex; flex-direction: column; min-width: 340px; max-width: 400px; z-index: 1000; transition: transform 0.3s ease-in-out; touch-action: none;}
#sidebar-content { padding: 20px; overflow-y: auto; flex: 1; }
.mobile-only { display: none; }

/* --- ELEMENTY HISTORII I DETALI --- */
.history-header { font-size: 18px; color: var(--bg-dark); border-bottom: 2px solid #eee; padding-bottom: 10px; margin-bottom: 15px; margin-top: 0;}
.history-item { background: #f8f9fa; border-left: 4px solid var(--color-primary); padding: 8px; margin-bottom: 8px; border-radius: 0 4px 4px 0; font-size: 13px; cursor: pointer; transition: background 0.2s;}
.history-item:hover { background: #eef2f5; }
.history-item.alarm { border-left-color: var(--color-danger); background: #fff5f5; }
.history-item.unmapped { border-left-color: #95a5a6; border-style: dashed; }
.hist-top { display: flex; justify-content: space-between; font-weight: bold; margin-bottom: 4px; color: var(--bg-dark); }
.hist-unit { color: var(--color-danger); font-size: 14px; margin-bottom: 2px; }
.hist-type { color: #7f8c8d; font-size: 11px; }

.unit-name { color: var(--color-danger); font-size: 22px; font-weight: bold; cursor: pointer; margin-bottom: 5px;}
.unit-name:hover { text-decoration: underline; }
.ksrg-tag { background: var(--color-danger); color: white; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: bold; margin-bottom: 15px; display: inline-block;}
.addr-info { color: #7f8c8d; font-size: 13px; margin-bottom: 20px; }

/* --- MODALE --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 3000; display: flex; justify-content: center; align-items: center; }
.modal-box { background: white; padding: 25px; border-radius: 8px; width: 90%; max-width: 400px; }
.modal-box h3 { margin-top: 0; color: var(--bg-dark); }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 12px; font-weight: bold; margin-bottom: 5px; color: #7f8c8d; }
.form-group select, .form-group input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; padding: 10px; border: none; border-radius: 4px; color: white; cursor: pointer; font-weight: bold;}
.btn-success { background: var(--color-success); }
.btn-danger { background: #95a5a6; } /* Szary dla anuluj */

/* --- RWD (MOBILE) UX --- */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block; }
    #main { flex-direction: column; }
    #map-controls { width: calc(100% - 20px); left: 10px; top: 10px; }
    #mobile-history-btn { width: 100%; margin-top: 10px; padding: 10px; background: var(--bg-dark); color: white; border: none; border-radius: 4px; font-weight: bold; }
    
    /* Bottom Sheet Magic */
    #sidebar { position: absolute; bottom: 0; left: 0; right: 0; min-width: 100%; max-width: 100%; height: 75vh; border-radius: 20px 20px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.3); transform: translateY(100%); z-index: 2000; }
    #sidebar.open { transform: translateY(0); }
    .drag-handle { width: 40px; height: 5px; background: #ccc; border-radius: 3px; margin: 10px auto; }
    #close-sidebar-btn { position: absolute; top: 15px; right: 20px; background: none; border: none; font-size: 24px; color: #7f8c8d; }
}
/* --- ANIMACJA ŚWIEŻEGO ALARMU --- */
@keyframes blink-marker {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.85); }
    100% { opacity: 1; transform: scale(1); }
}

.blinking-marker svg {
    animation: blink-marker 1.2s infinite ease-in-out;
}

/* --- SPLASH SCREEN --- */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #2c3e50; /* Ciemnogranatowe tło, możesz zmienić na białe #ffffff */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999; /* Zawsze na samym wierzchu */
    transition: opacity 0.5s ease-in-out; /* Płynne zanikanie na koniec */
}

.splash-logo {
    width: 50%; /* Rozmiar logo */
    height: auto;
    /* Dodajemy super efekt "pulsowania/oddychania" logo w trakcie ładowania */
    animation: splash-pulse 1.5s infinite ease-in-out;
}

@keyframes splash-pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}