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

:root {
    --bg-dark: #0a0a0c;
    --bg-card: #111115;
    --bg-card-hover: #16161c;
    --red: #c41e3a;
    --red-glow: rgba(196, 30, 58, 0.15);
    --red-soft: #e8354f;
    --green: #22c55e;
    --amber: #f59e0b;
    --text-primary: #f0ece6;
    --text-secondary: #8a8694;
    --text-dim: #5a5666;
    --border: rgba(255,255,255,0.06);
    --border-strong: rgba(255,255,255,0.12);
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px 120px;
    position: relative;
    z-index: 2;
}

/* ---- NAV ---- */
nav {
    padding: 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    text-decoration: none;
}
.logo span { color: var(--red); }

.nav-center { flex: 1; text-align: center; }

.nav-tag {
    font-size: 0.72rem;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.nav-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ---- BUTTONS ---- */
.btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--red);
    color: #fff;
}
.btn-primary:hover { background: var(--red-soft); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-strong); }

.btn-small {
    font-size: 0.75rem;
    padding: 5px 10px;
    border-radius: 6px;
}

.btn-outline {
    background: transparent;
    color: var(--red-soft);
    border: 1px solid rgba(196, 30, 58, 0.3);
}
.btn-outline:hover { background: var(--red-glow); }

.pulse-dot {
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

/* ---- CRON BANNER ---- */
.cron-banner {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 16px;
}

.cron-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.cron-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cron-active {
    background: var(--green);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
    animation: pulse 2s infinite;
}

.cron-error {
    background: var(--red);
    box-shadow: 0 0 8px rgba(196, 30, 58, 0.4);
}

.cron-pending {
    background: var(--amber);
    animation: pulse 2s infinite;
}

/* ---- STATS BAR ---- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}

.stat {
    background: var(--bg-card);
    padding: 20px 16px;
    text-align: center;
}

.stat-number {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.stat-number span { color: var(--red); }

.stat-label {
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* ---- STATE CARDS ---- */
.states-section {
    margin-bottom: 32px;
}

.section-label {
    font-size: 0.72rem;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 12px;
}

.state-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 500px;
}

.state-card {
    background: var(--bg-card);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.state-card:hover { background: var(--bg-card-hover); }
.state-card.active {
    background: var(--bg-card-hover);
    box-shadow: inset 0 -2px 0 var(--red);
}

.state-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.state-emoji {
    font-size: 1.1rem;
    opacity: 0.7;
}

.state-code {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.68rem;
    color: var(--red);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.state-show {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: -0.3px;
    margin-bottom: 2px;
}

.state-tagline {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 300;
    margin-bottom: 8px;
}

.state-stats {
    display: flex;
    gap: 12px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.state-stats strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ---- PIPELINE STATUS ---- */
.pipeline-status {
    background: var(--bg-card);
    border: 1px solid rgba(196, 30, 58, 0.2);
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.pipeline-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.pipeline-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ---- CONTENT AREA ---- */
.content-area {
    min-height: 300px;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.88rem;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---- CONTENT TABS ---- */
.content-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.content-tab {
    padding: 10px 20px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: 'DM Sans', sans-serif;
}
.content-tab:hover { color: var(--text-secondary); }
.content-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--red);
}

/* ---- STORY LIST ---- */
.story-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.story-item {
    background: var(--bg-card);
    padding: 16px 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: background 0.2s;
}
.story-item:hover { background: var(--bg-card-hover); }

.story-severity {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1rem;
}

.severity-high {
    background: rgba(196, 30, 58, 0.15);
    color: var(--red-soft);
    border: 1px solid rgba(196, 30, 58, 0.3);
}
.severity-mid {
    background: rgba(245, 158, 11, 0.1);
    color: var(--amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.severity-low {
    background: rgba(255,255,255,0.04);
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.severity-none {
    background: rgba(255,255,255,0.02);
    color: var(--text-dim);
    border: 1px solid var(--border);
    font-size: 0.7rem;
}

.story-content {
    flex: 1;
    min-width: 0;
}

.story-title {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 4px;
    line-height: 1.35;
}

.story-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.story-reasoning {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-style: italic;
    line-height: 1.4;
}

.story-actions {
    flex-shrink: 0;
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

/* ---- EPISODE LIST ---- */
.episode-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.episode-item {
    background: var(--bg-card);
    padding: 16px 20px;
    transition: background 0.2s;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(196, 30, 58, 0.15);
}
.episode-item:hover { background: var(--bg-card-hover); }
.episode-item:active { background: var(--bg-card-hover); }

.episode-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.episode-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: -0.3px;
}

.episode-status {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-weight: 500;
    white-space: nowrap;
}

.status-scripted {
    background: rgba(245, 158, 11, 0.1);
    color: var(--amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.status-produced {
    background: rgba(34, 197, 94, 0.1);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.2);
}
.status-draft {
    background: rgba(255,255,255,0.04);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.episode-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.episode-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ---- SCRIPT MODAL ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    max-width: 700px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 32px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.modal-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.script-content {
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--text-secondary);
    white-space: pre-wrap;
    font-family: 'DM Sans', sans-serif;
}

.script-content .pause {
    display: block;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.75rem;
    letter-spacing: 2px;
    margin: 16px 0;
}

/* ---- AUDIO PLAYER ---- */
.audio-player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #111115;
    border-top: 1px solid var(--border-strong);
    z-index: 50;
    padding: 12px 24px;
}

.player-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
}

.player-info {
    min-width: 0;
    flex-shrink: 0;
    max-width: 250px;
}

.player-show {
    font-size: 0.7rem;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 2px;
}

.player-title {
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-controls {
    flex: 1;
}

.player-controls audio {
    width: 100%;
    height: 36px;
    filter: invert(1) hue-rotate(180deg);
    opacity: 0.8;
}

.player-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
}
.player-close:hover { color: var(--text-primary); }

/* ---- FOOTER ---- */
footer {
    padding: 40px 0;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

footer .logo { font-size: 1rem; }

footer p {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .state-cards { grid-template-columns: repeat(2, 1fr); }
    nav { flex-wrap: wrap; }
    .nav-center { display: none; }
    .story-item { flex-direction: column; }
    .story-actions { align-self: flex-end; }
    footer { flex-direction: column; gap: 12px; text-align: center; }

    /* Mobile: larger touch targets for episode buttons (Apple HIG: 44px min) */
    .episode-actions .btn-small {
        min-height: 44px;
        padding: 10px 14px;
        font-size: 0.82rem;
    }

    /* Audio player: stack vertically on mobile */
    .player-inner {
        flex-wrap: wrap;
        gap: 8px;
    }
    .player-info {
        max-width: 100%;
        flex: 1 1 auto;
    }
    .player-controls {
        flex: 1 1 100%;
        order: 1;
    }
}

@media (max-width: 480px) {
    .state-cards { grid-template-columns: 1fr 1fr; }
    .nav-actions { gap: 4px; }
    .btn { padding: 6px 10px; font-size: 0.78rem; }
    .episode-header { flex-direction: column; align-items: flex-start; }

    /* Stack episode buttons vertically on very small screens */
    .episode-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .episode-actions .btn-small {
        justify-content: center;
        min-height: 44px;
    }
}

/* ---- LOADING STATES ---- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 0%, rgba(255,255,255,0.04) 50%, var(--bg-card) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---- TOAST NOTIFICATIONS ---- */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 14px 20px;
    font-size: 0.85rem;
    color: var(--text-primary);
    z-index: 200;
    max-width: 350px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: slideIn 0.3s ease;
}

.toast.error { border-color: rgba(196, 30, 58, 0.4); }
.toast.success { border-color: rgba(34, 197, 94, 0.3); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---- VIDEO MODAL ---- */
.video-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(6px);
}

.video-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 24px;
    max-width: 860px;
    width: 100%;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.video-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
}

.video-modal-show {
    font-size: 0.7rem;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.video-modal-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
}

.video-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    flex-wrap: wrap;
}

/* Generate video button style */
.btn-small[onclick*="generateVideo"] {
    background: linear-gradient(135deg, rgba(196,30,58,0.12), rgba(196,30,58,0.06));
    border-color: rgba(196,30,58,0.3);
    color: var(--red-soft);
}

.btn-small[onclick*="generateVideo"]:hover {
    background: rgba(196,30,58,0.2);
    border-color: rgba(196,30,58,0.5);
}
