/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a1f36;
    --bg-card-hover: #212845;
    --bg-input: #0d1224;
    --border-color: #2a3150;
    --border-focus: #4f7cff;
    --text-primary: #e8eaf6;
    --text-secondary: #8892b0;
    --text-muted: #5a6380;
    --accent-primary: #4f7cff;
    --accent-secondary: #6c5ce7;
    --accent-gradient: linear-gradient(135deg, #4f7cff 0%, #6c5ce7 100%);
    --success: #00c853;
    --success-bg: rgba(0, 200, 83, 0.12);
    --warning: #ffab00;
    --warning-bg: rgba(255, 171, 0, 0.12);
    --error: #ff5252;
    --error-bg: rgba(255, 82, 82, 0.12);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(79, 124, 255, 0.2);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== Header ===== */
.header {
    background: rgba(17, 24, 39, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 32px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.app-download-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: wrap;
}

.app-download-btn {
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    transition: var(--transition);
}

.app-download-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(79, 124, 255, 0.08);
    text-decoration: none;
}

.app-download-btn .material-icons-round {
    font-size: 16px;
}

.app-download-btn-android {
    border-color: rgba(0, 200, 83, 0.28);
    color: var(--success);
}

.app-download-btn-ios {
    border-color: rgba(148, 163, 184, 0.28);
}

.app-download-btn-desktop {
    border-color: rgba(79, 124, 255, 0.28);
    color: var(--accent-primary);
}

.app-download-btn.is-disabled {
    cursor: not-allowed;
    opacity: 0.45;
    pointer-events: none;
}

.app-download-card {
    padding: 14px;
}

.app-download-card .card-title {
    margin-bottom: 12px;
    font-size: 12px;
}

.app-download-actions-sidebar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.app-download-actions-sidebar .app-download-btn {
    min-height: 46px;
    flex-direction: column;
    gap: 4px;
    padding: 8px 6px;
    line-height: 1.2;
    text-align: center;
    white-space: normal;
}

.live-app-download-card {
    animation: slideDown 0.3s ease;
}

.live-app-download-card .card-title {
    margin-bottom: 12px;
    font-size: 12px;
}

.live-app-download-card .card-title .material-icons-round {
    font-size: 16px;
}

.live-download-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.live-download-grid .app-download-btn {
    min-height: 42px;
    padding: 7px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.12);
    font-size: 12px;
    font-weight: 500;
    gap: 6px;
}

.live-download-grid .app-download-btn .material-icons-round {
    font-size: 18px;
}

.sidebar .app-download-card {
    flex-shrink: 0;
    margin-bottom: 8px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.sidebar .app-download-card .card-title {
    margin-bottom: 8px;
    font-size: 11px;
}

.sidebar .app-download-actions-sidebar {
    grid-template-columns: 1fr;
    gap: 6px;
}

.sidebar .app-download-actions-sidebar .app-download-btn {
    min-height: 34px;
    flex-direction: row;
    justify-content: flex-start;
    padding: 7px 10px;
    text-align: left;
    white-space: nowrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-shrink: 0;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
}

.logo-icon .material-icons-round {
    font-size: 24px;
    color: white;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.logo-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.header-status.idle {
    background: rgba(90, 99, 128, 0.2);
    color: var(--text-muted);
}

.header-status.connecting {
    background: var(--warning-bg);
    color: var(--warning);
    animation: pulse 1.5s infinite;
}

.header-status.playing {
    background: var(--success-bg);
    color: var(--success);
}

.header-status.error,
.header-status.finished {
    background: var(--error-bg);
    color: var(--error);
}

.user-dropdown-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(3, 7, 18, 0.68);
    backdrop-filter: blur(3px);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ===== Main Layout ===== */
.main-container {
    margin: 0;
    padding: 24px 32px;
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    min-height: calc(100vh - 80px);
}

/* ===== Card ===== */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: var(--transition);
    min-width: 0;
}

.card:hover {
    border-color: rgba(79, 124, 255, 0.3);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-title .material-icons-round {
    font-size: 20px;
    color: var(--accent-primary);
}

/* ===== Form ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.15);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.form-input-sm {
    padding: 8px 12px;
    font-size: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

textarea.form-input {
    resize: vertical;
    min-height: 70px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.5;
}

select.form-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238892b0' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ===== DateTime Input (dark theme fix) ===== */
input[type="datetime-local"].form-input,
input[type="date"].form-input,
input[type="time"].form-input {
    color: var(--text-primary);
    color-scheme: dark;
    cursor: pointer;
    padding: 10px 14px;
    font-size: 13px;
    min-height: 42px;
}

select.form-input:disabled,
input[type="datetime-local"].form-input:disabled,
input[type="date"].form-input:disabled,
input[type="time"].form-input:disabled {
    cursor: not-allowed;
}

/* ===== Searchable Camera Select ===== */
.camera-combobox {
    display: none;
    position: relative;
}

.camera-combobox.enhanced {
    display: block;
}

.camera-native-select-hidden {
    display: none;
}

.camera-combobox-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 2;
}

.camera-search-input {
    padding-left: 40px;
}

.camera-search-results {
    display: none;
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

.camera-search-results.visible {
    display: block;
}

.camera-search-results::-webkit-scrollbar {
    width: 5px;
}

.camera-search-results::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

.camera-search-option {
    width: 100%;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    text-align: left;
    cursor: pointer;
}

.camera-search-option:hover,
.camera-search-option.active {
    background: rgba(79, 124, 255, 0.14);
}

.camera-search-option-name {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
}

.camera-search-option-meta {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--text-muted);
}

.camera-search-empty {
    padding: 14px 10px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}

input[type="datetime-local"].form-input::-webkit-calendar-picker-indicator,
input[type="date"].form-input::-webkit-calendar-picker-indicator,
input[type="time"].form-input::-webkit-calendar-picker-indicator {
    filter: invert(0.7) sepia(1) saturate(3) hue-rotate(190deg);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.8;
    transition: var(--transition);
}

input[type="datetime-local"].form-input::-webkit-calendar-picker-indicator:hover,
input[type="date"].form-input::-webkit-calendar-picker-indicator:hover,
input[type="time"].form-input::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
    background: rgba(79, 124, 255, 0.15);
}

input[type="datetime-local"].form-input::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
}

input[type="datetime-local"].form-input::-webkit-datetime-edit-text {
    color: var(--text-muted);
    padding: 0 2px;
}

input[type="datetime-local"].form-input::-webkit-datetime-edit-day-field,
input[type="datetime-local"].form-input::-webkit-datetime-edit-month-field,
input[type="datetime-local"].form-input::-webkit-datetime-edit-year-field,
input[type="datetime-local"].form-input::-webkit-datetime-edit-hour-field,
input[type="datetime-local"].form-input::-webkit-datetime-edit-minute-field {
    color: var(--text-primary);
    padding: 2px 4px;
    border-radius: 3px;
}

input[type="datetime-local"].form-input::-webkit-datetime-edit-day-field:focus,
input[type="datetime-local"].form-input::-webkit-datetime-edit-month-field:focus,
input[type="datetime-local"].form-input::-webkit-datetime-edit-year-field:focus,
input[type="datetime-local"].form-input::-webkit-datetime-edit-hour-field:focus,
input[type="datetime-local"].form-input::-webkit-datetime-edit-minute-field:focus {
    background: rgba(79, 124, 255, 0.2);
    color: white;
}

/* ===== Mode Tabs ===== */
.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}

.mode-tab {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-tab:hover {
    color: var(--text-secondary);
}

.mode-tab:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.mode-tab:disabled:hover {
    color: var(--text-muted);
}

.mode-tab.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
}

.mode-tab .material-icons-round {
    font-size: 18px;
}

/* ===== Playback Section ===== */
.playback-section {
    display: none;
    animation: slideDown 0.3s ease;
}

.playback-section.visible {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.quick-times {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.quick-time-btn {
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
}

.quick-time-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(79, 124, 255, 0.08);
}

.quick-time-btn.active,
.quick-time-btn:focus-visible {
    border-color: var(--accent-primary);
    color: white;
    background: rgba(79, 124, 255, 0.35);
    box-shadow: 0 0 0 2px rgba(79, 124, 255, 0.18);
    outline: none;
}

.quick-time-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.quick-time-btn:disabled:hover {
    border-color: var(--border-color);
    color: var(--text-secondary);
    background: transparent;
}

.quick-time-btn.active:disabled {
    opacity: 0.75;
}

.quick-time-btn.active:disabled:hover {
    border-color: var(--accent-primary);
    color: white;
    background: rgba(79, 124, 255, 0.35);
}

.playback-speed-control {
    margin-top: 14px;
}

.playback-speed-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.playback-speed-btn {
    min-height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(13, 18, 36, 0.7);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
}

.playback-speed-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(79, 124, 255, 0.08);
}

.playback-speed-btn.active,
.playback-speed-btn:focus-visible {
    border-color: var(--accent-primary);
    color: white;
    background: rgba(79, 124, 255, 0.35);
    box-shadow: 0 0 0 2px rgba(79, 124, 255, 0.18);
    outline: none;
}

.playback-speed-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.playback-speed-btn:disabled:hover {
    border-color: var(--border-color);
    color: var(--text-secondary);
    background: rgba(13, 18, 36, 0.7);
}

.playback-speed-btn.active:disabled {
    opacity: 0.75;
    border-color: var(--accent-primary);
    color: white;
    background: rgba(79, 124, 255, 0.35);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.btn .material-icons-round {
    font-size: 20px;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(79, 124, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(79, 124, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-danger {
    background: linear-gradient(135deg, #ff5252 0%, #d32f2f 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 82, 82, 0.3);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(255, 82, 82, 0.4);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(79, 124, 255, 0.08);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 12px;
    width: auto;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

/* ===== URL Preview ===== */
.url-preview {
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    display: none;
}

.url-preview.visible {
    display: block;
    animation: slideDown 0.3s ease;
}

.url-preview-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.url-preview-text {
    font-size: 11px;
    color: var(--accent-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    word-break: break-all;
    line-height: 1.5;
}

/* ===== Stream Info ===== */
.stream-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-item {
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.info-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.info-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.info-value.small {
    font-size: 13px;
    font-weight: 500;
}

/* ===== Video Panel ===== */
.video-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    min-width: 0;
}

.video-container {
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    height: clamp(380px, calc(100vh - 190px), 820px);
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center center;
    display: block;
    background: #000;
}

.video-container img.video-frame-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
}

.video-container img.video-frame-layer.visible {
    opacity: 1;
    visibility: visible;
}

#videoCanvas,
.video-canvas-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center center;
    display: none;
    background: #000;
}

.video-container.fit-mode img {
    object-fit: contain;
}

.video-container.fit-mode .video-canvas-layer {
    object-fit: contain;
}

.video-container.fill-mode img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-container.fill-mode .video-canvas-layer {
    object-fit: cover;
}

.playback-debug-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 30;
    max-width: 360px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.72);
    color: #d8ffe0;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    line-height: 1.35;
    white-space: pre-line;
    pointer-events: none;
}

.video-placeholder {
    text-align: center;
    padding: 60px 40px;
}

.video-placeholder .material-icons-round {
    font-size: 80px;
    color: var(--text-muted);
    opacity: 0.3;
    margin-bottom: 16px;
}

.video-placeholder h3 {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 8px;
}

.video-placeholder p {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 400px;
    margin: 0 auto;
}

.video-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.video-container:hover .video-overlay {
    opacity: 1;
}

.playback-timeline {
    display: none;
    padding: 6px 12px 24px;
}

.playback-timeline.visible {
    display: block;
}

.timeline-track-wrapper {
    position: relative;
    padding: 10px 0 8px;
    cursor: pointer;
    touch-action: none;
}

.timeline-track {
    position: relative;
    height: 4px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    overflow: visible;
    transition: height 0.15s ease;
}

.timeline-track-wrapper:hover .timeline-track,
.timeline-track-wrapper.dragging .timeline-track {
    height: 7px;
}

.timeline-progress {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: inherit;
}

.timeline-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    transform: translate(-50%, -50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.timeline-track-wrapper:hover .timeline-thumb,
.timeline-track-wrapper.dragging .timeline-thumb {
    opacity: 1;
}

.timeline-preview {
    display: none;
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    width: 192px;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(8, 12, 24, 0.96);
    box-shadow: var(--shadow-lg);
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 25;
}

.timeline-preview.visible {
    display: block;
}

.timeline-preview img,
.timeline-preview-empty {
    display: block;
    width: 184px;
    height: 104px;
    border-radius: 4px;
    background: #000;
    object-fit: cover;
}

.timeline-preview img:not([src]),
.timeline-preview img[src=""] {
    display: none;
}

.timeline-preview-empty {
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 12px;
}

.timeline-preview.empty .timeline-preview-empty {
    display: flex;
}

.timeline-preview.empty img {
    display: none;
}

.timeline-preview-time {
    padding-top: 4px;
    text-align: center;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11px;
    line-height: 1.2;
}

.timeline-labels {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11px;
}

.timeline-speed-badge {
    min-width: 40px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(79, 124, 255, 0.24);
    color: var(--text-primary);
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
}

.video-overlay-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.video-overlay-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.overlay-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.overlay-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.overlay-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.overlay-btn.active {
    background: rgba(96, 165, 250, 0.35);
}

.overlay-btn .material-icons-round {
    font-size: 20px;
}

.live-badge {
    padding: 4px 10px;
    background: var(--error);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: none;
}

.live-badge.visible {
    display: inline-block;
    animation: pulse 2s infinite;
}

.playback-badge {
    padding: 4px 10px;
    background: var(--accent-primary);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: none;
}

.playback-badge.visible {
    display: inline-block;
}

/* ===== Connecting Overlay ===== */
.connecting-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 14, 26, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
}

.connecting-overlay.visible {
    display: flex;
}

.connecting-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.connecting-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.spinner.visible {
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
}

.modal-header h3 .material-icons-round {
    color: var(--accent-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 82, 82, 0.15);
    color: var(--error);
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(255, 82, 82, 0.3);
}

.modal-body {
    padding: 24px;
}

/* ===== Modal Tabs ===== */
.modal-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-input);
}

.modal-tab {
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}

.modal-tab:hover {
    color: var(--text-secondary);
    background: rgba(79, 124, 255, 0.05);
}

.modal-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(79, 124, 255, 0.08);
}

.modal-tab .material-icons-round {
    font-size: 18px;
}

.tab-panel {
    display: none;
    animation: slideDown 0.3s ease;
}

.tab-panel.active {
    display: block;
}

/* ===== Camera List ===== */
.camera-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: var(--transition);
}

.camera-item:hover {
    border-color: rgba(79, 124, 255, 0.3);
}

.camera-item-info {
    flex: 1;
}

.camera-item-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.camera-item-url {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
    word-break: break-all;
    margin-top: 4px;
}

.camera-item-location {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.camera-item-actions {
    display: flex;
    gap: 6px;
    margin-left: 12px;
}

.camera-action-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.camera-action-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.camera-action-btn.delete:hover {
    border-color: var(--error);
    color: var(--error);
}

.camera-action-btn .material-icons-round {
    font-size: 16px;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 90px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s ease;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
}

.toast.success {
    background: #1a3a1a;
    border: 1px solid rgba(0, 200, 83, 0.3);
    color: var(--success);
}

.toast.error {
    background: #3a1a1a;
    border: 1px solid rgba(255, 82, 82, 0.3);
    color: var(--error);
}

.toast.info {
    background: #1a2a3a;
    border: 1px solid rgba(79, 124, 255, 0.3);
    color: var(--accent-primary);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== Instructions ===== */
.instructions {
    padding: 20px;
}

.instructions h4 {
    font-size: 13px;
    color: var(--accent-primary);
    margin-bottom: 12px;
}

.instructions ol {
    padding-left: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 2;
}

.instructions code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--accent-primary);
}

/* ===== Responsive ===== */

/* ===== Camera Info Box ===== */
.camera-info-box {
    margin-top: 12px;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    animation: slideDown 0.3s ease;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.table-responsive,
#accountTableWrapper {
    -webkit-overflow-scrolling: touch;
}

.data-table,
.account-table,
.shortcut-table {
    min-width: 720px;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .control-panel {
        order: -1;
    }

    .video-container {
        height: min(56vw, 620px);
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    body.user-menu-open {
        overflow: hidden;
    }

    .user-dropdown-backdrop.visible {
        display: block;
    }

    .header {
        padding: 12px 16px;
    }

    .header-content {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .header-right {
        width: 100%;
        justify-content: flex-start;
        gap: 8px;
    }

    body.user-menu-open #userMenuContainer {
        position: static !important;
    }

    body.user-menu-open #userDropdownPanel {
        display: block !important;
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        width: min(92vw, 360px) !important;
        max-height: 84vh;
        overflow-y: auto;
        transform: translate(-50%, -50%) !important;
        z-index: 101 !important;
        animation: none !important;
    }

    .logo-icon {
        width: 36px;
        height: 36px;
    }

    .logo-icon .material-icons-round {
        font-size: 20px;
    }

    .logo-text {
        font-size: 17px;
        white-space: normal;
        line-height: 1.15;
    }

    .logo-subtitle {
        font-size: 10px;
        letter-spacing: 0.6px;
    }

    .header-status {
        padding: 6px 10px;
        font-size: 12px;
    }

    .main-container {
        padding: 12px;
        gap: 12px;
        min-height: auto;
    }

    .card {
        padding: 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .btn-group {
        grid-template-columns: 1fr;
    }

    .stream-info,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .playback-speed-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .video-container {
        height: auto;
        min-height: 220px;
        aspect-ratio: 16 / 9;
        border-radius: var(--radius-md);
    }

    .video-placeholder {
        padding: 28px 16px;
    }

    .video-placeholder .material-icons-round {
        font-size: 48px;
    }

    .video-overlay {
        align-items: flex-start;
        flex-direction: column;
        opacity: 1;
        padding: 12px;
    }

    .btn-sm {
        padding: 6px 10px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    body {
        min-width: 0;
    }

    .header {
        padding: 10px 12px;
    }

    .header-right {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .header-right > * {
        flex: 0 0 auto;
    }

    .app-download-actions {
        flex-wrap: nowrap;
    }

    .app-download-actions-sidebar {
        grid-template-columns: 1fr;
    }

    .live-download-grid {
        grid-template-columns: 1fr;
    }

    .app-download-actions-sidebar .app-download-btn {
        min-height: 38px;
        flex-direction: row;
        justify-content: flex-start;
        padding: 8px 10px;
        text-align: left;
        white-space: nowrap;
    }

    .main-container {
        padding: 10px;
    }

    .card {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .btn {
        min-height: 42px;
        padding-left: 14px;
        padding-right: 14px;
    }

    .quick-time-btn {
        flex: 1 1 calc(50% - 6px);
    }

    .camera-search-results {
        max-height: 260px;
    }

    .toast-container {
        left: 10px;
        right: 10px;
        width: auto;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
