:root {
    --channelflow-bg: #0b0f14;
    --channelflow-surface: #151b24;
    --channelflow-surface-2: #1c2430;
    --channelflow-border: #2a3444;
    --channelflow-text: #e8edf4;
    --channelflow-muted: #9aa7b8;
    --channelflow-accent: #3b82f6;
    --channelflow-accent-hover: #2563eb;
    --channelflow-success: #22c55e;
    --channelflow-warning: #f59e0b;
    --channelflow-danger: #ef4444;
    --channelflow-radius: 10px;
}

body { font-family: system-ui, -apple-system, Segoe UI, sans-serif; margin: 0; background: var(--channelflow-bg); color: var(--channelflow-text); }
#channelflow-app { max-width: 1400px; margin: 0 auto; padding: 1.25rem; }

.channelflow-header { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start; margin-bottom: .5rem; }
.channelflow-header h1 { margin: 0 0 .25rem; font-size: 1.75rem; }
.channelflow-header p { margin: 0; color: var(--channelflow-muted); }

.dashboard-stats { display: flex; gap: .75rem; flex-wrap: wrap; }
.stat-pill { background: var(--channelflow-surface); border: 1px solid var(--channelflow-border); border-radius: 999px; padding: .45rem .9rem; font-size: .85rem; color: var(--channelflow-muted); }
.stat-pill strong { color: var(--channelflow-text); }

.channelflow-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 1.25rem; }
.channelflow-tabs .tab { background: var(--channelflow-surface); color: var(--channelflow-text); border: 1px solid var(--channelflow-border); padding: .55rem 1rem; cursor: pointer; border-radius: 999px; transition: background .15s, border-color .15s; }
.channelflow-tabs .tab:hover { border-color: var(--channelflow-accent); }
.channelflow-tabs .tab.active { background: var(--channelflow-accent); border-color: var(--channelflow-accent); color: #fff; }

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

.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.lineup-toolbar { align-items: flex-end; }
.search-input { min-width: 220px; max-width: 320px; }

.split-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 960px) {
    .split-layout.has-panel { grid-template-columns: 1fr 380px; }
}

.split-side { position: sticky; top: 1rem; align-self: start; max-height: calc(100vh - 2rem); overflow: auto; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.panel-header h2 { margin: 0; font-size: 1.15rem; }

.card, .section-card { background: var(--channelflow-surface); padding: 1rem 1.1rem; border-radius: var(--channelflow-radius); margin-bottom: 1rem; border: 1px solid var(--channelflow-border); }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.section-header h3 { margin: 0; }

.form-grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.checkbox-grid { display: grid; gap: .45rem .85rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: .85rem 0; }
.checkbox-grid label { display: flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--channelflow-muted); }
.field { display: grid; gap: .35rem; }
.field > span { font-size: .85rem; color: var(--channelflow-muted); }
.field-group { display: grid; gap: .85rem; padding: .75rem; border: 1px dashed var(--channelflow-border); border-radius: 8px; }
.checkbox-field {
    position: relative;
    display: flex !important;
    grid-template-columns: unset;
    align-items: center;
    gap: .55rem;
    cursor: pointer;
}
.inline-field { display: grid; gap: .35rem; }
.inline-field > span { font-size: .8rem; color: var(--channelflow-muted); }

.card input:not([type="checkbox"]):not([type="radio"]), .card select, .toolbar input, .toolbar select, .modal input:not([type="checkbox"]):not([type="radio"]), .modal select, .modal textarea {
    width: 100%; max-width: none; padding: .55rem .65rem; border-radius: 8px; border: 1px solid var(--channelflow-border);
    background: var(--channelflow-surface-2); color: var(--channelflow-text); box-sizing: border-box;
}
.card input:not([type="checkbox"]):not([type="radio"]):focus, .card select:focus, .modal input:not([type="checkbox"]):not([type="radio"]):focus, .modal select:focus, .modal textarea:focus {
    outline: 2px solid rgba(59, 130, 246, .35); border-color: var(--channelflow-accent);
}

/* Jellyfin dashboard CSS hides native checkboxes. Draw our own box and keep
   the real input as an invisible hit target so .checked still works. */
#ChannelFlowConfigPage .checkbox-field input[type="checkbox"],
#ChannelFlowConfigPage .checkbox-grid input[type="checkbox"],
#ChannelFlowConfigPage .modal .checkbox-field input[type="checkbox"] {
    appearance: none !important;
    -webkit-appearance: none !important;
    position: absolute !important;
    left: 0 !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 1.25rem !important;
    min-width: 1.25rem !important;
    max-width: 1.25rem !important;
    height: 1.25rem !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0 !important;
    clip: auto !important;
    clip-path: none !important;
    z-index: 2;
    cursor: pointer;
}
#ChannelFlowConfigPage .channelflow-check-box {
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
    border: 2px solid #7dd3fc;
    border-radius: 4px;
    background: #0f172a;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    flex-shrink: 0;
}
#ChannelFlowConfigPage .checkbox-field:has(input:checked) .channelflow-check-box {
    background: var(--channelflow-accent);
    border-color: #93c5fd;
}
#ChannelFlowConfigPage .checkbox-field:has(input:checked) .channelflow-check-box::after {
    content: "";
    width: .28rem;
    height: .55rem;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}
.checkbox-grid label.checkbox-field {
    display: flex !important;
    grid-template-columns: unset;
}
.checkbox-field > span:not(.channelflow-check-box) { color: var(--channelflow-text); font-size: .9rem; }

.hidden { display: none !important; }
.hint { color: var(--channelflow-muted); font-size: .9rem; margin: 0 0 .75rem; }
.hint-warning { color: var(--channelflow-warning); border-left: 3px solid var(--channelflow-warning); padding-left: .65rem; }
.weather-resource-list { margin: 0 0 .85rem 1.1rem; color: var(--channelflow-muted); font-size: .9rem; }
.weather-resource-list li { margin-bottom: .45rem; }
.weather-resource-list a { color: #93c5fd; }
.weather-docker-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-bottom: 1rem; }
.weather-docker-panel { border: 1px solid var(--channelflow-border); border-radius: 10px; padding: .85rem; background: var(--channelflow-surface-2); }
.weather-docker-panel h4 { margin: 0 0 .5rem; }
.weather-docker-panel .status-card { margin: .65rem 0; font-size: .88rem; }
.ai-template-select { min-width: 180px; }
.ai-daypart-badge { display: block; font-size: .72rem; color: #93c5fd; margin-top: .2rem; }
.btn-inline { display: inline-block; margin-left: .35rem; padding: .15rem .55rem; font-size: .78rem; vertical-align: middle; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
button, .emby-button { background: var(--channelflow-surface-2); color: var(--channelflow-text); border: 1px solid var(--channelflow-border); padding: .5rem 1rem; border-radius: 8px; cursor: pointer; }
button:hover, .emby-button:hover { border-color: var(--channelflow-accent); }
.raised.button-submit, button.raised { background: var(--channelflow-accent); border-color: var(--channelflow-accent); color: #fff; }
.raised.button-submit:hover { background: var(--channelflow-accent-hover); }
.btn-ghost { background: transparent; border: 0; font-size: 1.4rem; line-height: 1; padding: .2rem .45rem; color: var(--channelflow-muted); }
.btn-danger { background: rgba(239, 68, 68, .15); border-color: var(--channelflow-danger); color: #fecaca; }
.btn-danger:hover { background: rgba(239, 68, 68, .25); }

.data-table-wrap { overflow: auto; border: 1px solid var(--channelflow-border); border-radius: var(--channelflow-radius); }
table.data-table { width: 100%; border-collapse: collapse; min-width: 520px; }
table.data-table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--channelflow-muted); background: var(--channelflow-surface-2); position: sticky; top: 0; }
table.data-table td, table.data-table th { padding: .65rem .75rem; border-bottom: 1px solid var(--channelflow-border); vertical-align: middle; }
table.data-table tbody tr { cursor: pointer; transition: background .12s; }
table.data-table tbody tr:hover { background: rgba(59, 130, 246, .08); }
table.data-table tbody tr.selected { background: rgba(225, 29, 72, .16); }
table.data-table td.catalog-plot { max-width: 22rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--channelflow-muted); }
table.data-table td.catalog-path, table.data-table td.catalog-ids { max-width: 16rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catalog-media-table { max-height: 28rem; }

.badge { display: inline-block; padding: .15rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.badge-on { background: rgba(34, 197, 94, .18); color: #86efac; }
.badge-off { background: rgba(148, 163, 184, .15); color: #cbd5e1; }
.badge-air { background: rgba(250, 204, 21, .18); color: #fde047; }
.badge-idle { background: rgba(148, 163, 184, .1); color: #94a3b8; }
.badge-type { background: rgba(59, 130, 246, .15); color: #93c5fd; }

.status-badges { display: flex; flex-wrap: wrap; gap: .35rem; }

.row-actions { display: flex; gap: .35rem; }
.row-actions button { padding: .35rem .55rem; font-size: .8rem; }

.lineup-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: .55rem; margin-bottom: 1rem; }
.lineup-grid .slot-card.span-block,
.ai-preview-grid .slot-card.span-block { grid-column: span var(--slot-span, 1); }
.ai-channels-list { display: flex; flex-direction: column; gap: .75rem; }
.ai-channel-row { border: 1px solid var(--divider, rgba(255,255,255,.08)); border-radius: 8px; padding: .75rem; display: grid; gap: .5rem; }
.ai-channel-row .row-top { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.ai-channel-row textarea { min-height: 4rem; resize: vertical; }
.ai-channel-row .meta { opacity: .85; font-size: .9rem; }
.ai-channel-row.disabled-row { opacity: .55; }
.section-header-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.section-header-row .section-header-actions { margin-top: 0; }
.slot-card { background: var(--channelflow-surface); border: 1px solid var(--channelflow-border); border-radius: 8px; padding: .55rem .65rem; min-height: 96px; cursor: pointer; transition: border-color .12s, transform .12s; }
.slot-card:hover { border-color: var(--channelflow-accent); transform: translateY(-1px); }
.slot-card.has-items { border-color: rgba(34, 197, 94, .45); }
.slot-card.rerun-slot {
    background: #facc15;
    border-color: #ca8a04;
    opacity: 1;
}
.slot-card.rerun-slot .time,
.slot-card.rerun-slot .summary,
.slot-card.rerun-slot .count {
    color: #422006;
}
.slot-card.weather-slot { cursor: default; }
.slot-card.weather-slot:hover { transform: none; }
.slot-card.weather-slot .summary { color: #d1fae5; }
.slot-card.weather-single-slot { min-height: 5rem; grid-column: 1 / -1; }
.presentation-card, .list-card { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; border: 1px solid rgba(255,255,255,.08); border-radius: .5rem; margin-bottom: .65rem; }
.presentation-card .meta, .list-card .meta { opacity: .75; font-size: .9rem; margin-top: .25rem; }
.slot-card.empty { opacity: .75; }
.slot-card .time { font-size: .78rem; color: #93c5fd; margin-bottom: .35rem; font-weight: 600; }
.slot-card .summary { font-size: .82rem; color: var(--channelflow-muted); line-height: 1.35; }
.slot-card .count { font-size: .75rem; color: var(--channelflow-success); margin-top: .25rem; }

.preview-banner { background: rgba(59, 130, 246, .12); border: 1px solid rgba(59, 130, 246, .35); border-radius: 8px; padding: .65rem .85rem; margin-bottom: .75rem; font-size: .9rem; }

.brainz-preview-wrap { margin-top: .85rem; }
.brainz-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: .75rem;
}
.brainz-preview-card {
    display: grid;
    grid-template-rows: 1fr auto;
    background: var(--channelflow-surface-2);
    border: 1px solid var(--channelflow-border);
    border-radius: 8px;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    min-height: 0;
}
.brainz-preview-card:hover { border-color: var(--channelflow-accent); }
.brainz-preview-link {
    display: grid;
    grid-template-rows: auto 1fr;
    color: inherit;
    text-decoration: none;
    min-height: 0;
}
.brainz-preview-card .thumb {
    aspect-ratio: 16 / 9;
    background: #0a0d12;
    overflow: hidden;
}
.brainz-preview-card .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.brainz-preview-card .body { padding: .55rem .65rem .35rem; }
.brainz-preview-card .title {
    font-size: .82rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.brainz-preview-card .meta {
    margin-top: .35rem;
    font-size: .72rem;
    color: var(--channelflow-muted);
    line-height: 1.35;
}
.brainz-yt-btn {
    display: block;
    margin: 0 .65rem .55rem;
    padding: .28rem .5rem;
    border-radius: 6px;
    border: 1px solid rgba(239, 68, 68, .45);
    background: rgba(239, 68, 68, .16);
    color: #fecaca;
    font-size: .72rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}
.brainz-yt-btn:hover { border-color: #f87171; background: rgba(239, 68, 68, .28); }

.now-playing { background: var(--channelflow-surface-2); border-radius: 8px; padding: .65rem .75rem; font-size: .85rem; border: 1px solid var(--channelflow-border); }
.now-playing strong { display: block; margin-bottom: .25rem; color: #93c5fd; }

.status-card { background: var(--channelflow-surface-2); border: 1px solid var(--channelflow-border); border-radius: 8px; padding: .75rem; margin-bottom: 1rem; font-size: .85rem; white-space: pre-wrap; }

.url-row { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: .85rem; flex-wrap: wrap; }
.url-block { flex: 1; min-width: 240px; }
.url-block code { display: block; margin-top: .35rem; word-break: break-all; }

code { background: var(--channelflow-surface-2); padding: .2rem .45rem; border-radius: 4px; font-size: .85rem; }

.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .65rem; margin-top: 1rem; }
.logo-tile { background: var(--channelflow-surface-2); border: 1px solid var(--channelflow-border); border-radius: 8px; padding: .5rem; text-align: center; }
.logo-tile img { max-width: 100%; max-height: 64px; object-fit: contain; display: block; margin: 0 auto .35rem; }
.logo-tile span { font-size: .72rem; color: var(--channelflow-muted); word-break: break-all; display: block; }

.override-card { display: flex; justify-content: space-between; gap: .75rem; align-items: center; padding: .75rem; background: var(--channelflow-surface-2); border: 1px solid var(--channelflow-border); border-radius: 8px; margin-bottom: .5rem; cursor: pointer; }
.override-card .meta { font-size: .85rem; color: var(--channelflow-muted); }
.override-card.selected { border-color: var(--channelflow-accent); background: rgba(225, 29, 72, .14); }

.candidate-list { display: grid; gap: .5rem; margin: .75rem 0; }
.candidate-row { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .5rem; background: var(--channelflow-surface-2); border-radius: 8px; border: 1px solid var(--channelflow-border); }
.candidate-row .title { font-size: .85rem; }
.candidate-row .sub { font-size: .75rem; color: var(--channelflow-muted); }

.search-results { max-height: 220px; overflow: auto; border: 1px solid var(--channelflow-border); border-radius: 8px; margin-top: .5rem; }
.search-result { padding: .5rem .65rem; cursor: pointer; border-bottom: 1px solid var(--channelflow-border); }
.search-result:hover { background: rgba(59, 130, 246, .12); }
.search-result:last-child { border-bottom: 0; }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; display: grid; gap: .5rem; max-width: 360px; }
.toast { background: var(--channelflow-surface); border: 1px solid var(--channelflow-border); border-left: 4px solid var(--channelflow-accent); border-radius: 8px; padding: .65rem .85rem; box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: toast-in .2s ease; }
.toast.success { border-left-color: var(--channelflow-success); }
.toast.error { border-left-color: var(--channelflow-danger); }
.toast.info { border-left-color: #60a5fa; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 9000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--channelflow-surface); border: 1px solid var(--channelflow-border); border-radius: 12px; width: min(720px, 100%); max-height: calc(100vh - 2rem); display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.modal-wide { width: min(960px, 100%); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--channelflow-border); }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; overflow: auto; }
.modal-footer { padding: .75rem 1rem; border-top: 1px solid var(--channelflow-border); display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--channelflow-muted); }

.ebs-upload-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.ebs-upload-card {
    border: 1px solid var(--channelflow-border);
    border-radius: 8px;
    padding: 1rem;
    background: var(--channelflow-surface-2);
}

.ebs-upload-card h4 {
    margin: 0 0 0.5rem;
}

.ebs-live-preview {
    margin: 0 0 1.25rem;
}

.ebs-live-preview-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.45rem;
}

.ebs-live-preview-pair {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    margin-bottom: 0.5rem;
}

.ebs-live-preview-slot {
    min-width: 0;
}

.ebs-live-preview-aspect {
    display: block;
    font-size: 0.85rem;
    color: var(--channelflow-muted, var(--muted));
    margin-bottom: 0.35rem;
}

.ebs-live-preview-frame {
    position: relative;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 16 / 9;
    min-height: 180px;
    background: #0a0a0a;
    border: 1px solid var(--channelflow-border, var(--border));
    border-radius: 8px;
    overflow: hidden;
}

.ebs-live-preview-frame-43 {
    aspect-ratio: 4 / 3;
    min-height: 160px;
}

@media (max-width: 720px) {
    .ebs-live-preview-pair {
        grid-template-columns: 1fr;
    }
}

.ebs-live-preview-image,
.ebs-preview-bars,
.ebs-preview-static,
.ebs-preview-missing {
    position: absolute;
    inset: 0;
}

.ebs-live-preview-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.ebs-preview-bars {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right,
        #c0c0c0 0 14.28%,
        #c0c000 14.28% 28.57%,
        #00c0c0 28.57% 42.85%,
        #00c000 42.85% 57.14%,
        #c000c0 57.14% 71.42%,
        #c00000 71.42% 85.71%,
        #0000c0 85.71% 100%);
}

.ebs-preview-static {
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(0deg, #111 0 1px, #ddd 1px 2px),
        repeating-linear-gradient(90deg, #222 0 1px, #aaa 1px 2px);
    background-size: 3px 3px, 4px 4px;
    animation: ebs-static-shift 0.18s steps(4) infinite;
    filter: contrast(1.4) grayscale(1);
}

@keyframes ebs-static-shift {
    0% { background-position: 0 0, 0 0; }
    100% { background-position: 6px 4px, -4px 7px; }
}

.ebs-preview-missing {
    position: absolute;
    inset: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--channelflow-muted, var(--muted));
    background: #111;
}

.ebs-upload-preview-wrap {
    margin: 0 0 0.75rem;
    background: #0a0a0a;
    border: 1px solid var(--channelflow-border, var(--border));
    border-radius: 8px;
    overflow: hidden;
    min-height: 120px;
}

.ebs-upload-preview {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: #000;
}
