/* ================================================================
   CEAS Geo-Entity Viewer — viewer.css
================================================================ */

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

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: #f8f9fa;
  color: #212529;
}

/* ---- Landing page ------------------------------------------------ */
.landing-body {
  background-color: #f5f3e7;
  background-image:
    linear-gradient(rgba(61, 90, 128, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 90, 128, 0.12) 1px, transparent 1px);
  background-size: 20px 20px;
  color: #1a2744;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.landing-shell {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 14px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.landing-header {
  flex-shrink: 0;
}

.landing-header h1 {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 28px;
  margin-bottom: 4px;
}

.landing-header p {
  color: #3d5a80;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
}

.landing-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.landing-title-mark {
  color: #c77536;
  font-size: 20px;
}

.landing-map-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(26, 39, 68, 0.55);
  border-radius: 4px;
  background: rgba(248, 246, 236, 0.92);
  box-shadow: 0 12px 24px rgba(26, 39, 68, 0.18);
  padding: 8px 10px 8px;
}

.landing-map-card .map-status-msg {
  flex-shrink: 0;
  margin-top: 0;
  margin-bottom: 6px;
}

.landing-map-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.landing-svg-host {
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
  transition: opacity 0.18s ease-in-out, transform 0.18s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.landing-world-svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.landing-world-svg path[id] {
  fill: #3d5a80;
  fill-opacity: 0.86;
  stroke: #1a2744;
  stroke-width: 0.5;
  stroke-opacity: 0.9;
  vector-effect: non-scaling-stroke;
  transition: fill 0.12s ease-in-out, fill-opacity 0.12s ease-in-out;
  cursor: pointer;
}

.landing-world-svg path[id].is-hover,
.landing-world-svg path[id]:hover {
  fill: #d4915a;
  fill-opacity: 0.95;
}

.landing-world-svg path[id]:focus {
  outline: none;
  fill: #d4915a;
  fill-opacity: 0.95;
}

.landing-world-svg path[id]:focus-visible {
  stroke: #c77536;
  stroke-width: 1.1;
}

.landing-actions {
  flex-shrink: 0;
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}

.landing-fallback-link {
  color: #1a2744;
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.landing-fallback-link:hover {
  color: #c77536;
  text-decoration: underline;
}

.landing-transitioning .landing-svg-host {
  opacity: 0.55;
  transform: scale(0.99);
}

.landing-body .maplibregl-ctrl-group {
  background: #f8f6ec !important;
  border: 1px solid #1a2744 !important;
  border-radius: 2px !important;
  box-shadow: none !important;
}

.landing-body .maplibregl-ctrl-group button {
  width: 32px !important;
  height: 32px !important;
  border-color: #dce4ed !important;
}

.landing-body .maplibregl-ctrl-group button:hover {
  background: #eef2f7 !important;
}

.landing-body .maplibregl-ctrl-group button:focus {
  outline: 2px solid #c77536;
  outline-offset: -2px;
}

.landing-body .maplibregl-ctrl-icon {
  filter: brightness(0) saturate(100%) invert(15%) sepia(18%) saturate(976%) hue-rotate(188deg) brightness(93%) contrast(92%);
}

.landing-body .maplibregl-ctrl-attrib {
  background: rgba(248, 246, 236, 0.92) !important;
  color: #3d5a80 !important;
  font-family: "IBM Plex Mono", ui-monospace, monospace !important;
  font-size: 10px !important;
}

.landing-body .maplibregl-ctrl-attrib a {
  color: #1a2744 !important;
}

/* ---- Zoomer page ------------------------------------------------ */
.zoomer-body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #f5f3e7;
  color: #1a2744;
}

.zoomer-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto;
}

.zoomer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(26, 39, 68, 0.25);
  background: #f8f6ec;
}

.zoomer-toolbar h1 {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 18px;
  font-weight: 600;
}

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

.zoomer-actions button {
  border: 1px solid #1a2744;
  background: #ffffff;
  color: #1a2744;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.zoomer-actions button:hover {
  background: #eef2f7;
}

.zoomer-actions span {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
}

.zoomer-map {
  min-height: 240px;
  width: 100%;
  height: 100%;
}

.zoomer-status {
  min-height: 28px;
  padding: 6px 12px;
  border-top: 1px solid rgba(26, 39, 68, 0.18);
  background: #f8f6ec;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: #3d5a80;
}

.zoomer-status.is-error {
  color: #8a1c1c;
}

/* ---- Microscope page (phase-2 style slice) ----------------------------- */
.microscope-body {
  background-color: #f5f3e7;
  color: #1a2744;
}

.microscope-body .controls-bar--blueprint {
  background: #f8f6ec;
  color: #1a2744;
  border-bottom: 1px solid rgba(26, 39, 68, 0.24);
  box-shadow: 0 1px 0 rgba(26, 39, 68, 0.08);
}

.microscope-body .ctrl-group label {
  color: #3d5a80;
}

.microscope-body .ctrl-group select {
  border-color: rgba(26, 39, 68, 0.38);
  background: #fcfbf5;
  color: #1a2744;
}

.microscope-body .ctrl-group select:focus {
  outline: 2px solid #c77536;
}

.microscope-body #show-map-btn {
  background: #1a2744;
}

.microscope-body #show-map-btn:hover {
  background: #243352;
}

.microscope-body #screenshot-btn {
  background: #c77536;
}

.microscope-body #screenshot-btn:hover {
  background: #a65d1a;
}

.microscope-body #settings-btn {
  background: #3d5a80;
}

.microscope-body #settings-btn:hover {
  background: #2e4266;
}

.microscope-body .sidebar {
  background: #fcfbf5;
  border-right-color: rgba(26, 39, 68, 0.2);
}

.microscope-body .sidebar h3 {
  color: #1a2744;
  border-bottom-color: rgba(26, 39, 68, 0.2);
}

.microscope-body .muted {
  color: #5c7a9e;
}

.microscope-body .main-layout {
  height: calc(100vh - 62px);
  background-color: #f5f3e7;
}

.microscope-body .maplibregl-ctrl-group {
  background: #f8f6ec !important;
  border: 1px solid #1a2744 !important;
  border-radius: 2px !important;
  box-shadow: none !important;
}

.microscope-body .maplibregl-ctrl-group button {
  border-color: #dce4ed !important;
}

.microscope-body .maplibregl-ctrl-group button:hover {
  background: #eef2f7 !important;
}

.microscope-body .maplibregl-ctrl-group button:focus {
  outline: 2px solid #c77536;
  outline-offset: -2px;
}

.microscope-body .maplibregl-ctrl-icon {
  filter: brightness(0) saturate(100%) invert(15%) sepia(18%) saturate(976%) hue-rotate(188deg) brightness(93%) contrast(92%);
}

.microscope-body .maplibregl-popup-content {
  background: #f8f6ec;
  border: 1px solid #1a2744;
  border-radius: 2px;
}

.microscope-body .maplibregl-popup-content::before,
.microscope-body .maplibregl-popup-content::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: #c77536;
}

.microscope-body .maplibregl-popup-content::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.microscope-body .maplibregl-popup-content::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid;
  border-right: 2px solid;
}

/* ---- Controls bar ------------------------------------------------ */
.controls-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 10px 16px;
  background: #1e293b;
  color: #e2e8f0;
  flex-wrap: wrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  z-index: 10;
  position: relative;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-group label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.ctrl-group select {
  min-width: 180px;
  max-width: 260px;
  padding: 6px 10px;
  border: 1px solid #334155;
  border-radius: 4px;
  background: #0f172a;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 13px;
}
.ctrl-group select:disabled { opacity: .45; cursor: default; }
.ctrl-group select:focus { outline: 2px solid #3b82f6; outline-offset: 1px; }

.ctrl-button-group {
  align-self: flex-end;
  padding-bottom: 2px;
}

button#show-map-btn {
  padding: 8px 18px;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
button#show-map-btn:hover  { background: #2563eb; }
button#show-map-btn:active { background: #1d4ed8; }

/* HTMX loading indicator */
button#show-map-btn.htmx-request { opacity: .6; cursor: wait; }

button#screenshot-btn {
  padding: 8px 14px;
  background: #475569;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
button#screenshot-btn:hover  { background: #334155; }
button#screenshot-btn:active { background: #1e293b; }

/* HTMX loading indicator — keep this comment anchor */
button#show-map-btn.htmx-request { opacity: .6; cursor: wait; }

/* ---- Main layout ------------------------------------------------- */
.main-layout {
  display: flex;
  height: calc(100vh - 60px);   /* viewport minus controls bar */
}

/* ---- Sidebar ----------------------------------------------------- */
.sidebar {
  width: 260px;
  min-width: 220px;
  max-width: min(70vw, 900px);
  flex: 0 0 auto;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-resizer {
  width: 8px;
  flex: 0 0 8px;
  cursor: col-resize;
  background: linear-gradient(to right, #e2e8f0 0, #e2e8f0 1px, transparent 1px);
}
.sidebar-resizer:hover,
.sidebar-resizer.is-dragging {
  background: linear-gradient(to right, #93c5fd 0, #3b82f6 2px, rgba(59,130,246,0.12) 2px);
}
.sidebar h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 6px;
}

.muted { color: #94a3b8; font-size: 12px; }

/* ---- Hierarchy stats table --------------------------------------- */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.stats-table th,
.stats-table td {
  padding: 4px 6px;
}
.stats-table th {
  text-align: left;
  color: #64748b;
  font-weight: 400;
}
.stats-table td {
  text-align: right;
  font-weight: 600;
  color: #1e293b;
}

/* ---- Anomaly badges ---------------------------------------------- */
.anomaly-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  margin: 10px 0 4px;
}

.anomaly {
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 4px;
  line-height: 1.4;
}
.anomaly.warn  { background: #fef9c3; color: #854d0e; border-left: 3px solid #facc15; }
.anomaly.error { background: #fee2e2; color: #991b1b; border-left: 3px solid #ef4444; }

.ok-badge {
  font-size: 12px;
  color: #166534;
  background: #dcfce7;
  border-left: 3px solid #22c55e;
  border-radius: 4px;
  padding: 5px 8px;
  margin-top: 8px;
}

/* ---- Map status message ------------------------------------------ */
.map-status-msg {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 8px;
}
.map-status-msg.ok    { background: #dcfce7; color: #166534; }
.map-status-msg.warn  { background: #fef9c3; color: #854d0e; }
.map-status-msg.error { background: #fee2e2; color: #991b1b; }
.map-status-msg.info  { background: #eff6ff; color: #1e40af; }

/* ---- Map div ----------------------------------------------------- */
#map {
  flex: 1;
  min-height: 0;
}

/* ---- Popup drill-up / drill-down buttons ------------------------- */
.drill-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.drill-btn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.4;
  transition: background .12s, color .12s;
  white-space: nowrap;
}

.drill-btn.drill-down {
  background: #3b82f6;
  color: #fff;
  border: 1px solid #1d4ed8;
}
.drill-btn.drill-down:hover  { background: #1d4ed8; }
.drill-btn.drill-down:active { background: #1e40af; }

.drill-btn.drill-up {
  background: #fff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}
.drill-btn.drill-up:hover  { background: #eff6ff; }
.drill-btn.drill-up:active { background: #dbeafe; }

/* ---- Entity detail page ------------------------------------------- */
.entity-detail-page { display: flex; flex-direction: column; height: 100vh; }
.entity-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: #1e293b;
  color: #e2e8f0;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.entity-nav-link {
  color: #93c5fd;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}
.entity-nav-link:hover { text-decoration: underline; color: #bfdbfe; }
.entity-nav-title {
  flex: 1;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}
.entity-nav-close {
  padding: 6px 14px;
  background: #475569;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.entity-nav-close:hover { background: #334155; }

.entity-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.entity-detail-aside {
  width: 40%;
  min-width: 280px;
  max-width: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px;
  background: #fff;
  border-right: 1px solid #e2e8f0;
}
#entity-map {
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.detail-section { margin-bottom: 18px; }

/* ---- Entity detail: collapsible sections -------------------------- */
.detail-collapsible {
  margin-bottom: 18px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 2px 10px 10px;
  background: #fff;
}
.detail-collapsible > summary.detail-collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
  padding: 8px 4px 6px;
  user-select: none;
}
.detail-collapsible > summary.detail-collapsible-summary::-webkit-details-marker { display: none; }
.detail-collapsible > summary.detail-collapsible-summary::before {
  content: "▸";
  display: inline-block;
  font-size: 10px;
  width: 14px;
  transition: transform .15s ease;
}
.detail-collapsible[open] > summary.detail-collapsible-summary::before {
  transform: rotate(90deg);
}
.detail-collapsible-panel { padding: 0 4px 2px; }
.detail-collapsible-summary > span {
  flex: 1;
}
.detail-expand-btn {
  margin-left: auto;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 4px;
  width: 1.5rem;
  height: 1.5rem;
  line-height: 1.2rem;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 0;
}
.detail-expand-btn:hover {
  background: #eef2ff;
}

.livestock-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.livestock-year-range {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}
.livestock-year-label {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
}
.livestock-year-input {
  width: 4.2rem;
  margin-left: 4px;
  padding: 3px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
}
.livestock-btn-group {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.detail-action-btn--primary {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1e3a8a;
}
.detail-action-btn--primary:hover:not(:disabled) {
  background: #bfdbfe;
}

.detail-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.detail-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
  margin-bottom: 8px;
}
.detail-heading--inline {
  margin-bottom: 0;
}
.detail-action-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.detail-action-btn:hover:not(:disabled) { background: #dbeafe; }
.detail-action-btn:disabled {
  opacity: 0.75;
  cursor: default;
  color: #64748b;
  border-color: #cbd5e1;
  background: #f1f5f9;
}
.detail-livestock-range-hint {
  font-size: 11px;
  line-height: 1.4;
  margin: -2px 0 8px 0;
}
.detail-migration-status {
  font-size: 11px;
  margin: -4px 0 8px 0;
  word-break: break-all;
}
.detail-area { font-size: 18px; font-weight: 700; color: #1e293b; }
.detail-table-wrap {
  max-height: 11rem;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fff;
}
.detail-table-wide { overflow-x: auto; max-height: 11rem; }
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.detail-table th,
.detail-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}
.detail-table th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  font-weight: 600;
  color: #475569;
  z-index: 1;
}
.detail-table td:last-child,
.detail-table th:last-child { text-align: right; }
#child-table td:last-child,
#child-table th:last-child { text-align: right; }

.popup-detail-link {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}
.popup-detail-link a {
  color: #1d4ed8;
  font-weight: 600;
  font-size: 12px;
}
/* Map popup: entity detail link always visible above fold */
.popup-detail-link--top {
  margin-top: 4px;
  padding-top: 0;
  border-top: none;
}
.maplibregl-popup-content .popup-detail-anchor {
  display: inline-block;
  margin-top: 2px;
  padding: 4px 0;
  color: #1d4ed8 !important;
  font-weight: 700;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- Batch monitor panel ----------------------------------------- */
.batch-monitor {
  margin-top: 2px;
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}
.batch-monitor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
#batch-refresh-btn {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
}
#batch-refresh-btn:hover { background: #eef2ff; }
.batch-monitor-total {
  font-size: 12px;
  margin-bottom: 6px;
  color: #334155;
}
.batch-monitor-subhead {
  font-size: 11px;
  text-transform: uppercase;
  color: #64748b;
  margin: 8px 0 4px;
}
.batch-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 4px;
}
.batch-mini-table th,
.batch-mini-table td {
  padding: 4px 5px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}
.batch-mini-table th {
  color: #64748b;
  font-weight: 600;
}


/* ---- Expanded table modal ---------------------------------------- */
.table-expand-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 16px;
}
.table-expand-modal[hidden] {
  display: none;
}
.table-expand-dialog {
  width: min(96vw, 1200px);
  max-height: 92vh;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
}
.table-expand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
}
.table-expand-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
}
.table-expand-close {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
}
.table-expand-close:hover {
  background: #eef2ff;
}
.table-expand-body {
  padding: 8px 12px 12px;
  overflow: auto;
}
.table-expand-body .detail-table {
  font-size: 13px;
  min-width: 100%;
}
.table-expand-body .detail-table th {
  position: sticky;
  top: 0;
  z-index: 2;
}

#settings-btn {
  padding: 8px 14px;
  background: #0ea5e9;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
#settings-btn:hover { background: #0284c7; }

.ctrl-button-group-right {
  margin-left: auto;
}

.settings-modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
}
.settings-modal[hidden] {
  display: none;
}
.settings-dialog {
  width: min(1000px, 96vw);
  max-height: 90vh;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 36px rgba(2, 6, 23, 0.3);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #e2e8f0;
}
.settings-header h3 {
  font-size: 16px;
  color: #1e293b;
}
.settings-close {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
}
.settings-body {
  display: flex;
  min-height: 500px;
}
.settings-menu {
  width: 30%;
  border-right: 1px solid #e2e8f0;
  padding: 12px;
}
.settings-menu-item {
  width: 100%;
  text-align: left;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 600;
}
.settings-menu-item.active {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0c4a6e;
}
.settings-content {
  width: 70%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-tabs {
  display: flex;
  gap: 8px;
}
.settings-tab-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
}
.settings-tab-btn.active {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e3a8a;
}
.settings-subtab {
  display: none;
  overflow: auto;
}
.settings-subtab.active {
  display: block;
}
.settings-summary {
  font-size: 13px;
  color: #334155;
  margin-bottom: 10px;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.settings-row label {
  width: 120px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}
.settings-slider-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.settings-range {
  flex: 1;
}
.settings-value {
  width: 28px;
  text-align: right;
  font-weight: 700;
  color: #1e293b;
}
.settings-worker-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}
.settings-worker-title {
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 8px;
}
.settings-actions {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}
#settings-apply-btn {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
#settings-apply-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.settings-error {
  font-size: 12px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 6px;
  padding: 8px;
}
.settings-endpoints {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  padding: 8px;
}
.settings-endpoints-title {
  font-size: 11px;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 6px;
  font-weight: 700;
}
.settings-endpoint-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0;
  border-top: 1px solid #e2e8f0;
}
.settings-endpoint-row:first-of-type {
  border-top: none;
}
.settings-endpoint-host {
  font-weight: 600;
  color: #334155;
}
.settings-endpoint-url {
  color: #1e293b;
  word-break: break-all;
}
.settings-endpoint-status {
  font-weight: 700;
}
.settings-endpoint-row.ok .settings-endpoint-status {
  color: #166534;
}
.settings-endpoint-row.bad .settings-endpoint-status {
  color: #b91c1c;
}

.entity-create-panel {
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}

.entity-create-label {
  display: block;
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.entity-create-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
  color: #1e293b;
  background: #fff;
}

.entity-create-select {
  cursor: pointer;
}

.entity-create-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.entity-create-btn {
  margin-top: 10px;
  width: 100%;
}

/* ---- Explorer microscope (CEA-56) ----------------------------------- */
.explorer-microscope-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.explorer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  background: #f8f6ec;
  border-bottom: 1px solid rgba(26, 39, 68, 0.2);
}

.explorer-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 18px;
  color: #1a2744;
}

.explorer-header-brand-dot {
  color: #c77536;
}

.explorer-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.explorer-header-controls label {
  font-size: 12px;
  color: #3d5a80;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.explorer-header-controls select {
  min-width: 250px;
  padding: 7px 10px;
  border: 1px solid rgba(26, 39, 68, 0.35);
  border-radius: 4px;
  background: #fcfbf5;
  color: #1a2744;
}

.explorer-header-controls button {
  padding: 7px 10px;
  border: none;
  border-radius: 4px;
  background: #c77536;
  color: #fff;
  cursor: pointer;
}

.explorer-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(26, 39, 68, 0.2);
  background: #f3efe0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: #1a2744;
}

.explorer-breadcrumb-separator {
  color: #c77536;
}

.explorer-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  min-height: 0;
}

.explorer-fact-panel {
  border-right: 1px solid rgba(26, 39, 68, 0.2);
  background: #f8f6ec;
  padding: 12px;
  overflow: auto;
}

.explorer-panel-title {
  margin-bottom: 10px;
  font-size: 16px;
}

.explorer-panel-subtitle {
  margin-top: 14px;
  margin-bottom: 8px;
  font-size: 14px;
}

.explorer-fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.explorer-fact-card {
  border: 1px solid #e2dece;
  border-radius: 4px;
  background: #fdfcf7;
  padding: 8px;
  position: relative;
}

.explorer-fact-card--selectable {
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.explorer-fact-card--selectable:hover {
  border-color: #c77536;
  box-shadow: 0 1px 6px rgba(26, 39, 68, 0.12);
}

.explorer-fact-card--selectable:focus-visible {
  outline: 2px solid #c77536;
  outline-offset: 2px;
}

.explorer-fact-card--active {
  border-color: #c77536;
  border-left: 3px solid #c77536;
  box-shadow: 0 0 0 1px rgba(199, 117, 54, 0.25), 0 2px 8px rgba(26, 39, 68, 0.14);
}

.explorer-fact-card--active::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c77536;
}

.explorer-fact-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #3d5a80;
}

.explorer-fact-value {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  color: #1a2744;
  word-break: break-word;
}

.explorer-fact-note {
  margin-top: 10px;
  font-size: 12px;
  color: #3d5a80;
}

.explorer-hierarchy-grid {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.explorer-hierarchy-grid div {
  display: flex;
  justify-content: space-between;
  border: 1px solid #e2dece;
  border-radius: 4px;
  padding: 6px 8px;
  background: #fdfcf7;
}

.explorer-fact-card--action {
  display: flex;
  align-items: center;
  justify-content: center;
}

.explorer-more-info,
.explorer-switch-btn {
  width: 100%;
  border: 1px solid #c77536;
  border-radius: 4px;
  background: #fdfcf7;
  color: #1a2744;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  cursor: pointer;
}

.explorer-more-info:disabled,
.explorer-switch-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: #e2dece;
  color: #3d5a80;
}

.explorer-hierarchy-note {
  margin: 12px 0 8px;
  font-size: 12px;
  color: #3d5a80;
}

.explorer-switch-btn {
  margin-bottom: 4px;
}

.explorer-children-header {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.explorer-children-header .explorer-panel-subtitle {
  margin: 0;
}

.explorer-children-tree {
  margin-top: 8px;
  border: 1px solid #e2dece;
  border-radius: 4px;
  background: #fdfcf7;
  min-height: 72px;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  font-size: 12px;
  color: #3d5a80;
}

.explorer-child-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px;
  border-bottom: 1px solid #f0ead9;
}

.explorer-child-row:last-child {
  border-bottom: none;
}

.explorer-child-label {
  flex: 1;
  color: #1a2744;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.explorer-child-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.explorer-child-action-btn {
  border: 1px solid #c77536;
  border-radius: 3px;
  background: #fff;
  color: #1a2744;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.explorer-child-action-btn:hover:not(:disabled) {
  background: #f3efe0;
}

.explorer-child-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: #e2dece;
}

.explorer-map-wrap {
  position: relative;
  min-height: 0;
}

.explorer-map-wrap #map-status {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 10;
  width: min(440px, calc(100% - 28px));
}

.explorer-map-wrap #map {
  width: 100%;
  height: 100%;
}

.explorer-map-wrap .explorer-map-loading {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 12;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid rgba(26, 39, 68, 0.35);
  background: rgba(248, 246, 236, 0.92);
  color: #3d5a80;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.explorer-map-wrap .explorer-map-loading[hidden] {
  display: none;
}

.explorer-choropleth-legend {
  position: absolute;
  right: 14px;
  bottom: 44px;
  z-index: 12;
  width: 210px;
  padding: 8px 10px;
  border: 1px solid rgba(26, 39, 68, 0.35);
  border-radius: 4px;
  background: rgba(248, 246, 236, 0.96);
  box-shadow: 0 2px 8px rgba(26, 39, 68, 0.15);
}

.explorer-choropleth-legend[hidden] {
  display: none;
}

.explorer-choropleth-legend-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #1a2744;
}

.explorer-choropleth-legend-scale {
  margin-top: 6px;
  height: 10px;
  border-radius: 999px;
}

.explorer-choropleth-legend-scale--population {
  background: linear-gradient(90deg, #f7f7f7 0%, #cccccc 34%, #525252 68%, #000000 100%);
}

.explorer-choropleth-legend-scale--density {
  background: linear-gradient(90deg, #f7f7f7 0%, #fdd49e 34%, #fc8d59 68%, #b30000 100%);
}

.explorer-choropleth-legend-range {
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 10px;
  color: #3d5a80;
}

.explorer-microscope-body .drill-btn.drill-down {
  background: #c77536;
  color: #fff;
  border: 1px solid #a65d1a;
}

.explorer-microscope-body .drill-btn.drill-down:hover {
  background: #a65d1a;
}

/* ---- Explorer polish (CEA-59) ----------------------------------------- */

/* Button hover/focus states */
.explorer-header-controls button:hover {
  background: #d9864a;
}
.explorer-header-controls button:focus-visible {
  outline: 2px solid #c77536;
  outline-offset: 2px;
}

/* Select hover/focus states */
.explorer-header-controls select:hover {
  border-color: #c77536;
}
.explorer-header-controls select:focus {
  border-color: #c77536;
  outline: none;
  box-shadow: 0 0 0 2px rgba(199, 117, 54, 0.25);
}

/* Breadcrumb interactivity */
.explorer-breadcrumb a {
  color: #1a2744;
  text-decoration: none;
}
.explorer-breadcrumb a:hover {
  color: #c77536;
  text-decoration: underline;
}
.explorer-breadcrumb-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
  padding: 2px 8px;
  border: 1px solid rgba(26, 39, 68, 0.3);
  border-radius: 3px;
  background: #fcfbf5;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.explorer-breadcrumb-back:hover {
  border-color: #c77536;
  background: #fff;
}
.explorer-breadcrumb-back:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.explorer-breadcrumb-back:disabled:hover {
  border-color: rgba(26, 39, 68, 0.3);
  background: #fcfbf5;
}

/* Floating map drill-up button */
.map-drillup-btn {
  position: absolute;
  bottom: 100px;
  left: 10px;
  width: 36px;
  height: 36px;
  background: #f8f6ec;
  border: 1px solid #1a2744;
  border-radius: 4px;
  color: #1a2744;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  box-shadow: 0 2px 4px rgba(26, 39, 68, 0.15);
}
.map-drillup-btn:hover:not(:disabled) {
  background: #1a2744;
  color: #f8f6ec;
}
.map-drillup-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.map-drillup-btn:focus-visible {
  outline: 2px solid #c77536;
  outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Tier indicator dots */
.explorer-tier-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 10px;
  color: #3d5a80;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.explorer-tier-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid #1a2744;
  background: transparent;
  transition: background 0.2s, border-color 0.2s;
}
.explorer-tier-dot.active {
  background: #c77536;
  border-color: #c77536;
}
.explorer-tier-dot.visited {
  background: #1a2744;
}

/* Fact card bracket corners */
.explorer-fact-card {
  position: relative;
}
.explorer-fact-card::before,
.explorer-fact-card::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: #c77536;
}
.explorer-fact-card::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid;
  border-left: 2px solid;
}
.explorer-fact-card::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid;
  border-right: 2px solid;
}

/* Panel toggle button */
.explorer-panel-toggle {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 20px;
  height: 48px;
  border: 1px solid rgba(26, 39, 68, 0.3);
  border-left: none;
  border-radius: 0 4px 4px 0;
  background: #f8f6ec;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #3d5a80;
  transition: background 0.15s;
}
.explorer-panel-toggle:hover {
  background: #fff;
  color: #c77536;
}

/* Map info card (replaces popup for selected entity) */
.explorer-info-card {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 320px;
  max-width: calc(100% - 48px);
  background: #f8f6ec;
  border: 1px solid rgba(26, 39, 68, 0.3);
  border-radius: 4px;
  padding: 16px;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(26, 39, 68, 0.15);
}
.explorer-info-card::before,
.explorer-info-card::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: #c77536;
}
.explorer-info-card::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid;
  border-left: 2px solid;
}
.explorer-info-card::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid;
  border-right: 2px solid;
}
.explorer-info-card-title {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  color: #1a2744;
  margin-bottom: 4px;
}
.explorer-info-card-subtitle {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  color: #3d5a80;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.explorer-info-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.explorer-info-card-stat {
  font-size: 12px;
}
.explorer-info-card-stat-label {
  color: #3d5a80;
}
.explorer-info-card-stat-value {
  font-weight: 600;
  color: #1a2744;
}
.explorer-info-card-actions {
  display: flex;
  gap: 8px;
}
.explorer-info-card-btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #1a2744;
  border-radius: 3px;
  background: transparent;
  font-size: 12px;
  color: #1a2744;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.explorer-info-card-btn:hover {
  background: #1a2744;
  color: #f8f6ec;
}
.explorer-info-card-btn.primary {
  background: #c77536;
  border-color: #c77536;
  color: #fff;
}
.explorer-info-card-btn.primary:hover {
  background: #d9864a;
  border-color: #d9864a;
}

/* Responsive: stack layout on mobile */
@media (max-width: 768px) {
  .explorer-layout {
    grid-template-columns: 1fr;
  }
  .explorer-fact-panel {
    border-right: none;
    border-bottom: 1px solid rgba(26, 39, 68, 0.2);
    max-height: 200px;
    overflow: auto;
  }
  .explorer-header {
    flex-wrap: wrap;
  }
  .explorer-header-controls {
    width: 100%;
    justify-content: flex-end;
  }
  .explorer-info-card {
    bottom: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
  }
  .explorer-choropleth-legend {
    right: 12px;
    left: 12px;
    bottom: 52px;
    width: auto;
    max-width: none;
  }
}
