/* ── Wigmorean Index Engine — Drawer ───────────────────────────────────── */

:root {
    --wig-index-accent:  #5B3D9E;
    --wig-index-bg:      #1a1a2e;
    --wig-index-text:    #f0f0f0;
    --wig-index-hover:   #2e2e4e;
    --wig-index-width:   420px;
    --wig-index-shadow:  0 4px 32px rgba(0,0,0,.45);
    --wig-index-radius:  10px 0 0 10px;
    --wig-index-z:       99990;
    --wig-index-header:  56px;
    --wig-index-az-h:    44px;
    --wig-index-trans:   0.28s cubic-bezier(.4,0,.2,1);
}

/* ── Floating button ────────────────────────────────────────────────────── */
.wig-index-btn {
    position: fixed;
    bottom: 28px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wig-index-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
    z-index: var(--wig-index-z);
    transition: transform .2s ease, box-shadow .2s ease;
    outline: none;
}
.wig-index-btn--br { right: 24px; }
.wig-index-btn--bl { left: 24px; }
.wig-index-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.wig-index-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}
.wig-index-btn svg { pointer-events: none; }

/* ── Backdrop ────────────────────────────────────────────────────────────── */
.wig-index-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: calc(var(--wig-index-z) + 1);
    animation: wigBackdropIn .25s ease;
}
@keyframes wigBackdropIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Drawer panel ────────────────────────────────────────────────────────── */
.wig-index-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--wig-index-width);
    max-width: 95vw;
    height: 100%;
    background: var(--wig-index-bg);
    color: var(--wig-index-text);
    box-shadow: var(--wig-index-shadow);
    border-radius: var(--wig-index-radius);
    z-index: calc(var(--wig-index-z) + 2);
    display: flex;
    flex-direction: column;
    transform: translateX(105%);
    transition: transform var(--wig-index-trans);
    font-family: Georgia, 'Times New Roman', serif;
    overflow: hidden;
}
.wig-index-drawer--open  { transform: translateX(0); }
.wig-index-drawer--closed { transform: translateX(105%); }

/* ── Header ──────────────────────────────────────────────────────────────── */
.wig-index-drawer__header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    height: var(--wig-index-header);
    padding: 0 16px;
    background: var(--wig-index-accent);
    flex-shrink: 0;
}
.wig-index-drawer__title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .05em;
    color: #fff;
    font-family: Georgia, serif;
}
.wig-index-drawer__search-wrap { min-width: 0; }
.wig-index-search-input {
    width: 100%;
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 20px;
    padding: 5px 14px;
    color: #fff;
    font-size: .85rem;
    font-family: Georgia, serif;
    outline: none;
    transition: background .2s;
}
.wig-index-search-input::placeholder { color: rgba(255,255,255,.6); }
.wig-index-search-input:focus { background: rgba(255,255,255,.25); }

.wig-index-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    transition: color .15s;
}
.wig-index-close:hover { color: #fff; }

/* ── A–Z tabs ────────────────────────────────────────────────────────────── */
.wig-index-az-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 10px;
    background: rgba(255,255,255,.05);
    border-bottom: 1px solid rgba(255,255,255,.1);
    flex-shrink: 0;
    min-height: var(--wig-index-az-h);
}
.wig-index-az-tab {
    padding: 3px 7px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid rgba(255,255,255,.15);
    color: var(--wig-index-text);
    font-size: .78rem;
    font-family: Georgia, serif;
    cursor: pointer;
    transition: background .15s, color .15s;
    line-height: 1.4;
}
.wig-index-az-tab:hover,
.wig-index-az-tab.active {
    background: var(--wig-index-accent);
    color: #fff;
    border-color: var(--wig-index-accent);
}
.wig-index-az-tab--empty {
    opacity: .3;
    pointer-events: none;
}

/* ── Content area ────────────────────────────────────────────────────────── */
.wig-index-content,
.wig-index-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.wig-index-content::-webkit-scrollbar,
.wig-index-search-results::-webkit-scrollbar { width: 5px; }
.wig-index-content::-webkit-scrollbar-track,
.wig-index-search-results::-webkit-scrollbar-track { background: transparent; }
.wig-index-content::-webkit-scrollbar-thumb,
.wig-index-search-results::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.2);
    border-radius: 3px;
}

/* ── Letter section ──────────────────────────────────────────────────────── */
.wig-index-letter-section { margin-bottom: 4px; }

.wig-index-letter-heading {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--wig-index-accent);
    padding: 6px 16px 2px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255,255,255,.08);
    font-family: Georgia, serif;
}

/* ── Term rows ───────────────────────────────────────────────────────────── */
.wig-index-term { }

.wig-index-term-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    cursor: pointer;
    transition: background .15s;
    gap: 8px;
    user-select: none;
}
.wig-index-term-header:hover { background: var(--wig-index-hover); }

.wig-index-term-keyword {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: .9rem;
    font-weight: 600;
    flex: 1;
}
.wig-index-term-count {
    font-size: .72rem;
    color: rgba(255,255,255,.45);
    flex-shrink: 0;
}
.wig-index-term-toggle {
    font-size: .75rem;
    color: rgba(255,255,255,.45);
    transition: transform .2s;
    flex-shrink: 0;
}
.wig-index-term.open .wig-index-term-toggle { transform: rotate(90deg); }

/* ── Term description ────────────────────────────────────────────────────── */
.wig-index-term-desc {
    font-size: .78rem;
    color: rgba(255,255,255,.5);
    padding: 0 16px 4px 20px;
    font-style: italic;
}

/* ── Entries list ────────────────────────────────────────────────────────── */
.wig-index-entries {
    display: none;
    margin: 0;
    padding: 0;
    list-style: none;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.wig-index-term.open .wig-index-entries { display: block; }

.wig-index-entry {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 5px 16px 5px 24px;
    border-bottom: 1px solid rgba(255,255,255,.04);
    transition: background .12s;
}
.wig-index-entry:hover { background: var(--wig-index-hover); }

.wig-index-entry-link {
    flex: 1;
    color: rgba(255,255,255,.85);
    text-decoration: none;
    font-family: Georgia, serif;
    font-size: .83rem;
    transition: color .15s;
}
.wig-index-entry-link:hover { color: #fff; text-decoration: underline; }

.wig-index-entry-tc {
    font-size: .72rem;
    color: var(--wig-index-accent);
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
    opacity: .85;
}

/* Locked entries */
.wig-index-entry.locked .wig-index-entry-link {
    color: rgba(255,255,255,.3);
    cursor: default;
    pointer-events: none;
    text-decoration: none;
}
.wig-index-entry.locked::after {
    content: attr(data-locked-label);
    font-size: .7rem;
    color: rgba(255,255,255,.28);
    font-style: italic;
    margin-left: 6px;
}

/* Child terms (indented) */
.wig-index-term.child .wig-index-term-header { padding-left: 28px; }
.wig-index-term.child .wig-index-term-keyword { font-size: .85rem; font-weight: 500; }

/* ── Search results ──────────────────────────────────────────────────────── */
.wig-index-search-results { padding: 8px 0; }
.wig-search-term-group { margin-bottom: 4px; }
.wig-search-term-label {
    padding: 4px 16px;
    font-weight: 600;
    font-size: .85rem;
    color: var(--wig-index-accent);
    font-family: Georgia, serif;
}
.wig-index-search-results .wig-index-entry { padding-left: 24px; }
.wig-index-search-empty {
    padding: 24px 16px;
    text-align: center;
    color: rgba(255,255,255,.45);
    font-style: italic;
    font-size: .87rem;
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.wig-index-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px;
    color: rgba(255,255,255,.5);
    font-size: .87rem;
}
.wig-index-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.2);
    border-top-color: var(--wig-index-accent);
    border-radius: 50%;
    animation: wigSpin .7s linear infinite;
}
@keyframes wigSpin { to { transform: rotate(360deg); } }

/* ── Inline shortcode index page ─────────────────────────────────────────── */
.wig-index-page {
    font-family: Georgia, 'Times New Roman', serif;
}
.wig-index-page .wig-index-az-tabs {
    background: #f6f6f6;
    border-radius: 6px;
    border: 1px solid #ddd;
    padding: 10px;
    margin-bottom: 16px;
}
.wig-index-page .wig-index-az-tab {
    color: #333;
    border-color: #ccc;
}
.wig-index-page .wig-index-letter-heading { color: #5B3D9E; border-color: #e0d0ff; }
.wig-index-page .wig-index-term-header { background: #fafafa; border-bottom: 1px solid #eee; }
.wig-index-page .wig-index-term-header:hover { background: #f0e8ff; }
.wig-index-page .wig-index-term-keyword { color: #1a1a1a; }
.wig-index-page .wig-index-entry-link { color: #333; }
.wig-index-page .wig-index-entry:hover { background: #f5f0ff; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    :root { --wig-index-width: 100vw; --wig-index-radius: 0; }
    .wig-index-btn--br { right: 12px; bottom: 16px; }
    .wig-index-btn--bl { left: 12px;  bottom: 16px; }
}
