/* ==========================================
   KEY TERMS TOOLTIP STYLES - BRUTALIST
   ========================================== */

/* First instance of term in each section - prominent styling */
.key-term-first {
    color: var(--steel-blue);
    border-bottom: 2px dotted var(--steel-blue);
    cursor: help;
    position: relative;
    transition: all 0.1s ease;
    font-weight: 200;
    padding: 2px 4px;
    background: transparent;
}

.key-term-first:hover {
    color: var(--pure-black);
    background: var(--industrial-yellow);
    border-bottom-style: solid;
    border-bottom-width: 4px;
}

/* Subsequent instances - subtle styling */
.key-term-subsequent {
    /* 
    color: var(--steel-blue);
    border-bottom: 1px dotted var(--steel-blue); 
    opacity: 0.7;
    transition: all 0.1s ease;
    font-weight: 200;
    padding: 0px 2px;
    */
    cursor: help;
    position: relative;
    background: transparent;
}

.key-term-subsequent:hover {
    color: var(--pure-black);
    background: rgba(255, 193, 7, 0.3);
    border-bottom-style: solid;
    border-bottom-width: 2px;
    opacity: 1;
}

/* Backwards compatibility for unmarked instances */
.key-term:not(.key-term-first):not(.key-term-subsequent) {
    color: var(--steel-blue);
    border-bottom: 2px dotted var(--steel-blue);
    cursor: help;
    position: relative;
    transition: all 0.1s ease;
    font-weight: 200;
    padding: 2px 4px;
    background: transparent;
}

.key-term:not(.key-term-first):not(.key-term-subsequent):hover {
    color: var(--pure-black);
    background: var(--industrial-yellow);
    border-bottom-style: solid;
    border-bottom-width: 4px;
}

.key-term-tooltip {
    position: absolute;
    background: var(--pure-white);
    border: 5px solid var(--pure-black);
    border-radius: 0;
    padding: 20px;
    box-shadow: 10px 10px 0 var(--concrete-mid);
    max-width: 400px;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
}

.key-term-tooltip.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ── ARROW (::before) ──────────────────────────────────────────
   The JS adds either .arrow-up or .arrow-down to the tooltip.
   
   .arrow-up   = tooltip is BELOW the term  → triangle points UP
   .arrow-down = tooltip is ABOVE the term  → triangle points DOWN

   Without either class (e.g. on first paint) we default to
   arrow-up behaviour so nothing looks broken.
   ────────────────────────────────────────────────────────────── */

/* Arrow pointing UP — tooltip sits below the highlighted term */
.key-term-tooltip.arrow-up::before,
.key-term-tooltip:not(.arrow-down)::before {
    content: '';
    position: absolute;
    top: -15px;   /* above the tooltip box, accounting for border */
    left: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 10px solid var(--pure-black);
    pointer-events: none;
}

/* Arrow pointing DOWN — tooltip sits above the highlighted term */
.key-term-tooltip.arrow-down::before {
    content: '';
    position: absolute;
    bottom: -15px; /* below the tooltip box, accounting for border */
    top: auto;     /* reset the default top value */
    left: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--pure-black);
    border-bottom: none; /* reset */
    pointer-events: none;
}

/* ── "TERM" BADGE (::after) ────────────────────────────────────
   Unchanged from original — lives on ::after so it never
   conflicts with the directional arrow on ::before.
   ────────────────────────────────────────────────────────────── */
.key-term-tooltip::after {
    content: 'TERM';
    position: absolute;
    top: -20px;
    right: 15px;
    background: var(--industrial-yellow);
    color: var(--pure-black);
    padding: 4px 12px;
    font-size: 0.65rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    border: 3px solid var(--pure-black);
    pointer-events: none; /* badge must not block clicks on tooltip content */
}

.tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.tooltip-term {
    font-weight: 900;
    font-size: 1.2em;
    color: var(--pure-black);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0;
    border-bottom: 3px solid var(--pure-black);
    padding-bottom: 8px;
}

.tooltip-short {
    font-size: 0.9em;
    line-height: 1.6;
    color: var(--pure-black);
    font-weight: 500;
}

/* Links inside tooltip definitions (e.g. Key Populations Action Plan) */
.tooltip-short a {
    color: var(--steel-blue);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 2px;
}

.tooltip-short a:hover {
    color: var(--pure-black);
    background: var(--industrial-yellow);
    text-decoration: none;
    /* No padding here — adding padding on hover shifts surrounding text */
}

.tooltip-learn-more {
    background: var(--rust-orange);
    color: var(--pure-white);
    border: 4px solid var(--pure-black);
    padding: 10px 18px;
    border-radius: 0;
    cursor: pointer;
    font-weight: 900;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.1s ease;
    align-self: flex-start;
    margin-top: 0;
    box-shadow: 4px 4px 0 var(--pure-black);
}

.tooltip-learn-more:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--pure-black);
}

/* ==========================================
   GLOSSARY PAGE STYLES - BRUTALIST
   ========================================== */

#glossary-mode {
    min-height: 100vh;
    background: var(--concrete-bg);
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px);
}

.glossary-hero-header {
    background: var(--concrete-dark);
    color: var(--pure-white);
    padding: 100px 0 60px;
    position: relative;
    overflow: hidden;
    border-bottom: 15px solid var(--pure-black);
}

.glossary-hero-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 50px, rgba(255,255,255,0.03) 50px, rgba(255,255,255,0.03) 100px),
        repeating-linear-gradient(-45deg, transparent, transparent 50px, rgba(0,0,0,0.05) 50px, rgba(0,0,0,0.05) 100px);
}

.glossary-hero-header h1 {
    color: var(--industrial-yellow);
    font-size: 4.5rem;
    margin-bottom: 20px;
    text-shadow: 5px 5px 0 rgba(0,0,0,0.3);
    line-height: 0.85;
    letter-spacing: -0.03em;
    position: relative;
    z-index: 1;
    font-family: 'Arial Black', sans-serif;
    font-weight: 900;
    text-transform: uppercase;
}

.glossary-hero-header p {
    color: var(--pure-white);
    font-size: 1.1rem;
    opacity: 1;
    max-width: 600px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: bold;
    background: rgba(0,0,0,0.5);
    padding: 20px 30px;
    margin-left: 30px;
    border-left: 5px solid var(--pure-white);
    position: relative;
    z-index: 1;
}

.glossary-controls {
    background: var(--pure-white);
    padding: 25px 0;
    border-bottom: 8px solid var(--pure-black);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 0 var(--pure-black);
}

.glossary-controls .container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.glossary-view-toggle {
    display: flex;
    gap: 0;
    justify-content: center;
    background: var(--pure-black);
    border: 5px solid var(--pure-black);
    box-shadow: 8px 8px 0 var(--concrete-mid);
    width: fit-content;
    margin: 0 auto;
}

.view-btn {
    padding: 12px 24px;
    border: none;
    border-right: 3px solid var(--concrete-mid);
    background: var(--pure-white);
    color: var(--pure-black);
    border-radius: 0;
    cursor: pointer;
    font-family: 'Arial Black', sans-serif;
    font-weight: 900;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.1s ease;
}

.view-btn:last-child {
    border-right: none;
}

.view-btn:hover {
    background: var(--industrial-yellow);
    transform: translate(-2px, -2px);
}

.view-btn.active {
    background: var(--steel-blue);
    color: var(--industrial-yellow);
}

.glossary-main {
    padding: 60px 0;
}

.glossary-list {
    display: grid;
    gap: 20px;
}

.glossary-term {
    background: var(--pure-white);
    padding: 30px;
    border-radius: 0;
    box-shadow: 0 0 0 var(--pure-black);
    transition: all 0.1s ease;
    border: 5px solid var(--pure-black);
    border-left: 12px solid var(--concrete-mid);
    position: relative;
}

.glossary-term::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -12px;
    width: 12px;
    height: 12px;
    background: var(--industrial-yellow);
}

.glossary-term:hover {
    box-shadow: 8px 8px 0 var(--pure-black);
    border-left-color: var(--rust-orange);
    transform: translate(-3px, -3px);
}

.glossary-term.highlight-term {
    animation: highlightPulse 2s ease;
    border-left-color: var(--rust-orange);
    background: var(--industrial-yellow);
}

@keyframes highlightPulse {
    0%, 100% {
        background: var(--industrial-yellow);
        transform: scale(1);
    }
    50% {
        background: var(--pure-white);
        transform: scale(1.02);
    }
}

.glossary-term-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.glossary-term-header h3 {
    color: var(--pure-black);
    margin: 0;
    font-size: 1.8em;
    font-weight: 900;
    font-family: 'Arial Black', sans-serif;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    line-height: 1;
    background: none;
    border: none;
    padding: 0;
}

.acronym-badge {
    background: var(--pure-black);
    color: var(--industrial-yellow);
    padding: 6px 16px;
    border-radius: 0;
    font-size: 0.7em;
    font-weight: 900;
    letter-spacing: 0.1em;
    border: 3px solid var(--industrial-yellow);
}

.glossary-short {
    color: var(--pure-black);
    font-size: 0.9em;
    font-weight: 900;
    font-family: 'Arial Black', sans-serif;
    margin-bottom: 15px;
    line-height: 1.4;
    text-transform: uppercase;
    background: var(--concrete-bg);
    padding: 12px 15px;
    border-left: 5px solid var(--steel-blue);
}

.glossary-full {
    color: var(--pure-black);
    line-height: 1.7;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
}

/* ==========================================
   RESPONSIVE STYLES - BRUTALIST
   ========================================== */

@media (max-width: 768px) {
    .key-term-tooltip {
        max-width: 300px;
        padding: 15px;
        box-shadow: 6px 6px 0 var(--concrete-mid);
    }
    
    .glossary-hero-header h1 {
        font-size: 2.5rem;
    }
    
    .glossary-hero-header p {
        font-size: 0.9rem;
        padding: 15px 20px;
        margin-left: 20px;
    }
    
    .glossary-controls .container {
        gap: 16px;
    }
    
    .glossary-view-toggle {
        flex-direction: column;
        width: 100%;
    }
    
    .view-btn {
        width: 100%;
        border-right: none;
        border-bottom: 3px solid var(--concrete-mid);
    }

    .view-btn:last-child {
        border-bottom: none;
    }
    
    .glossary-term {
        padding: 20px;
    }
    
    .glossary-term-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .glossary-term-header h3 {
        font-size: 1.4em;
    }
}

/* ==========================================
   PRINT STYLES - BRUTALIST
   ========================================== */

@media print {
    .key-term-tooltip {
        display: none;
    }
    
    .key-term-first,
    .key-term-subsequent {
        border-bottom: 2px solid var(--pure-black);
        color: var(--pure-black);
        background: none;
    }
    
    .glossary-controls {
        display: none;
    }

    .glossary-term {
        border: 3px solid var(--pure-black);
        box-shadow: none;
        page-break-inside: avoid;
    }
}

/* ==========================================
   ACCESSIBILITY ENHANCEMENTS - BRUTALIST
   ========================================== */

.key-term-first:focus,
.key-term-subsequent:focus {
    outline: 4px solid var(--industrial-yellow);
    outline-offset: 2px;
    border-radius: 0;
    background: var(--industrial-yellow);
}

.tooltip-learn-more:focus {
    outline: 4px solid var(--industrial-yellow);
    outline-offset: 3px;
}

.view-btn:focus {
    outline: 4px solid var(--industrial-yellow);
    outline-offset: 3px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .key-term-first,
    .key-term-subsequent {
        border-bottom-width: 4px;
    }
    
    .key-term-tooltip {
        border-width: 6px;
    }

    .glossary-term {
        border-width: 6px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .key-term-first,
    .key-term-subsequent,
    .key-term-tooltip,
    .glossary-term,
    .tooltip-learn-more,
    .view-btn {
        transition: none;
    }
    
    .glossary-term.highlight-term {
        animation: none;
        background: var(--industrial-yellow);
        border-left-color: var(--rust-orange);
    }
}

/* ==========================================
   ADDITIONAL BRUTALIST ELEMENTS
   ========================================== */

/* Search box styling for glossary */
#glossary-search {
    width: 100%;
    padding: 18px 50px;
    font-size: 1rem;
    font-weight: bold;
    border: 4px solid var(--pure-black);
    background: var(--pure-white);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#glossary-search:focus {
    outline: none;
    background: var(--industrial-yellow);
    box-shadow: 6px 6px 0 var(--pure-black);
}

/* Loading state for glossary */
.glossary-list .loading-state {
    text-align: center;
    padding: 80px 20px;
}

.glossary-list .spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 25px;
    border: 6px solid var(--concrete-bg);
    border-top-color: var(--pure-black);
    border-radius: 0;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state for glossary search */
.glossary-no-results {
    text-align: center;
    padding: 80px 20px;
    background: var(--concrete-bg);
    border: 5px solid var(--pure-black);
    margin: 40px 0;
}

.glossary-no-results h3 {
    color: var(--pure-black);
    font-family: 'Arial Black', sans-serif;
    text-transform: uppercase;
    margin-bottom: 15px;
    background: none;
    border: none;
    padding: 0;
}

.glossary-no-results p {
    color: var(--concrete-mid);
}

/* Keyboard navigation indicators */
.key-term-first[data-keyboard-focus="true"],
.key-term-subsequent[data-keyboard-focus="true"] {
    outline: 4px solid var(--rust-orange);
    outline-offset: 2px;
    background: var(--industrial-yellow);
}