@font-face {
  font-family: Inter;
  src: url("../fonts/Inter-Regular.ttf");
}

h1,
a,
body,
.tooltip,
.dashboard {
  font-family: Inter, Helvetica, sans-serif;
}

html, body {
  background-color: #FFFAEC;
  /* remove browser default settings */
  margin: 0;
  padding: 0;
}

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

.navbar {
  background-color: #16404D;
  display: flex;
  align-items: center;
  height: 2.8rem;
  padding-inline: 10px;
  border-bottom: 1px solid;
  justify-content: space-between;
}

.nav-btn {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0;
}

#lang-btn img {
  width: 1.2rem;
  height: 1.2rem;
}

.title {
  color: #FAF7F4;
  font-weight: 600;
  font-size: x-large;
  margin: 0;
}

.navbar > ul {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  color: #FAF7F4;
  font-weight: 500;
}

.navbar > ul > li {
  display: inline-flex;
  align-items: center;
}

#download-icon {
  width: 1.2rem;
}

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

#export-btn {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dropdown { position: relative; }

.dropdown-menu {
  position: absolute; right: 0; top: 100%;
  background: #F5ECD5; border: 1px solid #16404D;
  border-radius: 6px; list-style: none; padding: 4px 0;
  min-width: 140px; z-index: 100;
  display: none;
  flex-direction: column;
}

.dropdown-menu.open { display: flex; }

.dropdown-menu li a {
  display: block; padding: 6px 12px; font-size: .75rem;
  color: #16404D; text-decoration: none; white-space: nowrap;
}

.dropdown-menu li a:hover { background: #D6E5DB; }

.dropdown-menu li {
  display: block;        /* overrides “inline” from .navbar li */
}

.dropdown-menu li a:hover {
  background: #D6E5DB;
  cursor: pointer;       /* visible hover feedback */
}

.dashboard-wrap {
  position: absolute;
  top: 2.8rem;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  overflow: hidden;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr 10rem;
  height: 100%;
  grid-template-rows: 1.25fr 1fr;
  gap: 15px;
}

.dashboard > * {
  min-width: 0;
}

.visualization {
  padding: 0.5rem;
  background-color: #F5ECD5;
  border-radius: 24px;
  position: relative;
}

.dashboard .visualization {
  min-height: 0;
  z-index: 0;
}

#modal-shield {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  z-index: 9998;
}

#conflict-popup,
#no-results-popup {
  z-index: 9999;
}

#conflict-keep-btn {
  border: none;
}

/* EXPANDABLE VISUALIZATION DETAILS */

.expand-btn {
  position: absolute;
  top: 4px;
  right: 8px;
  width: 22px; height: 22px;
  background: transparent;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.expand-btn:hover { background: #D6E5DB; }

.expand-btn img {
  width: 14px;
  height: 14px;
}

.viz-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.60);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}

.viz-panel {
  background: #F5ECD5;
  border-radius: 24px;
  width: 80vw; height: 80vh;
  padding: 1rem; overflow: hidden;
}

.viz-panel>.visualization { width: 100%; height: 100%; }

.viz-placeholder {
  visibility: hidden;
}

/* -------MAP------- */

#map-area {
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  flex: 2 1 0;
}

.map-canvas {
  flex: 1 1 0;
  position: relative;
  display: flex;
}

.map-canvas svg { width: 100%; height: auto; }

#map-area .map-canvas { position: relative; }

#map-area .map-canvas.blurred svg#map {
  filter: blur(2px);
  transition: filter .15s ease;
}

#map-area svg#map {
  width: 100%;
  background-color: white;
}

.map-offhint--hidden {
    visibility: hidden;
    pointer-events: none;
}

.map-nolocation-overlay {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 250, 236, 0.75);
  backdrop-filter: blur(2.5px) brightness(.8);
  -webkit-backdrop-filter: blur(2.5px) brightness(.8);
  font: 600 0.85rem/1 Inter, sans-serif;
  color: #16404D;
  text-align: center;
  pointer-events: none;
  z-index:3;
}

.map-nolocation-overlay[hidden] { display:none !important; }

.library-point.hovered-map-point {
  fill: red !important;
}

.map-color-scale {
  display: flex;
  flex-direction: column;
  padding-left: 6px;
  position: relative;
  z-index: 1;
  flex: 0 1 70px;
  min-width: 70px;
}

.map-offhint {
  margin: 4px 0 0;
  font-size: 0.6rem;
  font-style: italic;
  color: #606060;
  text-align: right;
  position: relative;
}

.map-color-scale .legend-title {
  font-size: 0.6rem;
  text-align: left;
  color: #16404D;
  margin-bottom: 8px;
  flex: 0 0 auto;
  display: inline-block;
  max-width: calc(100% - 30px);
  white-space: normal;
  word-wrap: break-word;
}

.map-color-scale .bar-wrapper {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: visible;
  width: 0.6em;
}

.map-color-scale .bar-wrapper .legend-bar {
  width: 100%;
  border: 0.5px solid #16404D;
  border-radius: 4px;
  position: relative;
}

.map-color-scale .bar-wrapper .legend-bar + .legend-bar {
  margin-top: -4px;
}

.map-color-scale .bar-wrapper .legend-bar .legend-label {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateX(4px) translateY(-50%);
  font-size: 0.55rem;
  color: #16404D;
  white-space: nowrap;
  pointer-events: none;
}

circle.library-point.location-dim {
  opacity: 0.25;
}

circle.library-point.location-selected {
  opacity: 1;
  stroke: #16404D !important;
  stroke-width: 1px;
}

#map.is-expanded circle.library-point.location-selected {
  stroke-width: 1px;
}

.zoom-button {
    cursor: pointer;
}

.zoom-button-bg {
    fill: #FFFAEC;
    stroke: #16404D;
    stroke-width: 1px;
}

.zoom-button:hover .zoom-button-bg { fill: #F0E7CF; }

.zoom-button.disabled { pointer-events: none; cursor: default; }

.zoom-button.disabled .zoom-button-bg {
  fill: #EAE4D2;
  stroke: #9a9a9a;
}

.zoom-button.disabled .zoom-icon { fill: #9a9a9a; }

.europe-outline {
    fill: #16404D;
}

.zoom-button:hover .zoom-button-bg {
    fill: #f0f0f0;
}

.zoom-button:hover .zoom-icon {
  font-weight: 900;
}

.zoom-icon   { fill: #16404D; font-weight: 700; }

.zoom-button.disabled {
    pointer-events: none;
    cursor: default;
}

.zoom-button.disabled .zoom-button-bg {
    fill: #d0d0d0;
    stroke: #9a9a9a;
}

.zoom-button.disabled .zoom-icon {
    fill: #9a9a9a;
}

.world-land {
  fill: #16404D;
}

.library-point {
  stroke: #16404D;
  stroke-width: 0.5;
  cursor: pointer;
}

#undo-last-btn {
  border: none;
}

.library-point.books-15plus   { fill: #7F5F24; }
.library-point.books-6to14   { fill: #B89B3C; }
.library-point.books-1to5     { fill: #F0E3C0; }

.map-tooltip {
  position: absolute;
  text-align: center;
  padding: 3px 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.6rem;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  text-align: left;
  z-index: 3000;
}

.map-limit-toast {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: #D6E5DB;
  color: #16404D;
  border: 1px solid #16404D;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.7rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 10;
}

.map-limit-toast.open {
  opacity: 1;
  transform: translateY(0);
}

#map-visualization {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  height: 100%;
  position: relative;
}

#map-visualization.is-expanded .map-color-scale .legend-title { font-size: 0.8rem; }
#map-visualization.is-expanded .map-color-scale .legend-bar .legend-label { font-size: 0.75rem; }

#map-visualization.is-expanded .filter-title { font-size: 0.85rem; }
#map-visualization.is-expanded #period-filter .period-bar .label { font-size: 0.75em; }
#map-visualization.is-expanded #period-filter .period-bar .count { font-size: 0.75em; }

#map-visualization.is-expanded .map-offhint { font-size: 0.8rem; }
#map-visualization.is-expanded .map-nolocation-overlay { font-size: 1rem; }

#map-visualization .expand-btn {
  z-index: 0;
}

.library-point.dimmed {
  opacity: .30;
}

.library-point.highlighted {
  filter: drop-shadow(0 0 4px rgba(0,0,0,.35));
}

.library-point.search-dim { opacity: 0.15; }

.period-filter-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  margin-top: 16px;
  flex:1 1 0;
}

#period-filter {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  width: 100%;
  flex: 1 1 auto;
  margin-top: 16px;
  gap: 6px;
}

#period-filter .period-bar {
  flex: 1 1 0;
  min-width: 50px;
  height: 100%;
  background: rgba(22,64,77,0.1);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

#period-filter .period-bar.selected {
  background: #16404D;
}

#period-filter .period-bar .label {
  font-size: 0.55em;
  color: #16404D;
  white-space: normal;
  overflow-wrap: break-word;
  text-align: center;
  line-height: 1.2;
}

#period-filter .period-bar.selected .label {
  color: #FFFAEC;
}

#period-filter .period-bar.dimmed:not(.inactive):not(.selected) {
  opacity: 0.45;
}

#period-filter .period-bar.search-dim { opacity: 0.25; }

.period-filter-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.filter-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: #16404D;
  margin-top: 8px;
}

g.node.hovered-network-node circle {
  stroke: red;
  stroke-width: 2px;
}

#period-filter .period-bar.pinned-period-bar {
  border: 2px solid red;
}

#period-filter .period-bar.hovered-period-bar{
  border: 2px solid red;
}

#period-filter .period-bar.hovered-period-bar .label { display: none; }
#period-filter .period-bar.hovered-period-bar .count { display: block; color: #16404D; }

#period-filter .period-bar.selected.hovered-period-bar .count { color: #FFFAEC; }

.period-bar .count {
  display: none;
  position: static;
  margin-top: 0.2em;
  font-size: 0.6em;
  font-weight: 700;
  color: #16404D;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.period-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.period-bar .count {
  font-size: 0.6em;
  color: #16404D;
  margin-top: 0.2em;
}

.period-bar .label,
.period-bar .count {
  transition: opacity 0.2s ease;
}

.period-bar:hover .label {
  display: none;
}

.period-bar:hover .count {
  display: block;
  color: #16404D;
}

#period-filter .period-bar.pinned-period-bar:not(:hover) .label { display: block; }
#period-filter .period-bar.pinned-period-bar:not(:hover) .count { display: none; }

#period-filter .period-bar.hovered-period-bar {
  border: 2px solid red;
}
#period-filter .period-bar.hovered-period-bar:not(:hover) .label { display: block; }
#period-filter .period-bar.hovered-period-bar:not(:hover) .count { display: none; }

.period-bar.selected .count,
.period-bar.hovered-period-bar .count {
  color: #FFFAEC;
}

.period-bar.inactive {
  opacity: .35;
}

.period-bar.inactive:hover {
  opacity: .55;
}

.period-filter-wrapper {
    margin-top: 1px;
}

.period-note {
  font-size: 0.6rem;
  font-style: italic;
  color: #606060;
  text-align: right;
  margin-top: 4px;
  position: static;
}

/* --- NETWORK GRAPH --- */

.viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--pad-h) 0 var(--pad-h);
}

.viz-header .expand-btn,
.viz-header .info-btn {
  position: static !important;
  top: auto;
  right: auto;
  width: 22px;
  height: 22px;
}

.viz-header .expand-btn img {
  width: 14px;
  height: 14px;
}

.viz-title {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.3;
  color: #16404D;
}

.viz-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#network-graph {
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  position: relative;
  overflow: visible;
}

#network-graph.is-expanded .legend-item span { font-size: 0.8rem; }
#network-graph.is-expanded .tools-label { font-size: 0.75rem; max-width: none; }

.network-wrapper {
  flex: 1 1 0;
  position: relative;
  overflow: hidden;
}

.network-wrapper svg {
  position: absolute;
  top:    0; left:  0;
  bottom: 0; right: 0;
  width:  100%;
  height: 100%;
}

.network-wrapper {
  margin: 0;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 3000;
}

.node text {
  font-size: 8px;
  text-anchor: middle;
  pointer-events: none;
}

.node {
  cursor: pointer;
}

.node.active circle {
  fill: #16404D;
}

.node.active text {
  fill: #FFFAEC;
  font-weight: 600;
}

.node.hovered circle {
  stroke-width: 1.5px;
}

.node.hovered text {
  font-weight: 500;
}

.node:hover circle {
  fill: #4F6F78;
}

.gender-label {
  fill: #FFFAEC;
}

svg:not(.node-active-mode) .node:hover text {
  fill: #FFFAEC;
  fill-opacity: 1;
}

.node-active-mode .node:not(.active):hover text {
  opacity: 0.65;
}

.node-active-mode .node.active:hover text {
  fill: #FFFAEC;
  fill-opacity: 1;
  font-weight: 600;
}

.node circle {
  fill: #FFFAEC;
  stroke: #16404D;
  stroke-width: 1px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* Update existing link styles to work with groups */
.link-group {
  mix-blend-mode: multiply;
  opacity: 0.6;
  fill: none;
  cursor: pointer;
}

.link-group:hover:not(.active),
.node-active-mode .link-group:hover:not(.active) {
  opacity: 0.9;
}

.link-group.active,
.node-active-mode .link-group.active {
  opacity: 1;
}

.link-group.active:hover,
.node-active-mode .link-group.active:hover {
  opacity: 1;
}

.link-group .link.book {
  stroke: #B65B8C;
}

.link-group .link.author {
  stroke: #578E7E;
}

.link-group.active .link.book {
  stroke: #8F3E6A;
}

.link-group.active .link.author {
  stroke: #467265;
}

.link-hitbox {
  fill: none;
  stroke: transparent;
  pointer-events: stroke;
}

.link-group.dimmed {
  opacity: 0.35 !important;
}

.link-group.dimmed.active {
  opacity: 0.45 !important;
}

.link-group.dimmed:hover:not(.active) {
  opacity: 0.45 !important;
}

.link-group.dimmed.active:hover {
  opacity: 0.50 !important;
}

#network-graph .links .link-group.search-dim {
  opacity: 0.25 !important;
}

#network-graph .links .link-group.search-dim.active {
  opacity: 0.40 !important;
}

#network-graph .links .link-group.search-dim:hover:not(.active) {
  opacity: 0.35 !important;
}

#network-graph .links .link-group.search-dim.active:hover {
  opacity: 0.40 !important;
}

.link-group:hover .link.book {
  stroke: #8F3E6A;
}

.link-group:hover .link.author {
  stroke: #467265;
}

.link-group.active:hover .link.book {
  stroke: #8F3E6A;
}

.link-group.active:hover .link.author {
  stroke: #467265;
}

.node-active-mode .node:not(.active) circle {
  fill: #F0EEE9;
  stroke-opacity: 0.37;
}

.node-active-mode .node:not(.active) text {
  opacity: 0.37;
}

.node-active-mode .node:not(.active) .gender-label {
  opacity: 0.37;
  fill:#16404D;
}

.node.hovered-network-node circle {
  stroke: red;
  stroke-width: 2px;
  stroke-opacity: 1;
}

.node-active-mode .node.hovered-network-node circle {
  stroke: red;
  stroke-width: 2px;
  stroke-opacity: 1;
}

.legend {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 var(--pad-h) 0 var(--pad-h);
  left: var(--pad-h);
  bottom: var(--pad-v);
}

.legend-item {
  display: flex;
  align-items: center;
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 5px;
  margin-right: 4px;
  flex-shrink: 0;
}

.legend-item.author::before {
  background-color: #578E7E;
}

.legend-item.book::before {
  background-color: #B65B8C;
}

.legend-item span {
  color: #16404D;
  font-family: Inter, Helvetica, sans-serif;
  font-size: 0.6rem;
  font-weight: 400;
  white-space: nowrap;
  line-height: 1;
}

.viz-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#network-graph .gender-tools {
  position: absolute;
  right: var(--pad-h);
  bottom: var(--pad-v);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 3;
  padding: 0 var(--pad-h) 0 var(--pad-h);
}

#network-graph .tools-label {
  white-space: normal;
  text-align: right;
  max-width: 5rem;
  font-size: 0.6rem;
  line-height: 1.15;
  color: #16404D;
  opacity: 0.9;
}

#network-graph .network-gender-controls {
  display: flex;
  gap: 6px;
}

#network-graph .nodes .node.search-dim { opacity: 0.25; }

.gender-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.gender-btn::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}

.gender-btn:hover,
.gender-btn.active {
  background: #D6E5DB;
}

.gender-btn img {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.tooltip::after {
    content: none;
    position: absolute;
    left: 10px;
    top: 100%;
    border: 6px solid transparent;
    border-top-color: rgba(0,0,0,0.7);
}

.gender-btn.disabled {
    opacity: .35;
    cursor: default;
    pointer-events: auto;
}

.gender-btn.disabled:hover { background: transparent; }

.info-btn {
  position: absolute;
  top: 4px; right: 35px;
  width: 22px; height: 22px;
  background: transparent;
  border: 1px solid #16404D;
  border-radius: 50%;
  font-size: 1rem; line-height: 20px;
  font-weight: 200;
  text-align: center; color: #16404D;
  cursor: pointer; z-index: 2;
  min-width: 22px;
  min-height: 22px;
  max-width: 22px;
  max-height: 22px;
}

.info-btn:hover { background:#D6E5DB; }

.info-panel {
  position: absolute;
  top: 32px; right: 6px;
  width: clamp(160px, 28vw, 240px);
  background: #D6E5DB;
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  font-size: 0.6rem;
  line-height: 1.2;
  display: none;
  z-index: 2;
}

#network-info-panel[hidden] {
  display: none;
}

#network-info-btn:hover + #network-info-panel {
  display: block;
}

#network-info-panel:hover {
  display: block;
}

.legend-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.info-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.legend-label {
  color:#16404D;
}

.legend-svg          { width: 100%; height: auto; }

.size-legend {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.12rem;
}

.size-legend svg circle {
  fill: #FFFAEC;
  stroke: #16404D;
  stroke-width: 0.4;
}

.size-legend svg line[marker-end] {
  stroke: #16404D;
}

.size-legend .legend-label {
  margin-top: 0;
  text-align: center;
}

#network-info-panel .info-body { gap: 1.5rem; }

.link-legend svg line   { stroke: #578E7E; }
.link-legend svg line[marker-end] { stroke: #16404D; }

.info-panel.open { display: block; }

.link-legend {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

/* GLOBAL FILTER BUTTON */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 100;
}

.modal.open {
  display: flex;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 101;
}

.modal-panel {
  position:relative;
  margin:auto;
  width:min(850px, 95vw);
  height:min(90vh, 600px);
  background:#FFFAEC;
  color:#16404D;
  border-radius:18px;
  display:flex;
  flex-direction:column;
  box-shadow:0 8px 24px rgba(0,0,0,.25);
  z-index: 102;
}

.modal-header {
  padding: 0.5rem 1.5rem;
  border-bottom:1px solid #D9D4C1;
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.modal-header h2 { margin:0; font-size:1.1rem; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background:none; border:none; cursor:pointer;
  font-size:1.5rem; line-height:1; color:#16404D;
}

.modal-body {
  flex:1 1 auto; overflow-y:auto; padding:1rem 1.5rem;
  display:flex; flex-direction:column; gap:1.25rem;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable both-edges;
  scrollbar-color: #A6CDC6 #D6E5DB;
  scrollbar-width: thin;
  margin-right: 8px;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}
.modal-body::-webkit-scrollbar-track {
  background: #D6E5DB;
}
.modal-body::-webkit-scrollbar-thumb {
  background-color: #A6CDC6;
  border-radius: 4px;
  border: 2px solid #D6E5DB;
}

.filter-group { display:flex; flex-direction:column; gap:.75rem; }
.filter-group.two-col {
  display:grid; grid-template-columns:1fr 1fr; gap:1rem;
}

.group-title {
  margin:0 0 .25rem; font-size:.8rem; text-transform:uppercase;
  letter-spacing:.03em; color:#375A61;
}

details { border:1px solid #C5C0AD; border-radius:10px; background:#F8F4E8; }
details[open]   summary { background:#16404D; color:#FFFAEC; }
summary {
  list-style:none; padding:.45rem .75rem; font-weight:600;
  cursor:pointer; display:flex; align-items:center; justify-content:space-between;
}
summary::-webkit-details-marker { display:none; }
summary .count { font-weight:500; font-size:.7rem; }

.checklist {
  max-height:140px;
  overflow:auto;
  margin:0;
  padding:.5rem .75rem;
  list-style:none;
  margin-right: 6px;
}

.checklist li { display:flex; align-items:center; gap:.45rem; font-size:.75rem; }
.checklist input { accent-color:#16404D; }

.quick-search {
  width:100%; margin:0 .75rem .5rem; padding:.3rem .4rem;
  border:1px solid #C5C0AD; border-radius:6px; font-size:.75rem;
  box-sizing:border-box;
  width:calc(100% - 1.5rem);
  max-width:100%;
}

.guard-msg {
  margin: 0 .75rem .5rem;
  color: #606060;
  font-size: 0.7rem;
  font-style: italic;
}

.modal-footer {
  border-top:1px solid #D9D4C1; padding:.75rem 1.5rem;
  display:flex; justify-content:flex-end; gap:.5rem;
}
.text-btn {
  background:transparent; border:none; color:#16404D; cursor:pointer;
  font-weight:600; font-size:.85rem;
}
.solid-btn {
  background:#A6CDC6; color:#16404D; border:none; border-radius:10px;
  padding:.45rem 1.1rem; font-weight:600; font-size:.85rem; cursor:pointer;
}
.solid-btn:hover { background:#93c0ba; }

.modal-panel { background:#D6E5DB; }

summary {
  position:relative;
  padding-right:1.4rem;
}
summary::after {
  content:"▾";
  position:absolute; right:.6rem; top:50%;
  transform:translateY(-50%);
  transition:.2s transform;
  font-size:.7rem; pointer-events:none;
}

details[open] > summary::after {
  transform:translateY(-50%) rotate(180deg);
}

.text-btn.small {
  font-size:.7rem; padding:.2rem .3rem;
}

.text-btn.small.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.solid-btn.outline{
  background:#D6E5DB;
  border:1px solid #16404D;
  color:#16404D;
}
.solid-btn.outline:hover{ background:#cddad2; }

.filter-tags        { margin: .5rem   1.5rem; }
#clear-modal-filters{ margin: .3rem  1.5rem;   }

.checklist li label {
  display:flex; align-items:center; gap:.45rem;
  width:100%; padding:.25rem 0;
  cursor:pointer; border-radius:4px;
}
.checklist li label:hover { background:rgba(22,64,77,.08); }

.chk-txt { line-height:1.3; }

/* --- FILTER MENU --- */

#side-menu {
  grid-row: 1;
  grid-column: 3;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.button-group {
  display: flex;
  flex-direction: row;
  gap: 0.7rem;
}

.button-group button {
  flex: 1;
  border-radius: 10px;
  border: none;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

#filter-btn {
  position: relative;
  background: #A6CDC6;
}

#filter-btn span {
  color: #16404D;
  font-size: 0.75rem;
}

#filter-icon {
  width: 15px;
  align-items: center;
}

#clear-btn {
  background: #D6E5DB;
}

/* when there are any filters applied */
#clear-btn.active {
  background: #D9D9D9;
}

#clear-btn.active span {
  color: #16404D;
}

#clear-icon-inactive {
  width: 15px;
}

#clear-btn:not(.active) {
  cursor: default;
}

/* non-active mode*/
#clear-btn span {
  color: #A6CDC6;
  font-size: 0.75rem;
}

.details-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  --pad-v: 0.5rem;
  --pad-h: 0.5rem;
  --btn-size: 22px;
  --btn-gap: 6px;
  border-radius: 24px;
  background: #D6E5DB;
  box-sizing: border-box;
  min-height: 0;
  overflow: visible;
  padding: calc(var(--pad-v) + var(--btn-size) + var(--btn-gap))
           var(--pad-h)
           var(--pad-v)
           var(--pad-h);
}

.details-pin {
  position: absolute;
  top: var(--pad-v);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 3;
  pointer-events: none;
}

.details-pin.visible { display: inline-flex; }

.details-pin img {
  width: 18px;
  height: 18px;
}

.details-pin .label {
  font-size: 0.65rem;
  color: #16404D;
  display: none;
}

#hover-details.is-expanded .details-pin img {
    width: 24px;
    height: 24px;
}

.details-panel__info {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-right: 6px;
  min-height: 0;
  overflow: hidden;
  overflow-x: hidden;
}

#hover-details .details-panel__name {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.2;
  display: block;
  -webkit-box-orient: unset;
  max-height: none;
}

.details-panel__img-wrapper {
  aspect-ratio: 3/4;
  width: 6rem;
  overflow: hidden;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  display: none;
}

.details-panel--list-mode .details-panel__info {
  overflow-y: hidden;
  align-items: center;
  justify-content: flex-start;
}

.details-panel--list-mode #details-list {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
}

#details-list {
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.details-panel--book-mode .details-panel__name {
  font-weight: 700;
}

#hover-details.details-panel--book-mode:not(.is-expanded) .details-panel__name {
  font-size: 0.75rem;
}

.details-panel--book-mode .details-panel__books { order: 0; }
.details-panel--book-mode .details-panel__name  { order: 1; }
.details-panel--book-mode .details-panel__attrib       { order: 2; }
.details-panel--book-mode .details-panel__description  { order: 3; }
.details-panel--book-mode #details-list                { order: 4; }

.details-panel--book-mode .details-panel__authorship { display: none !important; }

.details-panel--book-mode .details-panel__attrib,
.details-panel--book-mode .details-panel__authorship {
  font-style: normal;
  font-size: 0.65rem;
  color: #16404D;
  text-align: left;
  margin: 0.2rem 0 0;
  max-width: 100%;
}

.details-panel--book-mode .meta-label {
  opacity: 0.8;
  margin-right: 4px;
}

.details-panel--book-mode .details-panel__description {
  font-style: italic;
  font-size: 0.7rem;
  color: #16404D;
  text-align: left;
  margin: 0.25rem 0 0;
  max-width: 100%;
}

.details-panel--book-mode .details-panel__name,
.details-panel--book-mode .details-panel__attrib,
.details-panel--book-mode .details-panel__authorship,
.details-panel--book-mode .details-panel__description {
  max-width: 100%;
  text-align: left;
}

.details-panel--book-mode .details-panel__books {
  display: block !important;
  font-style: normal;
  font-weight: 500;
  opacity: 0.85;
  margin: 0.25rem 0;
}

.details-panel__list .list-item > div + div {
  margin-top: 2px;
}

.details-panel--book-mode .details-panel__attrib .meta-toggle {
  margin-left: 6px;
  background: transparent;
  border: none;
  color: #16404D;
  opacity: 0.85;
  font-size: 0.65rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.details-panel--book-mode .details-panel__attrib .meta-more {
  display: inline;
  margin-left: 6px;
  font-style: italic;
  opacity: 0.9;
}

.details-panel--book-mode .details-panel__attrib .meta-more[hidden] {
  display: none;
}

.details-panel--book-mode .details-panel__attrib {
  margin-bottom: 10px;
}

.details-panel--book-mode .value--pending {
  color: #667085;
  opacity: 0.9;
  font-style: italic;
}

.details-panel__list .author-life { margin-top: 2px; opacity: 0.95; }
.details-panel__list .author-life > div + div { margin-top: 2px; }

.details-panel__list .list-item .subpoints {
  margin: 2px 0 0 0;
  padding-left: 1.2em;
  list-style: disc;
  opacity: 0.95;
}

.details-panel__list .list-item .subpoints li {
  margin: 2px 0;
}

.details-expand-btn {
  position: absolute;
  top: var(--pad-v);
  right: var(--pad-h);
  padding: 5px;
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.details-expand-btn:hover { background: #cddad2; }
.details-expand-btn.disabled,
.details-expand-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.details-expand-btn img { width: 14px; height: 14px; }

.details-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.60);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
.details-modal-panel {
  background: #D6E5DB;
  border-radius: 24px;
  width: min(820px, 90vw);
  height: min(80vh, 680px);
  padding: 1rem;
  overflow: hidden;
  display: flex;
}

.details-placeholder { visibility: hidden; }

#hover-details.is-expanded {
  width: 100%;
  height: 100%;
  border-radius: 18px;
  padding-top: calc(var(--pad-v) + var(--btn-size) + var(--btn-gap));
  padding-right: var(--pad-h);
  padding-bottom: var(--pad-v);
  padding-left: var(--pad-h);
}

#hover-details.is-expanded .details-panel__img-wrapper {
  width: 9rem;
}

#hover-details.is-expanded .details-panel__info {
  padding-right: 10px;
}

#hover-details.is-expanded .details-panel__placeholder {
  max-width: 100%;
  font-size: 0.9rem;
}

#hover-details.is-expanded .details-panel__name {
  font-size: 1.15rem;
  line-height: 1.25;
  max-width: 100%;
  white-space: normal;
  text-overflow: clip;
  text-align: center;
}

#hover-details.is-expanded.details-panel--book-mode .details-panel__name {
  font-size: 1.2rem;
}

#hover-details.is-expanded .details-panel__books {
  font-size: 0.95rem;
}

#hover-details.is-expanded .details-panel__dates,
#hover-details.is-expanded .details-panel__title,
#hover-details.is-expanded .details-panel__reign {
  font-size: 0.85rem;
  line-height: 1.35;
}

#hover-details.is-expanded .details-panel__list .list-item {
  font-size: 0.85rem;
  padding: 6px 8px;
}

#hover-details.is-expanded .details-panel__list .list-header {
  font-size: 0.95rem;
  margin-top: 0.6rem;
}

#hover-details.is-expanded .prob-badge {
  font-size: 0.85em;
}

#hover-details.is-expanded .details-panel__carousel-container {
  margin-top: 1rem;
}

#hover-details.is-expanded .details-panel__carousel .dot {
  width: 0.7rem;
  height: 0.7rem;
}

.prob-badge {
  position: relative;
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.8em;
  line-height: 1.2;
  white-space: normal;
  font-weight: 600;
  color: #0E302E;
  cursor: pointer;
  border: 0.5px solid rgba(22,64,77,.55);
}

.prob-badge.level-1 {
  background: #FFB3B3; /* red - indeterminada */
  color: #880404;
  border-color: rgba(139,0,0,.55);
}

.prob-badge.level-2 {
  background: #FFD4B3; /* orange - possível */
  color: #CC6600;
  border-color: rgba(204,102,0,.55);
}

.prob-badge.level-3 {
  background: #ffe699; /* yellow - provável */
  color: #B8860B;
  border-color: rgba(184,134,11,.55);
}

.prob-badge.level-4 {
  background: #9ad59a; /* green - segura/indisputada */
  color: #006400;
  border-color: rgba(0,100,0,.55);
}

.prob-badge::after {
  content: attr(data-tip);
  position: absolute;
  --tip-x: 18px;
  --tip-y: -16px;
  top: 0;
  right: 0;
  transform: translate(var(--tip-x), var(--tip-y)) scale(0.9);
  transform-origin: top right;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.6rem;
  padding: 3px 6px;
  border-radius: 9999px;
  white-space: nowrap;
  line-height: 1.2;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  opacity: 0;
  pointer-events: none;
  transition: transform .14s ease, opacity .14s ease;
  z-index: 3;
}

.prob-badge:hover::after,
.prob-badge:focus-visible::after {
  opacity: 1;
  transform: translate(calc(var(--tip-x) + 4px), calc(var(--tip-y) - 4px)) scale(1);
}

.prob-tip {
  position: fixed;
  z-index: 5000;
  background: rgba(0,0,0,.85);
  color: #fff;
  padding: 6px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  max-width: 260px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.prob-badge::after { content: none !important; }

.details-panel__carousel .dot {
  --dot-size: clamp(8px, 0.6rem, 12px);
  display: inline-block;
  inline-size: var(--dot-size);
  block-size: var(--dot-size);
  aspect-ratio: 1 / 1;
  border-radius: 9999px;
  border: 1px solid #16404D;
  background: transparent;
  padding: 0;
  line-height: 0;
  vertical-align: middle;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.details-panel__carousel .dot.active { background: #16404D; }
.details-panel__carousel .dot-ellipsis {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: #16404D; padding: 0 2px; cursor: default;
}

.details-panel__img {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.details-panel__carousel-container {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  flex: 0 0 auto;
  background: #D6E5DB;
  padding: 0 var(--pad-h);
}

.carousel-arrow.left  { left: var(--pad-h); }
.carousel-arrow.right { right: var(--pad-h); }

.details-panel__carousel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.5rem;
  justify-content: center;
  max-width: 100%;
  overflow: hidden;
}

.details-panel__list {
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.4rem 0;
}

.details-panel__list .list-item {
  background: #FFFAEC;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.65rem;
  color: #16404D;
  line-height: 1.25;
  word-break: break-word;
}

.details-panel__list .list-item > div + div {
  margin-top: 2px;
}

.details-panel__list .list-header {
  background: transparent;
  padding: 0;
  margin-top: 0.4rem;
  font-weight: 700;
  color: #16404D;
  font-size: 0.7rem;
}

.details-panel--list-mode .details-panel__name,
.details-panel--list-mode .details-panel__books {
  text-align: left;
  flex: 0 0 auto;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: #16404D;
  cursor: pointer;
  z-index: 1;
  display: none;
}

.carousel-arrow.left  { left: 0.5rem; }
.carousel-arrow.right { right: 0.5rem; }

.details-panel__placeholder {
  font-style: italic;
  color: #16404D;
  max-width: 5rem;
}

.details-panel .details-panel__name {
  max-width: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 0 0.1rem 0;
  text-align: center;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.details-panel .details-panel__books {
  max-width: 100%;
  text-align: center;
}

.details-panel p {
  max-width: 5rem;
  font-style: italic;
  font-size: 0.7rem;
  text-align: center;
  color: #16404D;
}

.details-panel .details-panel__dates,
.details-panel .details-panel__title,
.details-panel .details-panel__reign {
  align-self: flex-start;
  max-width: 100%;
  margin: 0.1rem 0 0;
  font-size: 0.6rem;
  line-height: 1.2;
  text-align: left;
  white-space: normal;
  overflow-wrap: break-word;
}

.details-panel__carousel {
  gap: 0.3rem;
  margin-top: 0.5rem;
  justify-content: center;
}

.details-panel__carousel .dot {
  width: 0.6rem;
  height: 0.6rem;
  border: 1px solid #16404D;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.details-panel__carousel .dot.active {
  background: #16404D;
}

.filter-badge {
  position:absolute; top:-6px; right:-6px;
  min-width:18px; height:18px;
  padding:0 4px;
  background:#16404D; color:#FFFAEC;
  border-radius:50%; font-size:.7rem;
  line-height:18px; text-align:center;
  display:none;
}

.filter-tag {
  display:inline-flex; align-items:center; gap:6px;
  background:#16404D; color:#FFFAEC;
  padding:2px 10px; border-radius:9999px;
  font-size:.65rem;
}

.filter-tag .remove { cursor:pointer; font-weight:700; }

.filter-tags {
  display:flex; flex-wrap:wrap; gap:6px;
  margin:.5rem 1.5rem;
}

#filter-btn.filters-active .filter-badge {
  display:block;
  color: white;
}

#filter-modal .modal-panel {
  font-size: 0.70rem;
}

.modal-panel {
  overflow: hidden;
}

#filter-modal h2           { font-size: 0.85rem; }
#filter-modal summary      { font-size: 0.75rem; }
#filter-modal .quick-search,
#filter-modal .checklist   { font-size: 0.70rem; }

.disabled-option {
  color: #888;
  cursor: not-allowed;
  pointer-events: auto;
}

.disabled-option input {
  cursor: not-allowed;
}

#filter-genre li.genre-item {
  position: relative;
}

.disabled-option label {
    cursor: default !important;
}

.genre-tooltip {
  position: fixed;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.6rem;
  padding: 4px 8px;
  border-radius: 9999px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  pointer-events: none;
  z-index: 10050;
  opacity: 0;
  transition: opacity .12s ease;
}

/* ---- TREEMAP ---- */

.treemap-header .viz-title {
  margin: 0;
  font-size: 0.9rem;
  color: #16404D;
}

.treemap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  position: relative;
  flex-wrap: nowrap;
}

.treemap-title-container {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  flex-wrap: nowrap;
}

.treemap-title-container .viz-title {
  margin: 0;
  font-size: 0.9rem;
  color: #16404D;
}

#treemap-info-btn {
  position: static;
  background: transparent;
  border: 1px solid #16404D;
  border-radius: 50%;
  font-size: 0.65rem;
  line-height: 14px;
  font-weight: 200;
  text-align: center;
  color: #16404D;
  cursor: pointer;
  z-index: 4;
  flex-shrink: 0;
  min-width: 16px;
  min-height: 16px;
  max-width: 16px;
  max-height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}

#treemap-info-btn:hover {
  background: #D6E5DB;
}

.treemap-info-panel {
  position: absolute;
  top: 26px;
  left: 0;
  width: clamp(200px, 28vw, 260px);
  background: #D6E5DB;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  font-size: 0.65rem;
  line-height: 1.2;
  display: none;
  z-index: 100;
}

.treemap-info-panel[hidden] {
  display: none;
}

#treemap-info-btn:hover + #treemap-info-panel {
  display: block;
}

#treemap-info-panel:hover {
  display: block;
}

.classification-tree {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tree-svg {
  width: 100%;
  height: auto;
  max-width: 280px;
}

.tree-svg text {
  font-family: Inter, Helvetica, sans-serif;
  pointer-events: none;
  font-size: 10px;
}

.tree-svg line {
  stroke: #16404D;
}

.tree-svg rect {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

#treemap.is-expanded .treemap-title-container .viz-title {
  font-size: 1.15rem;
}

#treemap.is-expanded #treemap-info-btn {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  max-width: 18px;
  max-height: 18px;
  font-size: 0.75rem;
  line-height: 16px;
}

#treemap.is-expanded .treemap-info-panel {
  width: clamp(260px, 40vw, 380px);
  padding: 1rem;
  font-size: 0.6rem;
}

#treemap.is-expanded .tree-svg text {
  font-size: 0.6rem;
}

#treemap.is-expanded .tree-svg rect {
  width: 105px;
  height: 18px;
}

.mode-button {
  position: relative;
  border-radius: 8px;
  padding: 3px 5px;
  font-size: 0.65rem;
  background-color: #FFFAEC;
  color: #16404D;
  border: 0.5px solid #16404D;
  cursor: pointer;
}

.mode-button:not(.active):hover {
  background-color: #DCDED4;
}

.mode-button.active {
  background-color: #16404D;
  color: white;
}

.mode-button .filter-indicator {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 10px;
  height: 10px;
  background: #A6CDC6;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #F5ECD5;
  display: none;
  cursor: default;
  outline: none;
  z-index: 2;
}

.mode-button.has-filter .filter-indicator { display: block; }

.mode-button .filter-indicator::after {
  content: 'Filter active';
  position: absolute;
  --tip-x: 20px;
  --tip-y: -18px;

  top: 0;
  right: 0;
  transform: translate(var(--tip-x), var(--tip-y)) scale(0.85);
  transform-origin: top right;

  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.6rem;
  padding: 4px 8px;
  border-radius: 9999px;
  white-space: nowrap;
  line-height: 1.2;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);

  opacity: 0;
  pointer-events: none;
  transition: transform .14s ease, opacity .14s ease;
  z-index: 3;
}

.mode-button .filter-indicator:hover::after,
.mode-button .filter-indicator:focus-visible::after {
  opacity: 1;
  transform: translate(calc(var(--tip-x) + 4px), calc(var(--tip-y) - 4px)) scale(1);
}

.mode-button[data-mode="tradition"].active {
  background-color: #A6CDC6;
  color: #16404D;
}

#treemap {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.25rem;
  color: #16404D;
  width: 100%;
  position: relative;
  z-index: 55;
}

#treemap.is-expanded .mode-button { font-size: 0.85rem; padding: 5px 8px; }
#treemap.is-expanded #treemap-breadcrumbs { font-size: 0.85rem; }

#treemap.is-expanded #treemap-area text { font-size: 0.8rem !important; }

#treemap-controls {
  margin-right: 30px;
  margin-left: 15px;
}

#treemap-area {
  flex: 1;
  position: relative;
  width: 100%;
  margin-top: 10px;
}

#treemap-breadcrumbs {
  font-size: 0.7rem;
  font-weight: bold;
  color: #16404D;
  margin-bottom: 10px;
  cursor: pointer;
  margin-inline: 0 var(--pad-h);
}

#tooltip {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 3px 6px;
  border-radius: 5px;
  pointer-events: none;
  visibility: hidden;
  z-index: 60;
  font-size: 0.6rem;
}

#treemap-area rect.hovered-treemap-rect {
  stroke: red;
  stroke-width: 2px;
}

#treemap-area rect.search-dim { opacity: 0.20; }

.library-point,
#period-filter .period-bar,
#treemap-area rect,
#network-graph .nodes .node,
#network-graph .links .link {
  transition: opacity .15s ease;
}

/* ----CATALOG---- */

#catalog {
  grid-column: 2 / -1;
  grid-row: 2;
  display: flex; /* Limit the entries to the catalog area*/
  flex-direction: column;
  padding: 0.75rem 1.25rem;
  color: #16404D;
  --catalog-columns: 1fr 1fr 1fr 0.5fr;
  --catalog-col-gap: 20px;
  --cell-pad-x: 6px;
  --search-icon-size: 15px;
  --search-icon-gap: 6px;
  --catalog-gutter: 1rem;
  --expand-size: 22px;
  --expand-gap: 6px;
  position: relative;
  z-index: 50;
}

.search-container {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  position: relative;
}

#catalog .search-container {
  position: relative;
  padding-right: calc(var(--expand-size) + var(--expand-gap) + 1.6rem);
}

#search-input {
  width: 100%;
  padding: 0.1rem 0.2rem;
  border: none;
  border-bottom: 0.5px solid;
  background: transparent;
  outline: none;
}

#search-clear-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: calc(var(--expand-size) + var(--expand-gap));
  z-index: 3;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #16404D;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease, background-color .12s ease;
}


#search-clear-btn.visible {
  opacity: 0.5;
  pointer-events: auto;
}

#search-clear-btn:hover {
  opacity: 0.9;
  background: rgba(22,64,77,0.08);
}

#search-clear-btn svg {
  width: 12px;
  height: 12px;
}

.header-info {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: 1px solid #16404D;
  border-radius: 50%;
  font-size: 0.55rem;
  line-height: 1;
  color: #16404D;
  background: transparent;
  padding: 0;
  z-index: 4000;
}

.header-info:hover {
  background: #D6E5DB;
}

.header-info::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  right: auto;
  top: auto;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) scale(0.95);
  transform-origin: bottom center;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.6rem;
  padding: 4px 8px;
  border-radius: 9999px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
  z-index: 4001;
}

.header-info:hover::after,
.header-info:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

:root {
  --catalog-gutter: 1rem;
}

#catalog-entries { padding-right: var(--catalog-gutter); }

.catalog-entry.pinned {
  background-color: #16404D;
  color: #FFFAEC;
  box-shadow:
    inset 0 0 0 2px #16404D,
    0 2px 10px rgba(22,64,77,.25);
}

.catalog-entry.pinned > * {
  color: inherit;
  font-weight: 600;
}

.catalog-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 20;
  opacity: 0;
  transition: opacity .18s ease;
  pointer-events: none;
}

#catalog.is-expanded .search-container { gap: 0.5rem; }
#catalog.is-expanded #search-input { font-size: 0.85rem; }
#catalog.is-expanded #search-input::placeholder { font-size: 0.85rem; }
#catalog.is-expanded #search-icon { width: 18px; }

#catalog.is-expanded .catalog-header h5 { font-size: 1.05rem; }
#catalog.is-expanded .sortable { font-size: 0.85rem; }

#catalog.is-expanded .catalog-entry { font-size: 0.8rem; }

#catalog.is-expanded #book-count { font-size: 0.8rem; }

.catalog-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.catalog-overlay__panel {
  background: #FFFAEC;
  border: 2px solid #16404D;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  color: #16404D;
  font-size: 0.75rem;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}

.catalog-overlay[hidden] {
  display: none !important;
}

.catalog-toast {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: #D6E5DB;
  color: #16404D;
  border: 1px solid #16404D;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.7rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 21;
}

.catalog-toast.open {
  opacity: 1;
  transform: translateY(0);
}

#catalog.toast-open #catalog-entries .catalog-entry {
  filter: blur(1.2px) brightness(.95);
  transition: filter .15s ease;}


#catalog.overlay-open #catalog-entries .catalog-entry {
  filter: blur(1.2px) brightness(.95);
  transition: filter .15s ease;
}

#catalog.overlay-open #catalog-entries .catalog-entry.pinned,
#catalog.overlay-open #catalog-entries .catalog-entry:hover {
  filter: none;
}

#catalog.toast-open #catalog-entries .catalog-entry.pinned,
#catalog.toast-open #catalog-entries .catalog-entry:hover {
  filter: none;
}

.search-container{ padding-right: var(--catalog-gutter); }

#search-input::placeholder {
  color: #aaa;
  font-style: italic;
  font-size: 0.7rem;
}

/* ensure html2canvas captures the placeholder exactly as seen */
#search-input::placeholder {
  opacity: 1;          /* make it render */
}

#search-icon {
  width: 15px;
  align-items: center;
}

.catalog-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 0.5fr;
  grid-template-rows: 30px;
  gap: 20px; /* Aligns with the entries */
  font-weight: 600;
  font-size: 0.9rem;
  align-items: center;
  padding: 5px;
}

.catalog-header h5 { margin: 0; }

.catalog-header,
.catalog-entry {
  display: grid;
  grid-template-columns: var(--catalog-columns);
  gap: var(--catalog-col-gap);
  align-items: center;
}

.catalog-header > *,
.catalog-entry > * {
  padding-inline: var(--cell-pad-x);
  text-align: left;
}

.catalog-entry > * {
  white-space: normal;
  overflow-wrap: anywhere;
  hyphens: auto;
  overflow: visible;
  text-overflow: clip;
}

.catalog-header { padding-right: var(--catalog-gutter); }

.sortable {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  font-size: 0.7rem;
}

.sort-icon {
  width: 15px;
}

#catalog-entries {
  flex: 1 1 auto;
  margin-bottom: 0.5rem;
  overflow-y: scroll;
  padding-right: 0.8rem;
  scrollbar-gutter: stable both-edges;
  scrollbar-color: #A6CDC6 #D6E5DB;
  scrollbar-width: auto;
}

.catalog-entry {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 0.5fr;
  gap: 20px;
  padding: 5px;
  margin: 10px 0;
  background: #FFFAEC;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  font-size: 0.65rem;
  align-items: center;
  cursor: pointer;
}

.catalog-entry.hovered-entry {
  background-color: #16404D;
  color: #FFFAEC;
}

/* Scrollbar styling */
#catalog-entries::-webkit-scrollbar {
  width: 8px;
}

#catalog-entries::-webkit-scrollbar-track {
  background: #D6E5DB;
}

#catalog-entries::-webkit-scrollbar-thumb {
  background-color: #A6CDC6;
  border-radius: 4px;
  border: 2px solid #D6E5DB;
}

#book-count {
  font-size: 0.65rem;
  display: flex;
  justify-content: flex-end;
}

/* ---------- ZERO-RESULT OVERLAY ---------- */

.empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  background: #FFFAEC;
  border: 2px solid #16404D;
  border-radius: 14px;
  padding: 1.2rem 1.6rem;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  z-index: 4000;
  text-align: center;
}

.empty-state p {
  margin: 0 0 .9rem;
  font-size: .8rem;
  color: #16404D;
}

.empty-state .button-row {
  display: flex;
  gap: .6rem;
  justify-content: center;
}

.viz-header .expand-btn,
.viz-header .info-btn {
  position: static !important;
  top:auto; right:auto;
}

.visualization {
  --pad-v: 0.5rem;
  --pad-h: 0.5rem;
  padding: var(--pad-v) var(--pad-h);
}

.visualization.is-expanded .viz-title {
  font-size: 1.15rem;
}

#treemap,
#catalog{
  --pad-v: 0.75rem;
  --pad-h: 1.25rem;
}

.viz-header{
  padding: 0 var(--pad-h) 0 var(--pad-h);
}

#map-area,
.period-filter-wrapper {
  padding: 0 var(--pad-h);
}

.expand-btn {
  position: absolute;
  top:  var(--pad-v);
  right:var(--pad-h);
}

.map-offhint,
.period-note,
#book-count {
  position: static;
  margin: var(--pad-v) 0 0;
  text-align: right;
}

/* ----VIEWPORT WARNING---- */
.viewport-warning {
  position: fixed;
  inset: 0;
  background: rgba(22, 64, 77, 0.95);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: #FFFAEC;
}

.viewport-warning__panel {
  background: #16404D;
  border: 2px solid #A6CDC6;
  border-radius: 18px;
  padding: 2rem;
  max-width: min(90vw, 500px);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.viewport-warning__panel h3 {
  margin: 0 0 1rem 0;
  font-size: 1.4rem;
  color: #A6CDC6;
}

.viewport-warning__panel p {
  margin: 0 0 1.5rem 0;
  line-height: 1.5;
  color: #FAF7F4;
}

.viewport-info {
  padding: 1rem;
  background: rgba(166, 205, 198, 0.1);
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.9rem;
}

.viewport-warning[hidden] {
  display: none !important;
}

/* Hide main content when viewport warning is shown */
.viewport-too-small .dashboard-wrap {
  visibility: hidden;
}

/* Improved responsive grid for smaller screens */
@media (max-width: 1400px) {
  .dashboard {
    grid-template-columns: 1fr 1fr 9rem;
  }
}

@media (max-width: 1200px) and (min-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr 1fr 8rem;
    grid-template-rows: 1fr 1fr;
  }

  .visualization {
    padding: 0.4rem;
  }

  #hover-details {
    --pad-h: 0.5rem;
    --pad-v: 0.4rem;
  }

  #hover-details.is-expanded .details-panel__img-wrapper {
    width: 7rem;
  }

  .dashboard {
    gap: 10px;
  }

  .treemap-title-container {
    flex-shrink: 0;
    gap: 1px;
  }

  .treemap-title-container .viz-title {
    font-size: 0.75rem;
    white-space: normal;
    max-width: 110px;
    line-height: 1.2;
  }

  #treemap-info-btn {
    flex-shrink: 0;
  }
}

/* Larger screens (external monitors) */
@media (min-width: 1600px) {
  /* Navbar and titles */
  .title { font-size: x-large; }

  /* Map visualization */
  .map-color-scale { width: 200px; }
  .map-color-scale .legend-title {
    font-size: 0.75rem;
    max-width: 200px;  /* Override default max-width to allow wider title */
  }
  .map-color-scale .bar-wrapper .legend-bar .legend-label { font-size: 0.75rem; }
  .legend-label { font-size: 0.75rem; }
  .filter-title { font-size: 0.85rem; }
  #period-filter .period-bar .label { font-size: 0.65em; }
  #period-filter .period-bar .count { font-size: 0.7em; }
  .map-offhint { font-size: 0.75rem; }
  .period-note { font-size: 0.75rem; }
  .map-tooltip { font-size: 0.75rem; }
  .map-limit-toast { font-size: 0.85rem; }

  /* Network graph */
  .viz-title { font-size: 1.05rem; }
  .legend-item span { font-size: 0.75rem; }
  #network-graph .tools-label {
    font-size: 0.75rem;
    max-width: 100px;
  }  /* Gender filter label */
  .tooltip { font-size: 0.75rem; }
  .info-btn {
    font-size: 1.15rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #network-info-btn {
    font-size: 1.15rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #network-info-panel { font-size: 0.8rem; }
  #network-info-panel .legend-label { font-size: 0.75rem; }

  /* Details panel */
  .details-panel__placeholder { font-size: 0.9rem; }
  .details-panel__name { font-size: 0.85rem; }
  .details-panel__books { font-size: 0.8rem; }
  .details-panel .details-panel__dates,
  .details-panel .details-panel__title,
  .details-panel .details-panel__reign { font-size: 0.75rem; }
  #hover-details.is-expanded .details-panel__dates,
  #hover-details.is-expanded .details-panel__title,
  #hover-details.is-expanded .details-panel__reign { font-size: 0.7rem; }
  .details-panel__list .list-item { font-size: 0.75rem; }
  .details-panel__list .list-header { font-size: 0.9rem; }
  .details-panel--book-mode .details-panel__attrib,
  .details-panel--book-mode .details-panel__authorship { font-size: 0.8rem; }
  .details-panel--book-mode .details-panel__description { font-size: 0.8rem; }
  .details-panel p { font-size: 0.85rem; }

  /* Treemap */
  #treemap-breadcrumbs { font-size: 0.85rem; }
  .mode-button { font-size: 0.8rem; }
  .mode-button .filter-indicator { width: 12px; height: 12px; }
  .mode-button .filter-indicator::after { font-size: 0.75rem; }
  #tooltip { font-size: 0.75rem; }
  .treemap-info-panel { font-size: 0.8rem; }
  #treemap-info-btn { font-size: 0.8rem; }
  #treemap-area text { font-size: 0.75rem !important; }

  /* Classification tree diagram */
  .treemap-info-panel {
    padding: 0.6rem 1rem;
    width: clamp(280px, 30vw, 320px);
  }
  .classification-tree {
    padding: 0.5rem 0;
  }
  .classification-tree .tree-svg {
    max-width: 100%;
    width: 100%;
    transform: scale(1.05);
    transform-origin: center center;
  }

  /* Catalog */
  #search-input { font-size: 0.85rem; }
  #search-input::placeholder { font-size: 0.85rem; }
  .catalog-header h5 { font-size: 1.05rem; }
  .sortable { font-size: 0.85rem; }
  .catalog-entry { font-size: 0.8rem; }
  #book-count { font-size: 0.8rem; }
  .catalog-toast { font-size: 0.85rem; }

  /* Filter modal */
  .modal-header h2 { font-size: 1.25rem; }
  summary { font-size: 0.9rem; }
  summary .count { font-size: 0.85rem; }
  .checklist li { font-size: 0.9rem; }
  .quick-search { font-size: 0.9rem; }
  .guard-msg { font-size: 0.85rem; }
  .text-btn { font-size: 1rem; }
  .solid-btn { font-size: 1rem; }

  /* Info buttons and tooltips */
  .header-info { font-size: 0.7rem; }
  .header-info::after { font-size: 0.75rem; }
  .prob-badge { font-size: 0.9em; }
  .prob-badge::after { font-size: 0.75rem; }
  .prob-tip { font-size: 0.9rem; }

  /* Buttons and controls */
  .dropdown-menu li a { font-size: 0.9rem; }
  #filter-btn span, #clear-btn span { font-size: 0.85rem; }
  .filter-badge { font-size: 0.85rem; }
  .filter-tag { font-size: 0.8rem; }
}