/**
 * Stream Panel - Main Stylesheet
 * Dark theme inspired by Cloudflare / Google Cloud
 */

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #181e26;
    --bg-tertiary: #1f2937;
    --bg-card: #1c2634;
    --bg-hover: #263244;
    --bg-input: #0d1117;
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-info: #06b6d4;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border-color: #374151;
    --border-light: #4b5563;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --transition-speed: 0.25s;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-speed);
}

a:hover {
    color: var(--accent-primary-hover);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
}

input,
textarea,
select {
    font-family: inherit;
    font-size: 1rem;
}

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    background: var(--bg-primary);
    min-height: 100vh;
    transition: margin-left var(--transition-speed);
}

.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed);
    z-index: 100;
    overflow: hidden;
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 64px;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.sidebar-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 1;
    transition: opacity var(--transition-speed);
}

.sidebar-collapsed .sidebar-title {
    opacity: 0;
    pointer-events: none;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.5rem;
    color: var(--text-secondary);
    transition: all var(--transition-speed);
    border-left: 3px solid transparent;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-hover);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item span {
    white-space: nowrap;
    opacity: 1;
    transition: opacity var(--transition-speed);
}

.sidebar-collapsed .nav-item span {
    opacity: 0;
    pointer-events: none;
}

.sidebar-toggle {
    position: absolute;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-speed);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
    transition: transform var(--transition-speed);
}

.sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
    opacity: 1;
    transition: opacity var(--transition-speed);
}

.sidebar-collapsed .user-details {
    opacity: 0;
    pointer-events: none;
}

.user-name {
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Admin Nav */
.nav-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.75rem 1rem;
}

.nav-admin {
    color: var(--accent-secondary) !important;
}

.nav-admin:hover {
    background: rgba(139, 92, 246, 0.15) !important;
}

.nav-admin.active {
    border-left-color: var(--accent-secondary) !important;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header .logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all var(--transition-speed);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-error {
    color: var(--accent-danger);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-speed);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-primary-hover);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn-success {
    background: var(--accent-success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
}

.btn svg {
    width: 18px;
    height: 18px;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 600;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    margin-top: 0.25rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: all var(--transition-speed);
}

.card-hover:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: all var(--transition-speed);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-light);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-primary);
}

.stat-icon.orange {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-secondary);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-value.online {
    color: var(--accent-success);
}

.stat-value.offline {
    color: var(--accent-danger);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.table th,
.table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr {
    transition: background var(--transition-speed);
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

.badge-info {
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-info);
}

.badge-neutral {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background: var(--accent-success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--accent-danger);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* URLs */
.url-container {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.url-text {
    flex: 1;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.8125rem;
    color: var(--text-primary);
    word-break: break-all;
}

.url-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.copy-btn {
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-speed);
    flex-shrink: 0;
}

.copy-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.copy-btn.copied {
    background: var(--accent-success);
    border-color: var(--accent-success);
    color: white;
}

.copy-btn svg {
    width: 16px;
    height: 16px;
}

.stream-urls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.url-block {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.url-block-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.url-block-title svg {
    width: 18px;
    height: 18px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-speed);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: 100%;
    max-width: 500px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform var(--transition-speed);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-speed);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Toast */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 400px;
    transform: translateX(120%);
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(0);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: var(--accent-success);
}

.toast.error .toast-icon {
    color: var(--accent-danger);
}

.toast-message {
    flex: 1;
    font-size: 0.875rem;
}

.toast-close {
    background: transparent;
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-speed);
}

.toast-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.toast-close svg {
    width: 16px;
    height: 16px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    max-width: 400px;
    margin: 0 auto;
}

/* Loading */
.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--bg-tertiary);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition-speed);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Actions */
.actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.actions-cell {
    white-space: nowrap;
}

/* Utilities */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-secondary);
}

.text-success {
    color: var(--accent-success);
}

.text-danger {
    color: var(--accent-danger);
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 1rem;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.d-flex {
    display: flex;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 1rem;
}

.hidden {
    display: none !important;
}

.monospace {
    font-family: 'Roboto Mono', monospace;
}

/* ─────────────────────────────────────────────────────────────────────────────
   OBS CONTROL MODULE
   ───────────────────────────────────────────────────────────────────────────── */

.scene-control-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.scene-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
}

/* Spinner for loading states */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* OBS Scene Display */
.obs-current-scene {
    font-size: 1.25rem !important;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.obs-scene-name {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Scene Selector */
#scene-selector {
    max-width: 400px;
}

/* Empty State */
.empty-state {
    padding: 2rem;
    text-align: center;
}

.empty-state p {
    margin: 0.5rem 0;
}

/* Button Large */
.btn-lg {
    padding: 1rem 2rem;
    font-size: 1rem;
}

/* =========================================
   MOBILE OPTIMIZATION & RESPONSIVE OVERRIDES
   ========================================= */

@media (max-width: 768px) {

    /* --- Layout Reset --- */
    .layout {
        flex-direction: column;
        overflow-x: hidden;
        position: relative;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 1rem;
        padding-top: 70px;
        /* Header space */
        width: 100%;
        min-width: 0;
    }

    /* --- Common Mobile Fixes --- */
    .form-row,
    .scene-actions {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .scene-actions .btn {
        width: 100% !important;
    }

    #scene-selector {
        max-width: 100% !important;
    }

    /* --- Mobile Header --- */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1100;
        /* Above sidebar */
        width: 40px;
        height: 40px;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    /* --- Sidebar Drawer --- */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: 1000;
        /* Below Modals (2000), Above Content (1) */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active,
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(2px);
        z-index: 999;
        /* Below Sidebar */
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-toggle {
        display: none !important;
    }

    /* --- MODAL FIX (CRITICAL) --- */
    .modal,
    .cp-modal-content {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 90% !important;
        max-width: 90% !important;
        max-height: 85vh !important;
        margin: 0 !important;
        z-index: 2000 !important;
        /* Highest Layer */
        border-radius: 16px !important;
        overflow-y: auto !important;
        animation: modalFadeIn 0.3s ease-out;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5) !important;
        background: var(--bg-card) !important;
    }

    .modal-overlay,
    .cp-modal-backdrop,
    .cp-modal {
        z-index: 1999 !important;
        /* Just below modal content */
        background: rgba(0, 0, 0, 0.85);
        backdrop-filter: blur(4px);
        align-items: center;
        /* Helper for flex modals */
        justify-content: center;
        display: flex;
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .modal.active,
    .cp-modal.active {
        opacity: 1;
        visibility: visible;
    }

    @keyframes modalFadeIn {
        from {
            opacity: 0;
            transform: translate(-50%, -45%);
        }

        to {
            opacity: 1;
            transform: translate(-50%, -50%);
        }
    }

    /* --- Grids (Force Single Column) --- */
    .stats-grid,
    .connection-info-grid,
    .scene-grid-container,
    .cp-stats,
    .cp-form-row {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* --- Responsive Tables --- */
    .table-wrapper,
    .cp-card-body {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-card);
        margin-bottom: 1rem;
    }

    .table {
        min-width: 600px;
        /* Force scroll */
        border: none;
        width: 100%;
    }

    .table td,
    .table th {
        white-space: nowrap;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
        font-size: 0.85rem;
    }

    .table-wrapper::-webkit-scrollbar {
        height: 4px;
    }

    .table-wrapper::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 3px;
    }

    /* --- Typography & Spacing --- */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
        margin-left: 3rem;
        /* Space for hamburger */
    }

    .page-title {
        font-size: 1.5rem;
    }

    .card {
        padding: 1rem;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .btn-sm {
        width: auto;
    }

    /* Exception for small buttons */
    .btn-icon {
        width: 40px;
    }

    /* Login Page Mobile */
    .login-card {
        padding: 1.5rem;
        width: 100%;
    }

    /* --- OBS Mobile Specifics --- */
    /* Toolbar Buttons: Wrap them so they don't overflow */
    .card-header+div>div:first-child {
        flex-wrap: wrap !important;
        width: 100% !important;
    }

    .card-header+div>div:first-child .btn {
        flex: 1 1 auto !important;
        /* Grow to fill space */
        min-width: 120px !important;
    }

    /* Stats Bar: Stack or Grid to prevent overflow */
    #inline-stats-container {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        height: auto !important;
        width: 100% !important;
    }

    /* Hide the vertical dividers in stats since we are using grid */
    #inline-stats-container>div[style*="width: 1px"] {
        display: none !important;
    }

    /* Table Header Fix */
    .table th:first-child {
        min-width: 120px;
        /* Ensure Alias has space */
    }
}