/* IPTV Proxy Server - Main Stylesheet */

:root {
    --primary: #4a7cc4;
    --primary-dark: #3a6bb0;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #a84040;
    --gray-50: #1a1a2e;
    --gray-100: #16162a;
    --gray-200: #2a2a4a;
    --gray-300: #3d3d5c;
    --gray-500: #8888a0;
    --gray-600: #a0a0b8;
    --gray-700: #c0c0d0;
    --gray-800: #e0e0e8;
    --gray-900: #0f0f1a;
    --card-bg: #1e1e36;
    --body-bg: #12121e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--body-bg);
    color: var(--gray-800);
    min-height: 100vh;
}

/* Header & Navigation */
header {
    background: var(--gray-900);
    color: white;
    padding: 1rem;
    padding-bottom: 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 { font-size: 1.25rem; display: flex; align-items: center; }
header .subtitle { font-size: 0.875rem; color: var(--gray-300); }

.header-icon {
    display: inline-flex;
    align-items: center;
    line-height: 1;
    margin-right: 0.25rem;
}

.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#header-streamcheck-row {
    display: none;
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

#header-streamcheck-row.active {
    display: block;
}

nav {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--gray-100);
    overflow-x: auto;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.75rem;
}

nav button {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--gray-600);
    cursor: pointer;
    border-radius: 0.375rem;
    white-space: nowrap;
    font-size: 0.875rem;
}

nav button:hover, nav button.active {
    background: var(--primary);
    color: white;
}

main { padding: 1rem; max-width: 1400px; margin: 0 auto; }

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    margin-bottom: 1rem;
}

.card-header {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 { font-size: 1rem; }
.card-body { padding: 1rem; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    text-align: center;
}

.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--gray-600); text-transform: uppercase; }

/* Tables */
.table-container { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--gray-200); }
th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); }
tr:hover { background: var(--gray-50); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover { background: var(--gray-300); }
.btn:disabled, .btn[disabled] {
    background: var(--gray-200) !important;
    color: var(--gray-400) !important;
    cursor: not-allowed;
    opacity: 0.6;
}
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-outline { background: var(--card-bg); border: 1px solid var(--gray-300); color: var(--gray-700); }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    min-height: 1.5rem;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-quality { background: #e0e7ff; color: #3730a3; font-weight: 600; }
.badge-muted { background: var(--gray-100); color: var(--gray-600); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.875rem; color: var(--gray-700); }
.form-control {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: var(--gray-50);
    color: var(--gray-800);
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-control-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.form-row { display: flex; gap: 0.5rem; align-items: center; }

/* Sections */
.section { display: none; }
.section.active { display: block; }

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
    overflow-y: auto;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: 0.5rem;
    max-width: 600px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-lg { max-width: 800px; }

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body { padding: 1rem; }
.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-600); }

/* Credentials */
.credential-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.credential-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.credential-name { font-weight: 600; font-size: 0.875rem; }

.url-display {
    background: var(--gray-100);
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-family: monospace;
    font-size: 0.75rem;
    word-break: break-all;
}

.help-text { font-size: 0.75rem; color: var(--gray-600); margin-top: 0.25rem; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--gray-200); margin-bottom: 1rem; }
.tab-btn {
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
    color: var(--gray-600);
}
.tab-btn.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 500; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Toast notifications */
.toast-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 300; }
.toast {
    background: var(--gray-900);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-top: 0.5rem;
    animation: slideIn 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Loading spinner */
.spinner { width: 40px; height: 40px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 2rem; }

/* Log viewer */
.log-viewer {
    background: var(--gray-900);
    color: #e5e7eb;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    padding: 0.75rem;
    border-radius: 0.375rem;
    height: 500px;
    overflow-y: auto;
    overflow-x: auto;
}
.log-entry { white-space: pre-wrap; word-break: break-all; padding: 0.125rem 0; }
.log-entry:hover { background: rgba(255,255,255,0.05); }
.log-level-DEBUG { color: #9ca3af; }
.log-level-INFO { color: #e5e7eb; }  /* Fallback: light gray */
.log-level-WARNING { color: #fbbf24; }  /* Fallback: yellow */
.log-level-ERROR { color: #f87171; }  /* Fallback: red */
.log-level-CRITICAL { color: #f87171; font-weight: bold; }  /* Fallback: red bold */
.log-controls { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; flex-wrap: wrap; }
.log-status { font-size: 0.75rem; color: var(--gray-600); }
.log-status.connected { color: var(--success); }
.log-status.disconnected { color: var(--danger); }

/* Log syntax highlighting */
.log-timestamp { color: #6b7280; }  /* Gray - muted */
.log-service { color: #22d3ee; }   /* Cyan - service names */
.log-level-tag { font-weight: bold; }
.log-level-tag.info { color: #60a5fa; }    /* Blue */
.log-level-tag.warning { color: #fbbf24; } /* Yellow */
.log-level-tag.error { color: #f87171; }   /* Red */
.log-level-tag.debug { color: #9ca3af; }   /* Gray */
.log-level-tag.critical { color: #f87171; background: rgba(248,113,113,0.2); padding: 0 0.25rem; border-radius: 2px; }
.log-url { color: #a78bfa; }       /* Purple - URLs */
.log-status-alive { color: #4ade80; font-weight: bold; }   /* Green */
.log-status-dead { color: #f87171; font-weight: bold; }    /* Red */
.log-status-black { color: #fb923c; font-weight: bold; }   /* Orange */
.log-status-timeout { color: #fbbf24; font-weight: bold; } /* Yellow */
.log-action { color: #f472b6; font-weight: bold; }  /* Pink - STREAM, FAILOVER, etc */
.log-channel { color: #fcd34d; }   /* Yellow/gold - channel names */
.log-quality { font-weight: bold; }
.log-quality-4k { color: #c084fc; }   /* Purple */
.log-quality-fhd { color: #34d399; }  /* Green */
.log-quality-hd { color: #60a5fa; }   /* Blue */
.log-quality-sd { color: #9ca3af; }   /* Gray */
.log-group-id { color: #a1a1aa; }     /* Zinc - muted */
.log-cuid { color: #a1a1aa; }         /* Zinc - muted */
.log-arrow { color: #6b7280; }        /* Gray arrows */
.log-bracket { color: #6b7280; }      /* Gray brackets */
.log-duration { color: #86efac; }     /* Light green - time durations */
.log-resolution { color: #67e8f9; }   /* Light cyan - resolution info */

/* Stream cards */
.stream-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}
.stream-card {
    background: var(--gray-900);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.stream-card-main {
    margin: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.stream-card-header {
    display: flex;
    gap: 0.75rem;
    padding: 0.375rem;
    min-height: 60px;
    justify-content: space-between;
    align-items: center;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.25rem;
    position: relative;
}
.stream-card-logo {
    position: absolute;
    left: 75%;
    top: 20%;
    width: 20%;       /* 95% - 75% */
    height: 60%;       /* 80% - 20% */
    border-radius: 0.375rem;
    object-fit: contain;
    background: transparent;
}
.stream-card-logo-square {
    /* no longer needed, kept for compat */
}
.stream-card-logo-placeholder {
    position: absolute;
    left: 75%;
    top: 20%;
    width: 20%;       /* 95% - 75% */
    height: 60%;       /* 80% - 20% */
    border-radius: 0.375rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: white;
}
.stream-card-title {
    flex: 1;
    min-width: 0;
    padding-left: 0.15rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.stream-card-title h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
}
.stream-type-icon {
    height: 24px;
    width: 24px;
    object-fit: contain;
    flex-shrink: 0;
    margin-left: 6px;
    margin-right: 2px;
}
.stream-card-title .group-device {
    font-size: 0.7rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
}
.stream-card-title .group-device .separator {
    margin: 0 0.15rem;
    color: var(--gray-400);
}
/* Scroll animation for overflowing text */
.stream-card-title h3 .scroll-text,
.stream-card-title .group-device .scroll-text {
    display: inline-block;
    white-space: nowrap;
    padding-right: 15px;
}
.stream-card-title h3.overflow .scroll-text,
.stream-card-title .group-device.overflow .scroll-text {
    animation: scroll-text 10s ease-in-out infinite;
}
@keyframes scroll-text {
    0%, 8% { transform: translateX(0); }
    45%, 55% { transform: translateX(var(--scroll-distance, -50px)); }
    92%, 100% { transform: translateX(0); }
}
.stream-card-now-playing {
    background: var(--gray-50);
    border-radius: 0.375rem;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
}
.stream-card-now-playing .label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}
.stream-card-now-playing .programme {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stream-card-stats {
    display: flex;
    flex-direction: column;
    font-size: 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.25rem;
}
.stream-stat-row {
    display: flex;
    position: relative;
}
.stream-stat-row:first-child::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 2%;
    width: 96%;
    height: 1px;
    background: var(--gray-300);
}
.stream-stat {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.375rem;
    transition: background-color 0.15s;
    position: relative;
}
/* Top row vertical dividers: 15% padding at top, extend to bottom */
.stream-stat-row:first-child .stream-stat:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 15%;
    height: 85%;
    width: 1px;
    background: var(--gray-300);
}
/* Bottom row vertical dividers: extend from top, 15% padding at bottom */
.stream-stat-row:last-child .stream-stat:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    height: 85%;
    width: 1px;
    background: var(--gray-300);
}
.stream-stat[onclick] {
    cursor: pointer;
}
.stream-stat[onclick]:hover {
    background: var(--gray-200);
}
.stream-stat-value {
    font-weight: 600;
    color: var(--gray-800);
}
.stream-stat-label {
    color: var(--gray-500);
    font-size: 0.65rem;
    text-transform: uppercase;
}
.stream-card-footer {
    padding: 0 0.5rem 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}
.stream-card-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.35rem;
}
.stream-card-meta .badge { width: 100%; }
.stream-card-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}
.stream-card-actions .btn {
    justify-content: center;
    padding: 0.5rem 0.5rem;
    min-height: 2.25rem;
    line-height: 1.2;
    text-align: center;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    border: 1px solid var(--gray-200);
    border-radius: 0.25rem;
}
.stream-card-details {
    display: none;
    padding: 0.75rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    font-size: 0.8rem;
}
.stream-card-details.open {
    display: block;
}
.stream-detail-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
}
.stream-detail-row:last-child {
    margin-bottom: 0;
}
.stream-detail-label {
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
}
.stream-detail-value {
    color: var(--gray-800);
    word-break: break-all;
}
.stream-detail-url {
    font-family: monospace;
    font-size: 0.75rem;
}
.stream-card-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}
.stream-card-empty-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

/* Backup selection modal */
.backup-modal-actions-top {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    gap: 0.5rem;
}
.backup-modal-session {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.5rem;
}
.backup-modal-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--gray-500);
}
.backup-modal-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
}
.backup-modal-url {
    font-family: monospace;
    word-break: break-all;
    max-width: 360px;
}
.backup-modal-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
    padding: 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.backup-modal-status {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}
.backup-modal-list {
    display: flex;
    flex-direction: column;
}
.backup-modal-empty {
    padding: 1rem;
    text-align: center;
    color: var(--gray-500);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
}
.backup-option {
    display: flex;
    gap: 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    padding: 0.75rem;
    background: var(--gray-50);
    flex-wrap: wrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.backup-option.preferred {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.08);
}
.backup-option.blocked {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
    opacity: 0.7;
}
.backup-option.blocked .backup-option-title {
    text-decoration: line-through;
    color: var(--gray-500);
}
.backup-option + .backup-option {
    margin-top: 0.75rem;
}
.backup-option-body {
    flex: 1;
    min-width: 220px;
}
.backup-option-header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}
.backup-option-title {
    font-weight: 600;
    color: var(--gray-800);
}
.backup-option-subtitle {
    font-size: 0.8rem;
    color: var(--gray-600);
}
.backup-option-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
}
.backup-option-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--gray-600);
}
.backup-option-meta strong {
    color: var(--gray-800);
}
.backup-option-error {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--danger);
}
.backup-option-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 0.5rem;
    min-width: 120px;
}
.backup-option-actions .btn {
    min-width: 90px;
}
.backup-option-status-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
}
.backup-option-buttons {
    display: flex;
    gap: 0.5rem;
}
.badge-health {
    border-radius: 9999px;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
}
.badge-health.health-alive { background: #dcfce7; color: #166534; }
.badge-health.health-dead { background: #fee2e2; color: #991b1b; }
.badge-health.health-black { background: #fef3c7; color: #92400e; }
.badge-health.health-stalled { background: #e0f2fe; color: #075985; }
.badge-health.health-unknown { background: var(--gray-200); color: var(--gray-700); }

/* Stream Backups Styles - Light theme to match main UI */
.stream-backups-header {
    margin-bottom: 20px;
}

.stream-backups-header h3 {
    margin-bottom: 8px;
    color: var(--gray-800);
}

.stream-backups-header .help-text {
    color: var(--gray-600);
    margin-bottom: 12px;
}

.stats-row {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
}

.stats-row .stat {
    padding: 8px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    color: var(--gray-800);
}

.actions-row {
    display: flex;
    gap: 10px;
}

.master-groups-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.master-group-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.master-group-card.disabled {
    opacity: 0.6;
}

.master-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.master-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--gray-800);
}

.group-icon {
    font-size: 1.2em;
}

.master-group-actions {
    display: flex;
    gap: 8px;
}

.backup-groups-section {
    margin-top: 12px;
}

.backup-groups-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    color: var(--gray-700);
}

.backup-groups-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.backup-group-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
}

.backup-group-info {
    flex: 1;
}

.backup-group-name {
    font-weight: bold;
    margin-bottom: 8px;
    display: block;
    color: var(--gray-800);
}

.backup-group-options {
    display: flex;
    gap: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--gray-700);
}

.empty-message {
    color: var(--gray-500);
    font-style: italic;
    padding: 16px;
    text-align: center;
}

/* Stream Backups Modal styles - uses separate class to avoid conflict with main modal */
.sb-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.sb-modal-overlay .sb-modal-content {
    background: var(--card-bg);
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    padding: 24px;
    min-width: 400px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    color: var(--gray-800);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.sb-modal-overlay .sb-modal-content.modal-large {
    min-width: 600px;
    max-width: 800px;
}

.sb-modal-overlay .sb-modal-content h3 {
    margin-bottom: 16px;
    color: var(--primary);
}

.sb-modal-overlay .sb-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.sb-modal-overlay .sb-form-group {
    margin-bottom: 16px;
}

.sb-modal-overlay .sb-form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--gray-700);
}

.sb-modal-overlay .sb-form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    color: var(--gray-800);
}

.sb-modal-overlay .sb-form-control:focus {
    outline: none;
    border-color: var(--primary);
}

/* Preview styles - Light theme */
.preview-channels {
    max-height: 60vh;
    overflow-y: auto;
}

.preview-channel {
    padding: 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    margin-bottom: 8px;
}

.preview-channel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    color: var(--gray-800);
}

.preview-base-name {
    font-size: 0.85em;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.match-count {
    margin-left: auto;
    color: var(--gray-600);
}

.requires-4k-toggle {
    margin-left: 8px;
    font-size: 0.85em;
    font-weight: normal;
}

.requires-4k-toggle input {
    margin-right: 4px;
}

.preview-matches {
    padding-left: 16px;
    border-left: 2px solid var(--gray-300);
}

.preview-match {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.9em;
    color: var(--gray-700);
}

.match-group {
    color: var(--gray-500);
}

/* Streamcheck grid layout - stacked vertically: results then groups */
.streamcheck-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Playlist Cards */
.playlist-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.playlist-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    padding: 1rem;
}

.playlist-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.playlist-card-header h3 {
    margin: 0;
    font-size: 1rem;
}

.playlist-card-header h3 a {
    color: var(--primary);
    text-decoration: none;
}

.playlist-card-header h3 a:hover {
    text-decoration: underline;
}

.playlist-card-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.playlist-stat {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.playlist-stat-value {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gray-800);
}

.playlist-stat-label {
    font-size: 0.7rem;
    color: var(--gray-500);
    text-transform: uppercase;
}

.playlist-card-meta {
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-bottom: 0.75rem;
}

.playlist-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 768px) {
    /* Stats grid - default 4 columns on mobile */
    .stats-grid { 
        grid-template-columns: repeat(4, 1fr);
        gap: 0.35rem;
    }
    /* Streamcheck stats - 3 columns */
    .stats-grid.streamcheck-stats {
        grid-template-columns: repeat(3, 1fr);
    }
    .stat-card {
        padding: 0.6rem 0.35rem;
    }
    .stat-value {
        font-size: 1.15rem;
    }
    .stat-label {
        font-size: 0.65rem;
    }
    .hide-mobile { display: none; }
    
    /* Header adjustments */
    header { padding: 1rem 0.6rem 1.25rem 0.6rem; }
    header h1 { font-size: 1.1rem; }
    .header-icon { display: none; }
    #proxy-links-bar { padding: 0 0.35rem; }
    #proxy-links-bar .btn { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
    #header-status-info { font-size: 0.75rem !important; }
    
    /* Streamcheck row - shows underneath on mobile when active */
    #header-streamcheck-row {
        text-align: left;
        font-size: 0.75rem;
    }
    
    /* Navigation - horizontal scroll with smaller buttons */
    nav {
        gap: 0.2rem;
        padding: 0.4rem 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        margin-bottom: 0.5rem;
    }
    nav::-webkit-scrollbar {
        display: none;
    }
    nav button {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    /* Main content */
    main { padding: 0.5rem; }
    
    /* Cards */
    .card { margin-bottom: 0.6rem; }
    .card-header { padding: 0.6rem; }
    .card-body { padding: 0.6rem; }
    .card-header h2 { font-size: 0.95rem; }
    
    /* Streamcheck section - stack cards on mobile */
    .streamcheck-grid {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: unset !important;
    }
    
    /* Streamcheck groups list */
    #sc-groups-list {
        max-height: 200px !important;
    }
    
    /* Schedule rows on mobile */
    .schedule-row {
        gap: 0.5rem !important;
    }
    .schedule-row label {
        min-width: auto !important;
        width: 100% !important;
        margin-bottom: 0.25rem !important;
    }
    .schedule-row select,
    .schedule-row button,
    .schedule-row span {
        min-width: auto !important;
    }
    
    /* Table containers - proper scrolling */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }
    table {
        font-size: 0.8rem;
        min-width: 320px;
    }
    th, td {
        padding: 0.4rem 0.35rem;
        white-space: nowrap;
    }
    
    /* Buttons */
    .btn { font-size: 0.8rem; padding: 0.4rem 0.6rem; }
    .btn-sm { font-size: 0.75rem; padding: 0.25rem 0.45rem; }
    
    /* Badges */
    .badge { font-size: 0.7rem; padding: 0.2rem 0.4rem; }
    
    /* Forms */
    .form-control { font-size: 0.85rem; padding: 0.4rem; }
    .form-group label { font-size: 0.8rem; }
    .form-group { margin-bottom: 0.6rem; }
    
    /* Modals */
    .modal { width: 98%; max-height: 95vh; margin: 0.25rem; }
    .modal-header { padding: 0.6rem; }
    .modal-body { padding: 0.6rem; }
    .modal-footer { padding: 0.6rem; flex-wrap: wrap; }
    
    /* Stream cards */
    .stream-cards { grid-template-columns: 1fr; }
    .stream-card-logo, .stream-card-logo-placeholder { font-size: 1.5rem; }
    .stream-card-title h3 { font-size: 0.9rem; }
    .stream-card-actions { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .stream-card-actions .btn { padding: 0.5rem 0.25rem; min-height: 2.5rem; font-size: 0.6rem; }
    
    /* Stream stat boxes - taller on mobile */
    .stream-stat { padding: 0.6rem 0.375rem; }
    
    /* Backup modal */
    .backup-option { flex-direction: column; gap: 0.4rem; padding: 0.6rem; }
    .backup-option-body { min-width: 100%; }
    .backup-option-actions { 
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap; 
        gap: 0.35rem;
    }
    .backup-option-status-badges {
        justify-content: flex-start;
    }
    .backup-option-buttons {
        flex-wrap: wrap;
        gap: 0.35rem;
    }
    .backup-option-actions .btn { flex: none; min-width: auto; font-size: 0.75rem; padding: 0.35rem 0.6rem; }
    
    /* Log viewer */
    .log-viewer { height: 250px; font-size: 0.75rem; }
    .log-controls { gap: 0.25rem; flex-wrap: wrap; }
    
    /* Stream backups section - mobile fixes */
    .stream-backups-header {
        padding: 0 !important;
    }
    .stream-backups-header h3 {
        font-size: 1rem;
    }
    .stream-backups-header .help-text {
        font-size: 0.8rem;
    }
    .stats-row {
        flex-direction: column;
        gap: 0.3rem;
    }
    .stats-row .stat {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
    .actions-row {
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .actions-row .btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }
    
    /* Master group cards */
    .master-group-card {
        padding: 0.6rem;
    }
    .master-group-header { 
        flex-direction: column; 
        gap: 0.4rem; 
        align-items: flex-start;
        padding-bottom: 0.6rem;
        margin-bottom: 0.6rem;
    }
    .master-group-title {
        flex-wrap: wrap;
        gap: 0.3rem;
        font-size: 0.95rem;
    }
    .master-group-title .badge {
        font-size: 0.65rem;
    }
    .master-group-actions { 
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .master-group-actions .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
    
    /* Backup groups section */
    .backup-groups-header {
        flex-direction: column;
        gap: 0.3rem;
        align-items: flex-start;
        font-size: 0.85rem;
    }
    .backup-groups-header .btn {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }
    .backup-group-item { 
        flex-direction: column; 
        gap: 0.4rem; 
        align-items: flex-start;
        padding: 0.6rem;
    }
    .backup-group-name {
        font-size: 0.85rem;
    }
    .backup-group-options { 
        width: 100%; 
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    .checkbox-label {
        font-size: 0.8rem;
    }
    .backup-group-item > .btn {
        margin-top: 0.3rem;
    }
    
    /* Playlist cards mobile */
    .playlist-cards {
        grid-template-columns: 1fr;
    }
    .playlist-card {
        padding: 0.75rem;
    }
    .playlist-card-header h3 {
        font-size: 0.95rem;
    }
    .playlist-card-stats {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    .playlist-stat-value {
        font-size: 0.85rem;
    }
    .playlist-stat-label {
        font-size: 0.65rem;
    }
    .playlist-card-meta {
        font-size: 0.75rem;
    }
    .playlist-card-actions {
        gap: 0.35rem;
    }
    .playlist-card-actions .btn {
        font-size: 0.75rem;
    }
    
    /* SB Modal (stream backups modal) */
    .sb-modal-overlay .sb-modal-content {
        min-width: unset;
        width: 95%;
        padding: 0.75rem;
    }
    .sb-modal-overlay .sb-modal-content.modal-large {
        min-width: unset;
        max-width: 95%;
    }
    .sb-modal-actions {
        flex-wrap: wrap;
    }
    .sb-modal-actions .btn {
        flex: 1;
        min-width: 80px;
    }
}

/* ============================================================
   Channel Viewer - Stream Backups Module (Light theme)
   ============================================================ */

.channel-viewer-list {
    max-height: 60vh;
    overflow-y: auto;
    padding: 8px;
}

.channel-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 6px;
    overflow: hidden;
}

.channel-item.has-backups .channel-header {
    cursor: pointer;
}

.channel-item.has-backups .channel-header:hover {
    background: var(--gray-100);
}

.channel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
}

.channel-name {
    flex: 1;
    font-weight: 500;
    color: var(--gray-800);
}

.status-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

.status-indicator.status-alive {
    background: var(--success);
    color: white;
}

.status-indicator.status-dead {
    background: var(--danger);
    color: white;
}

.status-indicator.status-unknown {
    background: var(--gray-600);
    color: white;
}

.backup-count {
    color: var(--gray-500);
    font-size: 0.85em;
}

.backup-count.has-backups {
    color: var(--primary);
}

.expand-icon {
    width: 20px;
    text-align: center;
    color: var(--gray-500);
    transition: transform 0.2s;
}

.channel-item.expanded .expand-icon {
    transform: rotate(90deg);
}

.channel-backups {
    background: var(--gray-100);
    border-top: 1px solid var(--gray-200);
    padding: 8px 12px 8px 44px;
}

.backup-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-200);
}

.backup-item:last-child {
    border-bottom: none;
}

.backup-name {
    flex: 1;
    font-size: 0.9em;
    color: var(--gray-800);
}

.backup-group {
    color: var(--gray-500);
    font-size: 0.8em;
}

.quality-rank {
    color: var(--gray-500);
    font-size: 0.75em;
}

.channel-item.no-backups .channel-header {
    opacity: 0.7;
}

/* ============================================================
   Channel History Styles
   ============================================================ */

.channel-history-list {
    max-height: 60vh;
    overflow-y: auto;
}

.channel-history-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.channel-history-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.channel-history-name {
    font-size: 0.9rem;
    color: var(--gray-800);
}

.channel-history-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.history-stat {
    text-align: center;
    background: var(--gray-50);
    border-radius: 0.25rem;
    padding: 0.35rem;
    border: 1px solid var(--gray-200);
}

.history-stat-value {
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
}

.history-stat-label {
    font-size: 0.6rem;
    color: var(--gray-500);
    text-transform: uppercase;
}

.channel-history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.7rem;
    color: var(--gray-600);
}

.history-group-item {
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.history-group-item:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

@media (max-width: 768px) {
    .channel-history-list {
        max-height: 50vh;
    }
    
    .channel-history-item {
        padding: 0.5rem;
    }
    
    .channel-history-header {
        gap: 0.25rem;
    }
    
    .channel-history-name {
        font-size: 0.8rem;
        width: 100%;
    }
    
    .channel-history-stats {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.25rem;
    }
    
    .history-stat {
        padding: 0.25rem;
    }
    
    .history-stat-value {
        font-size: 0.75rem;
    }
    
    .history-stat-label {
        font-size: 0.5rem;
    }
    
    .channel-history-meta {
        gap: 0.35rem;
        font-size: 0.6rem;
    }
}
