/* Data Explorer styles. Loaded only by the explorer pages; tuned to sit on top
   of the shared cosmo theme defined in styles.css. */

#data-explorer {
  --ex-border: #e2e6ec;
  --ex-head-bg: #f6f8fa;
  --ex-zebra: #fafbfc;
  --ex-hover: #eef3fb;
  --ex-accent: #4c78a8;
  --ex-text: #1a1a2e;
  --ex-muted: #6a6a86;
  --ex-mono: "JetBrains Mono", "Fira Code", "Source Code Pro", ui-monospace, monospace;
  --ex-sans: "Source Sans Pro", "Helvetica Neue", Arial, sans-serif;
  font-family: var(--ex-sans);
  color: var(--ex-text);
  display: block;
  /* Full-bleed to the viewport width: the table owns its horizontal scroll, so it
     gains the most from breaking out of the themed (cosmo) content column. The
     content column is centered, so calc(50% - 50vw) puts the left edge at the
     viewport edge; --ex-sbw (the vertical-scrollbar width, set live in
     explorer.js) is subtracted so this never adds a horizontal page scrollbar. */
  width: calc(100vw - var(--ex-sbw, 0px));
  margin-top: 1rem;
  margin-bottom: 2rem;
  margin-left: calc(50% - 50vw + var(--ex-sbw, 0px) / 2);
  margin-right: calc(50% - 50vw + var(--ex-sbw, 0px) / 2);
  padding: 0 clamp(0.75rem, 2vw, 2rem);
  box-sizing: border-box;
}

/* --- loading ------------------------------------------------------------- */
.ex-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 3rem 1rem;
}

.ex-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--ex-border);
  border-top-color: var(--ex-accent);
  border-radius: 50%;
  animation: ex-spin 0.8s linear infinite;
}

@keyframes ex-spin {
  to {
    transform: rotate(360deg);
  }
}

.ex-loading-label {
  font-size: 0.9rem;
  color: var(--ex-muted);
}

.ex-progress {
  width: min(420px, 80%);
  height: 6px;
  background: var(--ex-border);
  border-radius: 3px;
  overflow: hidden;
}

.ex-progress-bar {
  height: 100%;
  width: 0;
  background: var(--ex-accent);
  transition: width 0.15s ease;
}

.ex-progress-bar.indeterminate {
  width: 40% !important;
  animation: ex-indet 1.1s ease-in-out infinite;
}

@keyframes ex-indet {
  0% {
    margin-left: -40%;
  }
  100% {
    margin-left: 100%;
  }
}

.ex-error {
  border-left: 4px solid var(--ex-accent);
  background: var(--ex-zebra);
  padding: 1rem 1.2rem;
  border-radius: 4px;
  font-size: 0.92rem;
}

.ex-error p {
  margin: 0.5rem 0 0;
  color: var(--ex-muted);
}

/* --- toolbar ------------------------------------------------------------- */
.ex-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
  position: relative;
}

.ex-tool {
  position: relative;
}

.ex-btn {
  font-family: var(--ex-sans);
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--ex-border);
  background: #fff;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ex-text);
}

.ex-btn:hover {
  border-color: var(--ex-accent);
}

.ex-btn-reset {
  color: var(--ex-muted);
}

/* Overflow ("⋯") menu: tucks away rarely-used output actions (CSV export) so
   they don't compete with the query controls. Sits at the toolbar's far right. */
.ex-tool-more {
  margin-left: 0;
}

.ex-btn-more {
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.3rem 0.6rem;
  color: var(--ex-muted);
}

/* Right-anchored so the menu opens toward the toolbar interior, not off-screen.
   The compound selector outranks `.ex-panel { left: 0 }`, which is defined later
   in this file and would otherwise win on source order. */
.ex-panel.ex-panel-menu {
  left: auto;
  right: 0;
  min-width: 190px;
  padding: 0.4rem;
}

.ex-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--ex-sans);
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  border: none;
  background: none;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ex-text);
}

.ex-menu-item:hover {
  background: var(--ex-hover);
}

/* CSV export is an output action, not a query control, so it lives in the
   overflow menu with a subtly distinct, accented treatment. */
.ex-btn-export {
  color: var(--ex-accent);
}

.ex-count {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--ex-muted);
  font-variant-numeric: tabular-nums;
}

.ex-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--ex-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(20, 30, 50, 0.12);
  padding: 0.8rem;
  max-height: 60vh;
  overflow: auto;
  min-width: 260px;
}

.ex-panel-wide {
  min-width: 340px;
}

/* Stats charts need room to breathe: the panel expands rightward into the
   full-bleed layout and grows taller before it scrolls. positionStatsPanel()
   (explorer.js) shifts it left if a wide panel would run past the viewport. */
.ex-panel-stats {
  width: 760px;
  min-width: 340px;
  max-width: calc(100vw - 1.5rem);
  max-height: 82vh;
}

.ex-presets {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
  border-bottom: 1px solid var(--ex-border);
  padding-bottom: 0.6rem;
}

.ex-chip {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--ex-border);
  background: var(--ex-head-bg);
  border-radius: 999px;
  cursor: pointer;
}

.ex-chip:hover {
  border-color: var(--ex-accent);
  color: var(--ex-accent);
}

.ex-check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.15rem 1rem;
}

.ex-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.1rem 0;
}

.ex-check-sm {
  font-size: 0.78rem;
}

/* A column display name stacked over its raw schema name (the SQL identifier). */
.ex-check-label {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.ex-col-raw {
  font-family: var(--ex-mono);
  font-size: 0.66rem;
  color: var(--ex-muted);
}

/* --- filter panel -------------------------------------------------------- */
.ex-filter-grid {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ex-filter-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: start;
  gap: 0.6rem;
}

.ex-filter-label {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  color: var(--ex-text);
  padding-top: 0.3rem;
  overflow-wrap: anywhere;
}

.ex-input {
  font-family: var(--ex-sans);
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--ex-border);
  border-radius: 4px;
  width: 100%;
  box-sizing: border-box;
}

.ex-input:focus {
  outline: none;
  border-color: var(--ex-accent);
}

.ex-range {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.ex-input-sm {
  width: 6rem;
}

.ex-range-sep {
  color: var(--ex-muted);
}

.ex-enum-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.8rem;
  max-height: 8rem;
  overflow: auto;
}

/* --- grid ---------------------------------------------------------------- */
.ex-grid {
  border: 1px solid var(--ex-border);
  border-radius: 6px;
  overflow: hidden;
}

.ex-grid-scroll {
  overflow: auto;
  height: 72vh;
  min-height: 360px;
  position: relative;
}

.ex-grid-inner {
  position: relative;
}

.ex-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  background: var(--ex-head-bg);
  border-bottom: 2px solid var(--ex-text);
}

.ex-th {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  padding: 0.5rem 0.6rem;
  font-family: var(--ex-mono);
  font-size: 0.74rem;
  color: var(--ex-muted);
  box-sizing: border-box;
  border-right: 1px solid var(--ex-border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}

/* Drag handle on the right edge of each header cell: drag to resize, */
/* double-click to autofit. Sits over the cell's right border. */
.ex-th-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}

.ex-th-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 2px;
  height: 100%;
  background: var(--ex-accent);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.ex-th-resizer:hover::after,
body.ex-resizing .ex-th-resizer::after {
  opacity: 0.6;
}

/* Keep the whole grid from selecting text while a column is being dragged. */
body.ex-resizing {
  cursor: col-resize;
  user-select: none;
}

.ex-th:hover {
  background: #eef1f5;
  color: var(--ex-accent);
}

.ex-th:focus-visible {
  outline: 2px solid var(--ex-accent);
  outline-offset: -2px;
}

.ex-th.ex-num {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.ex-th-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.ex-th-arrow {
  color: var(--ex-accent);
  font-size: 0.7rem;
}

.ex-body {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  will-change: transform;
}

.ex-row {
  display: flex;
  height: 30px;
  border-bottom: 1px solid var(--ex-border);
}

.ex-row:nth-child(even) {
  background: var(--ex-zebra);
}

.ex-row:hover {
  background: var(--ex-hover);
}

.ex-cell {
  flex: none;
  padding: 0 0.6rem;
  line-height: 30px;
  box-sizing: border-box;
  border-right: 1px solid var(--ex-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.82rem;
}

.ex-cell.ex-mono {
  font-family: var(--ex-mono);
  font-size: 0.78rem;
}

.ex-cell.ex-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--ex-mono);
  font-size: 0.78rem;
}

.ex-null {
  color: #c2c8d0;
}

/* Row-name link to the per-declaration detail page: inherit the cell's color so
   it reads as plain text until hovered. */
.ex-cell a.ex-link {
  color: inherit;
  text-decoration: none;
}

.ex-cell a.ex-link:hover {
  color: var(--ex-accent);
  text-decoration: underline;
}

.ex-bool-true {
  color: #2f8a4c;
  font-family: var(--ex-mono);
  font-size: 0.78rem;
}

.ex-bool-false {
  color: #b0566a;
  font-family: var(--ex-mono);
  font-size: 0.78rem;
}

.ex-empty {
  padding: 2rem;
  text-align: center;
  color: var(--ex-muted);
  font-size: 0.9rem;
}

/* --- composite sort indicators ------------------------------------------- */
.ex-th-sort {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* Priority badge shown on each sorted column when more than one key is active. */
.ex-th-pri {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ex-accent);
  background: #e6eef7;
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.35;
}

/* --- sort management panel ----------------------------------------------- */
.ex-sort-empty {
  font-size: 0.82rem;
  color: var(--ex-muted);
  padding: 0.3rem 0.1rem;
  max-width: 220px;
}

.ex-sort-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ex-sort-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--ex-border);
  border-radius: 5px;
  background: #fff;
}

.ex-sort-item.ex-sort-dragging {
  opacity: 0.5;
}

.ex-sort-item.ex-sort-over {
  border-color: var(--ex-accent);
  background: var(--ex-hover);
}

.ex-sort-grip {
  cursor: grab;
  color: var(--ex-muted);
  font-size: 0.9rem;
  line-height: 1;
}

.ex-sort-pri {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ex-accent);
  background: #e6eef7;
  border-radius: 3px;
  padding: 0 4px;
}

.ex-sort-name {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  font-size: 0.8rem;
  overflow: hidden;
}

.ex-sort-dir,
.ex-sort-del {
  border: 1px solid var(--ex-border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  width: 1.7rem;
  height: 1.5rem;
  line-height: 1;
  color: var(--ex-text);
}

.ex-sort-dir {
  color: var(--ex-accent);
}

.ex-sort-dir:hover {
  border-color: var(--ex-accent);
}

.ex-sort-del:hover {
  border-color: #b0566a;
  color: #b0566a;
}

.ex-sort-foot {
  margin-top: 0.6rem;
  display: flex;
  justify-content: flex-end;
}

/* --- filter: global connector + numeric modes + enum --------------------- */
.ex-filter-join {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--ex-border);
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.ex-filter-join-label {
  color: var(--ex-muted);
}

.ex-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

.ex-num-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ex-input-mode {
  width: auto;
  max-width: 100%;
  font-size: 0.76rem;
}

.ex-enum {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ex-enum-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.ex-enum-quick {
  display: flex;
  gap: 0.3rem;
}

.ex-chip-xs {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
}

/* --- stats panel --------------------------------------------------------- */
.ex-stats-empty {
  padding: 0.5rem 0.2rem;
  color: var(--ex-muted);
  font-size: 0.85rem;
}

.ex-stats-loading {
  display: flex;
  justify-content: center;
  padding: 1.2rem;
}

.ex-spinner-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.ex-stats-pick {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ex-muted);
  margin-bottom: 0.7rem;
}

.ex-stats-pick select {
  width: auto;
  max-width: 100%;
  font-family: var(--ex-mono);
}

.ex-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem 0.8rem;
  margin-bottom: 0.8rem;
}

.ex-stat {
  display: flex;
  flex-direction: column;
}

.ex-stat-k {
  font-size: 0.68rem;
  color: var(--ex-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.ex-stat-v {
  font-family: var(--ex-mono);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.ex-hist-note {
  font-size: 0.72rem;
  color: var(--ex-muted);
  margin-bottom: 0.4rem;
}

.ex-hist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 24rem;
  overflow: auto;
}

.ex-hist-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 4rem;
  align-items: center;
  gap: 0.5rem;
}

.ex-hist-label {
  font-family: var(--ex-mono);
  font-size: 0.72rem;
  color: var(--ex-muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ex-hist-track {
  background: var(--ex-zebra);
  border: 1px solid var(--ex-border);
  border-radius: 3px;
  height: 14px;
  overflow: hidden;
}

.ex-hist-fill {
  display: block;
  height: 100%;
  min-width: 1px;
  background: var(--ex-accent);
}

.ex-hist-count {
  font-family: var(--ex-mono);
  font-size: 0.72rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ex-text);
}

/* --- stats charts (column selection, chart-type chips, SVG plots) -------- */
.ex-stats-cols {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.8rem;
  margin-bottom: 0.7rem;
}

.ex-stats-cols .ex-stats-pick {
  margin-bottom: 0;
}

.ex-chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--ex-border);
}

.ex-chart-chip.is-active {
  background: var(--ex-accent);
  border-color: var(--ex-accent);
  color: #fff;
}

.ex-chart-chip.is-active:hover {
  color: #fff;
}

.ex-bins {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
  font-size: 0.74rem;
  color: var(--ex-muted);
}

.ex-bins select {
  width: auto;
  font-family: var(--ex-mono);
}

.ex-chart-svg {
  margin-top: 0.2rem;
}

.ex-chart-svg-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.ex-svg {
  display: block;
  width: 100%;
  height: auto;
}

.ex-svg-box {
  max-width: 100%;
}

.ex-svg-heatmap {
  max-height: 28rem;
}

.ex-axis {
  stroke: var(--ex-border);
  stroke-width: 1;
}

.ex-axt {
  font-family: var(--ex-mono);
  font-size: 8px;
  fill: var(--ex-muted);
}

.ex-axtitle {
  font-family: var(--ex-sans);
  font-size: 9px;
  fill: var(--ex-text);
}

.ex-pt {
  fill: var(--ex-accent);
  fill-opacity: 0.32;
}

.ex-box-line {
  stroke: var(--ex-muted);
  stroke-width: 1.2;
}

.ex-box-rect {
  fill: var(--ex-accent);
  fill-opacity: 0.3;
  stroke: var(--ex-accent);
  stroke-width: 1;
}

.ex-box-med {
  stroke: var(--ex-accent);
  stroke-width: 2;
}

.ex-hm-cell {
  fill: var(--ex-accent);
}

.ex-hm-empty {
  fill: var(--ex-zebra);
  stroke: var(--ex-border);
  stroke-width: 0.5;
}

@media (max-width: 768px) {
  .ex-check-grid {
    grid-template-columns: 1fr;
  }

  .ex-filter-row {
    grid-template-columns: 1fr;
  }

  .ex-stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .ex-grid-scroll {
    height: 64vh;
  }
}
