:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-card: #000000;
    --border-color: #333333;
    --text-primary: #ffffff;
    --text-secondary: #adb5bd;
    --accent-primary: #0d6efd;
    --accent-hover: #0b5ed7;
    --danger: #dc3545;
    --success: #198754;
    --live-green: #00cc66;
}

/* Базовые стили */
body {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #050505 100%);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Контейнеры */
.container-fluid {
    padding-left: 0;
    padding-right: 0;
    overflow-x: hidden;
}

@media (min-width: 768px) {
    .container-fluid {
        padding-left: calc(var(--bs-gutter-x) * 0.5);
        padding-right: calc(var(--bs-gutter-x) * 0.5);
    }
}

/* Карточки */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.card-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    /* Фиксированная высота, чтобы заголовок сайдбара "Камеры" и заголовок
     * плеера были на одной горизонтали, даже если содержимое разной высоты
     * (badge + h5 vs h5 + status-badges + кнопка). */
    min-height: 56px;
}

/* Навигация */
.navbar {
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    min-height: 60px;
}

.navbar-brand {
    font-size: 1.25rem;
    padding: 0.5rem 0;
    color: var(--text-primary) !important;
}

.nav-link {
    color: var(--text-secondary) !important;
    transition: all 0.2s ease;
    padding: 0.75rem 1rem !important;
    border-radius: 0.375rem;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary) !important;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Стили для имени пользователя и кнопки выхода */
.navbar-nav .nav-link.d-flex {
    padding: 0.5rem 1rem !important;
}

.user-name {
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
}

.logout-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    border-color: rgba(220, 53, 69, 0.3);
    color: #ff6b7b;
    white-space: nowrap;
}

.logout-btn:hover {
    background-color: var(--danger);
    border-color: var(--danger);
    color: var(--text-primary);
}

/* Сайдбар: фиксированная высота, не растягивается */
.sidebar-col {
    flex: 0 0 auto !important;
    max-width: none !important;
}

.sidebar-col .card {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* Список камер */
.camera-list {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.camera-item {
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-primary);
    text-decoration: none;
    width: 100%;
    min-height: 36px;
}

.camera-item .camera-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.camera-item .camera-badges {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    margin-left: 8px;
}

.camera-status-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.camera-online-slot { width: 28px; }
.camera-recording-slot { width: 18px; }
.camera-live-slot { width: 48px; }

.camera-item .camera-badges i {
    font-size: 0.75em;
}

.camera-item .camera-badges .badge {
    font-size: 0.55em !important;
}

/* Thin client dot indicator */
.tc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tc-dot.tc-online {
    background-color: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.tc-dot.tc-offline {
    background-color: #6c757d;
}

.camera-item:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-left-color: var(--accent-primary);
}

.camera-item.active {
    background-color: rgba(13, 110, 253, 0.1) !important;
    border-left-color: var(--accent-primary);
}

.camera-item .camera-name {
    font-weight: 500;
    color: var(--text-primary);
}

/* Индикаторы статуса камеры */
.camera-item .live-badge {
    color: var(--live-green);
    font-size: 0.65rem;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    visibility: hidden;
    white-space: nowrap;
}

.camera-item .live-badge.is-visible {
    visibility: visible;
}

.camera-item .recording-badge {
    color: var(--accent-primary);
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
}

/* Плеер */
.video-container {
    position: relative;
    width: 100%;
    background-color: #000;
    border-radius: 0;
    overflow: hidden;
    aspect-ratio: 16/9;
    max-height: 80vh;
}

@media (min-width: 768px) {
    .video-container {
        border-radius: 0 0 0.5rem 0.5rem;
    }
}

@media (max-width: 767.98px) {
    .video-container {
        /* Dynamic viewport follows the visible mobile browser area as its
         * address bar expands/collapses. Keep the full frame (no crop). */
        max-height: calc(100dvh - 7.25rem);
    }
}

.video-container video,
.video-container #hlsPlayer {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #000;
}

/* Полноэкранный режим для контейнера hls-плеера */
#hlsPlayer:fullscreen video,
#hlsPlayer:-webkit-full-screen video {
    object-fit: contain;
}

/* Индикаторы состояния */
.player-status-slots {
    display: grid;
    grid-template-columns: 72px 64px 132px;
    align-items: center;
    gap: 0.35rem;
}

.player-status-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.player-state-slot {
    position: relative;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.live {
    background-color: rgba(0, 204, 102, 0.15);
    color: var(--live-green);
    border: 1px solid rgba(0, 204, 102, 0.3);
}

.status-badge.live i {
    color: var(--live-green);
}

.status-badge.live-active {
    background-color: rgba(0, 204, 102, 0.25);
    color: var(--live-green);
    border: 1px solid var(--live-green);
    box-shadow: 0 0 10px rgba(0, 204, 102, 0.3);
}

.status-badge.recording {
    color: #ff5a67;
    border: 1px solid rgba(255, 90, 103, 0.45);
    background: rgba(220, 53, 69, 0.12);
}

.status-badge.connecting {
    background-color: rgba(255, 193, 7, 0.1);
    color: #ffc107;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

.status-badge.error {
    background-color: rgba(220, 53, 69, 0.1);
    color: #ff6b7b;
    border: 1px solid rgba(220, 53, 69, 0.3);
}

/* Оверлеи */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(20, 20, 30, 0.95) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay-content {
    text-align: center;
    max-width: 350px;
    padding: 2rem;
}

.overlay-content i {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

.overlay-content h5 {
    margin-bottom: 0.75rem;
    font-weight: 600;
    font-size: 1.25rem;
}

.overlay-content p {
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Спиннер загрузки */
.overlay .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.25rem;
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Таблицы */
.table {
    --bs-table-color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom-width: 1px;
}

.table td {
    vertical-align: middle;
}

/* Пагинация */
.pagination {
    --bs-pagination-bg: var(--bg-card);
    --bs-pagination-border-color: var(--border-color);
    --bs-pagination-color: var(--text-primary);
    --bs-pagination-hover-bg: rgba(255, 255, 255, 0.1);
    --bs-pagination-hover-color: var(--text-primary);
    --bs-pagination-focus-bg: rgba(255, 255, 255, 0.15);
    --bs-pagination-active-bg: var(--accent-primary);
    --bs-pagination-active-border-color: var(--accent-primary);
    gap: 0.25rem;
}

.page-link {
    border-radius: 0.25rem !important;
}

/* Кнопки */
.btn {
    transition: all 0.2s ease;
}

.btn-outline-primary {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-outline-primary:hover {
    background-color: var(--accent-primary);
    color: var(--text-primary);
}

/* Мобильные стили */
@media (max-width: 991.98px) {
    .navbar-collapse {
        background-color: var(--bg-card);
        padding: 1rem;
        border-radius: 0.5rem;
        margin-top: 0.5rem;
        border: 1px solid var(--border-color);
        max-height: 80vh;
        overflow-y: auto;
    }

    .navbar-nav {
        width: 100%;
    }

    .nav-item {
        width: 100%;
        margin-bottom: 0.25rem;
    }

    .nav-link {
        padding: 0.75rem 1rem !important;
        border-radius: 0.375rem;
        width: 100%;
        text-align: left;
    }

    /* Стили для блока с пользователем на мобильных */
    .navbar-nav .nav-link.d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
        background-color: rgba(255, 255, 255, 0.05);
    }

    .user-name {
        font-size: 1rem;
        padding: 0.25rem 0;
    }

    .logout-btn {
        width: 100%;
        padding: 0.5rem !important;
        font-size: 0.9rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 767.98px) {
    .viewer-page {
        padding-top: 0.25rem !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .viewer-layout {
        margin-left: 0;
        margin-right: 0;
    }

    .viewer-main {
        padding-left: 0;
        padding-right: 0;
    }

    .viewer-main > .card > .card-header {
        min-height: 44px;
        padding: 0.35rem 0.5rem !important;
    }

    .viewer-main > .card > .card-header h5 {
        min-width: 0;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 1rem;
    }

    .camera-menu-button {
        min-height: 34px;
    }

    .status-badge {
        padding: 0.2rem 0.45rem;
        font-size: 0.65rem;
    }

    .player-status-slots {
        grid-template-columns: 34px 34px 40px;
        gap: 0.15rem;
    }

    .player-status-slot .status-badge {
        width: 32px;
        min-height: 28px;
        padding: 0.2rem;
        justify-content: center;
    }

    .player-status-slot .status-badge i {
        margin-right: 0 !important;
    }

    .player-status-slot .status-badge span {
        display: none;
    }

    .mobile-camera-drawer {
        --bs-offcanvas-width: min(88vw, 360px);
        background: var(--bg-card);
    }

    .mobile-camera-drawer .offcanvas-header {
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-camera-drawer .offcanvas-body,
    .mobile-camera-drawer .card {
        height: 100%;
        max-height: none;
        border: 0 !important;
    }

    .mobile-camera-drawer .camera-list,
    .mobile-camera-drawer #cameraListCollapse {
        max-height: none;
        overflow-y: visible;
    }

    .card {
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    .video-container {
        border-radius: 0;
    }

    .camera-item {
        padding: 0.75rem !important;
    }

    .table-responsive {
        margin: 0 -0.75rem;
        width: calc(100% + 1.5rem);
    }

    .camera-list {
        max-height: none;
    }
}
