/*
 * FL/HFL link viewer components. Base typography, colours, layout, forms and
 * buttons come from /static/unified.css; the plot palette is local.
 */

:root {
  --fl-teal: #0f8b8d;
  --fl-teal-soft: #dff3f1;
  --fl-coral: #d65a31;
  --fl-amber: #b9851b;
  --fl-green: #208a56;
}

.subtle { color: var(--muted); }
.path-label { overflow-wrap: anywhere; }

/* Labels inside the viewer share one style: Manrope, small, muted. */
.search-field span,
.select-field span,
.view-mode-label,
.view-mode-help,
.plot-3d-controls,
.result-meta,
.pagination,
.fl-result h4 {
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: end;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.search-field { flex: 1 1 22rem; }
.select-field { flex: 0 0 12rem; }
.search-field span,
.select-field span { display: block; margin-bottom: var(--space-2); }
.search-field input,
.select-field select { width: 100%; }

.result-meta,
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

/* Sections */
.plot-panel,
.content-band {
  margin-bottom: var(--space-5);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.content-band h2 { margin-bottom: var(--space-4); font-size: var(--text-lg); }
.content-band > * + * { margin-top: var(--space-4); }
.content-band > .subtle { max-width: none; font-size: var(--text-sm); }

.plot-grid,
.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

/* Tables */
.table-frame {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table-frame.compact { max-height: 32rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  line-height: 1.5;
}
.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-muted);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table td > code { padding: 0; background: none; }

.link-name { display: block; font-weight: 600; }
.file-id {
  display: block;
  margin-top: var(--space-1);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem var(--space-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
}
.status-pill.success { background: #e3f5ec; border-color: #b7e0cb; color: var(--fl-green); }
.status-pill.error,
.status-pill.failed { background: #fae8e0; border-color: #efc4b3; color: var(--fl-coral); }

/* Plot view controls */
.view-mode-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.view-mode-label { margin-right: var(--space-1); }
.view-mode-help { margin-left: auto; font-weight: 400; }

.view-mode-button,
.reset-view {
  min-height: 2rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--deep-blue);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}
.view-mode-button:hover,
.reset-view:hover { background: var(--deep-blue-soft); border-color: var(--deep-blue); }
.view-mode-button.active { border-color: var(--fl-teal); background: var(--fl-teal-soft); color: var(--fl-teal); }

.plot-3d-view[hidden],
[data-plot-2d][hidden] { display: none; }

.polytope-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 520 / 360;
  min-height: 280px;
  border-radius: var(--radius);
  outline: none;
  cursor: grab;
  touch-action: none;
}
.polytope-canvas:focus-visible { box-shadow: var(--focus-ring); }
.polytope-canvas.is-dragging { cursor: grabbing; }

.plot-3d-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-2);
  font-weight: 400;
}

.caption { margin: var(--space-2) 0 0; color: var(--muted); font-size: var(--text-sm); }

.alexander-summary { margin-block: var(--space-4); }
.alexander-panel { min-width: 0; width: 50%; margin: 0 auto; }

.polytope-plot .vertex[data-vertex-coordinates] { cursor: pointer; }
.polytope-plot .vertex[data-vertex-coordinates]:focus { outline: none; stroke-width: 3.5; }

.plot-hover-tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: #172027f0;
  color: #ecf6f3;
  font: 600 var(--text-xs) var(--font-mono);
  white-space: nowrap;
}

.code-block {
  margin: 0;
  padding: var(--space-4);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--ink);
  font-size: var(--text-xs);
  white-space: pre-wrap;
}

/* F_L results */
.fl-results > .caption { margin-top: var(--space-2); }
.fl-result {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.fl-result-heading,
.fl-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-4);
}
.fl-grid {
  grid-template-columns: minmax(280px, 1.3fr) minmax(230px, 0.7fr);
  margin: var(--space-4) 0;
}
.fl-result h3,
.fl-result h4 { margin: 0; }

.vertex-pill {
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  background: var(--fl-teal-soft);
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
}
.vertex-pill.muted { background: var(--surface-muted); color: var(--muted); }
.braid-plot {
  display: block;
  width: 100%;
  max-height: 280px;
  margin-top: var(--space-4);
}

.braid-strand {
  stroke: #111820;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.braid-gap {
  stroke: #ffffff;
  stroke-width: 8;
  stroke-linecap: butt;
}

.braid-plot-bg {
  fill: #ffffff;
  stroke: var(--border);
}

.inversion-cycle-plot {
  display: block;
  width: 240px;
  min-width: 180px;
}

.inversion-negative {
  stroke: var(--fl-coral);
  stroke-width: 3.2;
  stroke-linecap: round;
}

.inline-code-block {
  max-height: 180px;
  margin: 0;
  padding: var(--space-2);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: var(--text-xs);
}

.table-code {
  max-width: 420px;
  max-height: 180px;
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 0;
  background: none;
  white-space: pre-wrap;
  font-size: var(--text-xs);
}

.copyable-cell {
  position: relative;
}

.copy-cell {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  padding: 0.125rem var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.copyable-cell:hover .copy-cell,
.copyable-cell:focus-within .copy-cell {
  opacity: 1;
  pointer-events: auto;
}

.copy-cell.copied {
  border-color: var(--fl-teal);
  color: var(--fl-teal);
}

.definition-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.4fr) minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.definition-grid dt {
  color: var(--muted);
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: 600;
}

.definition-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.polytope-plot {
  display: block;
  width: 100%;
  height: auto;
}

.plot-bg {
  fill: #fbfcfc;
  stroke: var(--border);
}

.plot-title {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.axis {
  stroke: #99a8af;
  stroke-width: 1;
}

.tick {
  stroke: #a7b3b8;
  stroke-width: 1;
}

.tick-label {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
}

.tick-label.y {
  text-anchor: end;
}

.axis-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-anchor: end;
}

.axis-label.y {
  text-anchor: start;
}

.poly-fill {
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.poly-fill.hfk {
  fill: rgba(15, 139, 141, 0.14);
  stroke: var(--fl-teal);
}

.poly-fill.thurston {
  fill: rgba(214, 90, 49, 0.13);
  stroke: var(--fl-coral);
}

.poly-edge {
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.poly-edge.hfk {
  stroke: var(--fl-teal);
}

.poly-edge.thurston {
  stroke: var(--fl-coral);
}

.poly-fill.alexander {
  fill: #7556a8;
  fill-opacity: 0.18;
  stroke: #7556a8;
}

.poly-edge.alexander {
  stroke: #7556a8;
}

/* Overlaid polygons need lighter fills so the inner one stays readable. */
.poly-fill.overlay {
  fill-opacity: 0.16;
}

.poly-fill.thurston.overlay {
  fill: var(--fl-coral);
}

.poly-fill.alexander.overlay {
  fill: #7556a8;
}

.legend-swatch {
  stroke-width: 1.4;
}

.legend-swatch.thurston {
  fill: rgba(214, 90, 49, 0.22);
  stroke: var(--fl-coral);
}

.legend-swatch.alexander {
  fill: rgba(117, 86, 168, 0.22);
  stroke: #7556a8;
}

.legend-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.support-point {
  fill: #263640;
  opacity: 0.62;
}

.vertex {
  fill: #ffffff;
  stroke: var(--fl-amber);
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.vertex.candidate {
  stroke: #c78a00;
  fill: #fff0b8;
}

.vertex.thurston {
  stroke: var(--fl-coral);
  fill: #fae8e0;
}

.vertex.thurston.candidate {
  stroke: #c78a00;
  fill: #fff0b8;
}

.thurston-panel {
  width: 50%;
  margin: 16px auto 0;
}

.hfl-panel {
  width: 50%;
  margin: 16px auto 0;
}

.vertex.alexander,
.vertex.alexander.candidate {
  stroke: #7556a8;
  fill: #eee7f7;
}

.empty-plot {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-anchor: middle;
}

@media (max-width: 900px) {
  .plot-grid,
  .split-grid,
  .fl-grid {
    grid-template-columns: 1fr;
  }

  .alexander-panel,
  .thurston-panel,
  .hfl-panel {
    width: 100%;
  }

  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .select-field {
    flex-basis: auto;
  }

  .view-mode-bar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .view-mode-help {
    flex-basis: 100%;
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  .plot-panel,
  .content-band {
    padding: var(--space-4);
  }
}

/* Detail pages use open sections; tables keep their own scrollable frames. */
.fl-detail .content-band,
.fl-detail .fl-result {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.fl-detail .content-band {
  margin-block: var(--space-7);
}
