/* --- Základní styly --- */
:root {
    --bg-color: #111;
    --text-color: #ddd;
    --header-bg: #1a1a1a;
    --border-color: #333;
    --cue-bg: #222;
    --cue-text: #999;
    --current-cue-bg: #555500;
    --current-cue-border: #aaaa00;
    --current-cue-text: #fff;
    --current-cue-id: #aaaa00;
    --highlight-color: #ff0;
    --btn-bg: #345a80;
    --btn-text: #fff;
    
    /* Proměnná pro globální jas (výchozí 100%) */
    --app-brightness: 1; 
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    overflow: hidden; 
    transition: background 0.3s, color 0.3s;
}

/* Aplikace jasu na hlavní obsah I na technická tlačítka */
.container, .tech-buttons {
    filter: brightness(var(--app-brightness));
}

/* === 🔴 RED MODE STYLY === */
body.red-mode {
    --bg-color: #000;
    --text-color: #a00; /* Tmavší červená pro běžný text */
    --header-bg: #000;
    --border-color: #300;
    --cue-bg: #000;
    --cue-text: #700;
    --current-cue-bg: #300; /* Aktivní cue pozadí */
    --current-cue-border: #f00; /* Aktivní cue rámeček */
    --current-cue-text: #f00; /* Aktivní cue text */
    --current-cue-id: #f00;
    --highlight-color: #f00;
    --btn-bg: #400;
    --btn-text: #f00;
}

/* Filtr pro obrázky v Red Mode (aby neoslňovaly) */
body.red-mode img {
    filter: grayscale(100%) sepia(100%) hue-rotate(-50deg) saturate(500%) brightness(0.7) contrast(1.2);
}
/* ========================== */

.container {
    display: flex;
    flex-direction: column;
    height: 100dvh; /* dvh pro mobily */
    max-width: 900px;
    margin: 0 auto;
}

/* --- Hlavička --- */
header {
    padding: 5px 10px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    flex-shrink: 0; 
    transition: background 0.3s, border-color 0.3s;
}
header h1 {
    font-size: 1.5em;
    color: #aaa;
    margin: 0 0 2px 0;
}
body.red-mode header h1 { color: #700; }

header p {
    font-size: 1.2em;
    color: #fff;
    margin: 0;
}
body.red-mode header p { color: #a00; }

/* Styl pro verzi showfile pod nadpisem */
.xml-info {
    font-size: 0.8em;
    font-style: italic;
    color: #777;
    margin-top: -3px;
    margin-bottom: 8px;
    font-weight: normal;
}
body.red-mode .xml-info { color: #500; }

/* --- Patička a Ovládání --- */
footer {
    padding: 5px;
    background: var(--header-bg);
    border-top: 1px solid var(--border-color);
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; 
    transition: background 0.3s, border-color 0.3s;
}
#status {
    color: var(--highlight-color);
    font-weight: bold;
    margin: 0 10px;
    flex-basis: 150px;
    text-align: left;
    font-size: 0.9em;
}
body.red-mode #status { color: #f00 !important; } /* V Red Mode vždy červeně */

.toggle-button {
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.3s;
}
.toggle-button:hover {
    opacity: 0.8;
}
.toggle-button.is-editing-active {
    background: #28a745; 
}
body.red-mode .toggle-button.is-editing-active {
    background: #030; /* Tmavě zelená v Red Mode */
    color: #0f0;
}

/* Ovládání Partů */
.part-nav {
    flex-grow: 1;
    text-align: center;
}
.part-nav-btn {
    background: #555;
    color: white;
    border: 1px solid #888;
    border-radius: 50%;
    font-size: 1.2em;
    font-weight: bold;
    width: 40px;
    height: 40px;
    margin: 0 5px;
    cursor: pointer;
}
body.red-mode .part-nav-btn {
    background: #200;
    color: #f00;
    border-color: #500;
}

.part-nav-btn:hover {
    background: #666;
}
body.red-mode .part-nav-btn:hover { background: #400; }

.part-nav-btn:disabled {
    background: #333;
    color: #666;
    border-color: #444;
    cursor: not-allowed;
}
body.red-mode .part-nav-btn:disabled {
    background: #100;
    color: #300;
    border-color: #200;
}

/* Styly pro Režimy */
#view-mode {
    display: flex;
    flex-grow: 1;
    flex-direction: column;
    position: relative; 
    overflow-y: auto; 
}
#edit-mode {
    display: none;
    flex-grow: 1;
    overflow-y: auto;
    text-align: left;
    padding: 20px;
    background: #333;
}
body.red-mode #edit-mode { background: #000; }

/* Vnitřek Režimu Prohlížení */
#edit-status-bar {
    display: none;
    padding: 5px;
    text-align: center;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 10;
    background: #004085;
    color: white;
    opacity: 1;
    transition: opacity 0.5s ease-out 2s;
}
body.red-mode #edit-status-bar { background: #300; color: #f00; }

#edit-status-bar.success {
    background: #28a745;
    color: white;
    opacity: 1;
    transition: none;
}
body.red-mode #edit-status-bar.success { background: #030; color: #0f0; }

#edit-status-bar.error {
    background: #d9534f;
    color: white;
    opacity: 1;
    transition: none;
}
body.red-mode #edit-status-bar.error { background: #500; color: #fff; }

#edit-status-bar.hidden {
    opacity: 0;
}

#cue-list-container {
    overflow-y: scroll;
    scroll-behavior: smooth;
    scroll-padding-top: 20vh;
    padding-left: 5px;
    padding-right: 5px;
    padding-bottom: 70vh;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
#cue-list-container::-webkit-scrollbar {
    display: none;
}

/* --- Položka v seznamu Cue --- */
.cue-item {
    padding: 5px 10px; 
    margin: 2px 0; 
    border-radius: 5px; 
    border: 2px solid var(--border-color);
    background: var(--cue-bg);
    color: var(--cue-text);
    text-align: left;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.cue-item-main {
    flex-grow: 1;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    min-width: 0; 
}

/* Barvy pro AKTUÁLNÍ Cue */
.cue-item.is-current {
    background: var(--current-cue-bg);
    border-color: var(--current-cue-border);
    color: var(--current-cue-text);
    transform: scale(1.01);
}
.cue-item.is-current .cue-item-id {
    color: var(--current-cue-id);
}
.cue-item.is-current .cue-item-note {
    color: #cccccc;
    font-weight: normal;
}
body.red-mode .cue-item.is-current .cue-item-note { color: #f00; }

.cue-item.is-current .cue-item-xml-name {
    color: var(--current-cue-id);
}

/* Styly pro REŽIM EDITACE */
#view-mode.is-editing-active .cue-item {
    cursor: pointer;
    border-color: #007bff;
}
body.red-mode #view-mode.is-editing-active .cue-item { border-color: #500; }

#view-mode.is-editing-active .cue-item:hover {
    background: #3a3a4a;
}
body.red-mode #view-mode.is-editing-active .cue-item:hover { background: #100; }

#view-mode.is-editing-active .cue-item.is-current {
    background: #222;
    border-color: #007bff;
    transform: none;
}
body.red-mode #view-mode.is-editing-active .cue-item.is-current {
    background: #100;
    border-color: #500;
}


.cue-item-header {
    display: flex;
    align-items: baseline;
    margin-bottom: 0;
    flex-wrap: wrap; 
}

.cue-item-id {
    font-size: 1.3em; 
    font-weight: bold;
    color: #aaa;
    margin-bottom: 2px;
    white-space: nowrap;
}
body.red-mode .cue-item-id { color: #700; }

.cue-item-xml-name {
    font-size: 0.9em; 
    font-style: italic;
    color: #aaa; 
    margin-left: 10px; 
    display: none;
}
body.red-mode .cue-item-xml-name { color: #500; }

#view-mode.show-xml-names .cue-item-xml-name {
    display: inline-block; 
}

.cue-item-note {
    font-size: 1.6em;
    color: #ddd;
    white-space: pre-wrap;
    min-height: 1.2em;
    line-height: 1.2;
}
body.red-mode .cue-item-note { color: #a00; }

.cue-item-note p { margin: 0; }
.cue-item-note strong, .cue-item-note b { font-weight: bold; }
.cue-item-note em, .cue-item-note i { font-style: italic; }
.cue-item-note u { text-decoration: underline; }

/* === ZMĚNA: Náhled obrázku === */
.cue-item-image {
    flex-basis: 80px;
    flex-shrink: 0; 
    margin-left: 10px;
}
.cue-item-image:empty {
    display: none;
}
.cue-item-image img {
    max-width: 100%;
    height: auto;
    border-radius: 3px;
    border: 1px solid #555;
    cursor: zoom-in; /* Naznačuje klikatelnost */
}
body.red-mode .cue-item-image img { border-color: #300; }


/* Styly pro Formulář (Editace) */
#edit-mode h2 { color: #fff; margin-top: 0; font-size: 1.5em; }
body.red-mode #edit-mode h2 { color: #f00; }

#edit-mode p { color: #ccc; }
body.red-mode #edit-mode p { color: #a00; }


#edit-mode textarea#edit-note-text { 
     display: none;
}

/* Nástrojová lišta */
.editor-toolbar {
    background: #444;
    padding: 5px;
    border-radius: 5px 5px 0 0;
    border: 1px solid #555;
    border-bottom: none;
}
body.red-mode .editor-toolbar { background: #200; border-color: #500; }

.editor-toolbar button {
    background: #666;
    color: white;
    border: 1px solid #777;
    border-radius: 3px;
    padding: 5px 8px;
    margin: 1px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9em;
}
body.red-mode .editor-toolbar button {
    background: #400;
    color: #f00;
    border-color: #600;
}

.editor-toolbar button:hover {
    background: #777;
}
body.red-mode .editor-toolbar button:hover { background: #600; }

.editor-toolbar button.arrow-btn {
    font-weight: bold;
    font-size: 1.1em;
    padding: 2px 6px;
    min-width: 25px;
}

/* Samotné editační pole */
#simple-editor {
    min-height: 120px; 
    padding: 15px;
    background: #222;
    color: #ddd;
    border: 1px solid #555;
    border-radius: 0 0 5px 5px;
    font-size: 1.2em;
    outline: none;
}
body.red-mode #simple-editor {
    background: #100;
    color: #f00;
    border-color: #500;
}


#edit-mode input[type=file] { padding: 10px 0; }

.form-actions {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
}
.form-actions button {
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
}
#btn-save-note {
    background: #007bff;
    color: white;
}
body.red-mode #btn-save-note { background: #500; color: #fff; }

#btn-save-note:hover {
    background: #0056b3;
}
#btn-save-and-close {
    background: #17a2b8;
    color: white;
}
body.red-mode #btn-save-and-close { background: #600; color: #fff; }

#btn-save-and-close:hover {
    background: #117a8b;
}

#edit-cue-display { font-size: 1.5em; color: #ff00ff; margin-bottom: 10px; text-align: center; }
body.red-mode #edit-cue-display { color: #f00; }

.form-back-button {
    background: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 20px;
}
body.red-mode .form-back-button { background: #333; color: #800; }

.form-back-button:hover {
    opacity: 0.8;
}

.part-management {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #555;
}
body.red-mode .part-management { border-color: #500; }

.part-management button {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    margin-right: 10px;
    margin-bottom: 10px;
}
#btn-add-part {
    background: #28a745;
    color: white;
}
body.red-mode #btn-add-part { background: #030; color: #0f0; }

#btn-delete-part {
    background: #d9534f;
    color: white;
}
body.red-mode #btn-delete-part { background: #500; color: #fff; }

#btn-delete-part:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
}
body.red-mode #btn-delete-part:disabled { background: #200; color: #500; }


/* Media Query pro responzivitu */
@media (max-width: 600px) {
    html {
        font-size: 90%;
    }
    header h1 { font-size: 1.1em; }
    header p { font-size: 1.0em; }
    .spot-popis { display: none; }
    
    .cue-item {
        padding: 5px 8px; 
    }
    .cue-item-image {
        flex-basis: 60px;
        margin-left: 8px;
    }
    .cue-item-id {
        font-size: 1.2em;
    }
    .cue-item-note {
        font-size: 1.4em;
    }
    
    .toggle-button { font-size: 0.8em; padding: 6px 8px; }
    #edit-cue-display { font-size: 1.3em; }

    .part-nav-btn {
        width: 35px;
        height: 35px;
        font-size: 1.0em;
    }
    #status {
        flex-basis: 100px;
        font-size: 0.8em;
    }
}

/* === Styly pro technická tlačítka (i, WakeLock, RED MODE) === */
.tech-buttons {
    position: fixed;
    top: 10px;
    right: 15px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end; /* Zarovnání doprava */
}

/* Společný styl pro kruhová tlačítka */
.tech-btn {
    background-color: #555;
    color: white;
    border: 2px solid #999;
    border-radius: 50%; 
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.3s, background-color 0.3s, border-color 0.3s;
}

/* Red mode tlačítka */
body.red-mode .tech-btn {
    background-color: #200;
    border-color: #500;
    color: #f00;
}

.tech-btn:hover {
    opacity: 1.0;
}

/* Aktivní stavy */
.tech-btn.active {
    opacity: 1.0;
}
#toggle-cue-names.active { background-color: #007bff; border-color: #fff; }
#wake-lock-toggle.active { background-color: #c99100; border-color: #fff; }

/* RED MODE přepínač aktivní */
#red-mode-toggle.active {
    background-color: #f00;
    color: #000;
    border-color: #f00;
    box-shadow: 0 0 10px #f00;
}

/* === Slider pro Jas (Nyní viditelný vždy) === */
.brightness-control {
    display: flex; /* Změna: viditelné vždy */
    background: rgba(30, 30, 30, 0.8); /* Neutrální pozadí */
    padding: 10px 5px;
    border-radius: 20px;
    border: 1px solid #555;
    margin-top: 5px;
    flex-direction: column;
    align-items: center;
}
body.red-mode .brightness-control {
    background: #200;
    border-color: #500;
}

/* Styl input range (slideru) vertikální */
input[type=range][orient=vertical] {
    writing-mode: bt-lr; /* IE */
    -webkit-appearance: slider-vertical; /* Webkit */
    width: 8px;
    height: 100px;
    padding: 0 5px;
}

/* === Lightbox (Modal) pro zvětšení obrázku === */
.image-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 5000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
body.red-mode .image-modal-overlay { background-color: rgba(0, 0, 0, 1); }

.image-modal-content {
    max-width: 98%;
    max-height: 98%;
    border: 2px solid #fff;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    object-fit: contain;
}
body.red-mode .image-modal-content {
    border-color: #f00;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.2);
    filter: grayscale(100%) sepia(100%) hue-rotate(-50deg) saturate(500%) brightness(0.7) contrast(1.2);
}

.image-modal-close-hint {
    position: absolute;
    bottom: 20px;
    color: #888;
    font-size: 1em;
    pointer-events: none;
}
body.red-mode .image-modal-close-hint { color: #f00; }