/* ==========================================================================
   DATABASE PAGE — Quad-Panel Layout
   A precision research instrument: map, search, timeline, results
   ========================================================================== */

/* ==========================================================================
   QUAD LAYOUT STRUCTURE
   ========================================================================== */

.db-layout {
  display: flex;
  flex-direction: row;
  height: 100%;
  position: relative;
}

.db-col-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.db-col-right {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.015);
}

[data-bs-theme="dark"] .db-col-right {
  background: rgba(255, 255, 255, 0.015);
}

/* Split.js gutter styling */
.gutter {
  background: var(--border-color);
  flex-shrink: 0;
  transition: background 0.15s;
}

.gutter:hover,
.gutter:active {
  background: var(--gold);
}

.gutter-horizontal {
  width: 5px;
  cursor: col-resize;
}

.gutter-vertical {
  height: 5px;
  cursor: row-resize;
}

/* ==========================================================================
   PANEL FOUNDATIONS
   ========================================================================== */

.db-panel {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem 0.3rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.02);
  flex-shrink: 0;
  min-height: 32px;
}

[data-bs-theme="dark"] .db-panel-header {
  background: rgba(255, 255, 255, 0.02);
}

.db-panel-title {
  font-family: 'Plantin MT Pro', serif;
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 0;
  line-height: 1;
}

.db-panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.db-panel-body-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Firefox scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

/* WebKit scrollbar */
.db-panel-body-scroll::-webkit-scrollbar {
  width: 6px;
}

.db-panel-body-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.db-panel-body-scroll::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.db-panel-body-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   MAP PANEL
   ========================================================================== */

#map-panel {
  overflow: hidden;
}

#map-panel .db-panel-body {
  position: relative;
}

#orations-map {
  width: 100%;
  height: 100%;
}

/* Leaflet control overrides for our color scheme */
.leaflet-control-zoom a {
  color: var(--navy) !important;
  border-color: var(--border-color) !important;
}

.leaflet-control-layers {
  border-color: var(--border-color) !important;
}

/* Map reset button */
.leaflet-control-reset a {
  font-size: 16px;
  line-height: 26px;
  text-align: center;
  color: var(--navy) !important;
  font-weight: 900;
  font-size: 26px;
  font-family: 'Plantin MT Pro';
  padding-top: 3px;
}

/* Dark mode overrides for Leaflet controls */
[data-bs-theme="dark"] .leaflet-control-zoom a {
  background-color: var(--dark-navy, #1a1f2e) !important;
  color: var(--text-dark) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

[data-bs-theme="dark"] .leaflet-control-zoom a:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .leaflet-control-layers {
  background-color: var(--dark-navy, #1a1f2e) !important;
  color: var(--text-dark) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

[data-bs-theme="dark"] .leaflet-control-layers label {
  color: var(--text-dark) !important;
}

[data-bs-theme="dark"] .leaflet-control-reset a {
  background-color: var(--dark-navy, #1a1f2e) !important;
  color: var(--text-dark) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

[data-bs-theme="dark"] .leaflet-control-reset a:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution {
  background-color: rgba(26, 31, 46, 0.8) !important;
  color: rgba(255, 255, 255, 0.5) !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution a {
  color: rgba(255, 255, 255, 0.6) !important;
}

/* Marker cluster custom styling */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  border-radius: 50%;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Plantin MT Pro', serif;
  font-weight: 600;
  color: var(--gold);
  background-color: var(--navy);
  border-radius: 50%;
  box-shadow: 2px -2px 4px rgba(27, 42, 74, 0.35);
}

.marker-cluster-small {
  background-color: transparent !important;
}
.marker-cluster-small div {
  width: 30px;
  height: 30px;
  font-size: 0.7rem;
}

.marker-cluster-medium {
  background-color: transparent !important;
}
.marker-cluster-medium div {
  width: 40px;
  height: 40px;
  font-size: 0.8rem;
}

.marker-cluster-large {
  background-color: transparent !important;
}
.marker-cluster-large div {
  width: 50px;
  height: 50px;
  font-size: 0.9rem;
}

/* Map popup styling */
.leaflet-popup-content-wrapper {
  border-radius: 2px;
  font-family: 'Plantin MT Pro', serif;
  font-size: 0.82rem;
  line-height: 1.45;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
  margin: 0.75rem 0.85rem;
}

.leaflet-popup-content .popup-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--navy);
  margin-bottom: 0.3rem;
  line-height: 1.25;
}

.leaflet-popup-content .popup-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.leaflet-popup-content .popup-meta span {
  display: block;
}

.leaflet-popup-content .popup-label {
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  color: var(--brick-red);
  margin-top: 0.4rem;
  margin-bottom: 0.1rem;
}

.leaflet-popup-content .popup-detail-link {
  margin-top: 0.4rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.7rem;
}

.leaflet-popup-content .popup-detail-link a {
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
}

.leaflet-popup-content .popup-detail-link a:hover {
  color: var(--brick-red);
}

[data-bs-theme="dark"] .leaflet-popup-content-wrapper {
  background: var(--parchment);
  color: var(--text-dark);
}

[data-bs-theme="dark"] .leaflet-popup-content .popup-title {
  color: var(--text-dark);
}

[data-bs-theme="dark"] .leaflet-popup-content .popup-detail-link a {
  color: var(--text-dark);
}

[data-bs-theme="dark"] .leaflet-popup-content .popup-detail-link a:hover {
  color: var(--brick-red);
}

[data-bs-theme="dark"] .leaflet-popup-tip {
  background: var(--parchment);
}

/* ==========================================================================
   SEARCH PANEL
   ========================================================================== */

#search-panel .db-panel-body-scroll {
  padding: 0.65rem 0.75rem;
}

/* Form elements — compact, archival-feeling */
.db-form-group {
  margin-bottom: 0.3rem;
}

.db-form-label {
  display: block;
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.db-form-control {
  display: block;
  width: 100%;
  padding: 0.3rem 0.5rem;
  font-family: 'Plantin MT Pro', serif;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-dark);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 1px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.db-form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(197, 165, 90, 0.15);
}

.db-form-control::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

[data-bs-theme="dark"] .db-form-control {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-color);
  color: var(--text-dark);
}

[data-bs-theme="dark"] .db-form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(197, 165, 90, 0.2);
}

select.db-form-control {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b6b6b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.5rem;
}

/* noUiSlider custom styling */
.slider-container {
  padding: 0rem 0.25rem 0.25rem 0.25rem;
}

.slider-range-label {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.5rem;
}

[data-bs-theme="dark"] .slider-range-label {
  color: var(--text-dark);
}

.noUi-target {
  background: var(--border-color) !important;
  border: none !important;
  box-shadow: none !important;
  height: 4px !important;
  border-radius: 2px !important;
}

.noUi-connect {
  background: var(--gold) !important;
}

.noUi-handle {
  width: 14px !important;
  height: 14px !important;
  border-radius: 50% !important;
  background: var(--navy) !important;
  border: 2px solid var(--gold) !important;
  box-shadow: none !important;
  cursor: grab;
  top: -5px !important;
  right: -7px !important;
}

.noUi-handle::before,
.noUi-handle::after {
  display: none !important;
}

.noUi-handle:active {
  cursor: grabbing;
}

.noUi-tooltip {
  font-family: 'Plantin MT Pro', serif;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--navy) !important;
  color: var(--gold) !important;
  border: none !important;
  border-radius: 1px !important;
  padding: 0.15rem 0.4rem !important;
}

/* Reset button */
.btn-reset {
  display: block;
  width: 100%;
  padding: 0.35rem 0.75rem;
  font-family: 'Plantin MT Pro', serif;
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 1px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  margin-top: 0.25rem;
}

.btn-reset:hover {
  color: var(--brick-red);
  border-color: var(--brick-red);
}

[data-bs-theme="dark"] .btn-reset:hover {
  color: var(--gold);
  border-color: var(--gold);
}

/* ==========================================================================
   TIMELINE + STATS PANEL
   ========================================================================== */

#timeline-panel .db-panel-body {
  display: flex;
  flex-direction: column;
}

#timeline-chart {
  flex: 65 0 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

#timeline-chart svg {
  width: 100%;
  height: 100%;
}

/* D3 chart styling */
.timeline-bar {
  fill: var(--navy);
  transition: opacity 0.2s;
  cursor: pointer;
}

.timeline-bar:hover {
  fill: var(--brick-red);
}

.timeline-bar.dimmed {
  opacity: 0.2;
}

.timeline-bar.selected {
  fill: var(--brick-red);
}

[data-bs-theme="dark"] .timeline-bar {
  fill: var(--gold);
}

[data-bs-theme="dark"] .timeline-bar:hover {
  fill: var(--gold-light);
}

.timeline-axis text {
  font-family: 'Plantin MT Pro', serif;
  font-size: 0.65rem;
  fill: var(--text-muted);
}

.timeline-axis line,
.timeline-axis path {
  stroke: var(--border-color);
}

[data-bs-theme="dark"] .timeline-axis text {
  fill: var(--text-muted);
}

[data-bs-theme="dark"] .timeline-axis line,
[data-bs-theme="dark"] .timeline-axis path {
  stroke: var(--border-color);
}

/* Stats sub-panel */
#stats-panel {
  flex: 35 0 0;
  min-height: 0;
  border-top: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.1rem 1rem;
}

.stat-block {
  flex: 1 0 45%;
  min-width: 0;
  padding: 0.2rem 0;
}

.stat-block-label {
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  line-height: 1.2;
}

.stat-block-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-bs-theme="dark"] .stat-block-value {
  color: var(--text-dark);
}

/* ==========================================================================
   RESULTS TABLE PANEL
   ========================================================================== */

#results-panel .db-panel-header {
  justify-content: space-between;
}

.results-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

#results-panel .db-panel-body-scroll {
  padding: 0;
}

#results-panel .dataTables_scrollBody {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#results-panel .dataTables_scrollBody::-webkit-scrollbar {
  width: 6px;
}

#results-panel .dataTables_scrollBody::-webkit-scrollbar-track {
  background: transparent;
}

#results-panel .dataTables_scrollBody::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

#results-panel .dataTables_scrollBody::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* DataTables overrides — compact, archival */
#results-panel .dataTables_wrapper {
  font-size: 0.75rem;
}

#results-panel .dataTables_wrapper .dataTables_length,
#results-panel .dataTables_wrapper .dataTables_filter,
#results-panel .dataTables_wrapper .dataTables_info {
  display: none; /* we provide our own search and info */
}

#results-panel table.dataTable {
  margin: 0 !important;
  width: 100% !important;
  border-collapse: collapse;
}

#results-panel table.dataTable thead th {
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.02);
  border-bottom: 1px solid var(--border-color) !important;
  padding: 0.4rem 0.5rem !important;
  white-space: nowrap;
}

[data-bs-theme="dark"] #results-panel table.dataTable thead th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted);
}

#results-panel table.dataTable tbody td {
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  color: var(--text-dark);
  vertical-align: top;
  line-height: 1.35;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-bs-theme="dark"] #results-panel table.dataTable tbody td {
  border-bottom-color: rgba(255, 255, 255, 0.04);
}

#results-panel table.dataTable tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

#results-panel table.table-striped > tbody > tr:nth-of-type(odd) > * {
  --bs-table-bg-type: rgba(0, 0, 0, 0.02);
}

[data-bs-theme="dark"] #results-panel table.table-striped > tbody > tr:nth-of-type(odd) > * {
  --bs-table-bg-type: rgba(255, 255, 255, 0.02);
}

#results-panel table.dataTable tbody tr:hover {
  background: rgba(197, 165, 90, 0.08) !important;
}

#results-panel table.dataTable tbody tr.selected {
  background: rgba(197, 165, 90, 0.15) !important;
}

/* DataTables pagination — compact */
#results-panel .dataTables_paginate {
  padding: 0.3rem 0.5rem !important;
  border-top: 1px solid var(--border-color);
  font-size: 0.65rem;
}

#results-panel .dataTables_paginate .paginate_button {
  /*padding: 0.15rem 0.4rem !important;*/
  font-size: 0.65rem !important;
  border-radius: 1px !important;
}

#results-panel .dataTables_paginate .paginate_button.current {
  background: var(--navy) !important;
  color: var(--gold) !important;
  border-color: var(--navy) !important;
}

.active>.page-link, .page-link.active {
    z-index: 3;
    color: var(--bs-pagination-active-color);
    background-color: var(--navy);
    border-color: var(--navy);
}

[data-bs-theme="dark"] .page-link, [data-bs-theme="dark"] .page-link:hover, [data-bs-theme="dark"] .page-link:focus, [data-bs-theme="dark"] .page-link:active, [data-bs-theme="dark"] .page-link.active {
  color: var(--gold);
}

.page-link, .page-link:hover, .page-link:focus, .page-link:active, .page-link.active {
  color: var(--brick-red);
  width: 35px;
  padding: 7px 7px 3px 5px;
}

.page-item:first-child .page-link, .page-item:last-child .page-link {
    padding-right: 14px;
}

/* Export buttons row */
.export-buttons {
  display: flex;
  gap: 0.25rem;
}

.export-buttons .dt-button {
  font-family: 'Plantin MT Pro', serif;
  font-size: 0.7rem !important;
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.4rem !important;
  background: transparent !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-muted) !important;
  border-radius: 1px !important;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.export-buttons .dt-button:hover {
  border-color: var(--gold) !important;
  color: var(--navy) !important;
}

[data-bs-theme="dark"] .export-buttons .dt-button:hover {
  color: var(--gold) !important;
}

/* ==========================================================================
   DETAIL OFFCANVAS — Full metadata view on row click
   ========================================================================== */

.offcanvas-detail {
  font-family: 'Plantin MT Pro', serif;
  background: var(--parchment);
  border-left: 2px solid var(--gold);
  max-width: min(420px, 100vw);
}

.offcanvas-detail .offcanvas-header {
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
}

.offcanvas-detail .offcanvas-title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
  color: var(--navy);
}

[data-bs-theme="dark"] .offcanvas-detail .offcanvas-title {
  color: var(--text-dark);
}

.offcanvas-detail .offcanvas-body {
  padding: 1rem;
  font-size: 0.85rem;
  line-height: 1.55;
}

.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section-title {
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--brick-red);
  margin-bottom: 0.4rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border-color);
}

[data-bs-theme="dark"] .detail-section-title {
  color: var(--gold);
}

.detail-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.15rem 0;
  font-size: 0.9rem;
}

.detail-label {
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
  padding-top: 0.1rem;
}

.detail-value {
  color: var(--text-dark);
  word-break: break-word;
}

.detail-citation {
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.detail-citation:last-child {
  border-bottom: none;
}

[data-bs-theme="dark"] .detail-citation {
  border-bottom-color: rgba(255, 255, 255, 0.04);
}

/* ==========================================================================
   RESPONSIVE — Stack panels below lg
   ========================================================================== */

@media (max-width: 991.98px) {
  .main-content-fixed {
    height: auto;
    overflow: auto;
    padding-bottom: var(--footer-height);
  }

  .db-layout {
    height: auto;
    flex-direction: column;
  }

  .db-col-left,
  .db-col-right {
    flex: none;
    width: 100% !important;
    border-right: none;
  }

  .db-col-left > .db-panel,
  .db-col-right > .db-panel {
    flex: none;
    height: auto !important;
  }

  .gutter {
    display: none;
  }

  /* Give panels explicit heights when stacked */
  #map-panel {
    height: 50vh !important;
  }

  #search-panel {
    height: auto !important;
  }

  #search-panel .db-panel-body-scroll {
    max-height: none;
    overflow: visible;
  }

  #timeline-panel {
    height: 35vh !important;
  }

  #results-panel {
    height: 50vh !important;
  }
}
