/* sidebar.css - the left panel (#left-panel, .sb-*): tab bar, page thumbnail strip,
   outline tree, search box and results, comments list and the resize edge; plus the
   search highlights drawn on pages (.search-layer .search-hit). */

/* Defaults only (zero specificity): the shell owns the panel's placement and drawer mode. */
:where(#left-panel) {
    width: var(--left-w);
    flex: none;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#left-panel[hidden],
#left-panel [hidden] { display: none !important; }

.sb-root {
    --sb-swipe: var(--swipe);
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: var(--surface);
    box-shadow: inset -1px 0 0 var(--line);
    font-size: var(--fs-m);
    color: var(--text);
}
/* the marker swipe, softened in dark mode so light text and icons stay readable on it */
:root[data-theme="dark"] .sb-root {
    --sb-swipe: linear-gradient(transparent 58%, color-mix(in srgb, var(--marker) 64%, transparent) 58%,
                color-mix(in srgb, var(--marker) 64%, transparent) 90%, transparent 90%);
}

/* ------------------------------------------------------------------ tab bar */

.sb-top {
    flex: none;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 8px 8px 8px 10px;
    border-bottom: 1px solid var(--line);
}
.sb-tabs {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 2px;
}
.sb-tab { color: var(--text-2); }
.sb-tab.active {
    color: var(--text);
    background: var(--sb-swipe) center / 78% 100% no-repeat;
}
.sb-close {
    margin-left: auto;
    color: var(--text-3);
}

/* ------------------------------------------------------------------ panes */

.sb-body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sb-pane {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.sb-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
    padding: 8px 14px 6px;
    background: var(--surface);
    font-size: var(--fs-s);
    font-weight: 600;
    color: var(--text-2);
}
.sb-count {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-3);
}
.sb-mono { font-family: var(--font-mono); }

.sb-link {
    padding: 2px 4px;
    border: 0;
    border-radius: var(--radius-xs);
    background: none;
    font: inherit;
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
}
.sb-link:hover { text-decoration: underline; text-decoration-color: var(--accent-line); text-decoration-thickness: 2px; }
.sb-link:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 1px;
}

/* ------------------------------------------------------------------ Pages tab: thumbnail strip */

.sb-thumbs-wrap {
    position: relative;
    padding: 2px 0 24px;
}
.sb-thumbs {
    display: flex;
    flex-direction: column;
    align-items: center;
    row-gap: 8px;
    padding: 0 10px;
}

.sb-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 6px 6px;
    border-radius: var(--radius);
    outline: none;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: pan-y;
    transition: background-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
@media (hover: hover) {
    .sb-thumb:hover { background: var(--surface-2); }
}
/* Keyboard focus only (sidebar.js sets data-input="pointer" after a press; clicking a
   thumbnail moves focus to it, which Chrome would otherwise draw as a keyboard ring). */
.sb-root:not([data-input="pointer"]) .sb-thumb:focus-visible { box-shadow: inset 0 0 0 2px var(--ink); }
.sb-thumb.dragging { opacity: 0.32; }

.sb-paper {
    position: relative;
    flex: none;
    max-width: 100%;
    height: auto !important;        /* width + aspect-ratio are set by sidebar.js */
    overflow: hidden;
    background: var(--paper);
    border-radius: 2px;
    box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.sb-paper > canvas,
.sb-paper > svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
/* the current page: an orange frame and an orange number chip */
.sb-thumb.current .sb-paper {
    outline: 2px solid var(--accent-line);
    outline-offset: 2px;
}
.sb-thumb.sb-lifted .sb-paper {
    transform: scale(1.04);
    box-shadow: var(--shadow-pop);
}

.sb-num {
    padding: 0 5px;
    border-radius: 2px;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    line-height: 18px;
    color: var(--text-2);
}
.sb-thumb.current .sb-num {
    color: var(--on-accent);
    font-weight: 600;
    background: var(--accent);
    border-radius: var(--radius-xs);
}
.sb-thumb.current.edited .sb-num::after { background: var(--on-accent); }
/* a small ink dot: the page has edits made in Bullet PDF */
.sb-thumb.edited .sb-num::after {
    content: "";
    display: inline-block;
    width: 5px;
    height: 5px;
    margin-left: 5px;
    border-radius: 50%;
    background: var(--ink);
    vertical-align: 2px;
}

.sb-spin {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    border: 2px solid var(--line);
    border-top-color: var(--accent-line);
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
    animation: sb-spin 0.8s linear infinite;
    pointer-events: none;
}
.sb-paper.sb-loading .sb-spin {
    opacity: 1;
    transition-delay: 150ms;
}
@keyframes sb-spin { to { transform: rotate(360deg); } }

.sb-insert {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 0;
    z-index: 1;
    height: 3px;
    border-radius: 2px;
    background: var(--accent-line);
    pointer-events: none;
}
.sb-insert::before,
.sb-insert::after {
    content: "";
    position: absolute;
    top: -3px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent-line);
}
.sb-insert::before { left: -5px; }
.sb-insert::after { right: -5px; }

.sb-dragging,
.sb-dragging * { cursor: grabbing !important; }

/* ------------------------------------------------------------------ Outline tab */

.sb-tree { padding: 0 6px 24px; }

.sb-ol-item { outline: none; }
.sb-ol-row {
    display: flex;
    align-items: flex-start;
    gap: 2px;
    padding: 5px 8px 5px calc(4px + var(--lvl, 0) * 14px);
    border-radius: var(--radius-s);
    font-size: var(--fs-s);
    line-height: 18px;
    color: var(--text);
    cursor: pointer;
}
@media (hover: hover) {
    .sb-ol-row:hover { background: var(--surface-3); }
}
.sb-ol-item:focus-visible > .sb-ol-row { box-shadow: inset 0 0 0 2px var(--ink); }

.sb-ol-twisty {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-xs);
    color: var(--text-3);
    transition: transform var(--dur-fast) var(--ease);
}
.sb-ol-twisty:not(:empty):hover {
    background: var(--surface-2);
    color: var(--text);
}
.sb-ol-item[aria-expanded="true"] > .sb-ol-row > .sb-ol-twisty { transform: rotate(90deg); }

.sb-ol-title {
    flex: 1;
    min-width: 0;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}
.sb-ol-title.bold { font-weight: 600; }
.sb-ol-title.italic { font-style: italic; }
.sb-ol-ext {
    margin-left: 4px;
    vertical-align: -1px;
    color: var(--text-3);
}
.sb-ol-item.disabled > .sb-ol-row {
    color: var(--text-3);
    cursor: default;
}

/* ------------------------------------------------------------------ Search tab */

.sb-sbox {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.sb-sfield {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 1px 0 10px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.sb-sfield:focus-within {
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--ink-soft);
}
.sb-sicon {
    flex: none;
    color: var(--text-3);
}
.sb-sinput {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    font-size: var(--fs-m);
    color: var(--text);
}
.sb-sinput::placeholder { color: var(--text-3); }
.sb-sinput::-webkit-search-cancel-button,
.sb-sinput::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}
.sb-sclear { flex: none; }

.sb-sopts {
    display: flex;
    align-items: center;
    gap: 2px;
}
.sb-sfill { flex: 1; }
.sb-toggle.on {
    background: var(--ink-soft);
    color: var(--ink);
}
.sb-spos {
    padding: 0 6px;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text-2);
}
.sb-sstatus {
    min-height: 18px;
    font-size: var(--fs-s);
    font-variant-numeric: tabular-nums;
    line-height: 18px;
    color: var(--text-2);
}
.sb-sstatus.empty { display: none; }

.sb-results { padding-bottom: 24px; }
.sb-rgroup-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 4px;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-3);
}
.sb-rcount {
    font-family: var(--font-mono);
    font-weight: 500;
}

.sb-result {
    display: block;
    width: 100%;
    margin: 0;
    padding: 6px 14px 6px 12px;
    border: 0;
    border-left: 2px solid transparent;
    background: none;
    text-align: left;
    font: inherit;
    font-size: var(--fs-s);
    line-height: 1.45;
    color: var(--text-2);
    overflow-wrap: anywhere;
    cursor: pointer;
}
@media (hover: hover) {
    .sb-result:hover {
        background: var(--surface-2);
        color: var(--text);
    }
}
.sb-result:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: -2px;
}
.sb-result.current {
    border-left-color: var(--ink);
    background: var(--ink-soft);
    color: var(--text);
}
.sb-result mark {
    padding: 0 1px;
    border-radius: 1px;
    background: var(--sb-swipe);
    color: var(--text);
    font-weight: 600;
}
.sb-rtag {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    border-radius: var(--pill);
    background: var(--surface-3);
    color: var(--text-3);
    font-size: var(--fs-xs);
    line-height: 16px;
    vertical-align: 1px;
}
.sb-more {
    padding: 12px 14px;
    font-size: var(--fs-xs);
    color: var(--text-3);
}

/* ------------------------------------------------------------------ Comments tab */

.sb-comments { padding-bottom: 24px; }

.sb-comment {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 10px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: none;
    text-align: left;
    font: inherit;
    color: var(--text);
    cursor: pointer;
}
@media (hover: hover) {
    .sb-comment:hover { background: var(--surface-2); }
}
.sb-comment:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: -2px;
}
.sb-comment.selected { background: var(--ink-soft); }

.sb-chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-s);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 14%, transparent);
}
.sb-chip.light { color: var(--marker-text); }
.sb-chip.dark { color: var(--paper); }

.sb-cbody {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.sb-ctext {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    overflow-wrap: anywhere;
    white-space: pre-line;
    font-size: var(--fs-s);
    line-height: 1.45;
    color: var(--text);
}
.sb-ctext.muted {
    color: var(--text-3);
    font-style: italic;
}
.sb-cmeta {
    font-size: var(--fs-xs);
    color: var(--text-3);
}

.sb-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 24px;
    text-align: center;
    font-size: var(--fs-s);
    line-height: 1.5;
    color: var(--text-3);
}
.sb-empty p {
    max-width: 220px;
    margin: 0;
}

/* ------------------------------------------------------------------ resize edge */

.sb-resize {
    position: absolute;
    top: 0;
    right: -4px;
    bottom: 0;
    z-index: 5;
    width: 8px;
    outline: none;
    cursor: col-resize;
    touch-action: none;
}
.sb-resize::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 3px;
    width: 2px;
    background: transparent;
    transition: background-color var(--dur-fast) var(--ease);
}
.sb-resize:hover::after,
.sb-resizing .sb-resize::after { background: var(--ink-line); }
.sb-resize:focus-visible::after { background: var(--ink); }
.sb-resizing {
    -webkit-user-select: none;
    user-select: none;
}
.sb-resizing * { cursor: col-resize !important; }

@media (pointer: coarse) {
    .sb-resize {
        right: -8px;
        width: 16px;
    }
    .sb-resize::after { left: 7px; }
}

/* ------------------------------------------------------------------ search hits on pages */

/* Inside .page-space (1 CSS px = 1 pt); outlines divide by --s to stay 1.5 screen px. */
.search-layer { pointer-events: none; }
.search-hit {
    position: absolute;
    border-radius: calc(1.5px / var(--s, 1));
    background: color-mix(in srgb, var(--marker) 40%, transparent);
    pointer-events: none;
}
.search-hit.current {
    background: color-mix(in srgb, var(--marker) 62%, transparent);
    box-shadow: 0 0 0 calc(1.5px / var(--s, 1)) var(--amber);
}

@media (prefers-reduced-motion: reduce) {
    .sb-spin { animation: none; }
    .sb-thumb.sb-lifted .sb-paper { transform: none; }
}
