/* Ogólne style dla całej strony */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f2ff;
    color: #333;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.app-container {
    background-color: #696969; /* Zmieniono na białe tło dla lepszego kontrastu */
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    margin: 20px;
    padding: 25px;
    width: 100%;
    max-width: 1800px;
    display: flex;
    flex-direction: column;
    position: relative; /* DODANO: Ustawienie pozycji względnej dla kontenera nadrzędnego */
}

header {
    text-align: center;
    margin-bottom: 25px;
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
    padding-top: 40px; /* DODANO: Większy padding, aby uniknąć nakładania się na przyciski w prawym górnym rogu */
}

/* Nowy kontener na górne przyciski */
.top-right-buttons {
    position: absolute;
    top: 15px;
    right: 20px;
    display: flex;
    gap: 10px; /* Odstęp między przyciskami */
}

/* Styl dla logo */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.header-logo {
    height: 60px; /* Dostosuj rozmiar logo */
    width: auto;
}

.header-logo.logo-left {
    margin-right: auto; /* Wypchnij logo w lewo */
}

.header-logo.logo-right {
    margin-left: auto; /* Wypchnij logo w prawo */
}

h1 {
    color: #007bff;
    font-size: 2.2em;
    margin: 0 20px; /* Margines po bokach dla H1 */
    flex-grow: 1; /* Pozwól H1 zająć dostępną przestrzeń */
}

main {
    display: flex;
    flex-wrap: wrap; /* Umożliwia zawijanie sekcji na mniejszych ekranach */
    gap: 25px;
    justify-content: center;
    flex-grow: 1;
    margin-bottom: 25px; /* Add margin-bottom to separate from the moved sterowanie */
}

.rozdzielnia-view {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    padding: 20px;
    flex: 2; /* Zajmuje więcej miejsca niż sterowanie */
    min-width: 600px; /* Minimalna szerokość, aby nie stało się zbyt małe */
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-grow: 1; /* Allow it to grow and take available space */
}

.rozdzielnia-selector-container {
    width: 100%;
    margin-bottom: 15px;
    text-align: center;
}

#rozdzielnia-selector {
    padding: 8px 60px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    width: 100%; /* Dostosuj szerokość selektora */
    max-width: 600px;
}

.rozdzielnia-image-container {
    position: relative; /* Zachowaj relative, aby SVG overlay było pozycjonowane względem niego */
    width: 100%;
    border: 1px solid #ddd;
    overflow: hidden;
    cursor: grab;
}

.rozdzielnia-image-container.dragging {
    cursor: grabbing;
}

.rozdzielnia-image-container img,
.rozdzielnia-image-container svg {
    /* Usunięto position: absolute; top: 0; left: 0; */
    width: 100%;
    height: auto;
    transform-origin: 0 0;
    transition: transform 0.2s ease-out;
    user-select: none;
    /* pointer-events: none; - To może powodować problemy z klikaniem na SVG. Zostawimy dla img, ale dla SVG zmienimy. */
}

/* SVG musi być absolutnie pozycjonowane, aby nakładało się na obraz i nie wpływało na układ */
.rozdzielnia-image-container svg {
    position: absolute;
    top: 0;
    left: 0;
    /* width i height auto dla svg, żeby nie tworzyło własnego miejsca */
    width: 100%;
    height: 100%; /* SVG powinno wypełnić kontener obrazu */
    pointer-events: auto; /* SVG powinno przechwytywać zdarzenia myszy dla interakcji z sekcjami */
}

/* Obraz, na którym jest tło, powinien być w normalnym przepływie */
.rozdzielnia-image-container img {
    display: block; /* Upewnia się, że obraz zajmuje całą dostępną szerokość */
    pointer-events: none; /* Obraz nie powinien przechwytywać zdarzeń myszy */
}


.svg-overlay rect,
.svg-overlay polygon {
    fill: none; /* Domyślne wypełnienie, zostanie zmienione przez JS */
    stroke: #000;
    stroke-width: 2;
    opacity: 0.6;
    transition: fill 0.3s ease, opacity 0.3s ease;
}

/* Style dla kolorów statusów w SVG */
.green-overlay { fill: #28a745; }
.yellow-overlay { fill: #ffc107; }
.red-overlay { fill: #dc3545; }
.blue-overlay { fill: #3598dc; }


.sterowanie {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    padding: 20px;
    width: 98%; /* Make it span full width */
    max-width: 100%; /* Ensure it doesn't exceed 100% of its parent */
    text-align: center;
    margin-top: 25px; /* Add margin-top for spacing from main */
}

.sterowanie h2 {
    color: #007bff;
    margin-top: 0;
    margin-bottom: 20px;
}

#sekcje-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: auto; /* Ogranicz wysokość, aby dodać przewijanie, jeśli jest dużo sekcji */
    overflow-y: auto; /* Włącz przewijanie pionowe */
    padding-right: 5px; /* Dodaj padding dla paska przewijania */
    margin-bottom: 20px;
}

.sekcja-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

.sekcja-item:hover {
    background-color: #e2e6ea;
}

.sekcja-name {
    font-weight: bold;
    color: #555;
    flex-basis: 70%; /* Dostosuj szerokość nazwy */
    text-align: left;
}

.current-status {
    flex-grow: 1; /* Pozwól na rozciąganie */
    padding: 5px 10px;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    text-align: center;
    margin: 0 10px;
    min-width: 80px; /* Minimalna szerokość dla statusu */
}

.status-selector {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    background-color: #fff;
    cursor: pointer;
    flex-basis: 15%; /* Dostosuj szerokość selektora */
}

.status-selector:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
}

/* Styl dla sekcji listy, gdy nie ma uprawnień do zapisu */
#sekcje-lista.disabled-for-viewer {
    opacity: 0.7;
    pointer-events: none; /* Blokuje wszystkie interakcje myszy */
}

.permission-message {
    color: #dc3545;
    font-weight: bold;
    margin-top: 20px;
    display: none; /* Domyślnie ukryte, widoczne po zalogowaniu jako viewer */
}

.historia-panel {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    padding: 20px;
    margin-top: 25px;
    width: 98%;
    max-width: 100%;
    text-align: center;
}

.historia-panel h2 {
    color: #007bff;
    margin-top: 0;
    margin-bottom: 20px;
}

#historia-lista {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 10px;
    border-radius: 5px;
    background-color: #fdfdfd;
    text-align: left;
}

.historia-item {
    padding: 8px 0;
    border-bottom: 1px dashed #eee;
    font-size: 0.9em;
}

.historia-item:last-child {
    border-bottom: none;
}

.timestamp {
    font-weight: bold;
    color: #666;
    margin-right: 5px;
}

.user-name-display {
    font-style: italic;
    color: #007bff;
}

.change-info {
    color: #333;
}

.change-info span {
    font-weight: bold;
}

.history-buttons-container {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.action-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

.action-button:hover {
    background-color: #0056b3;
}

.clear-history-button {
    background-color: #dc3545; /* Czerwony dla przycisku czyszczenia */
}

.clear-history-button:hover {
    background-color: #c82333;
}

/* Login Overlay Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-container {
    background-color: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 350px;
}

.login-container h2 {
    color: #007bff;
    margin-bottom: 25px;
}

.form-group {
    margin-bottom: 15px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: bold;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: calc(100% - 20px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

.login-container button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.3s ease;
    width: 100%;
    margin-top: 20px;
}

.login-container button:hover {
    background-color: #218838;
}

.error-message {
    color: #dc3545;
    margin-top: 15px;
    font-weight: bold;
}

.logged-in-user {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 0.9em;
    color: #fff; /* Kolor tekstu dla zalogowanego użytkownika */
    background-color: rgba(0, 123, 255, 0.7); /* Lekkie tło */
    padding: 5px 10px;
    border-radius: 5px;
    display: none; /* Domyślnie ukryte */
}

.logout-button {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 5px 10px; /* ZMIENIONO: Mniejszy padding */
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8em; /* ZMIENIONO: Mniejsza czcionka */
    transition: background-color 0.3s ease;
}

.logout-button:hover {
    background-color: #5a6268;
}

/* Responsywność */
@media (max-width: 1200px) {
    main {
        flex-direction: column;
        align-items: center;
    }

    .rozdzielnia-view {
        min-width: unset; /* Usuń minimalną szerokość dla mniejszych ekranów */
        width: 100%;
    }

    .history-buttons-container {
        flex-wrap: wrap; /* Zezwól na zawijanie przycisków na mniejszych ekranach */
        justify-content: center; /* Wyśrodkuj przyciski przy zawijaniu */
    }

    .history-buttons-container #clear-history-btn {
        margin-left: unset; /* Usuń automatyczny margines na małych ekranach */
    }
}

@media (max-width: 768px) {
    .app-container {
        margin: 10px;
        padding: 15px;
    }

    h1 {
        font-size: 1.8em;
    }

    /* Usunięto stałą wysokość kontenera obrazu na małych ekranach, aby skalował się z zawartością */
    .login-container {
        width: 90%;
        padding: 20px;
    }

    .header-logo {
        height: 40px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5em;
    }

    /* Usunięto stałą wysokość kontenera obrazu na małych ekranach, aby skalował się z zawartością */
}