/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-muted: #666;
    --border: #e0e0e0;
    --primary: #4361ee;
    --primary-hover: #3a56d4;
    --danger: #e63946;
    --accent: #4361ee;
    --player-bg: #1a1a2e;
    --player-text: #f5f5f5;
    --sidebar-width: 280px;
    --player-height: 90px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}

/* --- App Layout --- */
#app {
    display: flex;
    min-height: 100vh;
    padding-bottom: var(--player-height);
}

/* --- Sidebar --- */
#sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-header button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.sidebar-header button:hover {
    background: var(--primary-hover);
}

.sidebar-empty {
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* --- Podcast List Items --- */
.podcast-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.podcast-item:hover { background: #f0f0f0; }
.podcast-item.active { background: #e8eeff; border-left: 3px solid var(--primary); }

.podcast-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--border);
}

.podcast-item-text { min-width: 0; }

.podcast-item-title {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.podcast-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Main Content --- */
#content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
}

#main-view {
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 16px;
    font-size: 1rem;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

.spinner-inline {
    width: 18px;
    height: 18px;
    border-width: 2px;
    display: inline-block;
    vertical-align: middle;
}

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

/* --- Episode Header --- */
.episode-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
    padding: 4px 8px;
}

.podcast-hero {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
}

.podcast-header-text { flex: 1; min-width: 0; }
.podcast-header-text h2 { font-size: 1.25rem; }
.podcast-author { color: var(--text-muted); font-size: 0.875rem; }

.podcast-actions {
    display: flex;
    gap: 8px;
}

/* --- Download Indicators --- */
.icon-auto-dl,
.icon-downloaded {
    font-size: 0.7rem;
    color: var(--primary);
    vertical-align: middle;
}

/* --- Auto-download Toggle --- */
.auto-download-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.auto-download-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* --- Episode List --- */
.load-more-btn {
    display: block;
    margin: 16px auto;
    padding: 10px 32px;
}

.episode-list {
    display: flex;
    flex-direction: column;
}

.episode-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.episode-item.playing { background: #e8eeff; margin: 0 -16px; padding: 12px 16px; border-radius: 8px; }


.episode-play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    line-height: 1;
    padding: 0;
}

.episode-play-btn:hover {
    background: var(--primary);
    color: white;
}

.episode-info { flex: 1; min-width: 0; }

.episode-title {
    font-size: 0.9rem;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.episode-meta {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.episode-progress {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.episode-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
}

/* --- Modal --- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 440px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-content h2 { margin-bottom: 16px; }

.modal-content input[type="url"],
.modal-content input[type="search"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
}

.modal-content input:focus { border-color: var(--primary); }

/* --- Search Results --- */
#search-results {
    max-height: 360px;
    overflow-y: auto;
}

#search-results:empty { display: none; }

#search-results .search-status {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s;
}

.search-result:hover { background: #f0f0f0; }

.search-result img {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--border);
}

.search-result-text { min-width: 0; flex: 1; }

.search-result-title {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-artist {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.modal-divider::before,
.modal-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

#modal-error {
    margin-top: 12px;
    color: var(--danger);
    font-size: 0.85rem;
}

#modal-error.hidden { display: none; }

/* --- Buttons --- */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d0d0d0; }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }

/* --- Mobile-disabled state (button visible but not functional on mobile) --- */
.mobile-disabled {
    opacity: 0.45;
    cursor: help;
    filter: grayscale(1);
}

.sidebar-header button.mobile-disabled,
.sidebar-header button.mobile-disabled:hover {
    background: var(--text-muted);
}

.btn-secondary.mobile-disabled,
.btn-secondary.mobile-disabled:hover {
    background: var(--border);
    color: var(--text);
}

/* --- Player Bar --- */
#player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--player-height);
    background: var(--player-bg);
    color: var(--player-text);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

#player-bar.hidden { display: none; }

.player-progress-container {
    width: 100%;
    height: 4px;
    flex-shrink: 0;
}

#player-seek {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.2);
    outline: none;
    margin: 0;
    display: block;
    cursor: pointer;
}

#player-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

#player-seek::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

#player-seek::-webkit-slider-runnable-track {
    height: 4px;
}

#player-seek::-moz-range-track {
    height: 4px;
    background: rgba(255,255,255,0.2);
}

.player-controls {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

#player-art {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

#player-art.hidden { display: none; }

.player-text { min-width: 0; }

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

.player-podcast {
    font-size: 0.75rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.player-btn {
    background: none;
    border: none;
    color: var(--player-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transition: background 0.15s;
}

.player-btn:hover { background: rgba(255,255,255,0.1); }

.player-btn-main {
    width: 52px;
    height: 52px;
}

.player-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.player-time {
    font-size: 0.75rem;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.speed-btn {
    font-size: 0.8rem !important;
    font-weight: 600;
    width: auto !important;
    padding: 4px 10px !important;
    border-radius: 16px !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
}

/* --- Volume Control --- */
.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.volume-btn {
    width: 36px !important;
    height: 36px !important;
}

#volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--player-text);
    cursor: pointer;
}

#volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--player-text);
    cursor: pointer;
    border: none;
}

#volume-slider::-moz-range-track {
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

/* --- Queue Nav Item --- */
.queue-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    background: #f8f9ff;
    transition: background 0.1s;
    font-weight: 600;
    font-size: 0.9rem;
}

.queue-nav-item:hover { background: #eef0ff; }
.queue-nav-item.active { background: #e0e5ff; border-left: 3px solid var(--primary); }

.queue-nav-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.queue-nav-label { flex: 1; }

.queue-nav-count {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 2px 8px;
    min-width: 20px;
    text-align: center;
}

/* --- Queue View --- */
.queue-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.queue-header h2 { flex: 1; font-size: 1.25rem; }

.queue-list {
    display: flex;
    flex-direction: column;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.queue-thumb {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--border);
}

.queue-drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1rem;
    padding: 4px;
    flex-shrink: 0;
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.queue-drag-handle:hover { opacity: 1; }

.queue-item.dragging {
    opacity: 0.4;
}

.queue-item.drag-over {
    border-top: 2px solid var(--primary);
}

.queue-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.queue-remove-btn:hover {
    color: var(--danger);
    background: rgba(230, 57, 70, 0.1);
}

/* --- Downloads View --- */
.downloads-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    background: #f8f9ff;
    transition: background 0.1s;
    font-weight: 600;
    font-size: 0.9rem;
}

.downloads-nav-item:hover { background: #eef0ff; }
.downloads-nav-item.active { background: #e0e5ff; border-left: 3px solid var(--primary); }

.downloads-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.downloads-header h2 { flex: 1; font-size: 1.25rem; }

.downloads-list {
    display: flex;
    flex-direction: column;
}

.download-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.download-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.download-remove-btn:hover {
    color: var(--danger);
    background: rgba(230, 57, 70, 0.1);
}

/* --- Episode Download Button --- */
.episode-dl-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: all 0.15s;
    min-width: 32px;
    text-align: center;
}

.episode-dl-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.episode-dl-btn.downloaded {
    border-color: var(--primary);
    color: var(--primary);
}

.episode-dl-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* --- Episode Queue Button --- */
.episode-queue-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: all 0.15s;
    white-space: nowrap;
}

.episode-queue-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.episode-queue-btn.queued {
    border-color: var(--primary);
    color: var(--primary);
}

.episode-queue-btn.queued:hover {
    opacity: 0.8;
}

/* --- Finished Button --- */
.finished-btn {
    width: 32px !important;
    height: 32px !important;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.finished-btn:hover { opacity: 1; }

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    bottom: calc(var(--player-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--player-bg);
    color: var(--player-text);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: auto;
}

.toast.toast-visible { opacity: 1; }

.hidden { display: none !important; }

/* --- Mobile --- */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    /* When viewing a podcast on mobile, hide sidebar and show content */
    #app.show-content #sidebar { display: none; }
    #app.show-content #content { display: block; }

    .back-btn { display: block; }

    .podcast-hero { width: 60px; height: 60px; }

    .podcast-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Player bar adjustments */
    :root { --player-height: 140px; }

    .player-info {
        flex-basis: 100%;
    }

    .player-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .player-btn { width: 48px; height: 48px; }
    .player-btn-main { width: 56px; height: 56px; }

    .volume-control { display: none; }

    .queue-header .back-btn { display: block; }
    .downloads-header .back-btn { display: block; }
}

.signin-screen {
    text-align: center;
    padding: 60px 20px;
    max-width: 400px;
    margin: 0 auto;
}

.signin-screen h2 {
    margin-bottom: 16px;
}

.signin-screen p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}
