/* --- BAZA I UKŁAD GŁÓWNY --- */
body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    margin: 0; 
    padding: 20px; 
    background: #f0f2f5; 
    color: #333;
    /* Centrowanie kontenera na stronie */
    display: flex;
    justify-content: center;
}

.main-container { 
    display: flex; 
    gap: 30px; 
    max-width: 1300px; 
    width: 100%; /* Elastyczna szerokość */
    margin: 0 auto; 
    flex-direction: row;
    align-items: flex-start; /* Zapobiega rozciąganiu kolumn w pionie */
}

/* Lewy panel sterowania - stała szerokość */
.admin-controls {
    flex: 0 0 600px; 
    min-width: 400px;
}

/* Prawy panel podglądu */
.preview-section { 
    flex: 0 0 600px; /* Ustawiamy stałą szerokość kolumny podglądu */
    position: sticky; 
    top: 20px; 
    height: auto; /* Usuwamy sztywne 1300px */
}

/* --- ELEMENTY INTERFEJSU --- */
.admin-panel { 
    background: white; 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.05); 
    margin-bottom: 20px;
    width: 100%; /* Panel zajmuje całą dostępną szerokość kolumny */
    box-sizing: border-box;
}

.section-title { 
    border-bottom: 2px solid #eee; 
    padding-bottom: 10px; 
    margin-top: 0; 
    font-size: 1.1em; 
    color: #333; 
    display: flex;
    align-items: center;
    gap: 10px;
}

input, select, button { 
    padding: 10px; 
    margin: 5px 0; 
    width: 100%; 
    box-sizing: border-box; 
    border-radius: 6px; 
    border: 1px solid #ccc; 
    font-size: 0.9em; 
}

button { 
    cursor: pointer; 
    font-weight: bold; 
    transition: all 0.2s ease; 
    background: #3498db; 
    color: white; 
    border: none; 
}

button:hover { 
    background: #2980b9; 
    transform: translateY(-1px); 
}

.btn-emergency { background: #e74c3c; }
.btn-emergency:hover { background: #c0392b; }

.btn-add { background: #27ae60; }
.btn-add:hover { background: #219150; }

/* --- KOMPAKTOWY WYBÓR IKON (Admin Panel) --- */
.icon-picker {
    display: grid;
    grid-template-columns: repeat(5, 45px); 
    gap: 8px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin: 10px 0 20px 0;
    width: fit-content;
}

.icon-option {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 45px !important;
    height: 45px !important;
    background: white;
    border: 2px solid #eee;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-option input { display: none !important; }

.icon-option img {
    width: 24px !important;
    height: 24px !important;
    filter: brightness(0); /* Czarna ikona na białym tle w panelu */
    opacity: 0.4;
}

.icon-option:hover { background: #e9ecef; }
.icon-option:has(input:checked) { border-color: #3498db; background: #ebf5fb; }
.icon-option input:checked + img { opacity: 1; }

.no-icon { font-size: 18px; color: #888; font-weight: bold; }

/* --- LEGENDA I FILTRY --- */
.legend { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    margin-bottom: 15px; 
    background: #eaeff2; 
    padding: 12px; 
    border-radius: 8px; 
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8em;
    transition: 0.2s;
    background: transparent;
    color: #555;
}

.legend-item:hover { background: rgba(0,0,0,0.05); }

.legend-item.active-filter {
    background: white;
    border: 1px solid #bdc3c7;
    font-weight: bold;
    color: #000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot-active { background-color: #27ae60; }
.dot-future { background-color: #f1c40f; }
.dot-past   { background-color: #e74c3c; }

/* --- LISTA WIADOMOŚCI --- */
#messageList { list-style: none; padding: 0; }
.message-item { 
    background: #fff; 
    border: 1px solid #eee; 
    margin-bottom: 8px; 
    padding: 12px; 
    border-radius: 8px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 0.85em;
}

.message-item.status-past   { border-left: 6px solid #e74c3c !important; background: #fffafa; }
.message-item.status-active { border-left: 6px solid #27ae60 !important; background: #fafffa; }
.message-item.status-future { border-left: 6px solid #f1c40f !important; background: #fffff0; }

.message-info { flex-grow: 1; }
.btn-delete-msg { 
    width: auto; 
    background: #ff4d4d; 
    color: white; 
    padding: 6px 12px; 
    border-radius: 4px; 
    font-size: 0.8em; 
}

.badge { 
    font-size: 0.65em; 
    padding: 2px 6px; 
    border-radius: 3px; 
    color: white; 
    font-weight: 800; 
    margin-right: 8px; 
    display: inline-block; 
}
.badge-image { background: #3498db; }
.badge-video { background: #9b59b6; }
.badge-text  { background: #95a5a6; }

/* --- STATUS EKRANÓW (MONITORING) --- */
.display-badge { 
    display: flex !important; 
    justify-content: space-between !important; 
    align-items: center !important; 
    padding: 10px 15px; 
    border-radius: 10px; 
    margin-bottom: 8px; 
    color: white; 
}

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

.action-circle { 
    width: 32px !important; 
    height: 32px !important; 
    border-radius: 50%; 
    border: none; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    background-color: rgba(0, 0, 0, 0.15); 
    transition: 0.3s; 
    padding: 0 !important; 
}

.action-circle svg { width: 16px; height: 16px; fill: rgba(255, 255, 255, 0.8); }
.action-circle:hover svg { fill: #fff; }

.btn-edit:hover { background-color: #3498db !important; }
.btn-delete-display:hover { background-color: #e74c3c !important; }

/* --- PODGLĄD NA ŻYWO (IFRAME) --- */
#preview-wrapper {
    position: relative;
    width: 100%; /* Zajmuje całą szerokość kolumny */
    max-width: 594px; /* Maksymalny rozmiar na komputerze */
    aspect-ratio: 9 / 16; /* Utrzymuje proporcje pionowe automatycznie */
    background-color: #000;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border: 1px solid #ccc;
    margin: 0 auto 10px auto; /* Centrowanie samego podglądu */
}

#preview-iframe {
    /* Iframe musi mieć zawsze 1080px szerokości WEWNĄTRZ, 
       aby strona display renderowała się poprawnie */
    width: 1080px;
    height: 1920px;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    pointer-events: none;
}

.preview-caption {
    color: #666;
    text-align: center;
    width: 100%;
    margin-top: 5px;
}

/* --- SYSTEMOWE --- */
#emergencyStatusBadge {
    background: #e74c3c; 
    color: white; 
    padding: 10px; 
    border-radius: 6px; 
    margin-bottom: 15px; 
    font-weight: bold; 
    text-align: center; 
    border: 2px solid #c0392b;
    animation: blinker 2s linear infinite;
}

@keyframes blinker { 50% { opacity: 0.7; } }

/* --- RESPONSYWNOŚĆ --- */
@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
        align-items: center;
        padding: 10px;
    }
    .admin-controls, .preview-section {
        flex: 1 1 100%;
        width: 100%;
        max-width: 600px; /* Ograniczenie szerokości na tablecie/telefonie */
    }
}