:root {
    --bg:        #1a1a1a;
    --bg2:       #1e1e1e;
    --card:      #252525;
    --card-hover:#2a2a2a;
    --border:    #2e2e2e;
    --border2:   #383838;
    --text:      #d4d4d4;
    --text-dim:  #777;
    --text-faint:#444;
    --accent:    #4e8fce;

    --sb-bg:     #161616;
    --sb-border: #2a2a2a;
    --sb-text:   #999;
    --sb-hover:  #222;
}

/* ============================================================================
   Reset
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    display: flex;
    overflow: hidden;
}

/* ============================================================================
   Sidebar
   ========================================================================== */
#sidebar {
    width: 240px;
    min-width: 200px;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s, min-width 0.2s, opacity 0.15s;
    flex-shrink: 0;
}

#sidebar.hidden { width: 0; min-width: 0; opacity: 0; pointer-events: none; }

/* Drag-to-resize handle */
#sidebar-resize {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
    z-index: 10;
}

#sidebar-resize:hover,
#sidebar-resize.dragging { background: var(--accent); }

#sidebar-header {
    padding: 10px 8px 10px 12px;
    border-bottom: 1px solid var(--sb-border);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

#sidebar-header-btns {
    display: flex;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

#sidebar-header-btns button {
    font-size: 0.79rem;
    padding: 2px 5px;
    border-color: transparent;
    color: var(--text-faint);
}

#sidebar-header-btns button:hover { color: var(--text-dim); background: var(--sb-hover); }

#sidebar-title {
    font-weight: 700;
    font-size: 0.86rem;
    color: var(--text);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

#sidebar-count {
    font-size: 0.79rem;
    color: var(--text-dim);
    white-space: nowrap;
}

#sidebar-content {
    overflow-y: auto;
    flex: 1;
    padding: 8px 0;
}

#sidebar-content::-webkit-scrollbar       { width: 4px; }
#sidebar-content::-webkit-scrollbar-track { background: transparent; }
#sidebar-content::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Sidebar footer (timestamp) ─────────────────────────────────────────── */
#sidebar-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--sb-border);
    font-size: 0.71rem;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

/* ── TOC groups ─────────────────────────────────────────────────────────── */
.toc-group { margin-bottom: 4px; }

.toc-pkg {
    padding: 5px 12px;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-dim);
    font-family: monospace;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    gap: 6px;
}

.toc-pkg-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.toc-pkg:hover { color: var(--text); }

.toc-arrow {
    font-size: 0.71rem;
    opacity: 0.5;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.toc-list {
    list-style: none;
    padding: 0 0 4px 0;
    overflow: hidden;
    max-height: 2000px;
    opacity: 1;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.2s ease;
}

.toc-list.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
    pointer-events: none;
}

.toc-link {
    display: block;
    padding: 3px 12px 3px 20px;
    font-size: 0.86rem;
    font-family: monospace;
    color: var(--sb-text);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 2px solid transparent;
    transition: background 0.1s, color 0.1s;
}

.toc-link:hover        { background: var(--sb-hover); color: var(--text); }
.toc-link.active       { color: var(--text); background: var(--sb-hover); font-weight: 600; }
.toc-link.toc-struct   { border-color: var(--badge-struct-fg); }
.toc-link.toc-enum     { border-color: var(--badge-enum-fg); }
.toc-link.toc-proc     { border-color: var(--badge-proc-fg); }
.toc-link.toc-union    { border-color: var(--badge-union-fg); }

/* Type icon in sidebar links */
.toc-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    font-size: 0.71rem;
    font-weight: 700;
    border-radius: 2px;
    flex-shrink: 0;
    margin-right: 5px;
    letter-spacing: 0;
}

.toc-icon-struct { background: var(--badge-struct); color: var(--badge-struct-fg); }
.toc-icon-enum   { background: var(--badge-enum);   color: var(--badge-enum-fg); }
.toc-icon-proc   { background: var(--badge-proc);   color: var(--badge-proc-fg); }
.toc-icon-union  { background: var(--badge-union);  color: var(--badge-union-fg); }

.toc-link-name { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }

/* Symbol count badge next to each file group */
.toc-pkg-count {
    font-size: 0.71rem;
    color: var(--text-faint);
    font-weight: 400;
    flex-shrink: 0;
    letter-spacing: 0;
    font-family: monospace;
}

/* Search highlight inside sidebar names */
.search-hl {
    background: rgba(78, 143, 206, 0.30);
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    color: var(--text);
    border-radius: 2px;
    padding: 0 1px;
}

/* ============================================================================
   Main panel
   ========================================================================== */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

header {
    padding: 14px 20px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--bg2);
}

#header-left  { display: flex; align-items: center; gap: 12px; }
#title-row { display: flex; align-items: center; gap: 8px; }

h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
    line-height: 1.2;
}

#title-sub {
    font-weight: 400;
    color: var(--text-dim);
    font-size: 0.86rem;
    letter-spacing: 0;
}

#github-link {
    display: flex;
    align-items: center;
    color: var(--text-dim);
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}

#github-link:hover { opacity: 1; color: var(--text); }
#github-link svg   { width: 16px; height: 16px; display: block; }

.tagline { color: var(--text-dim); font-size: 0.79rem; margin-top: 2px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
button {
    background: none;
    border: 1px solid var(--border2);
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 3px;
    padding: 4px 7px;
    font-size: 0.86rem;
    font-family: inherit;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

button:hover     { background: var(--card-hover); color: var(--text); }
button:disabled  { opacity: 0.3; cursor: default; }
.icon-btn        { font-size: 0.93rem; padding: 3px 8px; border-color: transparent; }

/* ── Toolbar ────────────────────────────────────────────────────────────── */
#toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg2);
    flex-wrap: wrap;
}

#search {
    flex: 1;
    min-width: 140px;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 3px;
    padding: 5px 10px;
    color: var(--text);
    outline: none;
    font-family: monospace;
    font-size: 13px;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.15s;
}

#search:focus        { border-color: var(--accent); }
#search::placeholder { color: var(--text-faint); }

#filter-btns   { display: flex; gap: 4px; }
#toolbar-right { display: flex; gap: 4px; margin-left: auto; }

.filter-btn {
    font-size: 0.79rem;
    padding: 3px 9px;
    border-color: var(--border2);
}

.filter-count {
    font-size: 0.71rem;
    opacity: 0.65;
    margin-left: 2px;
}

.filter-btn.active {
    background: var(--btn-color, var(--accent));
    border-color: var(--btn-color, var(--accent));
    color: #fff;
}

.filter-btn.active .filter-count { opacity: 0.8; }

/* ── Content area ───────────────────────────────────────────────────────── */
#api-root {
    overflow-y: auto;
    flex: 1;
    padding: 0 20px 40px;
}

#api-root::-webkit-scrollbar       { width: 6px; }
#api-root::-webkit-scrollbar-track { background: transparent; }
#api-root::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── File sections ──────────────────────────────────────────────────────── */
.file-section             { margin-top: 24px; }
.file-section:first-child { margin-top: 16px; }

.file-header {
    font-family: monospace;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--text-dim);
    background: var(--bg2);
    padding: 5px 10px;
    border: 1px solid var(--border);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
}

.file-sym-count {
    margin-left: auto;
    font-size: 0.71rem;
    font-weight: 400;
    color: var(--text-faint);
    font-family: monospace;
    letter-spacing: 0;
}

/* ── Details / summary ──────────────────────────────────────────────────── */
details {
    border: 1px solid var(--border);
    border-top: none;
    background: var(--card);
    transition: background 0.1s;
}

details .content {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.2s ease;
    overflow: hidden;
}

details.is-open .content {
    grid-template-rows: 1fr;
}

details .content > * {
    min-height: 0;
}

summary {
    padding: 7px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    font-family: monospace;
    font-size: 0.93rem;
    user-select: none;
    transition: background 0.1s;
}

summary::-webkit-details-marker { display: none; }
summary:hover { background: var(--card-hover); }

.item-name { font-weight: 600; color: var(--text); }

.attr {
    font-size: 0.79rem;
    color: var(--m-orange);
    font-family: monospace;
    opacity: 0.85;
}

.badge {
    margin-left: auto;
    font-size: 0.71rem;
    font-family: monospace;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: 0.04em;
}

.badge-struct { background: var(--badge-struct); color: var(--badge-struct-fg); }
.badge-enum   { background: var(--badge-enum);   color: var(--badge-enum-fg); }
.badge-proc   { background: var(--badge-proc);   color: var(--badge-proc-fg); }
.badge-union  { background: var(--badge-union);  color: var(--badge-union-fg); }

/* ── Doc comment description ─────────────────────────────────────────────── */
.doc-text {
    padding: 7px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-size: 0.86rem;
    color: var(--text-dim);
    line-height: 1.6;
    font-style: italic;
}

/* ── Signature bar ──────────────────────────────────────────────────────── */
.sig-bar {
    padding: 5px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-family: monospace;
    font-size: 0.86rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    overflow-x: auto;
}

.sig-label {
    font-size: 0.71rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sig-val         { color: var(--text); }
.sig-ret         { color: var(--m-teal); }
.sig-param-name  { color: var(--text-dim); }
.sig-param-type  { color: var(--m-blue); font-style: italic; }
.sig-colon       { color: var(--text-faint); }
.sig-comma       { color: var(--text-faint); }

/* ── "Used by" back-link bar ─────────────────────────────────────────────── */
.refs-bar {
    padding: 5px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-family: monospace;
    font-size: 0.79rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.refs-label {
    font-size: 0.71rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 4px;
    flex-shrink: 0;
}

.ref-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.79rem;
    font-family: monospace;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(78, 143, 206, 0.12);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    transition: background 0.1s;
}

.ref-link:hover {
    background: rgba(78, 143, 206, 0.25);
    background: color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ── Code block ─────────────────────────────────────────────────────────── */
.content { border-top: 1px solid var(--border); }

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px 4px 14px;
    background: var(--m-bg);
    border-bottom: 1px solid transparent;
    opacity: 0.85;
}

.code-file {
    font-family: monospace;
    font-size: 0.79rem;
    color: var(--m-gray);
}

.copy-btn {
    font-size: 0.79rem;
    border-color: transparent;
    padding: 2px 6px;
    color: var(--m-gray);
    background: transparent;
}

.copy-btn:hover  { color: var(--m-fg); background: #ffffff15; border-color: transparent; }
.copy-btn.copied { color: var(--m-green) !important; }

.content pre {
    margin: 0;
    padding: 14px 16px;
    background: var(--m-bg);
    white-space: pre;
    overflow-x: auto;
    tab-size: 4;
}

.content code {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.65;
    color: var(--m-fg);
    background: none;
    white-space: pre;
}

/* ── Cross-reference links ───────────────────────────────────────────────── */
.sym-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
    opacity: 0.75;
    cursor: pointer;
    transition: opacity 0.1s;
}

.sym-link:hover { opacity: 1; border-bottom-style: solid; }

/* ── Flash animation ─────────────────────────────────────────────────────── */
@keyframes sym-flash {
    0%   { outline: 2px solid var(--accent); outline-offset: -1px; }
    100% { outline: 2px solid transparent;   outline-offset: -1px; }
}

details.flash { animation: sym-flash 0.8s ease-out forwards; }

/* ── No results empty state ─────────────────────────────────────────────── */
#no-results {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 10;
}

#no-results[aria-hidden="true"]  { opacity: 0; }
#no-results[aria-hidden="false"] { opacity: 1; }

#no-results-icon {
    font-size: 2.5rem;
    color: var(--text-faint);
    margin-bottom: 8px;
}

#no-results-text {
    font-size: 0.93rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 4px;
}

#no-results-sub {
    font-size: 0.79rem;
    color: var(--text-faint);
}

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 700px) {
    #sidebar      { display: none; }
    body          { overflow: auto; }
    #main         { overflow: visible; }
    #api-root     { overflow: visible; padding: 0 10px 40px; }
    header        { padding: 10px; }
    #toolbar      { padding: 6px 10px; }
    .badge        { display: none; }
    .filter-count { display: none; }
}
