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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f8f9fa;
    color: #1a1a1a;
    line-height: 1.6;
}

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

header {
    margin-bottom: 2rem;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #111;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-top: 1rem;
    border-bottom: 2px solid #e0e0e0;
}

.tab {
    padding: 0.5rem 1.2rem;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab:hover { color: #444; }
.tab.active { color: #4a7cff; border-bottom-color: #4a7cff; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Controls */
.controls {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

select, input[type="text"], input[type="number"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 1rem;
    background: #fff;
    color: #1a1a1a;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus {
    outline: none;
    border-color: #4a7cff;
    box-shadow: 0 0 0 2px rgba(74, 124, 255, 0.15);
}

.input-row { display: flex; gap: 0.6rem; }
.input-row input { flex: 1; }

.field-row { display: flex; gap: 0.8rem; margin-bottom: 1rem; }
.field-row .field { flex: 1; margin-bottom: 0; }
.field-narrow { max-width: 100px; }

.btn-primary, button#submit, #podcast-search-btn {
    padding: 0.6rem 1.4rem;
    background: #4a7cff;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-primary:hover:not(:disabled),
button#submit:hover:not(:disabled),
#podcast-search-btn:hover:not(:disabled) {
    background: #3a6ae0;
}

.btn-primary:disabled, button#submit:disabled, #podcast-search-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #666;
    font-style: italic;
}

.hidden { display: none; }

/* Search tab */
.toggle-field { margin-bottom: 0; }

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    text-transform: none;
    font-size: 0.9rem;
    font-weight: 400;
    color: #1a1a1a;
    letter-spacing: 0;
}

.toggle-text { font-weight: 600; }
.toggle-hint { color: #888; font-size: 0.8rem; }

.synthesis-section, .sources-section {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.synthesis-section { border-left: 3px solid #4a7cff; }

.synthesis-section h2, .sources-section h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    margin-bottom: 1rem;
}

#answer { white-space: pre-wrap; line-height: 1.7; }

.source-chunk {
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #fafafa;
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.source-label { font-size: 0.8rem; font-weight: 600; color: #4a7cff; }
.source-score { font-size: 0.75rem; color: #999; }

.source-header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.source-date {
    font-size: 0.72rem;
    color: #aaa;
}

.source-text {
    font-size: 0.9rem;
    color: #444;
    line-height: 1.6;
    white-space: pre-wrap;
}

.source-footer {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}

.btn-expand {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: #fff;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
}

.btn-expand:hover:not(:disabled) { background: #f5f5f5; color: #333; }
.btn-expand:disabled { opacity: 0.5; cursor: not-allowed; }

.xref-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.xref-link {
    font-size: 0.72rem;
    color: #8b5cf6;
    text-decoration: none;
    padding: 0.15rem 0.45rem;
    border: 1px solid #e0d4f5;
    border-radius: 3px;
    background: #faf5ff;
    white-space: nowrap;
}

.xref-link:hover {
    background: #f0e6ff;
    border-color: #8b5cf6;
}

.context-center {
    background: #fffde7;
    border-left: 2px solid #fbc02d;
    padding-left: 0.4rem;
    display: inline;
}

.context-surrounding {
    color: #888;
}

.chunk-highlight {
    animation: chunk-flash 2s ease-out;
}

@keyframes chunk-flash {
    0%   { box-shadow: 0 0 0 3px #8b5cf6; }
    100% { box-shadow: 0 0 0 0px transparent; }
}

.source-chunk { transition: box-shadow 0.3s; }

/* Pipeline tab - podcast search results */
.podcast-results {
    margin-top: 0.75rem;
}

.podcast-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border: 1px solid #eee;
    border-radius: 6px;
    margin-bottom: 0.4rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.podcast-item:hover { border-color: #4a7cff; background: #f5f8ff; }

.podcast-name { font-weight: 600; font-size: 0.9rem; }
.podcast-artist { color: #666; font-size: 0.8rem; }
.podcast-episodes { color: #999; font-size: 0.8rem; white-space: nowrap; }

.selected-podcast {
    background: #eef3ff;
    border: 1px solid #c5d5ff;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #2a5cdb;
}

.series-preview {
    margin-bottom: 1rem;
}

.series-preview h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    margin-bottom: 0.6rem;
}

.series-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.series-card {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
}

.series-card-name {
    font-weight: 600;
    color: #333;
}

.series-card-count {
    color: #888;
    font-size: 0.75rem;
}

.series-card-samples {
    color: #999;
    font-size: 0.7rem;
    margin-top: 0.3rem;
    line-height: 1.4;
}

.series-loading {
    color: #888;
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem 0;
}

/* Pipeline dashboard */
.phase-bar {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.8rem 1.2rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.phase-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.phase-bar.active { border-left: 3px solid #4a7cff; }
.phase-bar.complete { border-left: 3px solid #2ea44f; }
.phase-bar.complete .phase-label { color: #2ea44f; }

/* Stats */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #111;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #888;
    margin-top: 0.2rem;
}

/* Progress bars */
.progress-section {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.75rem;
}

.progress-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    margin-bottom: 0.6rem;
}

.progress-bar-wrap {
    background: #eee;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.progress-bar {
    height: 100%;
    background: #4a7cff;
    border-radius: 4px;
    transition: width 0.3s;
}

.progress-bar-green { background: #2ea44f; }

.progress-text {
    font-size: 0.8rem;
    color: #888;
}

/* Event log */
.event-log-section {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 1rem;
}

.event-log-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    margin-bottom: 0.6rem;
}

.event-log {
    max-height: 300px;
    overflow-y: auto;
    font-family: "SF Mono", "Menlo", "Monaco", monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #444;
}

.log-entry { padding: 0.15rem 0; }
.log-entry.download { color: #4a7cff; }
.log-entry.transcribe { color: #8b5cf6; }
.log-entry.ingest { color: #2ea44f; }
.log-entry.error { color: #d73a49; }
.log-entry.phase { color: #111; font-weight: 600; }

/* Episodes tab */
.ep-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    margin-bottom: 0.75rem;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.ep-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.ep-toolbar-right {
    display: flex;
    gap: 0.4rem;
}

#ep-selection-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4a7cff;
    min-width: 80px;
}

.ep-tag-input {
    width: 180px !important;
    padding: 0.35rem 0.6rem !important;
    font-size: 0.85rem !important;
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    background: #fff;
    color: #333;
    cursor: pointer;
}

.btn-sm:hover:not(:disabled) { background: #f5f5f5; }
.btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-sm.btn-muted { color: #888; }

#ep-apply-tag {
    background: #4a7cff;
    color: #fff;
    border-color: #4a7cff;
}

#ep-apply-tag:hover:not(:disabled) { background: #3a6ae0; }

.ep-summary {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.75rem;
}

.ep-summary h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #666;
    margin-bottom: 0.6rem;
}

.tag-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color 0.15s, background 0.15s;
}

.tag-pill:hover { filter: brightness(0.95); }

.tag-pill.active {
    border-color: #333;
    box-shadow: 0 0 0 1px #333;
}

.tag-pill-count {
    font-weight: 400;
    opacity: 0.7;
}

.tag-pill-untagged {
    background: #f0f0f0;
    color: #888;
}

.ep-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ep-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s, border-color 0.1s;
    font-size: 0.88rem;
}

.ep-row:hover { background: #f8faff; border-color: #c5d5ff; }

.ep-row.selected {
    background: #eef3ff;
    border-color: #4a7cff;
}

.ep-row.selected .ep-num { color: #4a7cff; }

.ep-num {
    font-weight: 700;
    color: #999;
    min-width: 32px;
    text-align: right;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.ep-title {
    flex: 1;
    color: #1a1a1a;
}

.ep-tag {
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.ep-tag-auto {
    background: #f0f0f0;
    color: #666;
}

.ep-tag-manual {
    background: #eef3ff;
    color: #4a7cff;
}

.ep-date {
    color: #bbb;
    font-size: 0.75rem;
    white-space: nowrap;
}

.pipeline-command {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f0f4f8;
    border-radius: 8px;
    border: 1px solid #e0e4e8;
}

.pipeline-command h3 {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.pipeline-command p {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 0.75rem;
}

.pipeline-command pre {
    background: #1a1a1a;
    color: #e0e0e0;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.5;
    user-select: all;
}
