/* D&D Companion — dark theme with bright pops */

:root {
    --bg: #0d0d0d;
    --surface: #161616;
    --surface-raised: #1e1e1e;
    --border: #2a2a2a;
    --border-hover: #444;
    --accent: #0dbc79;
    --accent-dim: #0a9460;
    --highlight: #58a6ff;
    --warm: #f0883e;
    --text: #e6e6e6;
    --text-secondary: #999;
    --text-dim: #666;
    --radius: 6px;
}

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

/* Top navigation tabs */
.top-nav {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    padding: 0 1.5rem;
}

.top-tab {
    padding: 0.6rem 1.2rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.top-tab:hover { color: var(--text); }
.top-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
}

/* Layout: sidebar + main */
.layout {
    display: flex;
    min-height: 100dvh;
}

/* --- Sidebar TOC --- */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 0 1rem 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.sidebar-header h2 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
}

.sidebar-header a {
    font-size: 0.7rem;
    color: var(--highlight);
    text-decoration: none;
    opacity: 0.8;
}

.sidebar-header a:hover {
    opacity: 1;
    text-decoration: underline;
}

.toc-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

.toc-item a {
    display: block;
    padding: 0.35rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s;
}

.toc-item a:hover {
    color: var(--accent);
    background: rgba(13, 188, 121, 0.05);
    border-left-color: var(--accent);
}

.toc-item.indent a {
    padding-left: 2rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.toc-item.indent a:hover {
    color: var(--accent);
}

.toc-divider {
    height: 1px;
    background: var(--border);
    margin: 0.4rem 1rem;
}

/* --- Main content --- */
.main {
    flex: 1;
    min-width: 0;
    max-width: 800px;
    padding: 1.5rem 2rem;
}

/* Header */
header {
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

header h1 span {
    color: var(--accent);
}

header p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

header p a {
    color: var(--highlight);
    text-decoration: none;
}

header p a:hover {
    text-decoration: underline;
}

/* Search form */
.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.search-input {
    flex: 1;
    padding: 0.6rem 0.85rem;
    font-size: 0.95rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--text-dim);
}

.type-filter {
    padding: 0.6rem 0.5rem;
    font-size: 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    outline: none;
    cursor: pointer;
}

.type-filter:focus {
    border-color: var(--accent);
}

.search-btn {
    padding: 0.6rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.search-btn:hover { background: var(--accent-dim); }
.search-btn:active { transform: scale(0.97); }

/* Results */
.results-meta {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 0.6rem;
    transition: border-color 0.15s;
}

.result-card:hover {
    border-color: var(--border-hover);
}

.result-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.result-path {
    font-size: 0.75rem;
    color: var(--highlight);
    font-weight: 600;
    flex: 1;
    min-width: 0;
}

.badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
    white-space: nowrap;
}

.badge-spell { background: #1a0a2e; color: #a78bfa; border: 1px solid #2d1b4e; }
.badge-feat { background: #0a1e14; color: #34d399; border: 1px solid #1b3a2a; }
.badge-class_feature { background: #1e1a0a; color: #fbbf24; border: 1px solid #3a341b; }
.badge-equipment { background: #0a1a1e; color: #22d3ee; border: 1px solid #1b2e3a; }
.badge-origin { background: #1e0a1a; color: #f472b6; border: 1px solid #3a1b2e; }
.badge-creature { background: #1e0a0a; color: #f87171; border: 1px solid #3a1b1b; }
.badge-glossary { background: #0a0a1e; color: #818cf8; border: 1px solid #1b1b3a; }
.badge-lore { background: #1e140a; color: #fb923c; border: 1px solid #3a2a1b; }
.badge-rule { background: #0a141e; color: #60a5fa; border: 1px solid #1b2a3a; }

.result-score {
    font-size: 0.65rem;
    color: var(--text-dim);
    font-family: monospace;
}

.result-content {
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--text-secondary);
    overflow-wrap: break-word;
}

.result-content strong {
    color: var(--text);
    font-weight: 600;
}

.result-content em {
    color: var(--warm);
    font-style: italic;
}

/* Low confidence */
.result-card.low-confidence {
    opacity: 0.45;
    border-style: dashed;
}

/* Error */
.error-box {
    background: #1e0a0a;
    border: 1px solid #7f1d1d;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    color: #fca5a5;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-dim);
}

.empty-state p {
    margin-bottom: 0.5rem;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1rem;
}

.suggestion {
    display: inline-block;
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2rem;
    color: var(--text-dim);
    text-decoration: none;
    transition: all 0.15s;
}

.suggestion:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Loading */
.search-form.loading .search-btn {
    background: var(--text-dim);
    cursor: wait;
    pointer-events: none;
}

.search-form.loading .search-input {
    opacity: 0.6;
}

/* Mobile: sidebar becomes top drawer */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #000;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        z-index: 50;
        width: 260px;
        transition: left 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 40;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main {
        padding: 1rem;
    }

    .search-form {
        flex-wrap: wrap;
    }

    .search-input {
        flex-basis: 100%;
    }

    .type-filter {
        flex: 1;
        max-width: none;
    }
}
