/* Reset & Base Styles */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --border-color: #334155;
    --border-hover: #475569;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    background-image:
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Prevent step-1 flash on refresh before JS restores the correct view. */
body.booting #step1,
body.booting #step2 {
    visibility: hidden;
}

body.booting .header,
body.booting .app-footer {
    visibility: hidden;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 10px;
    animation: fadeInDown 0.6s ease-out;
    position: relative;
}

.header-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.header-actions-left,
.header-actions-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions-left {
    display: none;
}

.header-actions-right {
    justify-content: center;
    flex-wrap: wrap;
}

.header-actions .btn {
    width: auto;
}

.auth-user-badge {
    font-size: 0.85rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.55);
}

.app-version-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.2);
    text-decoration: none;
    cursor: pointer;
}

.app-version-badge:hover {
    background: rgba(59, 130, 246, 0.3);
}

.app-footer {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

@media (max-width: 700px) and (orientation: portrait) {
    .header {
        margin-bottom: 1.5rem;
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.6rem;
        align-items: stretch;
    }

    .header-actions-left {
        width: 100%;
        justify-content: space-between;
        gap: 0.4rem;
        flex-wrap: nowrap;
    }

    .header-actions-right {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.45rem;
        justify-content: stretch;
    }

    .header-actions-right .btn {
        width: 100%;
        min-width: 0;
        justify-content: center;
        text-align: center;
        white-space: nowrap;
        padding: 0.55rem 0.5rem;
        height: auto !important;
        min-height: 36px;
    }

    .auth-user-badge {
        max-width: 60vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 0.35rem 0.5rem;
    }

    .app-version-badge {
        font-size: 0.72rem;
        padding: 0.3rem 0.45rem;
        flex: 0 0 auto;
    }
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-xl);
    border-color: var(--border-hover);
}

.card-header {
    background: rgba(15, 23, 42, 0.3);
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

.step2-tabs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.step2-tab-nav {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    margin-top: 10px;
    padding-bottom: 0.75rem;
}

.step2-tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.step2-tab-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.step2-tab-btn.active {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.2);
    color: var(--text-primary);
}

.step2-tab-panel {
    display: none;
}

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

.live-tv-filter-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .live-tv-filter-row {
        grid-template-columns: 1fr 1fr;
    }
}

.live-tv-guide {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.35);
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: clip;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 0.75rem;
    display: block;
}

.live-tv-guide-empty {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0.25rem;
}

.live-tv-guide-timeline {
    display: grid;
    gap: 0.65rem;
    position: relative;
}

.live-tv-guide-ticks {
    position: relative;
    height: 24px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    margin-left: 180px;
}

.live-tv-guide-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.live-tv-guide-tick:first-child {
    transform: translateX(0);
}

.live-tv-guide-tick:last-child {
    transform: translateX(-100%);
}

.live-tv-guide-rows {
    display: grid;
    gap: 0.5rem;
    position: relative;
}

.live-tv-guide-now-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(170px + 0.6rem + (100% - 170px - 0.6rem) * var(--guide-now-ratio, 0));
    width: 2px;
    background: rgba(250, 204, 21, 0.55);
    border-radius: 999px;
    pointer-events: none;
    z-index: 0;
}

.live-tv-guide-row2 {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 0.6rem;
    align-items: center;
    position: relative;
    z-index: 0;
}

.live-tv-guide-channel2 {
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 700;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    padding: 0.55rem 0.6rem;
    line-height: 1.25;
}

.live-tv-guide-channel-label {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    width: 100%;
}

.live-tv-guide-channel-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-tv-guide-channel2.is-clickable {
    cursor: pointer;
}

.live-tv-guide-channel2.is-clickable:hover,
.live-tv-guide-channel2.is-clickable:focus-visible {
    border-color: rgba(96, 165, 250, 0.55);
    color: #dbeafe;
    background: rgba(30, 58, 138, 0.35);
    outline: none;
}

.live-tv-guide-track {
    position: relative;
    height: 44px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(30, 41, 59, 0.3);
    overflow: hidden;
}

.live-tv-guide-timeline {
    user-select: none;
}

.live-tv-guide-hint {
    color: var(--text-secondary);
    font-size: 0.74rem;
}

.live-tv-guide-block {
    position: absolute;
    top: 0;
    bottom: 0;
    min-width: 48px;
    border-radius: 7px;
    background: rgba(37, 99, 235, 0.32);
    border: 1px solid rgba(96, 165, 250, 0.45);
    padding: 0.35rem 0.45rem;
    display: grid;
    gap: 0.1rem;
    overflow: hidden;
    cursor: default;
    z-index: 1;
    pointer-events: none;
}

.live-tv-guide-block.is-now {
    background: rgba(5, 150, 105, 0.34);
    border-color: rgba(52, 211, 153, 0.55);
}

.live-tv-guide-block:focus-visible {
    outline: 2px solid rgba(125, 211, 252, 0.95);
    outline-offset: 1px;
}

.live-tv-guide-hover-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.35rem 0.5rem;
    min-width: 0;
}

.live-tv-guide-hover-title {
    color: #e2e8f0;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.25;
    grid-column: 1 / -1;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.live-tv-guide-tooltip-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.45);
    color: #86efac;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.live-tv-guide-hover-meta {
    color: #93c5fd;
    font-size: 0.76rem;
    font-weight: 600;
    margin-top: 0.2rem;
}

.live-tv-guide-hover-channel {
    color: #cbd5e1;
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 0.15rem;
    display: block;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.live-tv-guide-hover-grid {
    margin-top: 0.45rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem 0.75rem;
}

.live-tv-guide-hover-row {
    display: grid;
    grid-template-columns: 82px 1fr;
    gap: 0.45rem;
    align-items: start;
}

.live-tv-guide-hover-label {
    color: #93c5fd;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.live-tv-guide-hover-value {
    color: #cbd5e1;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.live-tv-guide-hover-description {
    color: #cbd5e1;
    font-size: 0.78rem;
    line-height: 1.45;
    margin-top: 0.5rem;
    max-height: 7.5rem;
    overflow: auto;
    border-top: 1px solid rgba(148, 163, 184, 0.22);
    padding-top: 0.45rem;
}

.live-tv-guide-block-title {
    color: #f8fafc;
    font-size: 0.7rem;
    font-weight: 600;
    height: 14px;
    line-height: 14px;
    display: block;
    max-width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.live-tv-guide-block-time {
    color: rgba(226, 232, 240, 0.9);
    font-size: 0.68rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

.live-tv-guide-block.is-compact .live-tv-guide-block-time {
    display: none;
}

.live-tv-guide-block.is-tiny .live-tv-guide-block-title {
    display: none;
}

.live-tv-guide-empty-row {
    color: var(--text-secondary);
    font-size: 0.82rem;
    border: 1px dashed rgba(148, 163, 184, 0.35);
    border-radius: 8px;
    padding: 0.7rem;
    background: rgba(30, 41, 59, 0.25);
}

@media (max-width: 700px) and (orientation: portrait) {
    .live-tv-guide {
        max-height: 62vh;
        padding: 0.55rem;
    }

    .live-tv-guide-hint {
        font-size: 0.68rem;
    }

    .live-tv-guide-ticks {
        margin-left: 0;
        height: 20px;
    }

    .live-tv-guide-tick {
        font-size: 0.66rem;
    }

    .live-tv-guide-row2 {
        grid-template-columns: 1fr;
        gap: 0.35rem;
        align-items: stretch;
    }

    .live-tv-guide-channel2 {
        font-size: 0.78rem;
        padding: 0.4rem 0.5rem;
    }

    .live-tv-guide-track {
        height: 40px;
    }

    .live-tv-guide-block {
        top: 0;
        bottom: 0;
        min-width: 52px;
        padding: 0.2rem 0.32rem;
    }

    .live-tv-guide-block-title {
        font-size: 0.66rem;
        height: 12px;
        line-height: 12px;
    }

    .live-tv-guide-block-time {
        display: none;
    }

    .live-tv-guide-hover-grid {
        grid-template-columns: 1fr;
    }
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input[type="text"],
input[type="url"],
input[type="password"],
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
}

input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    background: var(--bg-tertiary);
}

input::placeholder {
    color: var(--text-muted);
}

.profile-controls {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .profile-controls {
        grid-template-columns: 1fr auto auto auto;
    }
}

.btn-compact {
    padding: 0.7rem 1rem;
}

/* Checkbox */
.checkbox-wrapper {
    display: flex;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    cursor: pointer;
    padding: 1rem;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
    width: 100%;
}

.checkbox-label:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
}

.checkbox-label input {
    display: none;
}

.checkmark {
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-muted);
    border-radius: 6px;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
    margin-top: 2px;
}

.checkbox-label input:checked + .checkmark {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.checkmark::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.checkbox-label input:checked + .checkmark::after {
    transform: rotate(45deg) scale(1);
}

.checkbox-text strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.checkbox-text small {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    gap: 0.5rem;
    width: 100%; /* Mobile first */
}

@media (min-width: 640px) {
    .btn {
        width: auto;
    }
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-success {
    background: var(--accent-success);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

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

.btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-text:hover {
    color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.1);
}

/* Steps */
.step {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.step.active {
    display: block;
}

/* Toolbar & Filters */
.toolbar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (min-width: 640px) {
    .toolbar {
        flex-direction: row;
        align-items: stretch;
    }
}

.filter-mode {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-secondary);
    padding: 0.25rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    flex: 1;
}

.filter-mode label {
    flex: 1;
    text-align: center;
    padding: 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    margin: 0;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.filter-mode label:hover {
    background: rgba(255, 255, 255, 0.05);
}

.filter-mode input {
    display: none;
}

.filter-mode input:checked + span {
    color: var(--text-primary);
    font-weight: 600;
}

.filter-mode label:has(input:checked) {
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-sm);
}

.search-box {
    position: relative;
    flex: 1.5;
}

.search-box input {
    padding-right: 2.5rem;
    height: 100%;
}

.search-icon {
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    pointer-events: none;
}

/* Categories */
.category-chips {
    max-height: none;
    overflow: visible;
    padding: 0.5rem;
    border: none;
    border-radius: 0;
    background: transparent;
}

.category-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0.5rem;
    position: relative;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    border-radius: 8px 8px 0 0;
    box-shadow: none;
}

.category-group-wrapper {
    position: relative;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.2);
    overflow: hidden;
}

.category-section-header h3 {
    font-size: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.chevron {
    transition: transform 0.2s ease;
}

.category-section-header.collapsed .chevron {
    transform: rotate(-90deg);
}

.category-section-header.collapsed {
    border-bottom-color: transparent;
    border-radius: 8px;
}

.btn-section-select-all {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 1rem;
}

.btn-section-select-all:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.category-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    padding: 1rem 0.5rem;
    background: transparent;
}

.category-section.hidden {
    display: none;
}

.category-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    text-align: left;
    white-space: normal;
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
    align-items: start;
}

.category-chip:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.category-chip.selected {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--accent-success);
    color: var(--accent-success);
    font-weight: 500;
}

.category-chip-main {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
}

.category-chip-title {
    font-weight: 600;
    color: var(--text-primary);
    white-space: normal;
    word-break: break-word;
}

.category-chip-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.btn-edit-channels {
    white-space: nowrap;
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    justify-self: start;
}

.btn-edit-channels:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.category-chip.hidden {
    display: none;
}

.selection-counter {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 1rem 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    gap: 1rem;
    flex-wrap: wrap;
}

.selection-counter.has-selection {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--accent-primary);
    font-weight: 500;
}

.selection-actions {
    display: flex;
    gap: 0.5rem;
}

/* Success State */
.success-state {
    text-align: center;
    padding: 3rem 1rem;
}

.success-checkmark {
    width: 80px;
    height: 80px;
    background: var(--accent-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: white;
    margin: 0 auto 1.5rem;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.success-title {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.success-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: center;
}

@media (min-width: 640px) {
    .success-actions {
        flex-direction: row;
    }
}

.download-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.saved-playlist-panel {
    margin-top: 1.5rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.3);
}

.saved-playlist-panel h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.saved-playlist-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

@media (min-width: 640px) {
    .saved-playlist-controls {
        grid-template-columns: 1fr auto;
        align-items: center;
    }
}

.saved-playlists-list {
    display: grid;
    gap: 0.5rem;
}

.playlist-custom-group-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.6rem;
}

.custom-group-chip {
    width: 100%;
    min-height: 66px;
}

.saved-playlist-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.35);
}

.saved-playlist-main {
    display: grid;
    gap: 0.15rem;
}

.saved-playlist-main small {
    color: var(--text-secondary);
    word-break: break-all;
}

.series-episode-list {
    max-height: 52vh;
    overflow: auto;
    display: grid;
    gap: 0.65rem;
    padding-right: 0.2rem;
}

.series-season-group {
    display: grid;
    gap: 0.4rem;
}

.series-season-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #93c5fd;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.series-episode-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.35);
}

#authUsersList .saved-playlist-item {
    align-items: flex-start;
}

#authUsersList .saved-playlist-main {
    width: 100%;
}

#authUsersList .saved-playlist-actions {
    display: flex;
    gap: 0.35rem;
    align-self: flex-start;
}

.auth-user-timezone-row {
    margin-top: 0.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.auth-user-timezone-row select {
    width: auto;
    max-width: 100%;
    min-width: 210px;
    padding: 0.5rem 0.65rem;
    font-size: 0.84rem;
}

@media (max-width: 768px) {
    #savedPlaylistsList .saved-playlist-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
    }

    #savedPlaylistsList .saved-playlist-actions {
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    #authUsersList .saved-playlist-item {
        flex-direction: column;
        align-items: stretch;
    }

    #authUsersList .saved-playlist-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

.subscription-details {
    padding: 1rem 1.5rem 0;
    text-align: left;
}

.subscription-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    margin-top: -10px;
    margin-bottom: 0 !important;
}

.subscription-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.subscription-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    .subscription-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem 1rem;
    }
}

.subscription-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.subscription-row:last-child {
    border-bottom: none;
}

.subscription-label {
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.subscription-value {
    color: var(--text-primary);
    font-size: 0.86rem;
    font-weight: 600;
    text-align: right;
}

.subscription-status-active {
    color: var(--accent-success);
}

.subscription-status-inactive {
    color: var(--accent-danger);
}

.epg-cache-progress-card {
    margin-top: 0.9rem;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    background: rgba(15, 23, 42, 0.3);
}

.epg-cache-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--text-primary);
    margin-bottom: 0.45rem;
    font-weight: 600;
}

.epg-cache-progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.2);
    overflow: hidden;
}

.epg-cache-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, #38bdf8 0%, #3b82f6 100%);
    transition: width 0.25s ease;
}

.epg-cache-progress-bar.is-complete {
    background: linear-gradient(90deg, #34d399 0%, #10b981 100%);
}

.epg-cache-progress-text {
    margin-top: 0.45rem;
    font-size: 0.76rem;
    color: var(--text-secondary);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideUp 0.3s ease-out;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 50;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* Ensure destructive confirmations are always above other modals. */
#deleteConfirmModal {
    z-index: 80;
}

#warningModal {
    z-index: 85;
}

#playlistBuilderModal {
    align-items: flex-start;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: rgb(30 41 59 / 95%);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

#channelEditorModal .modal-header h3 {
    max-width: 100%;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.modal-summary {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.summary-row:last-child {
    border-bottom: none;
}

.summary-label {
    color: var(--text-secondary);
}

.summary-value {
    color: var(--text-primary);
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* API Builder Styles */
.api-url-container {
    margin-top: 1rem;
}

.url-display-box {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.url-display-box code {
    flex: 1;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--accent-primary);
    overflow-x: auto;
    white-space: nowrap;
    padding-right: 2rem;
}

.channel-list {
    display: grid;
    gap: 0.4rem;
    max-height: 45vh;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    transition: all 0.2s ease;
}

.channel-item:hover {
    border-color: var(--border-hover);
    background: var(--bg-tertiary);
}

.channel-item.selected {
    border-color: var(--accent-success);
    background: rgba(16, 185, 129, 0.15);
}

.channel-item input {
    width: 16px;
    height: 16px;
}

.channel-item-main {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex: 1;
}

.channel-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-item-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.custom-group-editor-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.custom-group-editor-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.editor-helper-note {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin: 0.1rem 0 0.6rem;
}

.custom-group-selected-item {
    cursor: grab;
}

.custom-group-available-item {
    cursor: grab;
}

.custom-group-available-item:active {
    cursor: grabbing;
}

.custom-group-selected-item:active {
    cursor: grabbing;
}

.custom-group-selected-item.dragging {
    opacity: 0.55;
}

.custom-group-drop-target {
    border: 1px dashed var(--accent-primary);
}

.custom-group-selected-item.custom-group-drop-before {
    box-shadow: inset 0 2px 0 0 var(--accent-primary);
}

.custom-group-drop-target.custom-group-drop-end-active {
    box-shadow: inset 0 2px 0 0 var(--accent-primary);
    border-color: var(--accent-primary);
}

@media (min-width: 980px) {
    .custom-group-editor-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.channel-viewer-shell {
    display: grid;
    gap: 0.6rem;
}

.channel-viewer-program-info {
    border: 1px solid var(--border-color);
    background: rgba(30, 41, 59, 0.4);
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    margin-bottom: 0.7rem;
    display: grid;
    gap: 0.25rem;
}

.channel-viewer-program-title {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 700;
}

.channel-viewer-program-meta {
    color: var(--accent-primary);
    font-size: 0.8rem;
    font-weight: 600;
}

.channel-viewer-program-description {
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.35;
}

.channel-viewer-stream-info {
    border: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.45);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.7rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.4rem 0.75rem;
}

.channel-viewer-stream-row {
    display: grid;
    gap: 0.1rem;
}

.channel-viewer-stream-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.channel-viewer-stream-value {
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}

.channel-viewer-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
}

.channel-volume-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.channel-volume-wrap input[type="range"] {
    width: 100px;
}

.channel-latency-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    user-select: none;
}

.channel-latency-wrap input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

.channel-viewer-status {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

#channelViewerModal {
    align-items: flex-start;
    overflow-y: auto;
    z-index: 60;
}

#channelViewerModal .modal-content {
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
}

/* Keep custom channel-group editor usable on phones without changing desktop layout. */
#customGroupModal {
    align-items: flex-start;
    overflow-y: auto;
}

#customGroupModal .modal-content {
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
}

#channelEditorModal {
    align-items: flex-start;
    overflow-y: auto;
}

#channelEditorModal .modal-content {
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
}

@media (max-width: 840px) {
    #customGroupModal {
        padding: 0.5rem;
    }

    #customGroupModal .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 1rem);
        padding: 1rem;
    }

    #customGroupModal .form-group {
        margin-bottom: 0.8rem;
    }

    #customGroupModal .custom-group-editor-grid {
        gap: 0.6rem;
    }

    #customGroupModal .channel-list {
        max-height: 26vh;
        overscroll-behavior: contain;
    }

    #customGroupModal .channel-item {
        padding: 0.5rem 0.6rem;
    }

    #customGroupModal .modal-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin-top: 0.85rem;
        padding-top: 0.65rem;
        background: linear-gradient(180deg, rgba(30, 41, 59, 0), rgba(30, 41, 59, 0.97) 32%);
    }
}

.channel-viewer-log-wrap {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.5);
    overflow: hidden;
}

.channel-viewer-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0.55rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.channel-viewer-log {
    margin: 0;
    padding: 0.55rem;
    max-height: 160px;
    overflow: auto;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 768px) {
    #channelEditorModal {
        padding: 0.5rem;
    }

    #channelEditorModal .modal-content {
        width: calc(100vw - 1rem);
        max-width: calc(100vw - 1rem) !important;
        padding: 1rem;
        border-radius: 12px;
        margin: 0.25rem 0;
        max-height: calc(100dvh - 0.5rem);
    }

    #channelEditorModal .modal-header h3 {
        font-size: 0.96rem;
        margin-bottom: 0.35rem;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #channelEditorModal .channel-list {
        max-height: 26vh;
        overscroll-behavior: contain;
    }

    #channelEditorModal .modal-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin-top: 0.85rem;
        padding-top: 0.65rem;
        padding-bottom: 0.1rem;
        background: linear-gradient(180deg, rgba(30, 41, 59, 0), rgba(30, 41, 59, 0.97) 32%);
    }

    #channelViewerModal {
        padding: 0.5rem;
    }

    #channelViewerModal .modal-content {
        padding: 1rem;
        border-radius: 12px;
        margin: 0.25rem 0;
        max-height: calc(100vh - 0.5rem);
    }

    #channelViewerVideo {
        max-height: 42vh !important;
    }

    .channel-viewer-controls {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: rgba(15, 23, 42, 0.92);
    }

    .channel-viewer-status {
        width: 100%;
        margin-left: 0;
    }
}

.btn-copy {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.btn-copy:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
