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

:root {
    --bg:        #0d0f18;
    --surface:   #141720;
    --surface2:  #1c2030;
    --border:    #252a3d;
    --text:      #e2e8f0;
    --muted:     #6b7280;
    --accent:    #3b82f6;
    --blue:      #3b82f6;
    --green:     #22c55e;
    --yellow:    #eab308;
    --red:       #ef4444;
    --orange:    #f97316;
    --purple:    #a855f7;
    --cyan:      #06b6d4;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
}

/* ---------------------------------------------------------------- Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 1.4rem;
    color: var(--blue);
    line-height: 1;
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.last-updated {
    font-size: 0.72rem;
    color: var(--muted);
    margin-left: 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.refresh-label {
    font-size: 0.72rem;
    color: var(--muted);
}

#refresh-btn {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 14px;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

#refresh-btn:hover { background: #2563eb; }
#refresh-btn:disabled { background: #374151; cursor: not-allowed; }

#refresh-icon {
    display: inline-block;
    font-size: 1rem;
}

#refresh-icon.spinning {
    animation: spin 0.8s linear infinite;
}

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

/* ---------------------------------------------------------------- Stats bar */
.global-stats {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.stat-item {
    flex: 1;
    padding: 14px 20px;
    border-right: 1px solid var(--border);
    text-align: center;
    transition: background 0.2s;
}

.stat-item:last-child { border-right: none; }

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 4px;
}

.stat-up .stat-value   { color: var(--green); }
.stat-down .stat-value { color: var(--red); }
.stat-warn .stat-value { color: var(--yellow); }
.stat-warn             { background: rgba(234,179,8,0.05); }

/* ---------------------------------------------------------------- Tabs */
.tab-bar {
    display: flex;
    gap: 0;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 12px 18px;
    font-size: 0.82rem;
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

.tab-badge {
    background: var(--red);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
}

.tab-badge.pending-badge { background: var(--yellow); color: #000; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- Tab content */
.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* ---------------------------------------------------------------- Two column */
.two-col {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
}

.section-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

/* ---------------------------------------------------------------- Server cards */
.server-group {
    margin-bottom: 20px;
}
.server-group:last-child { margin-bottom: 0; }
.server-group-title {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
    font-weight: 600;
}
.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 12px;
}

.server-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.server-card.offline          { border-left: 3px solid #374151; opacity: 0.55; }
.server-card.border-green     { border-left: 3px solid var(--green); }
.server-card.border-yellow    { border-left: 3px solid var(--yellow); }
.server-card.border-red       { border-left: 3px solid var(--red); }

.server-name {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.server-ip {
    font-size: 0.68rem;
    color: var(--muted);
    font-family: monospace;
    margin-bottom: 10px;
}

.server-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.metric {}

.metric-label {
    font-size: 0.62rem;
    color: var(--muted);
    text-transform: uppercase;
}

.metric-value {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
}

.metric-value.green  { color: var(--green); }
.metric-value.yellow { color: var(--yellow); }
.metric-value.red    { color: var(--red); }

.bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s; }
.bar-fill.green  { background: var(--green); }
.bar-fill.yellow { background: var(--yellow); }
.bar-fill.red    { background: var(--red); }

.server-uptime {
    font-size: 0.68rem;
    color: var(--muted);
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- List rows */
.card-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.list-row {
    display: flex;
    align-items: center;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface2); }

.row-rank {
    font-size: 0.68rem;
    color: var(--muted);
    width: 22px;
    text-align: right;
    margin-right: 10px;
    flex-shrink: 0;
}

.row-name {
    flex: 1;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-viewers {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--cyan);
    margin-left: 8px;
    flex-shrink: 0;
}

.row-meta {
    font-size: 0.72rem;
    color: var(--muted);
    margin-left: 8px;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------- Health table */
.toolbar {
    margin-bottom: 14px;
}

.filter-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 5px 14px;
    transition: all 0.15s;
}

.pill:hover { border-color: var(--blue); color: var(--text); }
.pill.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.pill-count { background: #f97316; color: #fff; font-size: 0.65rem; padding: 1px 5px; border-radius: 8px; margin-left: 3px; font-weight: 700; }

.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

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

#health-table {
    table-layout: fixed;
    width: 100%;
}
.th-xc-id    { width: 5.5%; }
.th-channel  { width: 18%; }
.th-category { width: 12%; }
.th-country  { width: 5.5%; }
.th-status   { width: 8%; }
.th-checks   { width: 5.5%; text-align: center; }
.th-viewers  { width: 6%; text-align: center; }
.th-since    { width: 10%; }
.th-flags    { width: 8%; }
.th-actions  { width: 10%; }

thead th {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
    padding: 8px 10px;
    font-size: 0.8rem;
    vertical-align: middle;
}

.td-name     { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-category { color: var(--muted); font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-country  { color: var(--muted); font-size: 0.72rem; }
.td-num      { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.td-time     { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.td-notes    { color: var(--muted); font-size: 0.72rem; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- Status badges */
.badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 4px;
    padding: 2px 7px;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge-up       { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-suspect  { background: rgba(234,179,8,0.15);  color: var(--yellow); }
.badge-down     { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-warn     { background: rgba(249,115,22,0.15); color: var(--orange); }
.badge-swapped  { background: rgba(168,85,247,0.15); color: var(--purple); }
.badge-restore  { background: rgba(6,182,212,0.15);  color: var(--cyan); }
.badge-frozen   { background: rgba(107,114,128,0.15);color: var(--muted); }
.badge-quality-issue { background: rgba(251,191,36,0.2); color: #fbbf24; font-size: 0.68rem; padding: 2px 6px; margin-left: 4px; }
.badge-mass-exodus   { background: rgba(239,68,68,0.2);  color: #ef4444; font-size: 0.68rem; padding: 2px 6px; margin-left: 4px; animation: pulse-badge 1.5s infinite; }
.badge-group-outage  { background: rgba(239,68,68,0.25); color: #ef4444; font-size: 0.68rem; padding: 2px 6px; margin-left: 4px; font-weight: 700; }
.badge-flapping      { background: rgba(249,115,22,0.2); color: #f97316; font-size: 0.68rem; padding: 2px 6px; margin-left: 4px; font-weight: 600; animation: pulse-badge 2s infinite; }
@keyframes pulse-badge { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
tr.has-quality-issue { border-left: 3px solid #fbbf24; }
tr.is-flapping       { border-left: 3px solid #f97316; }

.flag {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    color: var(--muted);
    letter-spacing: 0.04em;
}

.flag-feeder { background: rgba(59,130,246,0.1); border-color: var(--blue); color: var(--blue); }

/* ---------------------------------------------------------------- Inline approval detail */
.approval-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.approval-label {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 110px;
    flex-shrink: 0;
}

.url-code {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.75rem;
    color: var(--cyan);
    background: var(--surface2);
    border-radius: 4px;
    padding: 2px 8px;
    word-break: break-all;
}

.btn-approve {
    background: rgba(34,197,94,0.15);
    border: 1px solid rgba(34,197,94,0.3);
    color: var(--green);
    border-radius: 6px;
    padding: 7px 18px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-approve:hover { background: rgba(34,197,94,0.25); }
.btn-approve:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-reject {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--red);
    border-radius: 6px;
    padding: 7px 18px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-reject:hover { background: rgba(239,68,68,0.2); }
.btn-reject:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-recheck {
    background: rgba(99,102,241,0.1);
    border: 1px solid rgba(99,102,241,0.25);
    color: #a5b4fc;
    border-radius: 6px;
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-recheck:hover { background: rgba(99,102,241,0.2); }
.btn-recheck:disabled { opacity: 0.45; cursor: not-allowed; }

/* XC ID column */
.td-xc-id {
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Panel link on channel name */
.link-panel {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed rgba(255,255,255,0.2);
    transition: color 0.15s, border-color 0.15s;
}
.link-panel:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Actions cell */
.td-actions {
    white-space: nowrap;
}

/* Snooze button + dropdown */
.snooze-wrap { position: relative; display: inline-block; }
.btn-snooze {
    background: rgba(148,163,184,0.1);
    border: 1px solid rgba(148,163,184,0.2);
    color: var(--muted);
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-snooze:hover { background: rgba(148,163,184,0.2); color: var(--text); }

.snooze-opts {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 50;
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.snooze-opts button {
    background: rgba(99,102,241,0.12);
    border: 1px solid rgba(99,102,241,0.25);
    color: #a5b4fc;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
}
.snooze-opts button:hover { background: rgba(99,102,241,0.25); }

/* Copy URL button */
.btn-copy {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(148,163,184,0.1);
    border: 1px solid rgba(148,163,184,0.2);
    color: var(--muted);
    border-radius: 5px;
    padding: 2px 8px;
    font-size: 0.73rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 5px;
}
.btn-copy:hover { background: rgba(148,163,184,0.2); color: var(--text); }

.btn-vlc {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(251,146,60,0.12);
    border: 1px solid rgba(251,146,60,0.25);
    color: #fb923c;
    border-radius: 5px;
    padding: 2px 9px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 8px;
}
.btn-vlc:hover { background: rgba(251,146,60,0.22); }

/* Provider health warning badge in approval cards */
.badge-provider-warn {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 4px;
    padding: 2px 7px;
    margin-left: 8px;
    vertical-align: middle;
}
.badge-provider-degraded {
    background: rgba(234,179,8,0.18);
    border: 1px solid rgba(234,179,8,0.35);
    color: #fbbf24;
}
.badge-provider-down {
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.3);
    color: #f87171;
}

/* Recheck result bar */
.recheck-result {
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    border-top: 1px solid var(--border);
}
.recheck-checking { color: var(--muted); font-style: italic; }
.recheck-alive    { color: var(--green); }
.recheck-dead     { color: var(--red); }

.action-id {
    font-size: 0.7rem;
    color: var(--muted);
    margin-left: auto;
}

.action-done {
    font-size: 0.8rem;
    color: var(--muted);
    font-style: italic;
}

/* ---------------------------------------------------------------- Providers */
.provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.provider-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.provider-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}

.provider-name {
    font-size: 0.85rem;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-dot { font-size: 0.65rem; }
.p-healthy  .status-dot, .p-healthy  { color: var(--green); }
.p-degraded .status-dot, .p-degraded { color: var(--yellow); }
.p-down     .status-dot, .p-down     { color: var(--red); }
.p-expired  .status-dot, .p-expired  { color: var(--muted); }

.provider-meta {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.p-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.p-label {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.p-val {
    font-size: 0.8rem;
    font-weight: 500;
}

.provider-status-bar {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: center;
    padding: 5px;
    background: var(--surface2);
}

.provider-status-bar.p-healthy  { background: rgba(34,197,94,0.1);  color: var(--green); }
.provider-status-bar.p-degraded { background: rgba(234,179,8,0.1);  color: var(--yellow); }
.provider-status-bar.p-down     { background: rgba(239,68,68,0.1);  color: var(--red); }
.provider-status-bar.p-expired  { background: rgba(107,114,128,0.1);color: var(--muted); }

/* ---------------------------------------------------------------- Empty / placeholder */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 72px 24px;
    text-align: center;
}

.empty-icon {
    font-size: 3rem;
    color: var(--green);
    margin-bottom: 12px;
}

.empty-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.empty-sub {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 4px;
}

.placeholder {
    color: var(--muted);
    font-size: 0.82rem;
    padding: 24px;
    text-align: center;
}

.text-red  { color: var(--red) !important; }
.text-green{ color: var(--green) !important; }

/* ---------------------------------------------------------------- Provider alive bar + chips */
.alive-bar {
    position: relative;
    height: 22px;
    background: rgba(239,68,68,0.15);
    overflow: hidden;
}
.alive-fill {
    height: 100%;
    background: rgba(34,197,94,0.25);
    transition: width 0.4s ease;
}
.alive-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.02em;
}

.rel-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
    font-size: 0.78rem;
}
.rel-good { background: rgba(34,197,94,0.15); color: var(--green); }
.rel-warn { background: rgba(234,179,8,0.15); color: var(--yellow); }
.rel-bad  { background: rgba(239,68,68,0.15); color: var(--red); }

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 14px 8px;
}
.chip {
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
}
.chip-res   { background: rgba(99,102,241,0.12); color: #818cf8; }
.chip-codec { background: rgba(168,85,247,0.12); color: #a855f7; }

.sub-prov-list {
    font-size: 0.7rem;
    word-break: break-word;
}

/* ---------------------------------------------------- Health action buttons */
.btn-action {
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.btn-action:disabled { opacity: 0.5; cursor: default; }
.btn-action:hover:not(:disabled) { opacity: 0.85; }

.btn-approve    { background: rgba(34,197,94,0.2); color: #22c55e; }
.btn-reject     { background: rgba(239,68,68,0.2); color: #ef4444; }
.btn-find-replace { background: rgba(59,130,246,0.2); color: #3b82f6; }
.btn-restart    { background: rgba(245,158,11,0.2); color: #f59e0b; }
.btn-restore    { background: rgba(168,85,247,0.2); color: #a855f7; }
.btn-failed     { background: rgba(239,68,68,0.15); color: #ef4444; cursor: default; }

.badge-queued {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(59,130,246,0.15);
    color: #3b82f6;
}

.spinning {
    position: relative;
    color: transparent !important;
}
.spinning::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 12px; height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid rgba(59,130,246,0.3);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.td-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

/* --------------------------------------------------- Provider capacity bar */
.capacity-val {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.capacity-bar {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    min-width: 60px;
    cursor: help;
}
.capacity-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.capacity-green  { background: #22c55e; }
.capacity-yellow { background: #eab308; }
.capacity-red    { background: #ef4444; }
.capacity-text {
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0.8;
}
.capacity-warn-badge {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    border-radius: 50%;
    background: rgba(239,68,68,0.25);
    color: #ef4444;
    font-size: 0.6rem;
    font-weight: 700;
    vertical-align: middle;
}
.badge-disabled {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.35);
}

/* ---------------------------------------------------------------- Channels tab */
.ch-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 0;
    min-height: 500px;
}

.ch-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px 0 0 8px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

.ch-sidebar-title {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 12px 14px 8px;
    border-bottom: 1px solid var(--border);
}

.ch-cat-list { display: flex; flex-direction: column; }

.ch-cat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.78rem;
    border-bottom: 1px solid rgba(37,42,61,0.5);
    transition: background 0.1s;
}
.ch-cat-item:hover { background: var(--surface2); }
.ch-cat-item.active {
    background: rgba(59,130,246,0.1);
    color: var(--blue);
    font-weight: 600;
    border-left: 2px solid var(--blue);
}
.ch-cat-count {
    font-size: 0.68rem;
    color: var(--muted);
    background: var(--surface2);
    border-radius: 10px;
    padding: 1px 7px;
    min-width: 22px;
    text-align: center;
}
.ch-cat-item.active .ch-cat-count { background: rgba(59,130,246,0.15); color: var(--blue); }

.ch-main {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.channels-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

.ch-search {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 7px 12px;
    font-size: 0.8rem;
    width: 240px;
    outline: none;
    transition: border-color 0.15s;
}
.ch-search:focus { border-color: var(--blue); }
.ch-search::placeholder { color: var(--muted); }

.ch-summary {
    font-size: 0.72rem;
    color: var(--muted);
}

#channels-table { table-layout: fixed; width: 100%; }

.ch-expand-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    transition: color 0.15s, transform 0.2s;
}
.ch-expand-btn:hover { color: var(--text); }
.ch-expand-btn.open { transform: rotate(90deg); color: var(--blue); }

.ch-detail-row td {
    padding: 0 !important;
    background: var(--bg);
}

.ch-detail-inner {
    padding: 12px 16px 12px 36px;
}

.ch-group-label {
    font-size: 0.7rem;
    color: var(--muted);
    margin-bottom: 8px;
}
.ch-group-label strong { color: var(--text); font-weight: 500; }

.ch-streams-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.ch-stream-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    transition: background 0.1s;
}
.ch-stream-row:last-child { border-bottom: none; }
.ch-stream-row:hover { background: rgba(255,255,255,0.02); }

.ch-stream-provider { min-width: 130px; font-weight: 500; }
.ch-stream-status { min-width: 60px; }
.ch-stream-status.alive { color: var(--green); }
.ch-stream-status.dead { color: var(--red); }
.ch-stream-status.unchecked { color: var(--muted); }
.ch-stream-score { min-width: 45px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-stream-sub { min-width: 90px; color: var(--muted); font-size: 0.72rem; }
.ch-stream-quality { min-width: 55px; font-size: 0.72rem; color: var(--cyan); }
.ch-stream-for {
    font-size: 0.72rem; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.ch-stream-canonical { font-size: 0.65rem; opacity: 0.75; }
.ch-stream-actions { margin-left: auto; flex-shrink: 0; }

.btn-remove-stream {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--red);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-remove-stream:hover { background: rgba(239,68,68,0.25); }

.btn-merge {
    background: rgba(168,85,247,0.1);
    border: 1px solid rgba(168,85,247,0.2);
    color: var(--purple);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-merge:hover { background: rgba(168,85,247,0.25); }

.ch-no-sources {
    font-size: 0.78rem;
    color: var(--muted);
    padding: 10px;
    text-align: center;
}

.ch-source-count-0 { color: var(--red); }
.ch-source-count-ok { color: var(--green); }

/* ---------------------------------------------------------------- Quick Fix */
#quick-fix {
    margin: 0 24px 16px;
}

.qf-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
}

.qf-icon { font-size: 1.1rem; }

.qf-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
}
.qf-input::placeholder { color: var(--muted); }

.qf-results {
    margin-top: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 480px;
    overflow-y: auto;
}

.qf-loading, .qf-empty {
    padding: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 0.82rem;
}

.qf-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}
.qf-row:last-child { border-bottom: none; }
.qf-row:hover { background: var(--surface2); }

.qf-name {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.qf-country {
    color: var(--muted);
    width: 30px;
    text-align: center;
    flex-shrink: 0;
}

.qf-xcid {
    color: var(--muted);
    font-size: 0.72rem;
    width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.qf-status {
    width: 70px;
    text-align: center;
    flex-shrink: 0;
}

.qf-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------- Ingestion tab */
.ingestion-stats-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 0;
}
.ing-stat-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    font-weight: 500;
}
.ing-stat-badge:hover { opacity: 0.9; }
.ing-badge-unmatched { background: var(--red); color: #fff; }
.ing-badge-suggested { background: var(--blue); color: #fff; }
.ing-badge-needs-review { background: var(--yellow); color: #000; }
.ing-badge-approved { background: var(--green); color: #fff; }
.ing-badge-published { background: var(--cyan); color: #000; }
.ing-badge-rejected { background: var(--muted); color: #fff; }

.ingestion-filters, .ingestion-bulk-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.ing-filter { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.ing-input { width: 60px; }
.ing-search { width: 180px; }
.ing-btn { padding: 6px 12px; border-radius: 6px; border: none; background: var(--blue); color: #fff; cursor: pointer; font-size: 0.9rem; }
.ing-btn:hover { opacity: 0.9; }
.ing-btn-approve { background: var(--green); }
.ing-btn-publish { background: var(--cyan); color: #000; }

.ing-row { cursor: pointer; }
.ing-row:hover { background: var(--surface2); }
.ing-expand { width: 24px; font-size: 0.7rem; }
.ing-detail-row.hidden { display: none; }
.ing-detail-inner { padding: 12px; background: var(--surface2); border-left: 3px solid var(--blue); }
.ing-detail-grid { display: grid; gap: 8px; font-size: 0.88rem; }
.ing-detail-grid ul { margin: 4px 0 0 16px; }
.ing-badge { padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }
.ing-actions { white-space: nowrap; }
.ing-btn-sm { padding: 4px 8px; margin-right: 4px; border-radius: 4px; border: none; cursor: pointer; font-size: 0.78rem; }
.ing-btn-sm.ing-btn-approve { background: var(--green); color: #fff; }
.ing-btn-sm.ing-btn-reject { background: var(--red); color: #fff; }
.ing-btn-sm.ing-btn-publish { background: var(--cyan); color: #000; }
.ing-warn { color: var(--orange); font-weight: 500; }

.ingestion-groups-section { margin-top: 24px; }
.ingestion-groups-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.ingestion-groups-toolbar label { display: flex; align-items: center; gap: 6px; }
.ing-groups-table { width: 100%; border-collapse: collapse; }
.ing-groups-table th, .ing-groups-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.ing-groups-table th { background: var(--surface2); font-weight: 500; }

/* ---------------------------------------------------------------- Events feed */
.events-feed { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }
.events-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; padding: 8px 0; }
.events-header h3 { margin: 0; font-size: 1rem; color: var(--text); }
.events-toggle { color: var(--muted); font-size: 0.85rem; }
.events-list { max-height: 400px; overflow-y: auto; }
.events-list.collapsed { display: none; }
.events-badge { background: var(--accent); color: white; border-radius: 10px; padding: 1px 7px; font-size: 0.7rem; margin-left: 8px; }

.event-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.event-card:hover { background: rgba(255,255,255,0.02); }
.event-severity { width: 4px; height: 32px; border-radius: 2px; flex-shrink: 0; }
.event-severity.sev-INFO { background: var(--green); }
.event-severity.sev-WARNING { background: var(--yellow); }
.event-severity.sev-CRITICAL { background: var(--red); }
.event-body { flex: 1; min-width: 0; }
.event-channel { font-weight: 600; font-size: 0.85rem; }
.event-type { font-size: 0.75rem; color: var(--muted); margin-left: 8px; }
.event-time { font-size: 0.72rem; color: var(--muted); }
.btn-dismiss { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 8px; }
.btn-dismiss:hover { color: var(--text); }

.expansion-row td { padding: 0 !important; border: none !important; }
.expansion-detail { background: rgba(59,130,246,0.05); border-left: 3px solid var(--accent); padding: 12px 16px; margin: 0; }
.expansion-detail .approval-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 0.82rem; }
.expansion-detail .approval-label { color: var(--muted); min-width: 100px; flex-shrink: 0; }
.expansion-detail code { font-size: 0.75rem; word-break: break-all; }
tr.has-pending { border-left: 3px solid var(--accent); cursor: pointer; }
tr.has-pending:hover { background: rgba(59,130,246,0.04); }

.btn-vlc { background: rgba(59,130,246,0.2); color: var(--blue); padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; text-decoration: none; margin-right: 6px; }
.btn-vlc:hover { opacity: 0.9; }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
    .global-stats { flex-wrap: wrap; }
    .stat-item { flex: 1 0 33%; }
    .ch-layout { grid-template-columns: 1fr; }
    .ch-sidebar { border-radius: 8px 8px 0 0; max-height: 200px; }
    .ch-main { border-left: 1px solid var(--border); border-radius: 0 0 8px 8px; }
}

@media (max-width: 600px) {
    .stat-item { flex: 1 0 50%; }
    .tab-btn { padding: 10px 12px; font-size: 0.75rem; }

    /* Channel Health table: hide non-essential columns, expand channel name */
    #health-table {
        table-layout: auto;
    }
    #health-table .th-xc-id,
    #health-table .th-category,
    #health-table .th-checks,
    #health-table .th-viewers,
    #health-table .th-flags,
    #health-table tbody td:nth-child(1),
    #health-table tbody td:nth-child(3),
    #health-table tbody td:nth-child(6),
    #health-table tbody td:nth-child(7),
    #health-table tbody td:nth-child(9) {
        display: none;
    }
    #health-table .th-channel { min-width: 0; }
    #health-table .td-name { min-width: 80px; max-width: none; }

    /* Health table action buttons: abbreviated text on mobile */
    #health-table .btn-action.btn-find-replace {
        font-size: 0;
        padding: 4px 8px;
    }
    #health-table .btn-action.btn-find-replace::after {
        content: 'Fix';
        font-size: 0.78rem;
    }
    #health-table .btn-action.btn-restart {
        font-size: 0;
        padding: 4px 8px;
    }
    #health-table .btn-action.btn-restart::after {
        content: 'Res';
        font-size: 0.78rem;
    }
    #health-table .btn-action.btn-restore {
        font-size: 0;
        padding: 4px 8px;
    }
    #health-table .btn-action.btn-restore::after {
        content: 'Undo';
        font-size: 0.78rem;
    }
    #health-table .btn-snooze {
        font-size: 0;
        padding: 4px 8px;
    }
    #health-table .btn-snooze::after {
        content: 'Snz';
        font-size: 0.78rem;
    }

    /* Quick Fix: hide xc-id and country, give name full flex */
    .qf-xcid,
    .qf-country {
        display: none;
    }
    .qf-name {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .qf-row {
        flex-wrap: wrap;
    }
    .qf-actions {
        flex-wrap: wrap;
    }
    /* Quick Fix buttons: abbreviated text on mobile */
    .qf-row .btn-action.btn-find-replace {
        font-size: 0;
        padding: 4px 8px;
    }
    .qf-row .btn-action.btn-find-replace::after {
        content: 'Fix';
        font-size: 0.78rem;
    }
    .qf-row .btn-action.btn-restart {
        font-size: 0;
        padding: 4px 8px;
    }
    .qf-row .btn-action.btn-restart::after {
        content: 'Res';
        font-size: 0.78rem;
    }
    .qf-row .btn-action.btn-restore {
        font-size: 0;
        padding: 4px 8px;
    }
    .qf-row .btn-action.btn-restore::after {
        content: 'Undo';
        font-size: 0.78rem;
    }
}

/* ---------------------------------------------------------------- Preview button */
.btn-preview {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: rgba(34,197,94,0.15);
    color: var(--green, #22c55e);
    white-space: nowrap;
    transition: background 0.15s;
}
.btn-preview:hover { background: rgba(34,197,94,0.28); }
.btn-preview.btn-sm { padding: 2px 7px; font-size: 0.72rem; }

/* ---------------------------------------------------------------- Preview overlay */
.preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.preview-overlay.hidden { display: none; }

.preview-modal {
    background: var(--card, #1e293b);
    border-radius: 14px;
    max-width: 720px;
    width: 100%;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.preview-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border, rgba(148,163,184,0.1));
}
.preview-title {
    flex: 1;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.preview-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
}
.preview-status.loading { background: rgba(251,191,36,0.2); color: #fbbf24; }
.preview-status.live    { background: rgba(34,197,94,0.2); color: #22c55e; }
.preview-status.offline { background: rgba(239,68,68,0.2); color: #ef4444; }

.preview-close {
    background: none;
    border: none;
    color: var(--muted, #94a3b8);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.preview-close:hover { color: var(--text, #e2e8f0); }

.preview-body {
    position: relative;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}
.preview-body img {
    width: 100%;
    height: auto;
    display: block;
}
.preview-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: var(--blue, #3b82f6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview-info {
    padding: 10px 16px;
    border-top: 1px solid var(--border, rgba(148,163,184,0.1));
    font-size: 0.78rem;
}
.preview-info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 12px;
    align-items: baseline;
}
.pi-label {
    color: var(--muted, #64748b);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.pi-value {
    color: var(--text, #e2e8f0);
    word-break: break-all;
}
.pi-url {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.72rem;
    color: var(--blue, #3b82f6);
    opacity: 0.85;
}

.preview-footer {
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--border, rgba(148,163,184,0.1));
}
.preview-footer .btn-action {
    flex: 1;
    text-align: center;
}

/* Deep Probe */
.badge-dp { font-size: 0.65rem; padding: 1px 5px; border-radius: 4px; font-weight: 600; }
.badge-dp-pass { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge-dp-warn { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-dp-fail { background: rgba(239,68,68,0.15); color: #ef4444; }

.btn-deep-probe {
    font-size: 0.7rem; padding: 3px 8px; border-radius: 4px;
    background: rgba(139,92,246,0.15); color: #a78bfa; border: 1px solid rgba(139,92,246,0.3);
    cursor: pointer; white-space: nowrap;
}
.btn-deep-probe:hover { background: rgba(139,92,246,0.3); }

.deep-probe-modal { max-width: 560px; }

.dp-modal-body {
    padding: 18px; max-height: 70vh; overflow-y: auto;
}
.dp-score-gauge {
    text-align: center; margin-bottom: 16px;
}
.dp-score-number {
    font-size: 2.4rem; font-weight: 700; line-height: 1;
}
.dp-score-label {
    font-size: 0.75rem; color: var(--muted, #64748b); text-transform: uppercase;
    letter-spacing: 0.05em; margin-top: 2px;
}
.dp-verdict {
    display: inline-block; padding: 2px 10px; border-radius: 4px;
    font-size: 0.75rem; font-weight: 700; margin-top: 6px;
}
.dp-verdict-pass { background: rgba(34,197,94,0.15); color: #22c55e; }
.dp-verdict-warn { background: rgba(245,158,11,0.15); color: #f59e0b; }
.dp-verdict-fail { background: rgba(239,68,68,0.15); color: #ef4444; }

.dp-metrics-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
    margin: 12px 0; font-size: 0.78rem;
}
.dp-metric-label { color: var(--muted, #64748b); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; }
.dp-metric-value { color: var(--text, #e2e8f0); }
.dp-metric-bad { color: #ef4444; }

.dp-reasons {
    margin: 12px 0; padding: 10px; border-radius: 6px;
    background: rgba(239,68,68,0.06); font-size: 0.78rem;
}
.dp-reasons li { margin: 4px 0; color: #fca5a5; }

.dp-history { margin-top: 16px; border-top: 1px solid var(--border, rgba(148,163,184,0.1)); padding-top: 12px; }
.dp-history-title { font-size: 0.75rem; font-weight: 600; color: var(--muted, #64748b); text-transform: uppercase; margin-bottom: 8px; }
.dp-history-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 0; border-bottom: 1px solid rgba(148,163,184,0.05); font-size: 0.75rem;
}
