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

:root {
    --bg: #0f1117;
    --bg-panel: #181a24;
    --bg-card: #1e2030;
    --bg-input: #252838;
    --border: #2a2d3e;
    --border-hover: #3d4158;
    --text: #e4e6f0;
    --text-dim: #8b8fa8;
    --text-muted: #5c6080;
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --accent2: #00cec9;
    --accent2-glow: rgba(0, 206, 201, 0.2);
    --danger: #e74c3c;
    --success: #2ecc71;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --font: 'Inter', -apple-system, sans-serif;
}

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
    background: linear-gradient(135deg, rgba(108,92,231,0.08), rgba(0,206,201,0.06));
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
}
.logo h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}
.badge {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 1px;
}

/* ── Layout ── */
.app { display: flex; flex-direction: column; height: 100vh; }

.main {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr 1fr;
    gap: 0;
    overflow: hidden;
}

/* ── Panels ── */
.panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.panel:last-child { border-right: none; }

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--bg-panel);
}
.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg);
}

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

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-dim);
}
.form-group-inline input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 4px 8px;
    font-size: 12px;
    font-family: var(--font);
}

/* ── Form ── */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select, input[type="date"], input[type="text"], input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
select:focus, input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
select option { background: var(--bg-card); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: #7c6ff0;
    box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-accent {
    background: var(--accent2);
    color: #0f1117;
    font-weight: 600;
}
.btn-accent:hover {
    background: #00e0db;
    box-shadow: 0 4px 16px var(--accent2-glow);
}
.btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger-sm {
    padding: 2px 8px;
    font-size: 11px;
    background: transparent;
    color: var(--danger);
    border: 1px solid transparent;
    cursor: pointer;
    font-family: var(--font);
    border-radius: 4px;
}
.btn-danger-sm:hover { border-color: var(--danger); background: rgba(231,76,60,0.1); }

/* ── Program List ── */
.program-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}
.program-item {
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}
.program-item:hover {
    border-color: var(--accent);
    background: rgba(108,92,231,0.06);
}
.program-item.active {
    border-color: var(--accent);
    background: rgba(108,92,231,0.1);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
.program-item .prog-title {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.program-item .prog-time {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Slider ── */
.trim-info {
    margin-bottom: 24px;
    text-align: center;
}
.trim-channel {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 20px;
    margin-right: 8px;
}
.trim-title {
    font-size: 15px;
    font-weight: 500;
}

.video-wrapper {
    margin-bottom: 20px;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border);
}
.video-wrapper video {
    width: 100%;
    display: block;
    max-height: 300px;
    background: #000;
}

.slider-container {
    padding: 20px 12px;
}
.slider-track {
    position: relative;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    margin: 0 8px;
}
.slider-range {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 4px;
    top: 0;
}
.slider-handle {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    background: #fff;
    border: 3px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    z-index: 2;
    transition: box-shadow 0.2s;
    outline: none;
}
.slider-handle:hover, .slider-handle:focus {
    box-shadow: 0 0 0 6px var(--accent-glow);
}
.slider-handle.handle-end {
    border-color: var(--accent2);
}
.slider-handle.handle-end:hover, .slider-handle.handle-end:focus {
    box-shadow: 0 0 0 6px var(--accent2-glow);
}
.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    padding: 0 8px;
}

/* ── Time Inputs ── */
.time-inputs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}
.time-input-group {
    text-align: center;
}
.time-input-group label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.time-input-group input {
    width: 110px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-size: 16px;
    font-weight: 600;
    padding: 8px;
}
.time-duration {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent2);
    min-width: 60px;
    text-align: center;
    padding-top: 18px;
}

/* ── Queue ── */
.queue-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}
.queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    animation: slideIn 0.3s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.queue-item .qi-info {
    flex: 1;
    min-width: 0;
}
.queue-item .qi-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.queue-item .qi-meta {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.queue-item .qi-channel {
    font-size: 11px;
    background: var(--bg-input);
    color: var(--text-dim);
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 10px;
    flex-shrink: 0;
}
.queue-item .qi-drag {
    cursor: grab;
    color: var(--text-muted);
    font-size: 16px;
    margin-right: 8px;
    flex-shrink: 0;
    user-select: none;
    transition: color 0.2s;
}
.queue-item .qi-drag:hover { color: var(--accent); }
.queue-item.dragging {
    opacity: 0.4;
    border-style: dashed;
}
.queue-item.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ── Output ── */
.output-section {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    animation: slideIn 0.3s ease;
}
.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.output-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.output-header div { display: flex; gap: 6px; }

.m3u8-output {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--accent2);
    max-height: 400px;
    overflow: auto;
    white-space: pre;
    tab-size: 2;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow);
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 999;
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

body.hide-scrollbars *::-webkit-scrollbar { display: none !important; }
body.hide-scrollbars * { scrollbar-width: none !important; -ms-overflow-style: none !important; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .main {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }
    .panel { border-right: none; border-bottom: 1px solid var(--border); }
    .panel-body { max-height: none; }
    .panel-trim { display: flex !important; }
}

/* ── Modal Player ── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-player {
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 24px 64px rgba(0,0,0,0.6);
    width: 90%; max-width: 800px; overflow: hidden;
    transform: scale(0.92) translateY(20px); transition: transform 0.3s ease;
}
.modal-overlay.active .modal-player { transform: scale(1) translateY(0); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(108,92,231,0.08), rgba(0,206,201,0.06));
}
.modal-title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.modal-channel {
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
    padding: 2px 10px; border-radius: 20px; flex-shrink: 0;
}
.modal-title {
    font-size: 14px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.modal-close {
    background: transparent; border: 1px solid var(--border); color: var(--text-dim);
    width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.modal-close:hover { border-color: var(--danger); color: var(--danger); background: rgba(231,76,60,0.1); }
.modal-video-wrap { background: #000; }
.modal-video-wrap video { width: 100%; display: block; max-height: 450px; }
.modal-meta {
    padding: 10px 20px; font-size: 12px; color: var(--text-muted);
    text-align: center; border-top: 1px solid var(--border);
}
.queue-item .qi-info { cursor: pointer; }
.queue-item .qi-info:hover .qi-title { color: var(--accent2); }
