/**
 * NatEdit — Stylesheet
 * 
 * Scalable, maintainable, and collaborative styling for the math document editor.
 * Includes dark/light theme tokens, responsive layouts, math layout components,
 * custom caret animations, and LaTeX code inspector panel.
 */

/* ==========================================================================
   1. Design Tokens & Themes
   ========================================================================== */

:root {
    /* Palette based on PacketMath dark theme */
    --bg: #151515;
    --panel: #111111;
    --line: #343434;
    --acc: #d97757;
    --blue: #689fe1;
    --tx: #f0efec;
    --dim: #8a8985;

    color-scheme: dark;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Light Theme: System Preference Override */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #e9e6e1;
        --panel: #dcd9d2;
        --line: #c2bdb4;
        --tx: #23211e;
        --dim: #6d6962;
        color-scheme: light;
    }
}

/* Light Theme: Explicit User Override */
:root[data-theme="light"] {
    --bg: #e9e6e1;
    --panel: #dcd9d2;
    --line: #c2bdb4;
    --tx: #23211e;
    --dim: #6d6962;
    color-scheme: light;
}

/* Explicit Dark Theme */
:root[data-theme="dark"] {
    --bg: #151515;
    --panel: #111111;
    --line: #343434;
    --acc: #d97757;
    --blue: #689fe1;
    --tx: #f0efec;
    --dim: #8a8985;
    color-scheme: dark;
}

/* ==========================================================================
   2. Base Document Layout
   ========================================================================== */

*, *::before, *::after {
    box-sizing: inherit;
}

html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--tx);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   3. Toolbar Header
   ========================================================================== */

.row[hidden] {
    display: none;
}

.row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.row b {
    color: var(--dim);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-right: 4px;
}

.row label {
    color: var(--dim);
    font-size: 13px;
    margin-left: 8px;
}

#cd {
    padding: 0;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#cd svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Split icon flip: crossfade the two filled halves smoothly */
.sp-fill,
.sp-fill-r {
    transition: opacity .25s ease;
}
.sp-fill-r {
    opacity: 0;
}
.flipped .sp-fill {
    opacity: 0;
}
.flipped .sp-fill-r {
    opacity: 1;
}

.sp {
    flex: 1;
}

.n {
    display: inline-block;
    min-width: 1.2em;
    text-align: center;
}

button,
select {
    font: inherit;
    color: var(--tx);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

button:hover:not(:disabled),
select:hover:not(:disabled) {
    border-color: var(--blue);
}

button:disabled,
select:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

button:focus-visible,
select:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

button:active:not(:disabled) {
    opacity: 0.85;
}

/* Font Awesome icons inside buttons */
button > i {
    vertical-align: -0.125em;
    color: var(--blue);
}

button > i + span,
button > i + * {
    margin-left: 5px;
}

button.pri > i {
    color: #151515;
}

button:disabled > i,
button:disabled i {
    color: var(--dim);
}

button.pri {
    background: var(--acc);
    border-color: var(--acc);
    color: #151515;
    font-weight: 600;
}

button.pri:hover:not(:disabled) {
    filter: brightness(1.08);
}

/* Document name field in toolbar */
#docname {
    font: inherit;
    font-size: 13px;
    color: var(--tx);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 8px;
    width: 10em;
    transition: border-color 0.15s ease;
}

#docname:hover {
    border-color: var(--blue);
}

#docname:focus {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

/* ==========================================================================
   Document Tabs Strip (Browser-style tabs)
   ========================================================================== */

.tab-bar {
    display: flex;
    align-items: center;
    background: #0d0d0d;
    border-bottom: 1px solid var(--line);
    padding: 6px 10px 0 10px;
    overflow-x: auto;
    overflow-y: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.tabs-container {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.tab-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: #181818;
    color: #888888;
    border: 1px solid var(--line);
    border-bottom: none;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    max-width: 160px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-item:hover {
    color: #cccccc;
    background: #202020;
}

.tab-item.active {
    background: #151515;
    color: #f0efec;
    border-color: #383838;
    border-bottom: 1px solid #151515;
    margin-bottom: -1px;
    font-weight: 500;
}

.tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-rename-input {
    background: var(--bg);
    color: var(--tx);
    border: 1px solid var(--blue);
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    max-width: 130px;
}

.tab-close {
    border: none;
    background: transparent;
    color: inherit;
    padding: 0;
    margin: 0;
    font-size: 13px;
    line-height: 1;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    cursor: pointer;
}

.tab-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.tab-add-btn {
    margin-left: 6px;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--blue);
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tab-add-btn:hover {
    background: #202020;
    border-color: var(--line);
}

/* ==========================================================================
   Unified Pill Groups (Undo/Redo, Steppers, Augmented Group)
   ========================================================================== */

.pill-group {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}

.pill-group button {
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 5px 10px;
    height: 100%;
}

.pill-group button:not(:last-child) {
    border-right: 1px solid var(--line);
}

.pill-group button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
}

/* Stepper capsules for Rows and Cols */
.pill-stepper {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 4px;
    gap: 6px;
}

.stepper-label {
    font-size: 12px;
    color: var(--dim);
    padding-left: 4px;
}

.stepper-btn {
    border: none;
    background: transparent;
    padding: 2px 6px;
    font-size: 13px;
    line-height: 1;
    border-radius: 4px;
    color: var(--tx);
}

.stepper-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.pill-stepper .n {
    min-width: 1.2em;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

/* Props bar titles and layout */
.props-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .05em;
    color: var(--tx);
    margin-right: 6px;
}

.blue-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--blue);
    display: inline-block;
}

.bracket-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 4px;
}

.bracket-wrap label {
    font-size: 12px;
    color: var(--dim);
    margin-left: 0;
}

/* Augmented Matrix Pill Group */
.aug-pill-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 3px 8px;
    margin-left: 6px;
}

.aug-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tx);
    letter-spacing: 0.05em;
}

.aug-lines-btn {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--tx);
}

.aug-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 4px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    min-width: 110px;
}

/* Switch Toggle (iOS / Capsule style) */
.switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    margin: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333333;
    transition: .2s;
    border-radius: 18px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .2s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--blue);
}

input:checked + .slider:before {
    transform: translateX(14px);
}

/* Delete Button (Red accent with trash icon) */
.del-btn {
    background: #2a1414 !important;
    border-color: #642525 !important;
    color: #f87171 !important;
    font-weight: 500;
}

.del-btn:hover:not(:disabled) {
    background: #3b1919 !important;
    border-color: #ef4444 !important;
    color: #fca5a5 !important;
}

.del-btn i {
    color: #f87171 !important;
    margin-right: 4px;
}



/* ==========================================================================
   3b. Symbols Drawer
   ========================================================================== */

#sym {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 6px 10px;
    user-select: none;
    -webkit-user-select: none;
}

#sym[hidden] {
    display: none;
}

#tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 6px;
}

#tabs button {
    padding: 3px 9px;
    font-size: 13px;
    white-space: nowrap;
}

#tabs button.active {
    border-color: var(--acc);
    color: var(--acc);
}

#syms {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 132px;
    overflow-y: auto;
    align-items: center;
}

/* ==========================================================================
   4. Editor Main Workspace & Document Canvas
   ========================================================================== */

#wrap {
    flex: 1;
    display: flex;
    min-height: 0;
}

#doc {
    flex: 1;
    min-width: 0;
    position: relative;
    overflow: auto;
    padding: 24px clamp(14px, 6vw, 64px);
    font-size: 18px;
    line-height: 2.3;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Editable slots inside math objects */
.cell {
    display: inline-block;
    min-width: 0.8em;
    padding: 0 2px;
    outline: none;
    cursor: text;
    white-space: pre-wrap;
    word-break: break-word;
    text-align: center;
}

.cell:empty::before {
    content: "\200b";
}

.mx .cell:empty::before {
    content: "\25a1";
    color: var(--dim);
    pointer-events: none;
}

/* ==========================================================================
   5. Math Objects (Atomic inline units)
   ========================================================================== */

.mx {
    display: inline-flex;
    vertical-align: middle;
    line-height: 1.5;
    margin: 0 0.15em;
    user-select: none;
    -webkit-user-select: none;
}

.mx .cell {
    display: inline-block;
    min-width: 0.6em;
    text-align: center;
    position: relative;
    user-select: text;
    -webkit-user-select: text;
}

/* Nested math scaling */
.mx .mx {
    font-size: 0.88em;
}

/* --- Matrices --- */
.mx:not([data-k]) {
    margin: 0.45em 0.12em;
}

.mx:not([data-k]) .cell {
    font-family: ui-monospace, Menlo, Consolas, "Courier New", monospace;
    min-width: 1.4em;
    text-align: center;
}

.grid {
    display: inline-grid;
    grid-template-columns: repeat(var(--c), auto);
    row-gap: 0.1em;
    column-gap: 0.6em;
    padding: 0.15em 0.25em;
    align-items: stretch;
}

/* Augmented matrix column border styling */
.mx:not([data-k]) .cell.aug-border-r {
    position: relative;
}

.mx:not([data-k]) .cell.aug-border-r::after {
    content: "";
    position: absolute;
    top: -0.1em;
    bottom: -0.1em;
    right: -0.3em;
    width: 1.5px;
    background-color: var(--tx);
    pointer-events: none;
}

.br {
    display: block;
    width: 0.4em;
    border: 2px solid var(--tx);
}

.br.l {
    border-right: 0;
}

.br.r {
    border-left: 0;
}

.mx[data-br="("] .br.l {
    border-radius: .7em 0 0 .7em / 50% 0 0 50%;
}

.mx[data-br="("] .br.r {
    border-radius: 0 .7em .7em 0 / 0 50% 50% 0;
}

.mx[data-br="|"] .br {
    border-top: 0;
    border-bottom: 0;
    width: 0;
    margin: 0 .15em;
}

.mx[data-br="none"] .br {
    border: 0;
}

/* --- Fractions --- */
.mx[data-k="f"] {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    margin: 0.45em 0.25em;
}

.bar {
    display: block;
    border-top: 2px solid var(--tx);
    margin: 0.05em 0;
}

.mx[data-k="f"][data-bar="none"] > .bar {
    border-top-color: transparent;
}

/* --- Scripts (Superscript / Subscript) --- */
.mx[data-k="p"] {
    display: inline-flex;
    vertical-align: baseline;
    font-size: 0.72em;
    line-height: 1;
    margin: 0 0.02em;
}

.mx[data-k="p"][data-w="sup"] {
    vertical-align: 0.58em;
}

.mx[data-k="p"][data-w="sub"] {
    vertical-align: -0.28em;
}

.mx[data-k="p"] .cell {
    font-family: inherit;
    min-width: 0.25em;
    padding: 0 1px;
    text-align: left;
}

.mx[data-k="p"] .cell:empty {
    min-width: 0.55em;
    text-align: center;
}

.mx[data-k="p"] .mx {
    font-size: 0.75em;
    line-height: 1.1;
}

/* Pull script tight against preceding matrix bracket or fraction */
.mx:not([data-k]) + .mx[data-k="p"],
.mx[data-k="f"] + .mx[data-k="p"] {
    margin-left: -0.06em;
}

/* --- Anchor Primitive (Root, Summation, Integral, Extensible Chrome) --- */
.mx[data-enclosure="radical"] {
    display: inline-flex;
    align-items: flex-end;
    position: relative;
    padding-top: 0.15em;
    margin: 0 0.15em;
}

/* .radical-chrome is positioned absolutely across the top and left of the radical,
   hosting the KaTeX SVG surd + vinculum as a single continuous piece. */
.mx[data-enclosure="radical"] .radical-chrome {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    color: var(--tx);
}

.mx[data-enclosure="radical"] .radical-chrome svg {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: block;
}

.mx[data-enclosure="radical"] .cell[data-slot="body"] {
    padding: 0.15em 0.25em 0 0.9em;
    min-width: 0.6em;
}

.mx[data-enclosure="radical"] .cell[data-slot="index"] {
    font-size: 0.65em;
    align-self: flex-start;
    margin-right: -0.15em;
    margin-left: 0.1em;
    margin-top: 0.1em;
    z-index: 1;
    min-width: 0.5em;
}

.anchor-glyph {
    font-size: 1.3em;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    margin-right: 0.1em;
}

.anchor-slot[data-role="top"],
.anchor-slot[data-role="bottom"] {
    font-size: 0.75em;
    min-width: 0.8em;
}

/* --- Summation Object (data-k="su") --- */
.mx[data-k="su"] {
    display: inline-grid;
    grid-template-areas:
        "top    ."
        "glyph  body"
        "bottom .";
    grid-template-columns: auto auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    justify-items: center;
    vertical-align: 0px;
    margin: 0 0.18em;
}

.mx[data-k="su"] > .sum-chrome {
    grid-area: glyph;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 2.2em;
    position: relative;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    color: var(--tx);
}

.mx[data-k="su"] > .sum-chrome svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

.mx[data-k="su"] > .cell[data-slot="top"] {
    grid-area: top;
    font-size: 0.68em;
    text-align: center;
    min-width: 0.8em;
    padding: 0 0.1em;
    margin-bottom: 2px;
}

.mx[data-k="su"] > .cell[data-slot="bottom"] {
    grid-area: bottom;
    font-size: 0.68em;
    text-align: center;
    min-width: 0.8em;
    padding: 0 0.1em;
    margin-top: 2px;
}

.mx[data-k="su"] > .cell[data-slot="body"] {
    grid-area: body;
    align-self: center;
    padding-left: 0.15em;
    min-width: 0.6em;
}

/* ==========================================================================
   7. Code Panel (Live LaTeX View)
   ========================================================================== */

#code {
    position: relative;
    width: min(38%, 460px);
    flex: none;
    border-left: 1px solid var(--line);
    background: var(--panel);
    overflow: auto;
    padding: 14px 16px;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
#code.open {
    transform: translateX(0);
}

#code[hidden] {
    display: none;
}

.code-content {
    margin: 0;
    font: 14px/1.75 ui-monospace, Menlo, Consolas, "Courier New", monospace;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--tx);
}

/* Copy LaTeX Button on Hover (Icon only) */
.code-copy-btn {
    position: sticky;
    top: 8px;
    float: right;
    margin-bottom: -32px;
    z-index: 10;
    padding: 6px 9px;
    font-size: 13px;
    background: rgba(21, 21, 21, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--dim);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, color 0.15s ease, background 0.15s ease;
}

#code:hover #code-copy-btn,
#code:hover .code-copy-btn,
#code-copy-btn:focus-visible,
.code-copy-btn:focus-visible {
    opacity: 1;
    pointer-events: auto;
}

.code-copy-btn:hover {
    color: var(--tx);
    background: var(--bg);
    border-color: var(--blue);
}

/* Responsive side-by-side or stacked layout */
@media (max-width: 700px) {
    #wrap {
        flex-direction: column;
    }

    #code {
        width: auto;
        max-height: 36%;
        border-left: 0;
        border-top: 1px solid var(--line);
        transform: translateY(100%);
    }
    #code.open {
        transform: translateY(0);
    }
}

/* ==========================================================================
   8. Status Bar & Hidden Inputs
   ========================================================================== */

#stat {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 12px;
    background: var(--panel);
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--dim);
    user-select: none;
    -webkit-user-select: none;
}


/* ==========================================================================
   9. Interactive Toast & Dialogs
   ========================================================================== */

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
    z-index: 100;
    font-size: 13.5px;
}

#toast[hidden] {
    display: none;
}

#toast button {
    padding: 2px 8px;
    color: var(--acc);
    font-weight: 600;
    border-color: transparent;
    background: transparent;
}

#toast button:hover {
    border-color: var(--acc);
}

dialog {
    background: var(--panel);
    color: var(--tx);
    border: 1px solid var(--line);
    border-radius: 12px;
    max-width: min(520px, 92vw);
    padding: 20px;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

dialog ol {
    padding-left: 20px;
    line-height: 1.5;
    font-size: 14px;
}

dialog li b {
    color: var(--acc);
}

/* ==========================================================================
   10. Left Navigation Sidebar Drawer
   ========================================================================== */

.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 998;
    transition: opacity 0.2s ease;
}

.sidebar-backdrop[hidden] {
    display: none;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--panel);
    border-right: 1px solid var(--line);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-sidebar[hidden] {
    transform: translateX(-100%);
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--acc);
    letter-spacing: 0.5px;
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    padding: 4px 8px;
    color: var(--dim);
    cursor: pointer;
    border-radius: 4px;
}

.sidebar-close-btn i {
    color: var(--dim);
}

.sidebar-close-btn:hover {
    color: var(--tx);
    background: var(--bg);
}

#menu-toggle-theme.sidebar-close-btn i {
    color: var(--blue);
}

#menu-toggle-theme.sidebar-close-btn:hover i {
    color: var(--acc);
}

.sidebar-name-section {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-bottom: 1px solid var(--line);
}

.sidebar-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--dim);
    font-weight: 600;
}

.sidebar-name-section #docname {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 13.5px;
    color: var(--tx);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 10px;
    transition: border-color 0.15s ease;
}

.sidebar-name-section #docname:hover {
    border-color: var(--blue);
}

.sidebar-name-section #docname:focus {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

.sidebar-nav {
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 13.5px;
    color: var(--tx);
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.sidebar-item:hover {
    background: var(--bg);
    border-color: var(--line);
}

.menu-icon {
    width: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--blue);
}

.sidebar-item:hover .menu-icon {
    color: var(--acc);
}

.sidebar-divider {
    height: 1px;
    background: var(--line);
    margin: 6px 8px;
}

.menu-btn {
    font-size: 16px;
    padding: 5px 9px;
    line-height: 1;
    font-weight: bold;
}

/* ==========================================================================
   IntelliSense Autocomplete Suggestion Popup
   ========================================================================== */

.ac-popup {
    position: fixed;
    z-index: 10000;
    width: 360px;
    max-width: calc(100vw - 20px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.05);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
    font-size: 13px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
}

.ac-popup[hidden] {
    display: none;
}

.ac-list {
    list-style: none;
    margin: 0;
    padding: 4px;
    max-height: 240px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ac-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.3;
    white-space: nowrap;
    color: var(--tx);
    transition: background-color 0.08s ease;
}

.ac-item:hover,
.ac-item.ac-selected {
    background: rgba(104, 159, 225, 0.16);
}

.ac-item.ac-selected {
    box-shadow: inset 2px 0 0 var(--blue);
}

.ac-num {
    font-size: 11px;
    font-family: ui-monospace, Menlo, Consolas, "Courier New", monospace;
    font-weight: 600;
    color: var(--dim);
    min-width: 14px;
    text-align: center;
    opacity: 0.65;
    flex-shrink: 0;
}

.ac-item:hover .ac-num,
.ac-item.ac-selected .ac-num {
    color: var(--blue);
    opacity: 1;
}

.ac-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.ac-badge-symbol {
    background: rgba(104, 159, 225, 0.2);
    color: var(--blue);
}

.ac-badge-object {
    background: rgba(217, 119, 87, 0.2);
    color: var(--acc);
}

.ac-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    font-size: 15px;
    font-weight: 600;
    color: var(--tx);
    flex-shrink: 0;
}

.ac-label {
    font-family: ui-monospace, Menlo, Consolas, "Courier New", monospace;
    font-weight: 600;
    color: var(--tx);
}

.ac-hl {
    color: var(--blue);
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ac-detail {
    margin-left: auto;
    font-size: 11.5px;
    color: var(--dim);
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 8px;
}
