/* ═══════════════════════════════════════════════════════════
   ShaneTV — Cinema Noir Dark Theme
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-deep: #0a0a0f;
    --bg-base: #111118;
    --bg-raised: #1a1a24;
    --bg-card: #1e1e2a;
    --bg-card-hover: #252535;
    --bg-input: #15151f;
    --border: #2a2a3a;
    --border-hover: #3a3a4f;
    --text-primary: #e8e8f0;
    --text-secondary: #8888a0;
    --text-muted: #555570;
    --accent: #e8a849;
    --accent-hover: #f0b85a;
    --accent-dim: rgba(232, 168, 73, 0.15);
    --accent-glow: rgba(232, 168, 73, 0.3);
    --selected-border: #e8a849;
    --selected-bg: rgba(232, 168, 73, 0.08);
    --danger: #e85a5a;
    --success: #5ae88a;
    --sidebar-width: 280px;
    --topbar-height: 64px;
    --selbar-height: 68px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --font-display: 'Outfit', sans-serif;
    --font-body: 'DM Sans', sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Grain Overlay */
.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ═══════════════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════════════ */
#login-screen {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 60% 50% at 50% 40%, rgba(232, 168, 73, 0.06) 0%, transparent 70%),
        var(--bg-deep);
}

.login-container {
    position: relative;
    text-align: center;
    padding: 3rem 2rem;
    animation: fadeUp 0.8s ease both;
}

.login-glow {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0.4;
    filter: blur(60px);
}

.login-brand {
    margin-bottom: 2.5rem;
    position: relative;
}

.logo-mark {
    width: 64px;
    height: 64px;
    color: var(--accent);
    margin: 0 auto 1rem;
    animation: fadeUp 0.6s ease both 0.2s;
    opacity: 0;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    animation: fadeUp 0.6s ease both 0.3s;
    opacity: 0;
}

.logo-text span {
    color: var(--accent);
}

.tagline {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 0.4rem;
    animation: fadeUp 0.6s ease both 0.4s;
    opacity: 0;
}

.login-form {
    max-width: 400px;
    margin: 0 auto;
    animation: fadeUp 0.6s ease both 0.5s;
    opacity: 0;
    position: relative;
}

.input-group {
    display: flex;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 50px;
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-group:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}

.input-group input {
    flex: 1;
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-family: var(--font-body);
    color: var(--text-primary);
    outline: none;
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.input-group button {
    background: var(--accent);
    border: none;
    width: 52px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.input-group button:hover {
    background: var(--accent-hover);
}

.input-group button svg {
    width: 20px;
    height: 20px;
    color: var(--bg-deep);
}

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.75rem;
    min-height: 1.2em;
    transition: opacity var(--transition);
}

.request-access-btn {
    margin-top: 1rem;
    padding: 0.7rem 1.8rem;
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.request-access-btn:hover {
    background: var(--accent-dim);
}

.request-status {
    color: var(--success);
    font-size: 0.85rem;
    margin-top: 0.75rem;
}

.request-status.denied {
    color: var(--danger);
}

.primary-btn {
    background: var(--accent) !important;
    color: var(--bg-deep) !important;
    font-weight: 600 !important;
}

.primary-btn:hover {
    background: var(--accent-hover) !important;
}

.login-footnote {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 2rem;
    animation: fadeUp 0.6s ease both 0.6s;
    opacity: 0;
}

/* ═══════════════════════════════════════════════════════════
   TOP BAR
   ═══════════════════════════════════════════════════════════ */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    z-index: 100;
    gap: 1rem;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: fit-content;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: color var(--transition), background var(--transition);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-raised);
}

.top-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.top-logo svg {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.top-logo span {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.top-logo em {
    font-style: normal;
    color: var(--accent);
}

.top-bar-center {
    flex: 1;
    max-width: 480px;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 0 1rem;
    gap: 0.5rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.search-box svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    padding: 0.6rem 0;
    font-size: 0.9rem;
    font-family: var(--font-body);
    color: var(--text-primary);
    outline: none;
}

.search-box input::placeholder { color: var(--text-muted); }

.search-clear {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 4px;
    transition: color var(--transition);
}

.search-clear:hover { color: var(--text-primary); }

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: fit-content;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), background var(--transition);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-raised);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.user-greeting {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════
   APP BODY
   ═══════════════════════════════════════════════════════════ */
#app-screen {
    flex-direction: column;
    min-height: 100vh;
}

.app-body {
    display: flex;
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    height: calc(100vh - var(--topbar-height));
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-inner {
    padding: 1rem 0 6rem;
}

.filter-section {
    margin-bottom: 0.5rem;
}

.filter-heading {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    padding: 1rem 1.25rem 0.5rem;
}

.filter-list {
    display: flex;
    flex-direction: column;
}

.filter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.25rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    border-left: 3px solid transparent;
    user-select: none;
}

.filter-item:hover {
    background: var(--bg-raised);
    color: var(--text-primary);
}

.filter-item.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-left-color: var(--accent);
}

.filter-item .filter-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 0.5rem;
}

.filter-item .filter-count {
    font-size: 0.75rem;
    background: var(--bg-card);
    padding: 0.1rem 0.5rem;
    border-radius: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.filter-item.active .filter-count {
    background: var(--accent-dim);
    color: var(--accent);
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ═══════════════════════════════════════════════════════════
   CHANNEL AREA
   ═══════════════════════════════════════════════════════════ */
.channel-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 1rem 1.5rem 6rem;
    min-height: calc(100vh - var(--topbar-height));
}

.channel-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.channel-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.channel-stats strong {
    color: var(--text-primary);
}

.channel-actions {
    display: flex;
    gap: 0.5rem;
}

.toolbar-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    padding: 0.4rem 0.9rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all var(--transition);
}

.toolbar-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* ── Channel Grid ───────────────────────────────────────── */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.channel-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    transition: all 0.25s ease;
    position: relative;
    animation: cardIn 0.4s ease both;
}

.channel-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.channel-card.selected {
    border-color: var(--selected-border);
    background: var(--selected-bg);
    box-shadow: 0 0 20px rgba(232, 168, 73, 0.1);
}

.channel-card .check-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.channel-card.selected .check-indicator {
    border-color: var(--accent);
    background: var(--accent);
}

.channel-card.selected .check-indicator::after {
    content: '';
    width: 6px;
    height: 10px;
    border: 2px solid var(--bg-deep);
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
}

.channel-logo {
    width: 128px;
    height: 80px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    padding: 8px;
}

.channel-logo-placeholder {
    width: 128px;
    height: 80px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--bg-raised), var(--bg-input));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.channel-name {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.channel-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

.badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    background: var(--bg-raised);
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.badge-country {
    font-size: 0.7rem;
}

/* ── Loading & Empty ────────────────────────────────────── */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 4rem 0;
    color: var(--text-muted);
}

.loading-spinner.hidden { display: none; }

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 4rem 0;
    color: var(--text-muted);
}

.no-results svg {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

.no-results.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════
   SELECTION BAR
   ═══════════════════════════════════════════════════════════ */
.selection-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--selbar-height);
    background: rgba(10, 10, 15, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem 0 calc(var(--sidebar-width) + 1.5rem);
    z-index: 100;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.selection-bar.visible {
    transform: translateY(0);
}

.selection-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.selection-info strong {
    color: var(--accent);
    font-family: var(--font-display);
    font-size: 1.1rem;
}

.selection-actions {
    display: flex;
    gap: 0.75rem;
}

.sel-btn {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 1.25rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sel-btn svg {
    width: 18px;
    height: 18px;
}

.sel-btn.secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.sel-btn.secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.sel-btn.primary {
    background: var(--accent);
    color: var(--bg-deep);
}

.sel-btn.primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px var(--accent-glow);
}

/* ═══════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease both;
}

.modal-content::-webkit-scrollbar { width: 5px; }
.modal-content::-webkit-scrollbar-track { background: transparent; }
.modal-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.modal-content h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.help-section {
    margin-bottom: 1.5rem;
}

.help-section h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.help-icon {
    width: 20px;
    height: 20px;
    color: var(--accent);
    flex-shrink: 0;
}

.help-section p,
.help-section ol {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.help-section ol {
    padding-left: 1.25rem;
}

.help-section li {
    margin-bottom: 0.3rem;
}

.help-section strong {
    color: var(--text-primary);
}

.help-tip {
    background: var(--accent-dim);
    border: 1px solid rgba(232, 168, 73, 0.2);
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.help-tip strong {
    color: var(--accent);
}

/* Generating overlay */
.generating-content {
    text-align: center;
    padding: 3rem 2rem;
}

.generating-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    color: var(--accent);
    animation: bounce 1.5s infinite;
}

.generating-icon svg {
    width: 100%;
    height: 100%;
}

.generating-content h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.generating-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ═══════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════ */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes cardIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.5);
    }

    .sidebar-toggle {
        display: flex;
    }

    .channel-area {
        margin-left: 0;
    }

    .selection-bar {
        padding-left: 1.5rem;
    }
}

@media (max-width: 768px) {
    .top-bar-center {
        max-width: none;
    }

    .user-greeting {
        display: none;
    }

    .channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .channel-logo,
    .channel-logo-placeholder {
        width: 100px;
        height: 64px;
    }

    .channel-name {
        font-size: 0.8rem;
    }

    .selection-bar {
        flex-direction: column;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .channel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .channel-card {
        padding: 0.75rem;
    }

    .logo-text {
        font-size: 2.2rem;
    }

    .top-logo span {
        display: none;
    }
}

/* ── Utility ────────────────────────────────────────────── */
.hidden { display: none !important; }
