* { margin: 0; padding: 0; box-sizing: border-box; }

/* Атрибут hidden должен побеждать display из классов (.empty-state, .main-image) */
[hidden] {
    display: none !important;
}

/* ===== ТЕМЫ ===== */
:root,
html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0a0a0f;
    --panel-bg: linear-gradient(145deg, #12121c, #16162a);
    --surface: #14141f;
    --surface-2: #1a1a2e;
    --hover-bg: #1f2036;
    --active-bg: #10263a;

    --border: #2a2a4a;
    --border-hover: #3d6fa8;

    --text: #e0e0e0;
    --text-strong: #ffffff;
    --text-muted: #888888;

    --accent: #00d4ff;
    --accent-contrast: #0a0a0f;
    --accent-soft: rgba(0, 212, 255, 0.18);
    --accent-glow: rgba(0, 212, 255, 0.3);

    --frame-bg: #111111;
    --thumb-hover-border: #555555;
    --scroll-track: #1a1a2e;

    --overlay: rgba(0, 0, 0, 0.95);
    --overlay-btn: rgba(255, 255, 255, 0.1);
    --overlay-btn-hover: rgba(255, 255, 255, 0.2);
    --overlay-text: #ffffff;
}

html[data-theme="light"] {
    color-scheme: light;

    --bg: #eef1f6;
    --panel-bg: linear-gradient(145deg, #ffffff, #f4f7fb);
    --surface: #ffffff;
    --surface-2: #f5f8fc;
    --hover-bg: #e9f1f9;
    --active-bg: #dceef8;

    --border: #cfd8e3;
    --border-hover: #8fb0cf;

    --text: #1e2430;
    --text-strong: #0f141c;
    --text-muted: #5d6a7a;

    --accent: #0077a8;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(0, 119, 168, 0.14);
    --accent-glow: rgba(0, 119, 168, 0.22);

    --frame-bg: #e6ebf2;
    --thumb-hover-border: #b6c2d1;
    --scroll-track: #dde4ee;

    --overlay: rgba(12, 18, 26, 0.92);
    --overlay-btn: rgba(255, 255, 255, 0.12);
    --overlay-btn-hover: rgba(255, 255, 255, 0.24);
    --overlay-text: #ffffff;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.25s ease, color 0.25s ease;
}

/* Приложение занимает ровно высоту экрана: на ПК вертикальной прокрутки нет */
.app {
    max-width: 1680px;
    height: 100%;
    margin: 0 auto;
    padding: 12px 20px 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.current-camera {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 1.05rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
    flex: 0 0 auto;
}

.current-camera i {
    color: var(--accent);
}

#currentIp {
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ===== LAYOUT: слайдер слева, панель камер справа напротив картинки ===== */
.layout {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "controls theme"
        "stage    side"
        "thumbs   side";
    gap: 10px 20px;
}

.viewer-controls {
    grid-area: controls;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

/* ===== ПЕРЕКЛЮЧАТЕЛЬ ТЕМЫ ===== */
.theme-toggle {
    grid-area: theme;
    justify-self: end;
    align-self: center;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.theme-toggle i {
    color: var(--accent);
}

/* ===== CAMERAS PANEL ===== */
.cameras {
    grid-area: side;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.cameras-title {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cameras-title i {
    color: var(--accent);
}

.camera-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
}

.camera-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.camera-item:hover {
    border-color: var(--border-hover);
    background: var(--hover-bg);
}

.camera-item.active {
    border-color: var(--accent);
    background: var(--active-bg);
    box-shadow: 0 0 16px var(--accent-soft);
}

.camera-icon {
    color: var(--accent);
    font-size: 1rem;
    flex-shrink: 0;
}

.camera-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.camera-ip {
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-strong);
}

.camera-count {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.ctrl-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 13px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.05rem;
    transition: all 0.3s;
}

.ctrl-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.play-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-color: var(--accent);
    color: var(--accent);
}

.play-btn.playing {
    background: var(--accent);
    color: var(--accent-contrast);
}

.speed-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.speed-label input[type="range"] {
    width: 100px;
    accent-color: var(--accent);
}

#speedVal {
    color: var(--accent);
    font-weight: 600;
    min-width: 35px;
}

.order-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.order-label input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.order-label i {
    color: var(--accent);
}

.refresh-status {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 110px;
}

.refresh-status.fresh {
    color: var(--accent);
    font-weight: 600;
}

/* ===== SLIDESHOW ===== */
.slideshow-container {
    grid-area: stage;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.slide-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    background: var(--frame-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border);
    cursor: zoom-in;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, background 0.25s ease;
}

.slide-wrapper:hover {
    border-color: var(--accent);
}

.main-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    transition: opacity 0.3s;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.05rem;
}

.slide-info {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

#slideDate {
    color: var(--accent);
    font-weight: 600;
}

/* ===== THUMBNAILS ===== */
.thumbnails-container {
    grid-area: thumbs;
    min-width: 0;
    min-height: 0;
}

.thumbnails-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 0 6px;
    scroll-behavior: smooth;
}

.thumbnails-scroll::-webkit-scrollbar {
    height: 6px;
}

.thumbnails-scroll::-webkit-scrollbar-track {
    background: var(--scroll-track);
    border-radius: 3px;
}

.thumbnails-scroll::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.thumb {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    width: 120px;
    height: 84px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    background: var(--surface);
    cursor: pointer;
    transition: all 0.3s;
    opacity: 0.6;
}

.thumb:hover {
    opacity: 1;
    border-color: var(--thumb-hover-border);
}

.thumb.active {
    border-color: var(--accent);
    opacity: 1;
    box-shadow: 0 0 15px var(--accent-glow);
}

.thumb img {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    object-fit: cover;
    display: block;
}

.thumb-date {
    flex: 0 0 auto;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    padding: 3px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== LIGHTBOX ===== */
.lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--overlay);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    max-width: 95%;
    max-height: 90vh;
    position: relative;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    background: var(--overlay-btn);
    border: none;
    color: var(--overlay-text);
    font-size: 2rem;
    cursor: pointer;
    padding: 10px 15px;
    border-radius: 8px;
    transition: background 0.3s;
    z-index: 1001;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: var(--overlay-btn-hover);
}

.lightbox-close {
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
}

.lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* ===== RESPONSIVE ===== */
/* На ПК (>= 1001px) приложение занимает ровно экран, прокрутки нет */
@media (min-width: 1001px) {
    body {
        overflow: hidden;
    }
}

@media (max-width: 1000px) {
    html, body {
        height: auto;
    }

    body {
        min-height: 100vh;
    }

    .app {
        height: auto;
        min-height: 100vh;
    }

    .layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto auto auto auto;
        grid-template-areas:
            "theme"
            "side"
            "controls"
            "stage"
            "thumbs";
    }

    .theme-toggle {
        justify-self: stretch;
        justify-content: center;
    }

    .cameras {
        max-height: 45vh;
    }

    .camera-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 4px;
    }

    .camera-item {
        width: auto;
        flex: 0 0 auto;
    }

    .slide-wrapper {
        flex: 0 0 auto;
        aspect-ratio: 16/9;
    }
}

@media (max-width: 768px) {
    .current-camera { font-size: 0.9rem; padding: 6px 10px; }
    .slide-wrapper { aspect-ratio: 4/3; }
    .thumb { width: 100px; height: 74px; }
    .lightbox-prev, .lightbox-next { font-size: 1.5rem; padding: 8px 12px; }
}
