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

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #666;
    --primary: #3498db;
    --primary-dark: #2980b9;
    --accent: #2c3e50;
    --border: #e1e5eb;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Navbar === */
.navbar {
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.nav-brand {
    color: #fff;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.bl-form {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.bl-label {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.bl-select {
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255,255,255,0.12) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 0.6rem center;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 0.4rem 2rem 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.bl-select:hover, .bl-select:focus {
    background-color: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.4);
    outline: none;
}
.bl-select option { color: var(--text); background: var(--surface); }

.nav-status {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    background: rgba(255,255,255,0.1);
}
.status-ready { color: #2ecc71; }
.status-pending { color: #f39c12; }

/* === Container === */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    flex: 1;
    width: 100%;
}

/* === Hero === */
.hero {
    text-align: center;
    padding: 2rem 0 2.5rem;
}
.hero h1 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.03em;
}
.hero-sub {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 0.5rem;
}
.hero .back-link {
    margin-top: 0.75rem;
}

/* === Cards Grid (Index) === */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
    box-shadow: var(--shadow);
}
.card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

.card-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    color: var(--primary);
}
.card-icon svg { width: 100%; height: 100%; }

.card-body { flex: 1; min-width: 0; }
.card-body h3 { font-size: 1.1rem; font-weight: 600; }
.card-file { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.2rem; }

.card-arrow {
    font-size: 1.3rem;
    color: var(--primary);
    flex-shrink: 0;
}

/* === Page Header === */
.page-header {
    margin-bottom: 1.5rem;
}
.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-block;
    margin-bottom: 0.5rem;
}
.back-link:hover { text-decoration: underline; }
.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}
.page-sub {
    color: var(--text-secondary);
    margin-top: 0.3rem;
}

/* === Toolbar === */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    position: sticky;
    top: 52px;
    z-index: 50;
    box-shadow: var(--shadow);
}
.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.selection-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* === Format labels === */
.format-label {
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* === Section Cards === */
.sections-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 5rem;
}

.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s;
}
.section-card.expanded {
    border-color: var(--primary);
}

.section-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    cursor: default;
}

.section-check {
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-top: 2px;
}
.section-check input { display: none; }

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: inline-block;
    position: relative;
    transition: all 0.15s;
}
.checkmark.small { width: 16px; height: 16px; }

input:checked + .checkmark {
    background: var(--primary);
    border-color: var(--primary);
}
input:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checkmark.small input:checked + .checkmark::after {
    left: 4px;
    top: 0;
    width: 4px;
    height: 8px;
}

input:indeterminate + .checkmark {
    background: var(--primary);
    border-color: var(--primary);
}
input:indeterminate + .checkmark::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 7px;
    width: 10px;
    height: 2px;
    background: #fff;
}

.section-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}
.section-number {
    font-weight: 700;
    color: var(--primary);
    margin-right: 0.3rem;
}
.section-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
    line-height: 1.4;
}

.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    background: #eef2f7;
    color: var(--text-secondary);
    margin-left: 0.4rem;
    vertical-align: middle;
}
.badge-warn {
    background: #ffeaa7;
    color: #856404;
}

.expand-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}
.expand-icon { width: 20px; height: 20px; }
.expanded .expand-btn { transform: rotate(180deg); }

/* === Begriffe List === */
.begriffe-list {
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
    background: #fafbfc;
}

.begriff-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 1rem 0.5rem 3rem;
    cursor: pointer;
    transition: background 0.1s;
}
.begriff-item:hover { background: #f0f4f8; }
.begriff-item input { display: none; }

.begriff-term {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.begriff-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.begriff-preview.missing {
    color: #e17055;
    font-style: italic;
}

/* === Bottom Bar === */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    z-index: 100;
}

/* === Flash === */
.flash-messages { margin-bottom: 1rem; }
.flash {
    background: #ffeaa7;
    color: #856404;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}
.empty-state code {
    background: #eef2f7;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* === Mindmap === */
.mindmap-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.mindmap-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.mermaid {
    max-width: 100%;
    overflow: auto;
    text-align: center;
}

.mermaid svg {
    max-width: 100%;
    height: auto;
}

.mindmap-toggle {
    cursor: default;
}
.mindmap-summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    user-select: none;
    color: var(--text);
}
.mindmap-toggle[open] > .mindmap-summary {
    margin-bottom: 1rem;
}

/* Mindmap node selection: checkmarks appended to text by JS. */

/* === Footer === */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* === Responsive === */
@media (max-width: 640px) {
    .container { padding: 1rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-right { justify-content: space-between; }
    .hero h1 { font-size: 1.6rem; }
    .card-grid { grid-template-columns: 1fr; }
}
