/* =======================
   EMC Page-Specific Overrides (conflict-free)
   Depends on the master stylesheet loaded first.
   ======================= */

/* ---------- Page-scoped tweaks and unique utilities ---------- */

/* Hide content inside a specific summary section when collapsed */
#summarySection.collapsed .collapsible-content {
  display: none;
}

/* Filter panel layout override: make left column narrower ONLY in this page's filter block */
#filtersTable .filter-left {
  flex: 0 0 25%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Table: page-specific column widths (scoped) ----------
   Replace #emcTable with your table's actual ID if different. */
#emcTable th:nth-child(1),
#emcTable td:nth-child(1) {
  width: 20px;
}

#emcTable th:nth-child(2),
#emcTable td:nth-child(2) {
  width: 150px;
}

#emcTable th:nth-child(3),
#emcTable td:nth-child(3) {
  width: 15%;
}

#emcTable th:nth-child(4),
#emcTable td:nth-child(4) {
  width: 20%;
}

#emcTable th:nth-child(5),
#emcTable td:nth-child(5) {
  width: 20%;
}

#emcTable th:nth-child(6),
#emcTable td:nth-child(6) {
  width: 15%;
}

#emcTable th:nth-child(7),
#emcTable td:nth-child(7) {
  width: 10%;
}

#emcTable th:nth-child(8),
#emcTable td:nth-child(8) {
  width: 10%;
}

/* Compact variable list rendering used on this page */
.var-list-compact {
  font-size: 12px;
  line-height: 1.35;
}

.var-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  border-bottom: 1px dashed #e5e7eb;
  padding: 2px 0;
}

.var-name {
  flex: 0 0 auto;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

.var-info {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ---------- Map legend specific to this page ---------- */
.map-legend.leaflet-control {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 1px 3px rgba(3, 7, 18, .06);
  font: 13px/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.map-legend .item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  white-space: nowrap;
}

.map-legend .swatch {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, .2);
  box-sizing: border-box;
}

.map-legend .swatch.blue {
  background: rgba(0, 0, 255, .08);
  outline: 2px solid blue;
  outline-offset: -2px;
}

.map-legend .swatch.orange {
  background: rgba(255, 120, 0, .08);
  outline: 2px solid #ff7800;
  outline-offset: -2px;
}

/* ---------- Toolbar container (buttons themselves come from master) ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0 10px;
}

/* ---------- Small components unique to this page ---------- */
.tip-box {
  background-color: #f9f2f2;
  border-left: 4px solid #690303;
  padding: 1em;
  margin-top: 1em;
  border-radius: 6px;
}

.tip-box h4 {
  margin-top: 0;
  font-size: 1.1em;
  color: #2f1d1d;
  display: flex;
  align-items: center;
  gap: 6px;
}

.info-icon {
  color: #690303;
  font-weight: bold;
}

.icon-bucket {
  margin-right: .25rem;
  vertical-align: -.125em;
}

.nav-icon {
  margin-right: .35rem;
  vertical-align: text-bottom;
  height: 1.1em;
  width: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

/* ---------- Media & badges ---------- */
#renderImage {
  max-width: 100%;
  height: auto;
  display: block;
}

.badge {
  margin-left: .5rem;
  font-size: .9em;
  padding: .15rem .4rem;
  border-radius: 999px;
  background: #f3f4f6;
}

.badge.muted {
  background: #fafafa;
  color: #555;
}

/* ---------- Jump-to-model row controls ---------- */
.jump-to-model {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 20px;
  max-width: 100%;
  flex-wrap: wrap;
  /* allow wrap on small screens */
}

.jump-label {
  white-space: normal;
}

#filteredModelsSelect {
  flex: 0 1 500px;
  max-width: 500px;
  min-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Description section (scoped collapsible behavior) ---------- */
#descriptionSection .collapsible-content {
  display: none;
}

#descriptionSection.open .collapsible-content {
  display: block;
}

/* Single, consistent triangle caret for this section */
#descriptionSection .triangle {
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  transform-origin: 3px 6px;
  transition: transform 150ms ease;
  margin-right: 6px;
  transform: rotate(90deg);
  /* closed: right-pointing */
}

#descriptionSection.open .triangle {
  transform: rotate(0deg);
  /* open: down-pointing */
}

#descriptionSection .collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

/* Generic plain variant (single definition) */
.collapsible-content.plain {
  margin: 0;
  padding: 0;
  background-color: transparent;
  border: none;
  box-shadow: none;
}

/* ---------- Misc. ---------- */
.desc-toggle {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
  text-decoration: none;
}

/* Hide when explicitly flagged with [hidden] */
#descriptionSection .collapsible-content[hidden] {
  display: none;
}

/* ---------- Filters Panel + Map: Taller layout (scoped to #filtersTable) ---------- */

/* A responsive height that grows with viewport but keeps a sensible min/max */
#filtersTable .two-column {
  min-height: 180px;
  height: 27.5vh;
  max-height: 390px;
}

/* Ensure left column stretches to full height */
#filtersTable .filter-left {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Make the Leaflet map fill the left column */
#filtersTable .filter-map {
  flex: 1 1 auto;
  min-height: 120px;
  /* guard-rail for smaller screens */
}

/* Right column: allow scrolling when content exceeds available height */
#filtersTable .filter-right {
  overflow: auto;
  max-height: 100%;
}

/* On wider screens give even more vertical space to filters */
@media (min-width: 1200px) {
  #filtersTable .two-column {
    height: 30vh;
    max-height: 450px;
  }
}

/* If the panel is collapsed, don't reserve height */
#filtersTable .collapsible:not(.open) .two-column {
  height: auto;
  min-height: 0;
  max-height: none;
}

/* ---------- Link-like button helper ---------- */
.linklike {
  background: none;
  border: none;
  padding: 0;
  color: #0645ad;
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
}

.linklike:hover {
  text-decoration: none;
}

/* ========== Models table layout ========== */
#modelsTable {
  table-layout: fixed;
  /* predictable sizing */
  width: 100%;
  font-size: 13px;
}

/* 1) Checkbox column: tiny, centered */
#modelsTable th:nth-child(1),
#modelsTable td:nth-child(1) {
  width: 28px;
  text-align: center;
  white-space: nowrap;
}

/* 2) Mini-map column: fixed visual box + metadata below */
#modelsTable th:nth-child(2),
#modelsTable td:nth-child(2) {
  width: 240px;
  /* tune: 200–260px works well */
  overflow: hidden;
  /* keep long metadata from blowing width */
}

/* Make the mini map consistent */
#modelsTable .mini-map {
  width: 100%;
  height: 100px;
  /* same as your global rule; can tweak */
  border: 1px solid #ccc;
  border-radius: 4px;
}

/* 3) Model info: medium column */
#modelsTable th:nth-child(3),
#modelsTable td:nth-child(3) {
  width: 18%;
}

/* 4) Title: a bit smaller than model info */
#modelsTable th:nth-child(4),
#modelsTable td:nth-child(4) {
  width: 14%;
}

/* 5) Summary: give this the most room among text cols */
#modelsTable th:nth-child(5),
#modelsTable td:nth-child(5) {
  width: 22%;
}

/* 6) Variables: medium */
#modelsTable th:nth-child(6),
#modelsTable td:nth-child(6) {
  width: 16%;
}

/* 7) Reference: smaller */
#modelsTable th:nth-child(7),
#modelsTable td:nth-child(7) {
  width: 12%;
}

/* 8) File info: smaller */
#modelsTable th:nth-child(8),
#modelsTable td:nth-child(8) {
  width: 10%;
}

/* ========== Readability & wrapping ========== */
#modelsTable th,
#modelsTable td {
  vertical-align: top;
  padding: 6px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: break-word;
  /* legacy */
  overflow-wrap: anywhere;
  /* modern */
}

/* Allow richer wrapping in the long text cells */
#modelsTable td:nth-child(5),
#modelsTable td:nth-child(6),
#modelsTable td:nth-child(7),
#modelsTable td:nth-child(8) {
  white-space: normal;
}

/* Keep link-heavy, meta blocks subdued */
#modelsTable td:nth-child(7),
#modelsTable td:nth-child(8) {
  font-size: 12px;
  color: #333;
}

/* Compact row height */
#modelsTable tbody tr {
  line-height: 1.25;
}

/* Subtle hover to track rows */
#modelsTable tbody tr:hover {
  background: #f7fafc;
}

/* Selected highlight you already use */
#modelsTable tr.selected {
  outline: 2px solid #4a90e2;
  background: #eef6ff;
}

/* Make variable list compact inside table */
#modelsTable .var-list-compact {
  font-size: 12px;
  line-height: 1.35;
}

/* Tighten the tiny metadata under the mini-map */
#modelsTable .mini-map+div {
  font-size: 11px;
  color: #444;
  margin-top: 4px;
  line-height: 1.25;
}

/* ========== Responsive tweaks ========== */
/* On narrow screens, relax fixed widths so it can squeeze */
@media (max-width: 1100px) {

  #modelsTable th:nth-child(2),
  #modelsTable td:nth-child(2) {
    width: 200px;
  }

  #modelsTable th:nth-child(3),
  #modelsTable td:nth-child(3),
  #modelsTable th:nth-child(5),
  #modelsTable td:nth-child(5) {
    width: auto;
  }
}

/* On very narrow screens, stack more gracefully */
@media (max-width: 900px) {
  #modelsTable {
    table-layout: auto;
  }

  /* let browser recalc */
  #modelsTable th:nth-child(1),
  #modelsTable td:nth-child(1) {
    width: 28px;
  }

  /* keep checkbox tiny */
  #modelsTable th:nth-child(2),
  #modelsTable td:nth-child(2) {
    width: 180px;
  }

  /* smallest usable map col */
}

/* Center the checkbox in the first column of #modelsTable */
#modelsTable th:nth-child(1),
#modelsTable td:nth-child(1) {
  text-align: center;
  /* horizontal center */
  vertical-align: top;
  /* add top spacing */
  padding-top: 6px;
  /* vertical center */
  width: 28px;
  /* keep it narrow */
  padding: 0;
  /* optional: tighter */
}

/* Make sure the checkbox itself doesn't have weird inline offsets */
#modelsTable td:nth-child(1) input[type="checkbox"] {
  display: inline-block;
  margin: 0;
  /* remove default form-control margins */
  vertical-align: top;
}