/* ==========================================================================
   The Bryan Record: research mode
   Record explorer, map, Governance DNA, administration.
   Light, spacious, dashboard-like. Glass only on floating map controls.
   ========================================================================== */

body.mode-research { background: var(--gray-100); }
body.mode-research .site-header { background: rgba(255, 255, 255, 0.92); }

/* ---------- Layout ---------- */

.research {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    gap: 0;
    max-width: 1560px;
    margin: 0 auto;
    min-height: calc(100vh - 80px);
}

.rs-side {
    position: sticky;
    top: 80px;
    align-self: start;
    height: calc(100vh - 80px);
    padding: 40px 20px 32px var(--gutter);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}
.rs-side__label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
    padding-left: 12px;
}
.rs-side__list { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.rs-side__list a {
    display: block;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    color: var(--ink-2);
    text-decoration: none;
    transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}
.rs-side__list a:hover { background: rgba(27, 38, 32, 0.05); color: var(--ink); }
.rs-side__list a[aria-current="page"] { background: var(--white); color: var(--ink); font-weight: 600; box-shadow: 0 1px 0 var(--line); }
.rs-side__note { margin-top: auto; padding: 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }

.rs-main {
    min-width: 0;
    margin: 24px var(--gutter) 64px 0;
    padding: clamp(28px, 3vw, 48px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.rs-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 32px;
    flex-wrap: wrap;
}
.rs-title {
    margin-top: 10px;
    font-family: var(--serif);
    font-size: clamp(40px, 4.4vw, 60px);
    line-height: 1;
    letter-spacing: -0.02em;
}
.rs-head__note { max-width: 380px; color: var(--ink-2); font-size: 15px; }
.rs-foot { margin-top: 18px; font-size: 13px; color: var(--muted); }

/* ---------- Search ---------- */

.rs-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 32px;
    padding: 6px 6px 6px 50px;
    background: var(--gray-100);
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.rs-search:focus-within { background: var(--white); border-color: var(--navy); }
.rs-search__icon { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.rs-search input {
    flex: 1;
    min-width: 0;
    height: 48px;
    border: 0;
    background: transparent;
    font-family: var(--serif);
    font-size: 19px;
    color: var(--ink);
    outline: none;
}
.rs-search input::placeholder { color: #8b958e; }
.rs-search__btn { min-height: 46px; }

.rs-interpret {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    font-size: 13px;
}
.rs-interpret__label { font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; font-size: 11px; color: var(--muted); }
.rs-interpret__list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rs-interpret__list li { padding: 5px 10px; background: var(--ivory); border-radius: 8px; color: var(--ink); }
.rs-interpret__list b { font-weight: 600; color: var(--muted); margin-right: 4px; }

/* ---------- Filters ---------- */

.rs-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--line);
}
.rs-field { display: grid; gap: 6px; min-width: 0; flex: 1 1 150px; }
.rs-field--narrow { min-width: 92px; flex: 0 1 96px; }
.rs-field span { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.rs-field select,
.rs-sort select {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7584' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 12px center;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    cursor: pointer;
}
.rs-field select:hover, .rs-sort select:hover { border-color: var(--line-strong); }
.rs-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
}
.rs-check input { accent-color: var(--gold); width: 16px; height: 16px; }
.rs-reset {
    height: 42px;
    padding: 0 4px;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 14px;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.rs-reset:hover { color: var(--ink); }

/* ---------- Stats ---------- */

.rs-stats {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 24px;
    padding: 32px 0;
    border-bottom: 1px solid var(--line);
}
.rs-stats > div { display: flex; flex-direction: column; }
.rs-stat__num { font-family: var(--serif); font-size: clamp(36px, 3.6vw, 52px); line-height: 1; letter-spacing: -0.02em; }
.rs-stat__lab { margin-top: 10px; font-size: 12px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.rs-stats > .sample-tag { position: absolute; top: 14px; right: 0; }

/* ---------- Results + aside ---------- */

.rs-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr);
    gap: clamp(24px, 3vw, 48px);
    margin-top: 32px;
}

.rs-results__head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 8px; }
.rs-results__title { font-family: var(--serif); font-size: 26px; }
.rs-sort select { height: 38px; font-size: 13px; }

.rs-list { margin: 0; padding: 0; list-style: none; }
.rs-item { border-bottom: 1px solid var(--line); }
.rs-item__link {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 4px;
    text-decoration: none;
    transition: background-color 0.2s var(--ease), padding 0.2s var(--ease);
    border-radius: var(--radius-sm);
}
.rs-item__link:hover { background: var(--gray-100); padding-left: 12px; padding-right: 12px; }
.rs-item__main { min-width: 0; }
.rs-item__meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.rs-item__code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.rs-item__title { margin-top: 6px; font-family: var(--serif); font-size: 22px; line-height: 1.2; }
.rs-item__sub { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.rs-item__side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; text-align: right; }
.rs-item__year { font-family: var(--serif); font-size: 20px; line-height: 1; }

.rs-empty { padding: 48px 0; color: var(--ink-2); }
.rs-empty__title { font-family: var(--serif); font-size: 26px; color: var(--ink); margin-bottom: 8px; }

.rs-aside {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 100px;
    align-self: start;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scrollbar-width: thin;
}
.rs-card {
    padding: 20px;
    background: var(--gray-100);
    border-radius: 20px;
}
.rs-card__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.rs-card__title { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.rs-card__link { font-size: 13px; font-weight: 500; text-decoration: none; color: var(--ink-2); }
.rs-card__link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.rs-card__foot { margin-top: 10px; font-size: 12px; color: var(--muted); }

.rs-minimap {
    position: relative;
    aspect-ratio: 848 / 470;
    border-radius: var(--radius-md);
    background: radial-gradient(80% 60% at 50% 40%, #eef5ef 0%, var(--sea) 70%, var(--sea-2) 100%);
    overflow: hidden;
}
.rs-minimap .map { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); }
.rs-minimap .map__label { font-size: 15px; }
.rs-minimap .map__inset text { display: none; }
.rs-minimap .map__point-dot { r: 6; }
.rs-minimap .map__point-halo { r: 13; }

.rs-years {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 6px;
    height: 150px;
}
.rs-year {
    display: grid;
    grid-template-rows: 18px 1fr 18px;
    align-items: end;
    justify-items: center;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    color: var(--ink);
}
.rs-year__count { font-size: 12px; color: var(--ink-2); align-self: end; }
.rs-year__bar { position: relative; width: 100%; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.rs-year__bar span { display: block; width: 70%; max-width: 26px; background: var(--navy); border-radius: 4px 4px 0 0; transition: height 0.4s var(--ease); }
.rs-year:hover .rs-year__bar span { background: var(--navy-3); }
.rs-year.is-out .rs-year__bar span { background: rgba(27, 38, 32, 0.14); }
.rs-year__label { font-size: 12px; color: var(--muted); }

/* ==========================================================================
   /explore: full map
   ========================================================================== */

.page-explore .site-header { background: rgba(255, 255, 255, 0.92); }

.explore-app {
    position: relative;
    height: calc(100svh - 118px);
    min-height: 620px;
    background: radial-gradient(70% 70% at 55% 45%, #edf3f4 0%, var(--sea) 62%, var(--sea-2) 100%);
    overflow: hidden;
}
.explore-app .map {
    position: absolute;
    top: 150px; bottom: 120px;
    left: 400px; right: 48px;
    width: calc(100% - 448px);
    height: calc(100% - 270px);
    overflow: hidden;
}

.explore-top {
    position: absolute;
    top: 24px; left: 24px; right: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    pointer-events: none;
}
.explore-top > * { pointer-events: auto; }
.explore-heading { max-width: 360px; }
.explore-heading h1 {
    margin-top: 8px;
    font-family: var(--serif);
    font-size: clamp(30px, 3vw, 42px);
    line-height: 1.05;
    letter-spacing: -0.015em;
}

.explore-search {
    position: relative;
    display: flex;
    align-items: center;
    width: min(460px, 100%);
    padding: 4px 4px 4px 44px;
    border-radius: 999px;
}
.explore-search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.explore-search input {
    flex: 1;
    min-width: 0;
    height: 44px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 15px;
    color: var(--ink);
    outline: none;
}
.explore-search__results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    margin: 0; padding: 6px;
    list-style: none;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: 0 16px 40px rgba(27, 38, 32, 0.12);
    max-height: 320px;
    overflow-y: auto;
}
.explore-search__results button {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
}
.explore-search__results button:hover,
.explore-search__results button:focus-visible { background: var(--gray-100); }
.explore-search__results small { display: block; color: var(--muted); font-size: 12px; }

.explore-controls {
    position: absolute;
    top: 150px; left: 24px;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.explore-layers { display: flex; padding: 4px; border-radius: 999px; }
.explore-layers .map-toggle__btn { flex: 1; white-space: nowrap; padding: 0 12px; }
.explore-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px;
    border-radius: 18px;
}
.explore-cat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    color: var(--ink-2);
    cursor: pointer;
}
.explore-cat:hover { border-color: var(--line-strong); }
.explore-cat[aria-pressed="true"] { background: var(--navy); color: var(--ivory); }

.explore-app .map-panel {
    position: absolute;
    top: auto;
    left: 24px;
    bottom: 24px;
    width: 340px;
}
.explore-app .map-bar { bottom: 24px; left: auto; right: 24px; transform: none; }
.explore-app .map-credit { right: 24px; bottom: auto; top: 96px; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
    .research { grid-template-columns: 1fr; }
    .rs-side {
        position: static;
        height: auto;
        padding: 16px var(--gutter) 0;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }
    .rs-side__label, .rs-side__note { display: none; }
    .rs-side__list { display: flex; gap: 4px; }
    .rs-side__list a { white-space: nowrap; font-size: 14px; }
    .rs-main { margin: 16px var(--gutter) 48px; }
    .rs-grid { grid-template-columns: 1fr; }
    .rs-aside { flex-direction: row; flex-wrap: wrap; position: static; max-height: none; overflow: visible; }
    .rs-aside .rs-card { flex: 1 1 300px; }

    .explore-app .map { left: 32px; right: 32px; width: calc(100% - 64px); top: 300px; height: calc(100% - 430px); }
    .explore-controls { width: auto; right: 24px; top: 150px; }
    .explore-cats { flex-wrap: nowrap; overflow-x: auto; }
    .explore-cat { white-space: nowrap; }
}

@media (max-width: 760px) {
    .rs-main { padding: 22px 18px; border-radius: 20px; margin: 12px 12px 40px; }
    .rs-stats { grid-template-columns: 1fr 1fr; gap: 20px; }
    .rs-stats > .sample-tag { position: static; grid-column: 1 / -1; justify-self: start; }
    .rs-field { flex: 1 1 calc(50% - 6px); min-width: 0; }
    .rs-field--narrow { flex: 1 1 calc(50% - 6px); }
    .rs-check { flex: 1 1 100%; }
    .rs-search { padding-left: 42px; }
    .rs-search__icon { left: 16px; }
    .rs-search input { font-size: 16px; }
    .rs-item__link { flex-direction: column; gap: 10px; }
    .rs-item__side { flex-direction: row; align-items: center; flex-wrap: wrap; text-align: left; }
    .rs-item__year { font-size: 16px; }
}

@media (max-width: 860px) {
    /* Explore on phones and small tablets: map first, controls stacked beneath */
    .explore-app { height: auto; min-height: 0; display: flex; flex-direction: column; overflow: visible; }
    .explore-top { position: static; flex-direction: column; padding: 20px 16px 0; }
    .explore-search { width: 100%; }
    .explore-app .map { position: relative; inset: auto; width: 100%; height: auto; aspect-ratio: 848 / 470; margin: 12px 0; padding: 8px; order: 2; }
    .explore-controls { position: static; width: auto; padding: 0 16px; order: 3; }
    .explore-app .map-panel { position: relative; left: auto; bottom: auto; width: auto; margin: 12px 16px; order: 4; }
    .explore-app .map-bar { position: relative; right: auto; bottom: auto; margin: 0 16px 16px; order: 5; flex-wrap: wrap; white-space: normal; gap: 16px; justify-content: space-between; }
    .explore-app .map-credit { position: relative; top: auto; right: auto; margin: 0 16px 24px; order: 6; }
    .explore-top { order: 1; }
}
