/* ============================================================
   style.css — espeleoPT
   Palette: dark stone + terracotta + cream + moss
   ============================================================ */

/* ---------- Self-hosted fonts (latin subset, variable weight) ----------
   Inter for text, Source Serif 4 for headings. Served from assets/fonts/ so no
   third-party requests are made (no Google Fonts, better for privacy/GDPR). */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('../fonts/inter-latin-wght-normal.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: italic;
    font-weight: 100 900;
    font-display: swap;
    src: url('../fonts/inter-latin-wght-italic.woff2') format('woff2');
}
@font-face {
    font-family: 'Source Serif 4';
    font-style: normal;
    font-weight: 200 900;
    font-display: swap;
    src: url('../fonts/source-serif-4-latin-wght-normal.woff2') format('woff2');
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --stone-dark:   #1e1c1a;
    --stone-mid:    #2e2b27;
    --stone-light:  #3d3a34;
    --terra:        #b5592a;
    --terra-light:  #d4733f;
    --cream:        #e8e0d0;
    --cream-muted:  #a09080;
    --moss:         #4a5e3a;
    --moss-light:   #6a8050;
    --white:        #f5f0e8;

    --radius:       2px;
    --radius-lg:    3px;
    --shadow:       2px 2px 0 rgba(0,0,0,.35);
    --shadow-lg:    3px 3px 0 rgba(0,0,0,.4);

    --font-body:    'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-heading: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-mono:    'Courier New', monospace;

    /* Sidebar is wider: 30% wider at the cost of the left column */
    --sidebar-width: 440px;
}

html { scroll-behavior: smooth; }
body {
    background: var(--stone-dark);
    color: var(--cream);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.65;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
/* Form controls do not inherit the page font by default */
button, input, select, textarea { font-family: inherit; }

/* ---------- Nav ---------- */
.navbar {
    background: var(--stone-mid);
    border-bottom: 2px solid var(--terra);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 2rem;
    position: sticky;
    top: 0;
    z-index: 2000;
    flex-wrap: wrap;
}
.nav-brand {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 650;
    color: var(--terra-light);
    text-decoration: none;
    letter-spacing: .01em;
    white-space: nowrap;
}
.nav-links { display: flex; gap: .25rem; list-style: none; flex-wrap: wrap; }
.nav-links a {
    color: var(--cream-muted);
    text-decoration: none;
    padding: .35rem .9rem;
    border-radius: var(--radius);
    font-size: .92rem;
    transition: background .15s, color .15s;
}
.nav-links a:hover, .nav-links a.active { background: var(--stone-light); color: var(--cream); }
.nav-links a.active { color: var(--terra-light); font-weight: 600; }
.nav-search { margin-left: auto; display: flex; gap: .35rem; }
.nav-search input {
    background: var(--stone-dark);
    border: 1px solid var(--stone-light);
    color: var(--cream);
    padding: .4rem .7rem;
    border-radius: var(--radius);
    font-size: .88rem;
    outline: none;
    width: 180px;
    transition: border-color .15s;
}
.nav-search input:focus { border-color: var(--terra); }
.nav-search button {
    background: var(--stone-light);
    border: none;
    color: var(--cream);
    padding: .4rem .65rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .9rem;
}
.nav-search button:hover { background: var(--terra); }

/* ---------- Layout ---------- */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ---------- Page header ---------- */
.page-header { margin-bottom: 2rem; border-bottom: 1px solid var(--stone-light); padding-bottom: 1rem; }
.page-header h1 { font-family: var(--font-heading); font-size: 2.1rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; color: var(--white); }
.page-header .subtitle { color: var(--cream-muted); margin-top: .25rem; font-size: .95rem; }

/* ---------- Search / filter bar ---------- */
.search-bar { display: flex; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
.search-bar input, .search-bar select {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    color: var(--cream);
    padding: .5rem .85rem;
    border-radius: var(--radius);
    font-size: .92rem;
    outline: none;
    transition: border-color .15s;
}
.search-bar input:focus, .search-bar select:focus { border-color: var(--terra); }
.search-bar input[type="text"] { flex: 1; min-width: 200px; }

/* ---------- Buttons ---------- */
.btn {
    background: var(--terra);
    color: var(--white);
    border: none;
    padding: .5rem 1.1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .92rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: background .15s;
}
.btn:hover { background: var(--terra-light); }
.btn-outline { background: transparent; border: 1px solid var(--terra); color: var(--terra-light); }
.btn-outline:hover { background: var(--terra); color: var(--white); }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }

/* ---------- Catalog grid ---------- */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.25rem; }
.catalog-card {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-left: 3px solid transparent;
    border-radius: var(--radius-lg);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s;
    display: block;
}
.catalog-card:hover { border-color: var(--stone-light); border-left-color: var(--terra); }
.catalog-card .thumb { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--stone-light); }
.catalog-card .thumb-placeholder {
    width: 100%; aspect-ratio: 4/3; background: var(--stone-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 2.5rem; color: var(--cream-muted);
}
.catalog-card .card-body { padding: .75rem 1rem; }
.catalog-card .card-id {
    font-size: .75rem; color: var(--terra-light);
    font-weight: 600; letter-spacing: .03em;
}
.catalog-card .card-name {
    font-size: .98rem; font-weight: 500; color: var(--cream); margin-top: .15rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.catalog-card .card-synonym {
    font-size: .82rem; color: var(--cream-muted); font-style: italic; margin-top: .1rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.catalog-card .card-meta { font-size: .8rem; color: var(--cream-muted); margin-top: .2rem; }
.catalog-card .card-meta-row {
    font-size: .78rem; color: var(--cream-muted); margin-top: .25rem;
    display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
}

/* ---------- Detail page layout ---------- */
/* Sidebar is ~30% wider than before (340px -> 440px), left column shrinks accordingly */
.detail-layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: 2rem;
    align-items: start;
}
@media (max-width: 900px) {
    .detail-layout { grid-template-columns: 1fr; }
}

.detail-main h1 { font-family: var(--font-heading); font-size: 2rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; color: var(--white); }
.detail-id { color: var(--terra-light); font-size: .9rem; margin-bottom: .5rem; font-weight: 500; }

.info-table { width: 100%; border-collapse: collapse; margin: 1.25rem 0; }
.info-table th, .info-table td {
    padding: .55rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--stone-light);
    font-size: .9rem;
}
.info-table th { color: var(--cream-muted); font-weight: 500; width: 38%; white-space: nowrap; }
.info-table td { color: var(--cream); }

/* ---------- Sidebar ---------- */
/* Entrance photo and map are visually separated into two distinct cards */
.sidebar-photo-card {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 1rem;
}
.sidebar-map-card {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.entrance-photo {
    width: 100%;
    display: block;
    object-fit: cover;
    aspect-ratio: 4/3;
    cursor: pointer;
    transition: opacity .15s;
}
.entrance-photo:hover { opacity: .9; }
.entrance-placeholder {
    width: 100%; aspect-ratio: 4/3; background: var(--stone-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem; color: var(--cream-muted);
}
.sidebar-photo-meta {
    padding: .75rem 1rem;
    font-size: .95rem;
    color: var(--cream-muted);
    line-height: 1.4;
}
/* Map height matches entrance photo 4:3 aspect ratio */
.sidebar-map-container { width: 100%; aspect-ratio: 4/3; display: block; position: relative; }
.sidebar-coords {
    padding: .75rem 1rem;
    font-size: .95rem;
    color: var(--cream-muted);
}

/* ---------- Photo zoom overlay ---------- */
.photo-zoom-link { display: block; }
.photo-zoom-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.88);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.photo-zoom-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,.8);
}

/* ---------- Sections ---------- */
.section { margin-top: 2rem; }
.section-title {
    font-size: 1.05rem; font-weight: 500; color: var(--terra-light);
    margin-bottom: 1rem;
}

.section-title-white { color: var(--white); }

/* ---------- Logs ---------- */
.log-list { list-style: none; }
.log-item {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: .6rem;
}
/* log-date: keep terra color and size, but use the same body font (no monospace) */
.log-item .log-date {
    font-size: .85rem;
    color: var(--terra-light);
    font-family: var(--font-body);
    font-weight: 600;
}
.log-item .log-text { margin-top: .25rem; font-size: .92rem; }
.log-item .log-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px,1fr));
    gap: .35rem .75rem;
    margin-top: .5rem;
    font-size: .8rem;
    color: var(--cream-muted);
}
.log-item .log-meta-grid b { color: var(--cream); font-weight: 600; }

/* ---------- Gallery with captions ---------- */
.thumb-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.thumb-item { display: block; border-radius: var(--radius); overflow: hidden; text-decoration: none; }
.thumb-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; transition: opacity .15s; }
.thumb-item:hover img { opacity: .8; }
.thumb-caption {
    padding: .3rem .4rem;
    font-size: .72rem;
    color: var(--cream-muted);
    line-height: 1.3;
    background: var(--stone-mid);
}
.thumb-caption .thumb-desc { display: block; }
.thumb-caption .thumb-autor { display: block; color: var(--cream-muted); opacity: .8; }

/* ---------- Topografia cards ---------- */
.topo-card {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
}
.topo-card-header {
    padding: .55rem 1rem;
    display: flex;
    align-items: baseline;
    gap: .5rem;
    border-bottom: 1px solid var(--stone-light);
    font-size: .9rem;
    font-weight: 600;
}
.topo-card-header .topo-autor {
    color: var(--terra-light);
    font-weight: 400;
    font-size: .85rem;
}
.topo-card-body { padding: .75rem 1rem; }
.topo-img-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.topo-img-wrap img {
    max-width: 100%;
    border-radius: var(--radius);
    display: block;
    cursor: pointer;
    transition: opacity .15s;
}
.topo-img-wrap img:hover { opacity: .9; }
.topo-downloads { margin-top: .6rem; display: flex; gap: .75rem; flex-wrap: wrap; }

/* ---------- Sidebar photos section ---------- */
.sidebar-photos-section { margin-top: 1rem; }
.sidebar-photos-section .section-title { font-size: .95rem; }

/* ---------- Expandable blocks ---------- */
details.expand-block {
    background: var(--stone-mid); border: 1px solid var(--stone-light);
    border-radius: var(--radius); margin-bottom: .5rem;
}
details.expand-block summary {
    padding: .65rem 1rem; cursor: pointer; font-weight: 600; color: var(--cream);
    list-style: none; display: flex; justify-content: space-between; align-items: center;
    user-select: none;
}
details.expand-block summary::after { content: '▾'; color: var(--terra-light); }
details.expand-block[open] summary::after { content: '▴'; }
details.expand-block .expand-body { padding: .75rem 1rem 1rem; }

/* ---------- Related bibliography rows (cave.php) ---------- */
.bib-row {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    background: var(--stone-mid); border: 1px solid var(--stone-light);
    border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: .5rem;
}
.bib-row-text { min-width: 0; }
.bib-row-title { color: var(--white); font-weight: 500; line-height: 1.35; }
.bib-row-meta { color: var(--cream-muted); font-size: .85rem; margin-top: .15rem; }
.bib-row .btn { flex-shrink: 0; white-space: nowrap; }
@media (max-width: 480px) {
    .bib-row { flex-wrap: wrap; }
}

/* ---------- Maps ---------- */
.map-full { width: 100%; height: calc(100vh - 80px); border-radius: var(--radius-lg); overflow: hidden; position: relative; }
.map-fullscreen-btn {
    position: absolute; top: 10px; right: 10px; z-index: 500;
    background: var(--stone-mid); border: 1px solid var(--stone-light); color: var(--cream);
    width: 34px; height: 34px; border-radius: var(--radius); cursor: pointer; font-size: 1rem;
    display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
.map-fullscreen-btn:hover { background: var(--terra); border-color: var(--terra); }
.map-fullscreen-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) {
    .map-fullscreen-btn { width: 40px; height: 40px; }
}
/* Fallback "fullscreen" for browsers without the Fullscreen API (e.g. iPhone Safari) */
.map-pseudo-fullscreen {
    position: fixed !important;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: auto !important;
    max-width: none !important;
    border-radius: 0 !important;
    z-index: 3000;
}
html.map-fs-lock, html.map-fs-lock body { overflow: hidden; }

/* Leaflet popup */
.map-popup { font-size: .85rem; line-height: 1.5; min-width: 160px; }
.map-popup img.popup-thumb { width: 100%; max-width: 220px; height: 110px; object-fit: cover; border-radius: var(--radius); display: block; margin-bottom: .4rem; }
.map-popup .popup-title { font-weight: 600; color: #2e2b27; }
.map-popup .popup-line { color: #4a453d; margin-top: .15rem; }
.map-popup .popup-link { display: inline-block; margin-top: .4rem; color: #b5592a; font-weight: 600; text-decoration: none; }
.map-popup .popup-link:hover { text-decoration: underline; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: var(--radius); font-size: .75rem; font-weight: 600; background: var(--moss); color: #d4f0b0; }
.badge-yes     { background: #1f4a1f; color: #9be09b; }
.badge-no      { background: #4a1f1f; color: #e0a0a0; }
.badge-neutral { background: var(--stone-light); color: var(--cream-muted); }

/* ---------- Homepage stat squares ---------- */
.stat-square {
    background: var(--stone-mid); border: 1px solid var(--stone-light);
    border-radius: var(--radius-lg); padding: 1.25rem 1rem; text-align: center;
}
.stat-square-link {
    text-decoration: none; display: block; border-radius: var(--radius-lg);
    border: 1px solid var(--terra); border-top: 3px solid var(--terra);
    transition: background .15s;
}
.stat-square-link:hover .stat-square { background: var(--stone-light); }
.stat-square-link .stat-square { border: none; }
.stat-square-static .stat-square { cursor: default; }
.stat-count { font-family: var(--font-heading); font-size: 1.8rem; font-weight: 600; color: var(--terra-light); font-variant-numeric: lining-nums; }
.stat-label { font-size: .82rem; color: var(--cream-muted); margin-top: .15rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: .4rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    background: var(--stone-mid); border: 1px solid var(--stone-light); color: var(--cream-muted);
    padding: .35rem .75rem; border-radius: var(--radius); text-decoration: none; font-size: .88rem;
    transition: background .15s;
}
.pagination a:hover { background: var(--stone-light); color: var(--cream); }
.pagination .current { background: var(--terra); border-color: var(--terra); color: var(--white); font-weight: 600; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--cream-muted); }
.download-link {
    display: inline-flex; align-items: center; gap: .4rem; color: var(--terra-light);
    text-decoration: none; font-size: .9rem; padding: .3rem .6rem; border-radius: var(--radius);
    transition: background .15s;
}
.download-link:hover { background: var(--stone-light); }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error   { background: #3a1515; border: 1px solid #7a2020; color: #f0a0a0; }
.alert-success { background: #152a15; border: 1px solid #2a5a2a; color: #a0d0a0; }
.alert-info    { background: #15222a; border: 1px solid #204060; color: #90c0e0; }

.site-footer {
    background: var(--stone-mid); border-top: 1px solid var(--stone-light);
    text-align: center; padding: .75rem; font-size: .8rem; color: var(--cream-muted);
}
.site-footer a { color: var(--cream-muted); text-decoration: none; }
.site-footer a:hover { color: var(--cream); }

/* ---------- Contacts ---------- */
.contacts-list { list-style: none; }
.contacts-list li { padding: .5rem 0; border-bottom: 1px solid var(--stone-light); font-size: .92rem; }
.contacts-list li:last-child { border-bottom: none; }
.contacts-list a { color: var(--terra-light); text-decoration: none; font-weight: 600; }
.contacts-list a:hover { text-decoration: underline; }

/* ---------- Search results ---------- */
.result-group { margin-bottom: 2rem; }
.result-group h2 { font-family: var(--font-heading); font-size: 1.15rem; color: var(--terra-light); margin-bottom: .75rem; }
.result-row {
    display: flex; gap: .75rem; align-items: center; padding: .6rem .75rem;
    background: var(--stone-mid); border: 1px solid var(--stone-light); border-radius: var(--radius);
    margin-bottom: .5rem; text-decoration: none; color: inherit; transition: border-color .15s;
}
.result-row:hover { border-color: var(--terra); }
.result-row img { width: 48px; height: 48px; object-fit: cover; border-radius: var(--radius); flex-shrink: 0; }
.result-row .placeholder-icon {
    width: 48px; height: 48px; border-radius: var(--radius); background: var(--stone-light);
    display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0;
}
.result-row .result-name { font-weight: 600; font-size: .95rem; }
.result-row .result-meta { font-size: .8rem; color: var(--cream-muted); }

/* ---------- Cascade filter selects ---------- */
.cascade-filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.cascade-filters select { flex: 1; min-width: 140px; }

/* sidebar-card alias for bibliography_item.php (single card, no photo/map separation) */
.sidebar-card {
    background: var(--stone-mid);
    border: 1px solid var(--stone-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.sidebar-card .entrance-photo { width: 100%; display: block; object-fit: cover; max-height: 340px; }
.sidebar-card .entrance-placeholder {
    width: 100%; height: 200px; background: var(--stone-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem; color: var(--cream-muted);
}
.sidebar-card-body { padding: 1rem; }
@media (max-width: 600px) {
    .navbar { gap: 1rem; padding: .6rem 1rem; }
    .nav-search { width: 100%; margin-left: 0; order: 3; }
    .nav-search input { flex: 1; width: auto; }
    .main-content { padding: 1.25rem 1rem; }
    .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Hide the browser's up/down spinner arrows on numeric fields site-wide */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}