/* ──────────────── Base & Variables ──────────────── */
:root {
    --bg: #f8f9fa;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a2e;
    --bg-sidebar-hover: #16213e;
    --text: #2d3436;
    --text-muted: #636e72;
    --text-sidebar: #e0e0e0;
    --accent: #2d5aa6;
    --accent-light: #e8f0fe;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 8px;
    --sidebar-width: 300px;
    --progress-color: #2d5aa6;
    --defined-term-bg: #fff3cd;
    --defined-term-border: #ffc107;
    --badge-bg: #e3f2fd;
    --badge-text: #1565c0;
}

[data-theme="dark"] {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-sidebar: #0a0a15;
    --bg-sidebar-hover: #151528;
    --text: #e0e0e0;
    --text-muted: #888;
    --text-sidebar: #ccc;
    --accent: #5c8ad4;
    --accent-light: #1a2a4a;
    --border: #2a2a3e;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --defined-term-bg: #2a2a1a;
    --defined-term-border: #555;
    --badge-bg: #1a2a4a;
    --badge-text: #5c8ad4;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    font-size: 16px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ──────────────── Progress Bar ──────────────── */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--progress-color);
    z-index: 1000;
    transition: width 0.1s;
    border-radius: 0 2px 2px 0;
}

/* ──────────────── Layout ──────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: white !important;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px 40px;
    max-width: 900px;
}

/* ──────────────── Search ──────────────── */
.search-box {
    padding: 12px 16px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 14px;
}

.search-box input::placeholder { color: rgba(255,255,255,0.5); }
.search-box input:focus { outline: none; border-color: var(--accent); }

.search-results {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 100%;
    background: var(--bg-card);
    color: var(--text);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 400px;
    overflow-y: auto;
    z-index: 200;
}

.search-results.hidden { display: none; }

.search-result-item {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
}

.search-result-item:hover { background: var(--accent-light); }
.search-result-item .result-source { font-size: 12px; color: var(--text-muted); }

/* ──────────────── Navigation ──────────────── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: block;
    padding: 8px 20px;
    color: var(--text-sidebar);
    font-size: 14px;
    transition: background 0.2s;
}

.sidebar-nav li a:hover {
    background: var(--bg-sidebar-hover);
    text-decoration: none;
}

.sidebar-nav li.active > a {
    background: rgba(45,90,166,0.3);
    color: white;
    font-weight: 600;
}

.nav-sub { padding-left: 16px !important; }
.nav-count { font-size: 11px; color: var(--text-muted); margin-left: 4px; }

.sidebar-nav hr {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 8px 20px;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.theme-toggle {
    width: 100%;
    padding: 8px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    font-size: 14px;
}

.theme-toggle:hover { background: rgba(255,255,255,0.2); }

/* ──────────────── Breadcrumb ──────────────── */
.breadcrumb {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.breadcrumb a { color: var(--accent); }
.breadcrumb span { margin: 0 6px; }

/* ──────────────── Main content ──────────────── */
.main-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
    border-bottom: 3px solid var(--accent);
    padding-bottom: 12px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 16px;
}

/* ──────────────── Article blocks ──────────────── */
.article-block {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent);
}

.article-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.article-anchor {
    font-size: 16px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
}

.article-block:hover .article-anchor { opacity: 1; }

.article-content {
    font-size: 15px;
    line-height: 1.8;
}

.article-content p { margin-bottom: 12px; }

.article-content ul {
    margin: 8px 0 12px 24px;
}

.article-content li {
    margin-bottom: 4px;
}

.section-anchor {
    scroll-margin-top: 20px;
}

.section-heading {
    font-size: 22px;
    font-weight: 700;
    margin: 32px 0 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
    color: var(--text);
}

.section-heading:first-child {
    margin-top: 0;
}

.article-meta {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.source-badge {
    background: var(--badge-bg);
    color: var(--badge-text);
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 12px;
}

.bookmarks-btn {
    cursor: pointer;
    color: var(--accent);
    transition: color 0.2s;
}

.bookmarks-btn:hover { color: #ffc107; }
.bookmarks-btn.bookmarked { color: #ffc107; }

/* ──────────────── Defined terms (tooltips) ──────────────── */
.defined-term {
    background: var(--defined-term-bg);
    border-bottom: 2px dotted var(--defined-term-border);
    cursor: help;
    padding: 1px 4px;
    border-radius: 3px;
}

/* ──────────────── Child sections ──────────────── */
.child-sections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.child-section-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.child-section-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.child-section-card h4 { font-size: 15px; margin-bottom: 6px; }
.child-section-card .badge {
    background: var(--badge-bg);
    color: var(--badge-text);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.nav-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-card a { font-weight: 600; }
.nav-card-label { color: var(--text-muted); font-size: 13px; }

.siblings-block { margin-bottom: 20px; }
.siblings-block h3 { font-size: 14px; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.siblings-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sibling-link {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 14px;
    transition: background 0.2s, border-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.sibling-link:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    text-decoration: none;
}

.article-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 24px 0 12px;
}
.article-nav .nav-prev,
.article-nav .nav-next {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    font-size: 14px;
    max-width: 45%;
    transition: background 0.2s;
}
.article-nav .nav-prev:hover,
.article-nav .nav-next:hover {
    background: var(--accent-light);
    text-decoration: none;
}
.article-nav .nav-next { margin-left: auto; text-align: right; }

.article-full { border-left: 4px solid var(--accent); }
.article-permalink { color: var(--accent); opacity: 0.5; transition: opacity 0.2s; }
.article-permalink:hover { opacity: 1; }

.doc-tree { margin-top: 16px; }
.tree-item { margin: 4px 0; }
.tree-depth-0 > a { font-weight: 700; font-size: 15px; }
.tree-depth-1 > a { font-weight: 600; padding-left: 16px; }
.tree-depth-2 > a { padding-left: 32px; }
.tree-depth-3 > a { padding-left: 48px; font-size: 14px; }
.tree-depth-4 > a { padding-left: 64px; font-size: 14px; }
.tree-item > a { display: inline-block; padding: 3px 0; }
.tree-item .badge { font-size: 11px; vertical-align: middle; margin-left: 4px; }
.tree-children { border-left: 2px solid var(--border); margin-left: 8px; }
.tree-article {
    display: inline-block;
    padding: 2px 8px;
    margin: 2px 4px;
    font-size: 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.tree-article:hover {
    background: var(--accent-light);
    text-decoration: none;
}
.tree-articles { margin: 4px 0 4px 16px; display: flex; flex-wrap: wrap; gap: 2px; }

/* ──────────────── Index page ──────────────── */
.doc-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.doc-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--accent);
    transition: transform 0.2s;
}

.doc-card:hover { transform: translateY(-3px); }
.doc-card h2 { font-size: 18px; margin-bottom: 8px; }
.doc-card p { color: var(--text-muted); font-size: 14px; margin-bottom: 12px; }
.doc-card .doc-stats { display: flex; gap: 16px; font-size: 13px; color: var(--text-muted); }
.doc-card .doc-stats strong { color: var(--accent); }

.features-bar {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.feature-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
    font-size: 14px;
}

.feature-card:hover { transform: translateY(-2px); }
.feature-icon { font-size: 24px; display: block; margin-bottom: 8px; }

.stats-bar {
    display: flex;
    gap: 24px;
    justify-content: center;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat { font-size: 15px; color: var(--text-muted); }
.stat strong { color: var(--accent); font-size: 20px; display: block; }

/* ──────────────── Definitions page ──────────────── */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: all 0.2s;
}

.filter-btn:hover { border-color: var(--accent); }
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.definition-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent);
}

.definition-item h3 {
    font-size: 17px;
    margin-bottom: 8px;
    color: var(--accent);
}

.definition-item .def-text {
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 10px;
}

.definition-item .def-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

/* ──────────────── Bookmarks page ──────────────── */
.bookmarks-list .bookmark-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bookmark-item .bm-info h3 { font-size: 16px; }
.bookmark-item .bm-info p { font-size: 13px; color: var(--text-muted); }
.bookmark-item .bm-actions button {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 16px;
}

/* ──────────────── Responsive ──────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .main-content { margin-left: 0; padding: 20px; }
}

/* ──────────────── Tippy customization ──────────────── */
.tippy-box {
    font-size: 14px;
    max-width: 400px;
    line-height: 1.6;
}

.tippy-content {
    padding: 12px 16px;
}

/* ──────────────── Print styles ──────────────── */
@media print {
    .sidebar, .progress-bar, .bookmarks-btn, .breadcrumb { display: none; }
    .main-content { margin-left: 0; }
    .article-block { box-shadow: none; break-inside: avoid; }
}
