/* ── Global Variables ── */
:root {
    --lapis: #9e5237;
    --gold: #2A5F5A;
    --papyrus: #e7c9a5;
    --sand: #EDE0C8;
    --sand-bg: #E2D1B4;
    --text: #2c2c2c;
    --border: #c4956e;
    font-size: max(1rem, calc(12px + 0.2083vw));
}

/* ── Reset & Base ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Lato', sans-serif;
    color: var(--text);
    background: var(--papyrus);
    background-image: url("https://www.transparenttextures.com/patterns/sandpaper.png");
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--lapis);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    color: var(--gold);
    text-decoration: underline;
}

/* ── Typography ── */
h1, h2, .filter-subheading {
    font-family: 'Playfair Display', serif;
    letter-spacing: 1px;
}

em,
select option[style*="italic"],
select[style*="italic"],
.ts-italic {
    font-family: 'EB Garamond', 'Playfair Display', serif;
    font-size: 1.25em;
    line-height: 1;
}

/* Tom Select tweaks to match native select look */
.ts-wrapper.single {
    position: relative;
}
.ts-wrapper.single .ts-control {
    padding: 0.45rem 1.8rem 0.45rem 0.55rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    min-height: 0;
    box-shadow: none;
    transition: border-color 0.15s;
}
.ts-wrapper.single::after {
    content: "";
    position: absolute;
    right: 0.7rem;
    top: 50%;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--border);
    transform: translateY(-50%);
    pointer-events: none;
    transition: transform 0.15s;
}
.ts-wrapper.single.dropdown-active::after {
    transform: translateY(-50%) rotate(180deg);
}
.ts-wrapper.single.focus .ts-control,
.ts-wrapper.single .ts-control:focus-within {
    background-color: transparent;
    border-color: var(--lapis);
    box-shadow: 0 0 0 3px rgba(150, 82, 59, 0.2);
}
.ts-wrapper.single.input-active .ts-control,
.ts-wrapper.single.dropdown-active .ts-control,
.ts-wrapper.single.has-items .ts-control {
    background-color: transparent;
}
.ts-dropdown {
    background: #FAF0E1;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    margin-top: 2px;
    color: var(--text);
    font-size: 0.85rem;
}
.ts-dropdown .option {
    font-size: 0.85rem;
}
.ts-dropdown .active {
    background: rgba(150, 82, 59, 0.15);
    color: var(--text);
}
.ts-control .item.ts-italic,
.ts-control .item .ts-italic,
.ts-dropdown .option.ts-italic,
.ts-dropdown .option .ts-italic {
    font-style: italic;
    font-family: 'EB Garamond', 'Playfair Display', serif;
    font-size: 1.4em;
    line-height: 1;
}
.ts-wrapper.single .ts-control .item,
.ts-wrapper.single .ts-control .item.active,
.ts-wrapper.single.focus .ts-control .item {
    background: transparent;
    background-image: none;
    color: var(--text);
    padding: 0;
    box-shadow: none;
}
.ts-wrapper.single .ts-control > *:not(.item) {
    background-image: none;
}

/* ── Layout ── */
header {
    background:
        repeating-linear-gradient(
            90deg,
            rgba(255,255,255,0.03) 0px,
            rgba(255,255,255,0.03) 1px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(255,255,255,0.03) 0px,
            rgba(255,255,255,0.03) 1px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            45deg,
            rgba(255,255,255,0.04) 0px,
            rgba(255,255,255,0.04) 1px,
            transparent 1px,
            transparent 14px
        ),
        repeating-linear-gradient(
            -45deg,
            rgba(255,255,255,0.04) 0px,
            rgba(255,255,255,0.04) 1px,
            transparent 1px,
            transparent 14px
        ),
        var(--lapis);
    color: var(--sand);
    padding: 2.3rem 2rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
header h1 {
    font-size: 3rem;
    font-weight: 700;
}
header h1 a {
    color: #F9EDD5;
    text-decoration: none;
}
header h1 a:hover {
    color: #fff;
    text-decoration: none;
}

/* ── Tab Navigation ── */
.tab-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.tab-link {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.35rem 1.6rem 0.35rem 0.95rem;
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--gold);
    color: var(--sand);
    text-decoration: none;
    border: 1px solid var(--gold);
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.tab-link.tab-no-icon {
    padding: 0.35rem 2.6rem;
}
.tab-icon {
    height: 1em;
    width: auto;
    fill: currentColor;
    flex-shrink: 0;
}
.chevron-icon {
    height: 0.8em;
    width: auto;
    fill: currentColor;
    vertical-align: -0.05em;
    flex-shrink: 0;
}
.tab-link:hover {
    background: #224E4A;
    border-color: #224E4A;
    color: var(--sand);
    text-decoration: none;
}
.tab-link.active {
    background: #1B403C;
    border-color: #1B403C;
    color: var(--sand);
    font-weight: 600;
}

/* ── Page Layout with Sidebar ── */
.page-layout {
    flex: 1;
    width: 100%;
    overflow-x: hidden;
}

main {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    padding: 1.5rem 2rem;
}

.sidebar {
    position: fixed;
    right: 2rem;
    top: calc(var(--header-height, 80px) + 5rem);
    width: 280px;
    padding: 0 0 1rem;
    display: none;
    align-items: flex-start;
    justify-content: center;
    pointer-events: none;
}

.page-record .sidebar {
    top: calc(var(--header-height, 80px) + 4.3rem);
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar-img {
    max-width: 100%;
    max-height: 75vh;
    object-fit: contain;
    opacity: 0.75;
}

.sidebar-credit {
    margin-top: 0.5rem;
    font-size: 0.65rem;
    color: #999;
    text-align: center;
    line-height: 1.3;
}

/* Wide enough for sidebar: show it and offset content */
@media (min-width: 1750px) {
    .sidebar {
        display: flex;
    }
    main {
        margin-right: 300px;
    }
}

/* Extra wide: scale sidebar with viewport */
@media (min-width: 1900px) {
    .sidebar {
        width: max(280px, calc((100vw - 1400px) / 2));
    }
    .sidebar-img {
        max-width: clamp(280px, calc(-66px + 18.2vw), 480px);
    }
    main {
        margin-right: max(300px, calc((100vw - 1400px) / 2 + 20px));
    }
}

footer {
    background:
        repeating-linear-gradient(
            90deg,
            rgba(255,255,255,0.03) 0px,
            rgba(255,255,255,0.03) 1px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(255,255,255,0.03) 0px,
            rgba(255,255,255,0.03) 1px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            45deg,
            rgba(255,255,255,0.04) 0px,
            rgba(255,255,255,0.04) 1px,
            transparent 1px,
            transparent 14px
        ),
        repeating-linear-gradient(
            -45deg,
            rgba(255,255,255,0.04) 0px,
            rgba(255,255,255,0.04) 1px,
            transparent 1px,
            transparent 14px
        ),
        var(--lapis);
    color: var(--sand);
    margin-top: 3rem;
    padding: 2rem 2rem;
    font-size: 0.85rem;
    line-height: 1.6;
}

footer a {
    color: #f5d8a8;
    text-decoration: underline;
    text-decoration-color: rgba(245, 216, 168, 0.5);
    text-underline-offset: 2px;
}

footer a:hover {
    color: #ffffff;
    text-decoration-color: #ffffff;
}

footer p {
    margin-bottom: 0.4rem;
}

footer p:last-child {
    margin-bottom: 0;
}

.footer-content {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.footer-logo {
    height: 130px;
    width: auto;
    flex-shrink: 0;
}

.footer-text {
    flex: 1;
}

.footer-eu {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(245, 216, 168, 0.25);
}

.footer-eu-logo {
    height: 56px;
    width: auto;
    flex-shrink: 0;
    background: #fff;
    padding: 8px 12px;
    border-radius: 6px;
}

.footer-disclaimer {
    flex: 1;
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.5;
    color: rgba(245, 234, 214, 0.85);
}

/* ── Search Section ── */
.search-section,
.filter-section {
    background: #FAF0E1;
    border-radius: 8px;
    padding: 1.25rem 1.5rem 2.25rem;
    margin-bottom: 1rem;
}

.search-section h2,
.filter-section h2 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    color: var(--gold);
    padding-bottom: 0.5rem;
}

.search-fields,
.filter-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.filter-subsection {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
}
.filter-subsection:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.filter-subheading {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gold);
    margin-bottom: 0.5rem;
    letter-spacing: 0.03em;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
}

.label-help {
    font-size: 0.78rem;
    color: #6f7785;
    font-weight: 400;
}

.text-with-match {
    display: flex;
    gap: 0.35rem;
}

.text-with-match input {
    flex: 1;
    min-width: 0;
}

.text-with-match select,
.text-with-match .ts-wrapper {
    width: 130px;
    flex-shrink: 0;
}

input[type="text"],
select {
    padding: 0.45rem 0.55rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s;
}
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--lapis);
    box-shadow: 0 0 0 3px rgba(150, 82, 59, 0.2);
}

/* ── Autocomplete ── */
.text-with-match {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 130px;
    background: #FAF0E1;
    border: 1.5px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    scrollbar-width: thin;
    scrollbar-color: var(--sand-bg) #FAF0E1;
}

.autocomplete-list div {
    padding: 0.4rem 0.55rem;
    cursor: pointer;
    font-size: 0.88rem;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autocomplete-list div:last-child {
    border-bottom: none;
}

.autocomplete-list div:hover,
.autocomplete-list div.ac-active {
    background: var(--sand-bg);
}

.autocomplete-list div mark {
    background: rgba(150, 82, 59, 0.2);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

@media (max-width: 768px) {
    .autocomplete-list {
        right: 0;
    }
}

/* ── Toggle Button ── */
.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--lapis);
    padding: 0;
}
.toggle-btn:hover {
    color: var(--gold);
}

.filter-panel {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease;
}
.filter-panel.collapsed {
    max-height: 0;
}

/* ── Buttons ── */
.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.btn {
    display: inline-block;
    box-sizing: border-box;
    padding: 0.5rem 1.1rem;
    min-width: 6.5rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.4;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    text-align: center;
    transition: background-color 0.15s, color 0.15s;
}

.btn-search,
.btn-reset {
    background: var(--lapis);
    color: #F7F0E2;
    font-size: 1.1rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}
.btn-search:hover,
.btn-reset:hover {
    background: #7A4230;
    text-decoration: none;
    color: var(--sand);
}

/* ── Results ── */
.results-section {
    margin-top: 0.5rem;
}

.results-header {
    margin-bottom: 0.75rem;
    color: #555;
    font-size: 0.95rem;
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 75vh;
    background: #FAF0E1;
    border-radius: 8px;
    /* Styled scrollbars (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: var(--sand-bg) #FAF0E1;
}
/* Styled scrollbars (Chrome/Safari/Edge) */
.table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.table-wrapper::-webkit-scrollbar-track {
    background: var(--sand-bg);
    border-radius: 4px;
}
.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #224E4A;
}
.table-wrapper::-webkit-scrollbar-corner {
    background: var(--sand-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    white-space: nowrap;
}

thead th {
    position: sticky;
    top: 0;
    background:
        repeating-linear-gradient(90deg, rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 1px, transparent 1px, transparent 20px),
        repeating-linear-gradient(0deg, rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 1px, transparent 1px, transparent 20px),
        repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0px, rgba(255,255,255,0.04) 1px, transparent 1px, transparent 14px),
        repeating-linear-gradient(-45deg, rgba(255,255,255,0.04) 0px, rgba(255,255,255,0.04) 1px, transparent 1px, transparent 14px),
        var(--gold);
    color: var(--sand);
    padding: 0.6rem 0.7rem;
    text-align: left;
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    z-index: 2;
}

.results-loading {
    opacity: 0.55;
    transition: opacity 0.1s ease;
    pointer-events: none;
}

/* ── Sortable column headers ── */
thead th.sortable-th {
    padding: 0;
}
thead th.sortable-th .sort-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.6rem 0.7rem;
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
thead th.sortable-th .sort-link:hover {
    background: rgba(0, 0, 0, 0.08);
}
.sort-indicator {
    font-size: 0.8rem;
    flex-shrink: 0;
}
.sort-indicator-idle {
    opacity: 0.4;
}
thead th.sortable-th.sorted .sort-link {
    background: rgba(0, 0, 0, 0.12);
}

tbody td {
    padding: 0.7rem 0.7rem;
    border-bottom: 1px solid #eee;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Frozen columns: # and OG No ── */
thead th.col-frozen {
    position: sticky;
    z-index: 3;
}
tbody td.col-frozen {
    position: sticky;
    background: #FAF0E1;
    z-index: 1;
}
tbody tr:hover td.col-frozen {
    background: #F5EBDA;
}
.col-frozen-0 {
    left: 0;
}
.col-frozen-1 {
    left: var(--frozen-col-0-width, 3rem);
    box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}

tbody tr.row-even {
    background: #F0E4D0;
}

tbody tr.clickable-row:hover {
    background: #fff9eb !important;
}

td.row-num {
    color: #999;
    font-size: 0.8rem;
    text-align: right;
    width: 3rem;
}

td.col-bib {
    max-width: 400px;
    font-size: 0.8rem;
}

td.col-bib[data-full] {
    cursor: default;
}

.bib-tooltip {
    position: fixed;
    background: #FAF0E1;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: normal;
    max-width: 500px;
    width: max-content;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 9999;
    pointer-events: none;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn-page {
    padding: 0.35rem 0.7rem;
    font-size: 0.92rem;
    background: #FAF0E1;
    border: 1px solid var(--border);
    color: var(--lapis);
}
.btn-page:hover {
    background: var(--sand-bg);
    color: var(--lapis);
    text-decoration: none;
}
.btn-page.active {
    background: var(--lapis);
    color: #fff;
    border-color: var(--lapis);
    pointer-events: none;
}

.no-results {
    padding: 2rem;
    text-align: center;
    color: #888;
    font-size: 1rem;
    background: #FAF0E1;
    border: 1px solid var(--border);
    border-radius: 8px;
}

/* ── Titles browse (list of distinct titles) ── */
.title-filter-wrap {
    margin-bottom: 1.25rem;
}
.title-filter-input {
    width: 100%;
    max-width: 28rem;
    padding: 0.6rem 0.9rem;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    background: #FAF0E1;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.title-filter-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(42, 95, 90, 0.2);
}

.titles-hint {
    margin-bottom: 0.85rem;
    color: #6f7785;
    font-size: 0.9rem;
    font-style: italic;
}

.titles-list {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}
.title-category-group {
    background: #FAF0E1;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.title-category-group[hidden] {
    display: none;
}
.title-category-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.title-category-summary::-webkit-details-marker {
    display: none;
}
.title-category-summary:hover {
    background: var(--sand);
}
/* When expanded, separate the header from its title list so the hover
   highlight reads as its own region instead of bleeding into the cards. */
.title-category-group[open] > .title-category-summary {
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.85rem;
}
.cat-chevron {
    flex-shrink: 0;
    width: 0.85rem;
    height: 0.85rem;
    fill: var(--gold);
    transform: rotate(-90deg);
    transition: transform 0.15s;
}
.title-category-group[open] > .title-category-summary .cat-chevron {
    transform: rotate(0deg);
}
.title-category-heading {
    flex: 1;
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem;
    color: var(--gold);
}
.title-category-count {
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: #6f7785;
    white-space: nowrap;
}

.title-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.5rem;
    padding: 0 1rem 1rem;
}
.title-list-item[hidden] {
    display: none;
}
.title-list-item a {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    background: #FAF0E1;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    transition: background-color 0.15s, border-color 0.15s;
}
.title-list-item a:hover {
    background: var(--sand);
    border-color: var(--gold);
    text-decoration: none;
}
.title-name {
    font-family: 'EB Garamond', serif;
    font-size: 1.05rem;
}
.title-count {
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
}

/* ── Titles detail (women who held a title) ── */
.btn-back-titles {
    background: #FAF0E1;
    border: 1px solid var(--border);
    color: var(--lapis);
    margin-bottom: 1rem;
}
.btn-back-titles:hover {
    background: var(--sand-bg);
    color: var(--lapis);
    text-decoration: none;
}
.title-detail-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    color: var(--gold);
    margin-bottom: 0.35rem;
}
.title-detail-header h2 em {
    font-family: 'EB Garamond', serif;
}

/* ── Clickable Rows ── */
.clickable-row {
    cursor: pointer;
}

.clickable-row td a {
    color: var(--lapis);
    font-weight: 500;
}
.clickable-row td a:hover {
    text-decoration: underline;
}

/* ── Breadcrumb ── */
.breadcrumb {
    font-size: 1.1rem;
    font-weight: 700;
    color: #666;
    margin-bottom: 1rem;
}
.breadcrumb a {
    color: var(--lapis);
}
.breadcrumb span {
    color: #333;
    font-weight: 500;
}

/* ── Record Detail ── */
.record-detail {
    background: #FAF0E1;
    border-radius: 8px;
    padding: 1.5rem;
}

.record-detail h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2.3rem;
    margin-bottom: 1.25rem;
    color: var(--gold);
}

.record-detail .record-id {
    font-size: 1rem;
    font-weight: 400;
    color: #888;
    margin-left: 0.5rem;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table th,
.detail-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: none;
    text-align: left;
    vertical-align: top;
    font-size: 0.9rem;
}

.detail-table tr:nth-child(even) th,
.detail-table tr:nth-child(even) td {
    background: #F0E4D0;
}

.detail-table th {
    width: 200px;
    font-weight: 600;
    color: var(--lapis);
    white-space: nowrap;
}

.detail-table td {
    color: var(--text);
    word-break: break-word;
    white-space: normal;
}

.detail-table .empty-row td {
    color: #bbb;
}

/* ── Cell Truncation (mobile) ── */
.cell-content.cell-truncatable {
    max-height: 3.2em;
    overflow: hidden;
}

.cell-content.cell-expanded {
    max-height: none;
}

.cell-toggle {
    display: inline-block;
    color: var(--lapis);
    cursor: pointer;
    font-size: 0.85em;
    user-select: none;
    opacity: 0.7;
    margin-top: 0.15em;
}

.cell-toggle:hover {
    opacity: 1;
    color: var(--gold);
}

/* ── Associated Minor Females ── */
.btn-minor-females {
    background: transparent;
    color: var(--lapis);
    border: 1px solid var(--lapis);
    padding: 0.3rem 0.7rem 0.3rem 0rem;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 400;
    cursor: pointer;
    white-space: nowrap;
}
.btn-minor-females:hover {
    background: rgba(150, 82, 59, 0.12);
}
.btn-minor-females:not(.btn-minor-females-detail) {
    border: none;
}

.minor-females-row td {
    background: #FAF0E1;
    padding: 0.75rem 1rem;
}
.minor-females-row:hover {
    background: #FAF0E1 !important;
}

.minor-females-content {
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--sand-bg) #FAF0E1;
}
.minor-females-content::-webkit-scrollbar {
    height: 8px;
}
.minor-females-content::-webkit-scrollbar-track {
    background: var(--sand-bg);
    border-radius: 4px;
}
.minor-females-content::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}

.minor-females-table {
    width: auto;
    border-collapse: collapse;
    font-size: 0.92rem;
    white-space: nowrap;
}
.minor-females-table thead th {
    background: var(--sand-bg);
    color: var(--text);
    padding: 0.4rem 0.7rem;
    font-size: 0.92rem;
}
.minor-females-table tbody td {
    padding: 0.35rem 0.7rem;
    border-bottom: 1px solid #e0e0e0;
}
.minor-females-table a {
    color: var(--lapis);
    font-weight: 500;
}

.btn-minor-females-detail {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    background: var(--gold);
    color: var(--sand);
    border: 1px solid var(--gold);
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.5rem 1.6rem 0.5rem 0.95rem;
}
.btn-minor-females-detail:hover {
    background: #224E4A;
    border-color: #224E4A;
    color: var(--sand);
}

.associated-minor-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.associated-minor-section .minor-females-content {
    margin-top: 0.75rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    main {
        padding: 1rem;
    }
    .tab-nav {
        flex-direction: column;
        align-items: stretch;
        overflow-x: visible;
        gap: 0.4rem;
    }
    .tab-link,
    .tab-link.tab-no-icon {
        justify-content: center;
        padding: 0.55rem 1rem;
    }
    .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    .form-actions .btn {
        width: 100%;
    }
    footer {
        padding: 1.5rem 1rem;
    }
    .footer-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.25rem;
    }
    .footer-logo {
        height: 100px;
    }
    .footer-text p {
        margin-bottom: 0.7rem;
    }
    .footer-eu {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1rem;
    }
    .footer-eu-logo {
        height: 48px;
        max-width: 100%;
    }
    .search-fields,
    .filter-fields {
        grid-template-columns: 1fr;
    }
    .text-with-match {
        flex-direction: column;
    }
    .text-with-match select {
        width: 100%;
    }
    .field-group {
        min-width: 0;
    }
    .field-group select {
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .detail-table th {
        width: auto;
        min-width: 80px;
    }
    .minor-females-content {
        overflow-x: auto;
    }
    .minor-females-table {
        width: 100%;
        white-space: normal;
    }
    .minor-females-table tbody td {
        white-space: normal;
        word-break: break-word;
    }
}

/* Mobile-only synthetic cells hidden on desktop */
.mobile-toggle-cell,
.mobile-only-cell { display: none; }

.mobile-tag {
    display: inline-block;
    background: var(--lapis);
    color: #F7F0E2;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-right: 0.7rem;
    width: 4.5rem;
    box-sizing: border-box;
    text-align: center;
    vertical-align: middle;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.mobile-tag-minor {
    background: var(--gold);
}

@media (max-width: 520px) {
    .table-wrapper { overflow: visible; max-height: none; background: transparent; }
    .table-wrapper table,
    .table-wrapper tbody { display: block; width: 100%; }
    .table-wrapper thead { display: none; }
    .table-wrapper tr.clickable-row {
        display: block;
        position: relative;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #FAF0E1;
        padding: 0.6rem 2.6rem 0.6rem 0.8rem;
        margin-bottom: 0.5rem;
    }
    .table-wrapper tr.clickable-row.row-even {
        background: #F3E6CC;
    }
    .table-wrapper tr.clickable-row > td {
        display: none;
        padding: 0.15rem 0;
        border: none;
        position: static;
        width: auto;
        min-width: 0;
        max-width: none;
        white-space: normal;
    }
    .table-wrapper tr.clickable-row > td.col-mobile-primary,
    .table-wrapper tr.clickable-row > td.mobile-only-cell {
        display: block;
        font-size: 1.05rem;
    }
    .table-wrapper tr.clickable-row.expanded > td.col-mobile-expanded {
        display: block;
        font-size: 0.9rem;
    }
    .table-wrapper tr.clickable-row.expanded > td.col-mobile-expanded::before {
        content: attr(data-label) ": ";
        font-weight: 600;
    }
    .table-wrapper tr.clickable-row > td.mobile-toggle-cell {
        display: block;
        position: absolute;
        top: 0.3rem;
        right: 0.3rem;
        padding: 0;
    }
    .row-toggle {
        background: transparent;
        border: none;
        color: var(--text);
        cursor: pointer;
        padding: 0.3rem 0.5rem;
        font-size: 1rem;
        line-height: 1;
    }
    .row-toggle .chevron-icon { transition: transform 0.15s; }
    .table-wrapper tr.expanded .row-toggle .chevron-icon { transform: rotate(180deg); }
    .table-wrapper tr.minor-females-row { display: none; }
    .table-wrapper tr.minor-females-row[style*="display: block"],
    .table-wrapper tr.minor-females-row[style*="display:block"] { display: block !important; }
    .table-wrapper tr.minor-females-row td { display: block; padding: 0.5rem 0.8rem; }
}

/* ── Bibliography: results grouped by publication ── */
.bib-group-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.bib-group {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: #FAF0E1;
    overflow: hidden;
}
.bib-group-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.7rem 1rem;
    color: var(--text);
    font-size: 1rem;
}
.bib-group-header:hover {
    background: rgba(150, 82, 59, 0.08);
}
.bib-group-header .chevron-icon {
    transition: transform 0.15s;
    color: var(--lapis);
}
.bib-group-header.expanded .chevron-icon {
    transform: rotate(180deg);
}
.bib-group-title {
    flex: 1;
    font-weight: 500;
    color: var(--lapis);
}
.bib-group-count {
    flex-shrink: 0;
    font-size: 0.85rem;
    color: var(--gold);
    white-space: nowrap;
}
.bib-group-body {
    padding: 0 1rem 0.75rem 1rem;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--sand-bg) #FAF0E1;
}
.bib-records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.bib-records-table thead th {
    background: var(--sand-bg);
    color: var(--text);
    padding: 0.4rem 0.7rem;
    text-align: left;
    white-space: nowrap;
}
.bib-records-table tbody td {
    padding: 0.35rem 0.7rem;
    border-bottom: 1px solid #e0e0e0;
    vertical-align: top;
}
.bib-records-table a {
    color: var(--lapis);
    font-weight: 500;
}
