/* ═══════════════════ Variables ═══════════════════ */
body,
body.light {
    color-scheme: light;
    --bg: #f5f5f5;
    --bg-alt: #e8e8e8;
    --bg-elevated: #ffffff;
    --text: #1a1a1a;
    --text-dim: #555;
    --text-muted: #888;
    --border: #ddd;
    --accent: #ff008b;
    --category-psychedelic: #ffb6c1;
    --category-stimulant: #f0c040;
    --category-depressant: #a0c8e0;
    --category-dissociative: #70b0e8;
    --category-opioid: #c070d8;
    --category-benzodiazepine: #d4b896;
    --category-cannabinoid: #80d080;
    --category-empathogen: #f070b0;
    --category-barbiturate: #e08080;
    --category-nootropic: #80d0d0;
    --category-deliriant: #e0b0a8;
    --category-supplement: #80d080;
    --category-research-chemical: #80d080;
    --category-habit-forming: #e0a060;
    --category-tentative: #b0b0b8;
    --category-common: #80b8e0;
    --category-default: #a0a0a8;
}

body.dark {
    color-scheme: dark;
    --bg: #121212;
    --bg-alt: #1e1e1e;
    --bg-elevated: #2a2a2a;
    --text: #e0e0e0;
    --text-dim: #aaa;
    --text-muted: #777;
    --border: #333;
    --accent: #ff008b;
    --category-psychedelic: #c07080;
    --category-stimulant: #c8a030;
    --category-depressant: #6090a8;
    --category-dissociative: #5088b0;
    --category-opioid: #9050a8;
    --category-benzodiazepine: #a08860;
    --category-cannabinoid: #50a050;
    --category-empathogen: #c05088;
    --category-barbiturate: #a85050;
    --category-nootropic: #50a0a0;
    --category-deliriant: #a87868;
    --category-supplement: #50a050;
    --category-research-chemical: #50a050;
    --category-habit-forming: #b07830;
    --category-tentative: #686870;
    --category-common: #5088b0;
    --category-default: #585860;
}

/* ═══════════════════ Base ═══════════════════ */
*, *::before, *::after { box-sizing: border-box; }

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
}

.container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    row-gap: 1rem;
    overflow-x: hidden;
}

main {
    flex-grow: 1;
    margin-bottom: auto;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { line-height: 1.6; }

h1 { font-size: 2.5rem; margin-bottom: 10px; color: var(--text); }

/* ═══════════════════ Header / Nav ═══════════════════ */
.header-container {
    margin-top: 1rem;
    display: flex;
    column-gap: 0.75rem;
    justify-content: flex-start;
    padding: 1rem 0;
    flex-wrap: nowrap;
    align-items: center;
}

.header-container .nav-link {
    text-decoration: none;
    color: white;
    border-radius: 5px;
    flex: 0 0 auto;
    height: 3rem;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    font-weight: bold;
    font-size: 0.95rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.header-container .nav-link:hover {
    cursor: pointer;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.25);
    text-decoration: none;
}
.header-container button { border: none; padding: 0; cursor: pointer; }

#home-link { background-color: #ff008b; }
#home-link::after { content: " 💊"; }

#disclaimer-link { background-color: #9185b5; }
#disclaimer-link::after { content: " ⚠️"; }

#theme-toggle {
    color: var(--text);
    background-color: var(--bg-alt);
    width: 3rem;
}
#theme-toggle > .theme-icon { transform: scale(1.3); }

/* ═══════════════════ Search ═══════════════════ */
.search-container {
    flex: 1 1 0;
    min-width: 0;
    position: relative;
}

#search {
    width: 100%;
    height: 3rem;
    padding: 0 1rem;
    font-size: 16px;
    line-height: 3rem;
    border: none;
    border-bottom: 2px solid var(--border);
    border-radius: 5px;
    background: var(--bg-alt);
    color: var(--text);
    box-sizing: border-box;
    margin: 0;
    box-shadow: none;
}
#search:focus {
    outline: none;
    border-bottom-color: var(--accent);
}
#search::placeholder { color: var(--text-muted); }

/* Generic text input — scoped to main content only, not header */
main input[type="text"] {
    width: 100%;
    padding: 12px 15px;
    font-size: 18px;
    border: 2px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    margin-bottom: 20px;
    background-color: var(--bg-alt);
    color: var(--text);
}
main input[type="text"]::placeholder { color: var(--text-muted); }
main input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

#suggestions:empty { display: none; }
#suggestions {
    list-style-type: none;
    padding: 0;
    margin: 0;
    color: var(--text);
    background: var(--bg-elevated);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    max-height: 60vh;
    overflow-y: auto;
}

/* When suggestions are inside header search-container, float as dropdown */
.search-container #suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
}
#suggestions li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}
#suggestions li:hover { background-color: var(--bg-alt); }
#suggestions li strong { font-size: 1rem; white-space: nowrap; }
#suggestions li small {
    font-size: 0.8rem;
    color: var(--text-dim);
    opacity: 0.7;
    word-break: break-word;
}

/* ═══════════════════ Footer ═══════════════════ */
.footer-container {
    display: flex;
    flex-direction: row;
    column-gap: 4rem;
    row-gap: 2rem;
    color: #777;
    font-size: 14px;
    margin: 5rem 0 2rem 0;
}
.footer-block { flex: 0 1 100%; min-width: 0; }
.footer-block h2 { font-size: inherit; color: inherit; margin: 0; }
.footer-block ul {
    display: flex;
    flex-wrap: wrap;
    padding: 0; margin: 0; gap: 0.5rem 2rem;
}
.footer-block li { list-style: none; margin: 0.5rem 0 0 0; }
.footer-block a { text-decoration: none; color: inherit; white-space: nowrap; }
.footer-block a:hover { color: var(--text); text-decoration: none; }

/* ═══════════════════ Mobile ═══════════════════ */
@media (max-width: 768px) {
    h1 { font-size: 2em; }
    .container { width: 95%; }
    .footer-container { flex-direction: column; }
    #home-link::after { content: ""; }
    #disclaimer-link { display: none; }
}

@media (max-width: 480px) {
    .container { width: 100%; padding: 0 0.5rem; }
    .header-container { padding: 0.5rem 0; column-gap: 0.5rem; }
    .header-container .nav-link { height: 2.5rem; padding: 0 0.75rem; font-size: 0.85rem; }
    #search { height: 2.5rem; line-height: 2.5rem; padding: 0 0.75rem; font-size: 14px; }
    #theme-toggle { width: 2.5rem; }
}
