/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-text-muted: #555555;
    --color-primary: #1a5276;
    --color-primary-hover: #154360;
    --color-accent: #2980b9;
    --color-border: #d0d0d0;
    --color-focus: #4a90d9;
    --color-success: #1e7e34;
    --color-success-bg: #d4edda;
    --color-warning: #856404;
    --color-warning-bg: #fff3cd;
    --color-danger: #a71d2a;
    --color-danger-bg: #f8d7da;
    --color-pending: #6c757d;
    --color-pending-bg: #e9ecef;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-stack);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Accessibility === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    z-index: 1000;
    padding: 0.75rem 1.5rem;
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
    border-radius: 0 0 var(--radius) var(--radius);
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Focus styles for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex="0"]:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* === Header & Navigation === */
header[role="banner"] {
    background: var(--color-primary);
    color: #fff;
    padding: 0;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.site-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.site-title a {
    color: #fff;
    text-decoration: none;
}

.site-title a:hover {
    text-decoration: underline;
}

.nav-list {
    list-style: none;
    display: flex;
    gap: 0.25rem;
}

.nav-list a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: background 0.15s;
}

.nav-list a:hover,
.nav-list a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.nav-list a[aria-current="page"] {
    font-weight: 600;
}

/* === Layout === */
main[role="main"] {
    flex: 1;
    padding: 1.5rem 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

footer[role="contentinfo"] {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-size: 1.5rem;
}

/* === Breadcrumbs === */
.breadcrumb ol {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.breadcrumb li:not(:last-child)::after {
    content: "/";
    margin-left: 0.5rem;
}

.breadcrumb a {
    color: var(--color-accent);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
}

.btn:hover {
    background: #e8e8e8;
    border-color: #bbb;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-danger {
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.btn-danger:hover {
    background: var(--color-danger-bg);
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8125rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Tables === */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.data-table caption {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table thead th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-completed {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge-running,
.badge-processing,
.badge-downloading {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.badge-failed {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.badge-pending {
    background: var(--color-pending-bg);
    color: var(--color-pending);
}

.badge-drm,
.badge-drm_locked {
    background: #e2d6f3;
    color: #5b3a8c;
}

.drm-notice {
    background: #e2d6f3;
    color: #3d2066;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border-left: 4px solid #7c4dba;
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
}

.drm-notice a {
    color: #5b3a8c;
    font-weight: 600;
}

/* === Source badges === */
.badge-youtube {
    background: #ff0000;
    color: #fff;
}

.badge-bbc {
    background: #1a1a2e;
    color: #fff;
}

/* === YouTube video embed === */
.video-embed {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    max-width: 800px;
    margin-bottom: 0.75rem;
    border-radius: var(--radius);
}

.video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.video-link {
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.video-player-section {
    margin-bottom: 1.5rem;
}

/* === YouTube search results === */
.yt-search-results-grid {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

.yt-search-result {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    align-items: flex-start;
}

.yt-search-thumb {
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    object-fit: cover;
    flex-shrink: 0;
}

.yt-search-info {
    flex: 1;
    min-width: 0;
}

.yt-search-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

.yt-search-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0.25rem 0 0.5rem;
}

/* === API Keys page === */
.api-key-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    background: var(--surface);
}

.api-key-section h3 {
    margin-top: 0;
    margin-bottom: 0.25rem;
}

.api-key-current {
    margin: 0.75rem 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.api-key-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-family: monospace;
    font-size: 0.8125rem;
}

.api-key-remove {
    background: none;
    border: none;
    color: #c0392b;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.15rem;
    font-weight: bold;
}

.api-key-remove:hover {
    color: #e74c3c;
}

.api-key-none {
    color: var(--text-muted);
    font-style: italic;
    margin: 0.5rem 0;
}

.api-key-form {
    margin-top: 0.75rem;
}

.api-key-form .form-inline {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.api-key-input {
    flex: 1;
    min-width: 250px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.875rem;
}

.api-key-input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.api-key-test-result {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    min-height: 1.25rem;
}

.api-key-test-success {
    color: #27ae60;
    font-weight: 600;
}

.api-key-test-error {
    color: #c0392b;
    font-weight: 600;
}

.api-key-test-pending {
    color: var(--text-muted);
}

/* === Forms === */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.9375rem;
}

.form-group input[type="text"],
.form-group input[type="search"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    max-width: 400px;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
}

.form-help {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.form-inline {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 1rem;
}

.form-inline .form-group {
    margin-bottom: 0;
}

.search-input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 600px;
}

.search-input-group input {
    flex: 1;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
}

.checkbox-group label {
    display: inline;
    font-weight: normal;
    margin-bottom: 0;
}

fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    background: var(--color-surface);
}

legend {
    font-weight: 700;
    font-size: 1.125rem;
    padding: 0 0.5rem;
}

.form-actions {
    margin-top: 1.5rem;
}

/* === Cards === */
.podcast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

/* Dashboard clickable podcast cards */
.podcast-dashboard-card {
    text-decoration: none;
    color: inherit;
    display: block;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.podcast-dashboard-card:hover {
    border-color: var(--color-accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    text-decoration: none;
}

.podcast-dashboard-card-inner {
    display: flex;
    gap: 1rem;
    padding: 1rem;
}

.podcast-dashboard-image {
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    object-fit: cover;
    flex-shrink: 0;
}

.podcast-placeholder {
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
}

.podcast-dashboard-info {
    flex: 1;
    min-width: 0;
}

.podcast-dashboard-info h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.podcast-stats {
    display: flex;
    gap: 1rem;
    margin: 0;
}

.podcast-stats .stat {
    text-align: center;
}

.podcast-stats dt {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 600;
}

.podcast-stats dd {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.podcast-stats-horizontal {
    margin-top: 0.75rem;
}

/* Manage page cards */
.podcast-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.podcast-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
}

.podcast-card-body {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.podcast-card-body h4 {
    font-size: 1.125rem;
    margin-bottom: 0.35rem;
}

.podcast-card-body h4 a {
    color: var(--color-text);
    text-decoration: none;
}

.podcast-card-body h4 a:hover {
    text-decoration: underline;
    color: var(--color-accent);
}

.podcast-meta {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.podcast-desc {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
    flex: 1;
}

.podcast-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.page-header-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.activity-section {
    margin-top: 2.5rem;
}

/* === Podcast header === */
.podcast-header {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.podcast-header-image {
    width: 120px;
    height: 120px;
    border-radius: var(--radius);
    object-fit: cover;
    flex-shrink: 0;
}

.podcast-header-info h2 {
    margin-bottom: 0.35rem;
}

/* === Action bar === */
.action-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

/* === Transcript === */
.episode-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.episode-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.35rem;
}

.episode-meta {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.transcript-text {
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.9375rem;
}

/* === Search results === */
.search-form {
    margin-bottom: 2rem;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-result {
    background: var(--color-surface);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-accent);
}

.search-result h4 {
    margin-bottom: 0.25rem;
}

.search-result h4 a {
    color: var(--color-text);
    text-decoration: none;
}

.search-result h4 a:hover {
    text-decoration: underline;
    color: var(--color-accent);
}

.result-meta {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.result-snippet {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
}

/* === Flash messages === */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.flash-success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.flash-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.flash-info {
    background: #cce5ff;
    color: #004085;
}

/* === Error messages === */
.error-message {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

/* === Progress === */
progress {
    width: 80px;
    height: 8px;
    vertical-align: middle;
    margin-left: 0.5rem;
}

progress::-webkit-progress-bar {
    background: var(--color-pending-bg);
    border-radius: 4px;
}

progress::-webkit-progress-value {
    background: var(--color-accent);
    border-radius: 4px;
}

/* === Settings section === */
.settings-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    font-size: 0.9375rem;
}

.pagination a {
    color: var(--color-accent);
}

/* === Links === */
a {
    color: var(--color-accent);
}

a:hover {
    text-decoration: underline;
}

/* === Episode list === */
.episode-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.episode-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom: none;
}

.episode-row:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
}

.episode-row:last-child {
    border-bottom: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius) var(--radius);
}

.episode-row:only-child {
    border-radius: var(--radius);
    border-bottom: 1px solid var(--color-border);
}

.episode-row:hover {
    background: #f8f9fa;
}

.episode-main {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.episode-date {
    flex-shrink: 0;
    width: 90px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    padding-top: 0.15rem;
    font-variant-numeric: tabular-nums;
}

.episode-info {
    flex: 1;
    min-width: 0;
}

.episode-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    line-height: 1.4;
}

.episode-title a {
    color: var(--color-text);
    text-decoration: none;
}

.episode-title a:hover {
    color: var(--color-accent);
    text-decoration: underline;
}

.episode-desc {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.35rem;
    line-height: 1.4;
}

.episode-meta-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.episode-duration {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.episode-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
    align-items: flex-start;
    padding-top: 0.15rem;
}

/* === Audio player === */
.audio-player-section {
    margin-bottom: 1.5rem;
}

.audio-player-section audio {
    width: 100%;
    border-radius: var(--radius);
}

.episode-description-section {
    margin-bottom: 1.5rem;
}

.transcript-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

/* === Responsive === */
@media (max-width: 768px) {
    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .nav-list {
        flex-wrap: wrap;
    }

    .podcast-header {
        flex-direction: column;
    }

    .podcast-header-image {
        width: 80px;
        height: 80px;
    }

    .data-table {
        font-size: 0.875rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.65rem;
    }

    .podcast-grid {
        grid-template-columns: 1fr;
    }

    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .episode-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .episode-main {
        flex-direction: column;
        gap: 0.25rem;
    }

    .episode-date {
        width: auto;
    }

    .episode-actions {
        padding-top: 0;
    }
}
