/* =========================================================
   BookStack Style — a Publii theme mimicking a BookStack wiki
   ========================================================= */

:root {
    --color-primary: #206ea7;
    --color-primary-dark: #175683;
    --color-primary-light: #eaf2f8;
    --color-bg: #f2f4f7;
    --color-surface: #ffffff;
    --color-border: #e0e4e9;
    --color-text: #333c43;
    --color-text-muted: #6b7684;
    --color-code-bg: #f5f6f8;
    --sidebar-width: 270px;
    --topbar-height: 60px;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-hover: 0 4px 14px rgba(0,0,0,0.12);
}

html[data-theme="dark"] {
    --color-primary: #3b8fd4;
    --color-primary-dark: #2f74ab;
    --color-primary-light: #16324a;
    --color-bg: #1b1f24;
    --color-surface: #23282f;
    --color-border: #333a42;
    --color-text: #dde2e8;
    --color-text-muted: #97a1ab;
    --color-code-bg: #1a1e23;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-hover: 0 4px 14px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    transition: background .15s ease, color .15s ease;
}

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

img { max-width: 100%; height: auto; border-radius: var(--radius); }

/* ---------------- Top bar ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--topbar-height);
    background: var(--color-primary);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    box-shadow: var(--shadow);
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.topbar__brand img { width: 30px; height: 30px; border-radius: 4px; }
.topbar__brand:hover { text-decoration: none; opacity: .9; }

.topbar__menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
}

.topbar__search {
    flex: 1;
    max-width: 420px;
    position: relative;
}

.search-results {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    max-height: 360px;
    overflow-y: auto;
    z-index: 200;
}
.search-results.is-open { display: block; }

.search-results a {
    display: block;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}
.search-results a:last-child { border-bottom: none; }
.search-results a:hover { background: var(--color-primary-light); text-decoration: none; }
.search-results .result-title { font-weight: 600; font-size: 0.9rem; display: block; }
.search-results .result-excerpt {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 2px;
}
.search-results .no-results { padding: 14px; color: var(--color-text-muted); font-size: 0.88rem; }

.topbar__search input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 20px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 0.9rem;
}

.topbar__search input::placeholder { color: rgba(255,255,255,0.75); }
.topbar__search input:focus { outline: none; background: rgba(255,255,255,0.25); }

.topbar__nav {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-left: auto;
    flex-shrink: 0;
}

.topbar__nav a { color: rgba(255,255,255,0.9); font-size: 0.92rem; }
.topbar__nav a:hover { color: #fff; }

.topbar__theme-toggle {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.topbar__theme-toggle:hover { background: rgba(255,255,255,0.28); }

/* ---------------- Layout ---------------- */

.layout {
    display: flex;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 24px 16px;
    position: sticky;
    top: var(--topbar-height);
    max-height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
}

.sidebar h3 {
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    margin: 20px 0 8px;
    padding: 0 8px;
}
.sidebar h3:first-child { margin-top: 0; }

.book-list__book {
    font-weight: 600;
}

.book-list-items {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-hint {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    background: var(--color-primary-light);
    padding: 12px 14px;
    border-radius: var(--radius);
    line-height: 1.5;
}

.back-to-book { margin: 0 0 20px; }
.back-to-book a { font-size: 0.88rem; font-weight: 500; }

.book-list .page-list {
    margin: 2px 0 8px 12px;
    padding-left: 8px;
    border-left: 1px solid var(--color-border);
}
.book-list .page-list li a {
    font-size: 0.86rem;
    font-weight: 400;
    color: var(--color-text-muted);
    padding: 4px 8px;
}
.book-list .page-list li a:hover { color: var(--color-primary); }

.book-notes {
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
}
.book-notes h3 {
    margin: 0 0 14px;
    font-size: 0.95rem;
}

.book-list li a, .page-list li a {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: 0.92rem;
}
.book-list li a:hover, .page-list li a:hover {
    background: var(--color-primary-light);
    text-decoration: none;
    color: var(--color-primary);
}
.book-list li a.is-active {
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
}

.book-list .count {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    flex-shrink: 0;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 24px 28px 60px;
}

/* ---------------- Breadcrumb ---------------- */

.breadcrumb {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}
.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb a:hover { color: var(--color-primary); }

/* ---------------- Card grid (homepage / tag listings) ---------------- */

.page-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 8px;
}

.page-title-row h1 {
    margin: 0;
    font-size: 1.6rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    transition: box-shadow .15s ease, transform .15s ease;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }

.card__title { margin: 0; font-size: 1.05rem; }
.card__title a { color: var(--color-text); }
.card__title a:hover { color: var(--color-primary); text-decoration: none; }

.card__excerpt {
    color: var(--color-text-muted);
    font-size: 0.88rem;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card__meta {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    display: flex;
    gap: 10px;
    margin-top: auto;
    padding-top: 6px;
}

.tag-chip {
    display: inline-block;
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* ---------------- Single content page ---------------- */

.content-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 40px;
}

.content-card h1.entry-title {
    margin-top: 0;
    font-size: 1.9rem;
}

.entry-meta {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin: 4px 0 24px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 16px;
}

.entry-content { font-size: 1rem; }
.entry-content h2 { margin-top: 2em; font-size: 1.4rem; }
.entry-content h3 { margin-top: 1.6em; font-size: 1.15rem; }
.entry-content p { margin: 1em 0; }

.entry-content code {
    background: var(--color-code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
}
.entry-content pre {
    background: var(--color-code-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    overflow-x: auto;
}
.entry-content pre code { background: none; padding: 0; }

.entry-content blockquote {
    border-left: 3px solid var(--color-primary);
    margin: 1.2em 0;
    padding: 2px 18px;
    color: var(--color-text-muted);
    background: var(--color-primary-light);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.entry-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1.2em 0;
    font-size: 0.92rem;
}
.entry-content th, .entry-content td {
    border: 1px solid var(--color-border);
    padding: 8px 10px;
    text-align: left;
}
.entry-content th { background: var(--color-code-bg); }

.entry-tags {
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------------- Footer ---------------- */

.site-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--color-border);
    margin-top: 20px;
}
.site-footer a { color: var(--color-text-muted); }

/* ---------------- Pagination ---------------- */

.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 30px;
    list-style: none;
    padding: 0;
}
.pagination a, .pagination span {
    display: inline-block;
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 0.88rem;
}
.pagination a:hover { background: var(--color-primary-light); text-decoration: none; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------------- Empty state ---------------- */

.empty-state {
    color: var(--color-text-muted);
    text-align: center;
    padding: 60px 20px;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 900px) {
    .topbar__menu-toggle { display: block; }
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--topbar-height);
        height: calc(100vh - var(--topbar-height));
        background: var(--color-surface);
        width: 260px;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-hover);
        z-index: 90;
    }
    .sidebar.is-open { transform: translateX(0); }
    .main { padding: 18px 16px 50px; }
    .content-card { padding: 22px 20px; }
    .topbar__search { display: none; }
}
