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

:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --border: #2a2a2a;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #4a9eff;
    --accent-hover: #6bb3ff;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

nav .logo {
    flex: 1;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--accent);
    text-decoration: none;
}

nav .nav-title {
    flex: 1;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

nav .nav-links { flex: 1; display: flex; gap: 1.5rem; justify-content: flex-end; }
nav .nav-links a { color: var(--text-muted); text-decoration: none; }
nav .nav-links a:hover { color: var(--text); }

main {
    max-width: 960px;
    margin: 2rem auto;
    padding: 0 1rem;
}

h1 { margin-bottom: 0.5rem; }

form {
    display: flex;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

input[type="url"], input[type="text"], input[type="search"], textarea, select {
    flex: 1;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
}

button, .btn {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button:hover, .btn:hover { background: var(--accent-hover); }

.btn-danger { background: var(--error); }
.btn-danger:hover { background: #e53935; }

.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
    border-radius: 4px;
}
.btn-delete:hover { color: var(--error); background: rgba(244, 67, 54, 0.15); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1rem;
}

.card h3 { margin-bottom: 0.3rem; }
.card .meta { color: var(--text-muted); font-size: 0.9rem; }

.status { padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.85rem; font-weight: 500; }
.status-pending { background: var(--border); }
.status-completed { background: #1b5e20; color: #a5d6a7; }
.status-failed { background: #b71c1c; color: #ef9a9a; }
.status-downloading, .status-transcribing, .status-extracting_frames, .status-analyzing {
    background: #0d47a1; color: #90caf9;
}

.label-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    margin: 0.1rem;
    text-decoration: none;
    color: var(--text-muted);
    transition: color 0.15s, background 0.15s;
}

.label-tag:hover {
    color: var(--text);
    background: #333;
}

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

.frames-grid img {
    width: 100%;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Summary sections presentation */
.summary-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.summary-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.summary-section h3 {
    margin-bottom: 0.6rem;
    font-size: 1.1rem;
}

.section-frames {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    overflow-x: auto;
}

.section-frames img {
    height: 160px;
    width: auto;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.section-content {
    line-height: 1.7;
    color: var(--text);
}

.transcript-segments { margin: 1rem 0; }
.segment { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.segment-time { color: var(--accent); font-size: 0.85rem; font-family: monospace; }

.search-results { margin: 1rem 0; }

.empty { color: var(--text-muted); text-align: center; padding: 3rem; }

.error-msg { color: var(--error); margin: 0.5rem 0; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ── Subjects: two-panel layout ── */
.subjects-layout {
    display: flex;
    gap: 1.5rem;
    min-height: 70vh;
}

.tree-panel {
    width: 340px;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow-y: auto;
    max-height: 80vh;
}

.tree-header { margin-bottom: 0.75rem; }

.detail-panel {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    overflow-y: auto;
    max-height: 80vh;
}

/* Tree nodes */
.subject-tree, .tree-children {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.tree-children { padding-left: 1.2rem; }

.tree-node {
    margin: 0.15rem 0;
    user-select: none;
}

.tree-toggle {
    display: inline-block;
    width: 1.2rem;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.7rem;
    vertical-align: middle;
}

.tree-toggle.has-children::before { content: "▸"; }
.tree-node.expanded > .tree-toggle.has-children::before { content: "▼"; }
.tree-toggle:not(.has-children)::before { content: "·"; }

.node-label {
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.95rem;
    transition: background 0.15s;
}

.node-label:hover { background: var(--border); }
.node-label.selected { background: rgba(74, 158, 255, 0.2); color: var(--accent); }

.video-count { color: var(--text-muted); font-size: 0.8rem; }

/* Detail panel sections */
.detail-header { margin-bottom: 1rem; }
.detail-header h2 { margin-top: 0.3rem; }

.breadcrumb { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.breadcrumb-link { color: var(--accent); text-decoration: none; }
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb-sep { margin: 0 0.3rem; color: var(--text-muted); }
.breadcrumb-current { color: var(--text); }

.detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.detail-section {
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.detail-section h3 { margin-bottom: 0.5rem; font-size: 1rem; }

.detail-video-card {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-video-card:last-child { border-bottom: none; }

.child-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: inherit; }
.btn-link:hover { text-decoration: underline; background: none; }
.btn-danger-text { color: var(--error); }

.inline-form {
    display: flex;
    gap: 0.4rem;
    margin: 0.75rem 0;
    flex-wrap: wrap;
}

.inline-form input { flex: 1; min-width: 120px; padding: 0.3rem 0.6rem; font-size: 0.9rem; }

/* Assign video form */
.assign-form { margin: 0.75rem 0; }
.assign-form h4 { margin-bottom: 0.5rem; font-size: 0.95rem; }
.assign-form input { width: 100%; margin-bottom: 0.5rem; }

.assign-video-list { max-height: 300px; overflow-y: auto; }

.assign-video-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
}

/* ── Explore: graph layout ── */
/* Override main's max-width for the explore page */
main:has(.explore-wide) { max-width: 1400px; }
.explore-wide { width: 100%; }

.explore-container {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.explore-sidebar {
    width: 180px;
    flex-shrink: 0;
}

.explore-sidebar h3 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-muted); }

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin: 0.3rem 0;
    color: var(--text-muted);
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-rect {
    width: 14px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.filter-group { margin-top: 1rem; }

.filter-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    margin: 0.2rem 0;
}

.filter-group input[type="checkbox"] { accent-color: var(--accent); }

.layout-group { margin-top: 1rem; }

.layout-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    margin: 0.2rem 0;
}

.layout-group input[type="radio"] { accent-color: var(--accent); }

.explore-graph {
    flex: 1;
    min-height: 500px;
}

#cy {
    width: 100%;
    height: 600px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.explore-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    display: none;
}

.explore-detail.active { display: block; }

.explore-detail h3 { margin-bottom: 0.5rem; }

.explore-detail-videos {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.explore-video-card {
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.explore-video-card a { color: var(--text); text-decoration: none; }
.explore-video-card a:hover { color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
    .subjects-layout { flex-direction: column; }
    .tree-panel { width: 100%; max-height: 40vh; }
    .detail-panel { max-height: none; }
    .explore-container { flex-direction: column; }
    .explore-sidebar { width: 100%; }
}
