/* ===== Flussonic Stream Manager - Dark Theme ===== */

:root {
    --bg-body: #09090b;
    --bg-sidebar: #0f0f12;
    --bg-card: #18181b;
    --bg-input: #1c1c21;
    --bg-hover: #27272a;
    --bg-active: #1e293b;
    
    --border: #27272a;
    --border-focus: #3b82f6;
    --border-light: #1f1f23;
    
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-inverse: #09090b;
    
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.12);
    
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.12);
    --error: #ef4444;
    --error-soft: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.12);
    
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 240px;
    --transition: 0.15s ease;
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Layout ===== */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.sidebar-brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-section {
    padding: 20px 20px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.06em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 450;
    transition: all var(--transition);
    border-left: 2px solid transparent;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--accent);
    background: var(--accent-soft);
    border-left-color: var(--accent);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.sidebar-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-stats .dot {
    width: 3px;
    height: 3px;
    background: var(--text-muted);
    border-radius: 50%;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px 40px;
    min-height: 100vh;
    min-width: 0;
    overflow-x: hidden;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.page-actions {
    display: flex;
    gap: 8px;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-active { color: var(--success); }
.stat-inactive { color: var(--text-muted); }

/* ===== Filter Bar ===== */
.filter-bar {
    margin-bottom: 16px;
}

.filter-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-select {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--border-focus);
}

.filter-select-sm {
    padding: 5px 8px;
    font-size: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #fff;
}

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

.btn-secondary:hover {
    background: #333;
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
    color: #fff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: all var(--transition);
    background: none;
    border: none;
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon-danger:hover {
    background: var(--error-soft);
    color: var(--error);
}

/* ===== Tables ===== */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-body);
}

.data-table th {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.row-inactive {
    opacity: 0.5;
}

.cell-title {
    font-weight: 500;
    max-width: 200px;
}

.cell-url {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-footer {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* ===== Status Badge ===== */
.status-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
}

.status-active {
    background: var(--success-soft);
    color: var(--success);
}

.status-active:hover {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.status-inactive {
    background: rgba(113, 113, 122, 0.15);
    color: var(--text-muted);
}

.status-inactive:hover {
    background: rgba(113, 113, 122, 0.25);
    color: var(--text-secondary);
}

/* ===== Category Badge ===== */
.category-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.category-badge-sm {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-hover);
    color: var(--text-muted);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    flex-shrink: 0;
}

/* ===== Code Inline ===== */
.code-inline {
    background: var(--bg-body);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* ===== Action Buttons Row ===== */
.action-buttons {
    display: flex;
    gap: 2px;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 13px;
}

.empty-state-small {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Forms ===== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.form-section-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group {
    margin-bottom: 16px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

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

.form-check-group {
    margin-bottom: 8px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.form-actions-inline {
    margin-top: 16px;
}

.input-with-btn {
    display: flex;
    gap: 8px;
}

.input-with-btn input {
    flex: 1;
}

/* ===== UA Display ===== */
.ua-display {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.ua-display code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    word-break: break-all;
}

/* ===== Info / Preview Box ===== */
.info-box {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 20px;
}

.info-box h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.preview-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    background: transparent;
    margin: 0;
}

/* ===== Flash Messages ===== */
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: opacity 0.3s, transform 0.3s;
}

.flash-success {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.flash-error {
    background: var(--error-soft);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.flash-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    padding: 0 4px;
}

.flash-close:hover { opacity: 1; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 9999;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ===== Export Page ===== */
.export-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.export-count {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.stream-checklist {
    max-height: 500px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stream-check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition);
}

.stream-check-item:hover {
    background: var(--bg-hover);
}

.stream-check-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.stream-check-info {
    flex: 1;
    min-width: 0;
}

.stream-check-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.stream-check-url {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.export-result {
    margin-top: 20px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.export-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.export-result-header h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.export-result-actions {
    display: flex;
    gap: 6px;
}

.export-code {
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #a5d6ff;
    background: transparent;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    max-height: 500px;
    overflow-y: auto;
}

/* ===== Settings ===== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.bulk-op {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}

.bulk-op:last-child {
    border-bottom: none;
}

.bulk-op h4 {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.bulk-op-actions {
    margin-top: 8px;
}

.danger-zone {
    border-top: 1px solid rgba(239, 68, 68, 0.2);
    margin-top: 8px;
    padding-top: 20px;
}

.danger-zone h4 {
    color: var(--error);
}

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 1px 8px;
    background: var(--bg-hover);
    color: var(--text-muted);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }

/* ===== Checkboxes in table ===== */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ===== Table Wrapper (horizontal scroll) ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== Mobile Menu Toggle ===== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 90;
}

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

/* Tablets */
@media (max-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .settings-grid {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .quality-fields-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .backup-field-row {
        flex-wrap: wrap;
    }
    /* Inline rule rows in settings */
    .exclude-rule-row,
    .proxy-rule-row > div,
    .priority-rule-row {
        flex-wrap: wrap;
    }
    .exclude-rule-row .form-group[style*="flex:0 0 200px"],
    .priority-rule-row .form-group[style*="flex:0 0 70px"] {
        flex: 1 1 auto !important;
        min-width: 120px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    /* Hamburger button */
    .mobile-menu-toggle {
        display: flex;
    }
    
    /* Sidebar: off-canvas */
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 150;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar.open + .sidebar-overlay {
        display: block;
    }
    
    /* Main content: full width */
    .main-content {
        margin-left: 0;
        padding: 60px 12px 24px;
    }
    
    /* Page header */
    .page-header {
        flex-direction: column;
        gap: 12px;
    }
    .page-actions {
        flex-wrap: wrap;
        width: 100%;
    }
    .page-actions .btn {
        flex: 1;
        justify-content: center;
        min-width: 0;
        font-size: 12px;
        padding: 7px 10px;
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stat-card {
        padding: 14px;
    }
    .stat-value {
        font-size: 22px;
    }
    .stat-label {
        font-size: 10px;
    }
    
    /* Filter bar */
    .filter-form {
        flex-direction: column;
        align-items: stretch;
    }
    .search-box {
        min-width: 0;
        width: 100%;
    }
    .filter-form .filter-select {
        width: 100%;
    }
    
    /* Table: horizontal scroll */
    .table-container {
        border-radius: var(--radius);
    }
    .data-table {
        min-width: 650px;
    }
    .data-table th,
    .data-table td {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    /* Forms */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .form-section {
        padding: 16px;
    }
    .input-with-btn {
        flex-direction: column;
    }
    .input-with-btn .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    /* Export page */
    .export-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .export-count {
        margin-left: 0;
    }
    .export-result-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    .export-result-actions {
        width: 100%;
    }
    .export-result-actions .btn {
        flex: 1;
        justify-content: center;
    }
    
    /* Backup sources */
    .backup-field-row {
        flex-direction: column;
        gap: 8px;
    }
    .backup-field-row .form-group {
        flex: 1 1 100% !important;
    }
    .backup-source-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    .backup-source-actions-header {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Quality fields */
    .quality-fields-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    /* Action buttons in table */
    .action-buttons {
        gap: 0;
    }
    .btn-icon {
        width: 28px;
        height: 28px;
    }
    
    /* Settings inline rule rows - full stack on mobile */
    .exclude-rule-row,
    .priority-rule-row {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .exclude-rule-row .form-group,
    .priority-rule-row .form-group {
        flex: 1 1 100% !important;
    }
    .exclude-rule-row .btn-icon,
    .priority-rule-row .btn-icon {
        align-self: flex-end;
    }
    .proxy-rule-row > div {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .proxy-rule-row .form-group {
        flex: 1 1 100% !important;
    }
    
    /* Export code block */
    .export-code {
        font-size: 11px;
        max-height: 350px;
    }
    
    /* Stream checklist on export pages */
    .stream-checklist {
        max-height: 350px;
    }
    
    /* Online status row */
    .online-status-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* Preview section in stream edit */
    .preview-section pre {
        font-size: 11px;
        max-height: 300px;
    }
    
    /* Toast */
    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .main-content {
        padding: 56px 8px 20px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .stat-card {
        padding: 10px;
    }
    .stat-value {
        font-size: 20px;
    }
    .page-title {
        font-size: 18px;
    }
    .page-subtitle {
        font-size: 12px;
    }
    .form-section {
        padding: 12px;
    }
    .form-section-title {
        font-size: 13px;
        flex-wrap: wrap;
    }
    .quality-fields-grid {
        grid-template-columns: 1fr 1fr;
    }
    .data-table {
        min-width: 550px;
    }
    /* Buttons stack on very small screens */
    .form-actions-inline {
        flex-direction: column;
    }
    .form-actions-inline .btn {
        width: 100%;
        justify-content: center;
    }
    .export-result-actions {
        flex-direction: column;
        gap: 6px;
    }
    .export-result-actions .btn {
        width: 100%;
        justify-content: center;
    }
    /* Smaller badges */
    .badge, .backup-count-badge, .category-badge-sm {
        font-size: 10px;
        padding: 1px 5px;
    }
}

/* ===== Backup Sources ===== */
.backup-sources-section {
    margin-bottom: 24px;
}

.backup-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.backup-empty p {
    margin-top: 8px;
    font-size: 13px;
}

.backup-source-card {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.backup-source-card:hover {
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.backup-source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
}

.backup-source-handle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.backup-source-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.backup-source-actions-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.backup-source-body {
    padding: 16px;
}

.backup-field-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.backup-field-row:last-child {
    margin-bottom: 0;
}

.backup-field-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-check-sm {
    font-size: 12px;
}

.form-check-sm span {
    font-size: 12px;
}

/* Source count badge in dashboard table */
.source-count-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--warning-soft);
    color: var(--warning);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Backup count badge in export page */
.backup-count-badge {
    display: inline-block;
    padding: 1px 6px;
    background: var(--warning-soft);
    color: var(--warning);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    margin-left: 6px;
    vertical-align: middle;
}

/* Animations for backup source add/remove */
@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutSlide {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ===== Online/Offline Status ===== */
.online-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.online-yes {
    background: var(--success-soft);
    color: var(--success);
}

.online-no {
    background: var(--error-soft);
    color: var(--error);
}

.online-unknown {
    background: rgba(113, 113, 122, 0.15);
    color: var(--text-muted);
}

.online-testing {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent);
}

.online-sm {
    font-size: 10px;
    padding: 1px 6px;
}

.online-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-online {
    background: var(--success);
    box-shadow: 0 0 4px rgba(34, 197, 94, 0.5);
}

.dot-offline {
    background: var(--error);
    box-shadow: 0 0 4px rgba(239, 68, 68, 0.4);
}

.dot-unknown {
    background: var(--text-muted);
}

.dot-testing {
    background: var(--accent);
    animation: pulse 1s ease infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.online-status-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

/* ===== Quality Tags ===== */
.quality-info {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.quality-tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.01em;
}

.quality-tag-sm {
    font-size: 9px;
    padding: 1px 5px;
}

.quality-type {
    background: rgba(6, 182, 212, 0.15);
    color: #67e8f9;
}

.quality-res {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.quality-bitrate {
    background: rgba(34, 197, 94, 0.12);
    color: #86efac;
}

.quality-codec {
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
}

.quality-fps {
    background: rgba(236, 72, 153, 0.12);
    color: #f472b6;
}

.cell-quality {
    min-width: 100px;
}

.cell-stream-name {
    margin-top: 2px;
}

.cell-stream-name code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 10px;
    color: var(--text-muted);
}

/* ===== Quality Edit Section ===== */
.quality-edit-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.quality-edit-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 12px;
}

.quality-fields-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.quality-fields-grid .form-group {
    margin-bottom: 0;
}

.quality-fields-grid .form-group input {
    font-size: 12px;
    padding: 6px 8px;
}

/* ===== Test Result Box ===== */
.test-result-box {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    word-break: break-all;
}

.test-loading {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--accent);
}

.test-online {
    background: var(--success-soft);
    border: 1px solid rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.test-offline {
    background: var(--error-soft);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--error);
}

/* ===== Backup Quality Row ===== */
.backup-quality-row {
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

.backup-quality-row .form-group input {
    font-size: 12px;
    padding: 5px 8px;
}

/* ===== Spinner ===== */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spin {
    animation: spin 0.8s linear infinite;
}

.testing {
    opacity: 0.6;
}

/* ===== Probe button ===== */
.btn-probe,
.btn-icon-probe {
    color: #67e8f9 !important;
    border-color: rgba(6, 182, 212, 0.3) !important;
}

.btn-probe:hover,
.btn-icon-probe:hover {
    background: rgba(6, 182, 212, 0.15) !important;
    border-color: rgba(6, 182, 212, 0.5) !important;
}

/* ===== Logout nav item ===== */
.nav-logout {
    margin-top: 8px;
    color: #a1a1aa !important;
    font-size: 13px;
}

.nav-logout:hover {
    color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.08);
}

/* ===== Selection highlight ===== */
::selection {
    background: var(--accent);
    color: #fff;
}
