:root {
    --bg-body: #f4f6f8;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --table-header-bg: #f8fafc;
    --surface-color: #ffffff;
    --bg-tinted: #cfcfcf;

    --dyn-header-bg:   #d5e4f4;
    --dyn-header-edge: rgb(124 152 182 / 0.54);

    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --on-accent: #ffffff;
    --primary-row-hover: rgb(37 99 235 / 0.07);
    --focus-ring:      rgb(37 99 235 / 0.18);

    /* Second-level horizontal navigator (e.g. the FA page's sub-tab strip).
       Deliberately NOT --primary-color: level 2 has to read as a different
       band from the level-1 tabs above it. */
    --nav2: #4b35f6;

    --accent-omega6: #f59e0b;
    --accent-danger: #ef4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);

    --shadow-down: 0 2px 8px rgba(0, 0, 0, 0.12);

    --font-family:    'Inter', system-ui, -apple-system, sans-serif;
    --font-sans: var(--font-family);

    --fs-4xs:  0.60rem;
    --fs-3xs:  0.65rem;
    --fs-2xs:  0.72rem;
    --fs-xs:   0.78rem;
    --fs-sm:   0.85rem;
    --fs-md:   0.92rem;
    --fs-base: 1rem;
    --fs-lg:   1.10rem;
    --fs-xl:   1.25rem;
    --fs-2xl:  1.40rem;
    --fs-3xl:  2.00rem;
    --fs-4xl:  3.00rem;

    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --radius-md: 0.5rem;
    --radius-sm: 0.25rem;

    --button_apply_bg: #3b82f6;
    --button_cancel_bg: #e2e8f0;
    --button_del_bg: #ec3c7b;
    --form_toggle_on: #3bf6ca;
    --form_toggle_hover: #3be6f6;
    --form_toggle_off: #e2e8f0;

    --card-bg:         var(--bg-card);
    --text-color:      #12303f;
    --accent-color:    #2e5d78;
    --accent-primary:  #1d4ed8;
    --accent-secondary: var(--primary-color);
    --input-bg:        #ffffff;
    --hover-bg:        rgba(0, 0, 0, 0.05);

    /* ── Icon-button surface ramp ────────────────────────────────────────── */
    --icon-bg:        rgba(0, 0, 0, 0.035);
    --icon-bg-hover:  rgba(0, 0, 0, 0.06);
    --icon-bg-active: rgba(0, 0, 0, 0.12);
    --icon-bg-seg:    rgba(0, 0, 0, 0.07);
    --bg-surface-2:    #eef2f7;
    --bg-level-2:      #fff8e1;
    --bg-level-3:      #e2e8f0;
}

body.dark-mode {

    /* surface ramp — each step lighter than the last */
    --bg-body:          #000000;
    --bg-card:          #0d1117;
    --surface-color:    #0d1117;
    --bg-surface-2:     #161b22;
    --table-header-bg:  #161b22;
    --bg-tinted:        #21262d;
    --bg-level-3:       #21262d;
    --border-color:     #30363d;

    /* text */
    --text-main:        #f0f6fc;
    --text-muted:       #969da6;
    --text-color:       var(--text-main);

    /* primary — lighter than the light-mode blue, and hover goes LIGHTER.
       --on-accent is dark ink: white on this fill is only 2.6:1. */
    --primary-color:    #4d99dc;
    --primary-hover:    #a5d6ff;
    --on-accent:        #01040a;
    --primary-row-hover: rgb(77 153 220 / .10);
    --focus-ring:       rgb(77 153 220 / .38);
    --accent-primary:   #a5d6ff;
    --accent-secondary: var(--primary-color);
    --accent-color:     #76e3ea;

    /* level-2 nav keeps its own hue, per the note in :root */
    --nav2:             #d2a8ff;

    /* semantic accents */
    --accent-danger:    #ff7b72;
    --accent-omega6:    #e3b341;
    --bg-level-2:       #3b2300;

    --dyn-header-bg:    #05193e;
    --dyn-header-edge:  #30363d;

    /* controls */
    --card-bg:          var(--bg-card);
    --input-bg:         #010409;
    --hover-bg:         rgba(255, 255, 255, 0.06);

    /* Icon-button ramp — white tints on the dark ground. Slightly higher
       opacities than the light theme: a white veil over near-black reads
       weaker than a black veil over near-white at the same alpha. */
    --icon-bg:          rgba(255, 255, 255, 0.05);
    --icon-bg-hover:    rgba(255, 255, 255, 0.09);
    --icon-bg-active:   rgba(255, 255, 255, 0.16);
    --icon-bg-seg:      rgba(255, 255, 255, 0.10);
    --button_apply_bg:  var(--primary-color);
    --button_cancel_bg: #21262d;
    --button_del_bg:    #f778ba;
    --form_toggle_on:   #2ea8a0;
    --form_toggle_hover: #3fc4bb;
    --form_toggle_off:  #30363d;

    --shadow:           0 4px 10px rgba(0, 0, 0, 0.55);
    --shadow-down:      0 2px 8px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

html {
    font-size: calc(var(--font-scale, 1) * 100%);
}

body {
    font-family: var(--font-family);
    font-size:   var(--fs-base);
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    line-height: 1.5;
}

h1, h1 > span { font-size: var(--fs-xl);   font-weight: 700; margin: 10px 0 0.5rem; }
h2, h2 > span { font-size: var(--fs-lg);   font-weight: 600; margin: 0 0 0.5rem; }
h3 { font-size: var(--fs-lg);   font-weight: 600; margin: 0 0 0.4rem; }
h4 { font-size: var(--fs-base); font-weight: 600; margin: 0 0 0.4rem; }
h5, h6 { font-size: var(--fs-base); font-weight: 600; margin: 0 0 0.25rem; }

.smallGray {
    font-size: var(--fs-md);
    color: var(--text-muted);
}

a {
    text-decoration: none;
    color: inherit;
}

.app-header {
}

.logo {
    font-weight: 700;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.logo span {
    color: var(--primary-color);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--icon-bg);
    border: 0;
    padding: 0;
    height: 32px;
    width: 32px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: background .14s ease, color .14s ease;
}
.theme-toggle:hover  { background: var(--icon-bg-hover);  color: var(--primary-color); }
.theme-toggle:active { background: var(--icon-bg-active); }
/* The font picker's "A" while its panel is open. */
.theme-toggle[aria-expanded="true"] {
    background: var(--icon-bg-active);
    color: var(--primary-color);
}
.theme-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}
.card h3 {
    padding: 4px;
    margin: 0;
}
.card .browser_img_container {
    border: 1px solid var(--border-color);
    height: 140px;
    text-align: center;
    background: var(--bg-body);
}
.card .browser_img_container img {
    height: 140px;
}
.card-title {
    font-weight: 600;
    margin: 0;
}

.badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.sidebar {
    width: 320px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.filter-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.filter-section {
    margin-bottom: 1.5rem;
    position: relative;
}

.filter-title {
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: default;
}

.help-icon {
    color: var(--primary-color);
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
    padding: 0 5px;
}

.filter-title:hover .help-icon {
    opacity: 1;
}

.search-box {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-box input {
    width: 100%;
    padding: 0.6rem 0.6rem 0.6rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-body);
    color: var(--text-main);
}

.search-box i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

#select_single_type {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#select_single_type #omegas span.filter-chip {
    padding: 0.4rem 0.3rem;
}
#select_single_type hr {
    border: 0; border-top: 1px solid var(--border-color); margin: 2px 0;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    width: 800px;
    max-width: 95%;
    height: 80vh;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-body);
    flex-shrink: 0;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.data-table th {
    color: var(--text-muted);
    font-weight: 600;
    width: 40%;
}

.subsection-header {
    background-color: var(--table-header-bg);
    color: var(--text-main);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.visual-container {
    position: relative;
    height: 400px;
    background: var(--bg-body);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.btn-load-3d {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.text-muted {
    color: var(--text-muted);
}

.flex {
    display: flex;
}

.gap-2 {
    gap: 0.5rem;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    border-radius: var(--radius-md);
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: var(--fs-sm);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.nav-link:hover {
    color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.1);
}

.nav-has-sub {
    position: relative;
}

.nav-chevron {
    font-size: 0.65em;
    opacity: 0.7;
    transition: transform 160ms;
}
.nav-has-sub:hover .nav-chevron,
.nav-has-sub.nav-open .nav-chevron {
    transform: rotate(180deg);
}

.nav-sub {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.13);
    min-width: 190px;
    padding: 0.3rem;
    z-index: 300;
    display: none;
}
.nav-sub::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
    background: transparent;
}
body.dark-mode .nav-sub { box-shadow: 0 8px 24px rgba(0,0,0,0.45); }

.nav-has-sub:hover .nav-sub,
.nav-has-sub.nav-open .nav-sub { display: block; }

.nav-sub a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.8rem;
    border-radius: 5px;
    color: var(--text-main);
    font-size: var(--fs-sm);
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    transition: background 80ms, color 80ms;
}
.nav-sub a:hover {
    background: rgba(59,130,246,0.08);
    color: var(--primary-color);
}
.nav-sub a i {
    width: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8em;
}

.research-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.research-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.5rem 0;
    color: var(--text-muted);
}
.research-spinner {
    width: 1.05rem;
    height: 1.05rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color, #3b82f6);
    border-radius: 50%;
    display: inline-block;
    animation: research-spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes research-spin { to { transform: rotate(360deg); } }

.research-status {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.research-empty {
    padding: 1.5rem 0;
    color: var(--text-muted);
}
.research-footer {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}
.research-search-link {
    text-decoration: none;
}

.hist-loading {
    display: flex; align-items: center; gap: 0.6rem;
    color: var(--text-muted); padding: 1.5rem 0;
}
.hist-empty {
    background: var(--bg-body);
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1.75rem 1rem;
    text-align: center;
    color: var(--text-muted);
}
.hist-chart-wrap { position: relative; height: 260px; margin-bottom: 0.5rem; }
.hist-note { font-size: var(--fs-xs); color: var(--text-muted); margin: 0.5rem 0 0; line-height: 1.45; }
.hist-badge-est {
    display: inline-block; font-size: var(--fs-3xs); font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: #b45309; background: rgba(245,158,11,0.15);
    border: 1px solid rgba(245,158,11,0.4); border-radius: 4px; padding: 1px 6px; margin-right: 0.4rem;
}
.hist-unit-toggle { display: inline-flex; border: 1px solid var(--border-color); border-radius: 6px; overflow: hidden; }
.hist-unit-btn {
    border: 0; background: var(--bg-card); color: var(--text-muted);
    font-family: inherit; font-size: var(--fs-xs); font-weight: 600; padding: 0.25rem 0.6rem; cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.hist-unit-btn + .hist-unit-btn { border-left: 1px solid var(--border-color); }
.hist-unit-btn.active { background: #018bad; color: #fff; }

.hist-research { margin-top: 1.25rem; }
.hist-research-title {
    font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); margin-bottom: 0.5rem;
}
.hist-ref-list { list-style: none; padding: 0; margin: 0; }
.hist-ref-list li { padding: 0.4rem 0; border-bottom: 1px solid var(--border-color); font-size: var(--fs-md); }
.hist-ref-list li:last-child { border-bottom: 0; }
.hist-ref-meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 0.1rem; }

@media (max-width: 720px) {
    .diet-grid { grid-template-columns: 1fr !important; }
}

a.external_id { color: var(--primary-color); transition: 0.3s;}
a.external_id:hover { text-decoration: underline; }

.info-tooltip {
    display: inline-flex;
    position: relative;
    margin-left: 4px;
    cursor: help;
    color: var(--text-muted);
    outline: none;
    vertical-align: baseline;
}
.info-tooltip:hover,
.info-tooltip:focus-visible {
    color: var(--primary-color);
}

.info-tooltip-content { display: none; }

.gs-wrap {
    position: relative;
    flex: 0 0 160px;
    height: 36px;
    margin-right: 0.75rem;
}

.gs-wrap:focus-within { z-index: 5; }

.gs-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0 2.1rem 0 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: var(--fs-sm);
    font-family: inherit;
    outline: none;
    transition: width 260ms cubic-bezier(0.4, 0, 0.2, 1),
                border-color 120ms,
                box-shadow 120ms;
    z-index: 11;
}
.gs-input::placeholder { color: var(--text-muted); }
.gs-wrap:focus-within .gs-input {
    width: 680px;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.18);
}

.gs-icon {
    position: absolute;
    left: calc(160px - 1.55rem);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    pointer-events: none;
    z-index: 2;
    line-height: 1;
    transition: left 260ms cubic-bezier(0.4, 0, 0.2, 1);
}
.gs-wrap:focus-within .gs-icon { left: calc(680px - 1.55rem); }

.gs-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 160px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 1200;
    overflow: hidden;
    display: none;
}
.gs-wrap:focus-within .gs-dropdown { width: 480px; }
.gs-dropdown.gs-open { display: block; }

.gs-group-label {
    padding: 0.45rem 0.85rem 0.25rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}
.gs-group-label:first-child { border-top: none; }

.gs-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.85rem;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-main);
    transition: background 80ms;
    border-radius: 0;
}
.gs-item:hover,
.gs-item.gs-active {
    background: rgba(59,130,246,0.09);
    color: var(--primary-color);
}

.gs-item-icon {
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
    color: var(--text-muted);
}
.gs-item.gs-active .gs-item-icon { color: var(--primary-color); }

.gs-item-body { min-width: 0; }
.gs-item-label {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
}
.gs-item.gs-active .gs-item-label { color: var(--primary-color); }

.gs-item-sub {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gs-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
}

.adminOnly {
    position: relative;
    border: 1px dashed #7c3aed;
    border-radius: 8px;
    background: rgba(124, 58, 237, 0.05);
    padding: 0.85rem 0.9rem 0.75rem;
    margin-bottom: 1rem;
}
.adminOnly::after {
    content: "ADMIN ONLY";
    position: absolute;
    top: -9px;
    right: 10px;
    padding: 1px 7px;
    border-radius: 4px;
    background: #7c3aed;
    color: #fff;
    font-size: var(--fs-4xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1.5;
    pointer-events: none;
}

.research-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.research-toolbar.adminOnly { margin-bottom: 1.15rem; }
.research-load-btn { cursor: pointer; }
.research-load-btn.is-busy { opacity: 0.7; cursor: default; }
.research-updated {
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
.research-idle {
    background: var(--bg-body);
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1.5rem 1rem;
    text-align: center;
}


.abrv {
    margin-left: 10px;
    border-left: 1px solid var(--text-main);
    padding-left: 5px;
    text-shadow: -1px 0 1px yellow, 0 -1px 1px yellow, 1px 0 1px yellow, 0 1px 1px yellow;
}
body.dark-mode .abrv {
    text-shadow: -1px 0 1px rgb(0,0,0), 0 -1px 1px rgb(0,0,0), 1px 0 1px rgb(0,0,0), 0 1px 1px rgb(0,0,0);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE — cards and data tables below 820px
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 820px) {
    .card {
        padding: 0.85rem;
        margin-bottom: 1rem;
        border-radius: 10px;
        min-width: 0;
    }
    .card-header {
        margin-bottom: 0.7rem;
        padding-bottom: 0.5rem;
    }
    .card h3 { padding: 0; }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.4rem;
        overflow-wrap: anywhere;
        /* Once values wrap to three or four lines — which is the normal case
           in a ~230px column — a middle-aligned label floats halfway down its
           own row and stops reading as the label FOR the line beside it. */
        vertical-align: top;
    }
    /* 40% of a 400px card is 160px for a label column whose longest entry is
       "Traditional Name". The value column needs it more. */
    .data-table th { width: 34%; }
}
