/* Clean minimal.
 *
 * The previous stylesheet was a literal port of the Dash app's CSS: drop
 * shadows on every panel, 2px black fieldset borders, black inverted-pill
 * legends, darkorange links, and Gill Sans in the table against system-ui
 * everywhere else. This replaces the chrome with whitespace and hairlines, and
 * puts everything on one type scale and one family.
 *
 * Ink and surface values are the data-viz reference tokens, so the page and
 * the plots sit on the same palette.
 */

:root {
  --surface:        #fcfcfb;   /* chart + page surface */
  --raised:         #ffffff;
  --ink:            #0b0b0b;
  --ink-secondary:  #52514e;
  --ink-muted:      #898781;
  --hairline:       #e1e0d9;
  --accent:         #2a78d6;   /* categorical slot 1 */
  --accent-wash:    #eef4fd;

  --step--1: 0.8125rem;
  --step-0:  0.9375rem;
  --step-1:  1.125rem;
  --step-2:  1.5rem;
  --step-3:  1.875rem;

  --space:   1rem;
  --radius:  6px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* [hidden] is a UA rule with almost no specificity, so any `display` set by a
   class beats it. `.field` and `.checkbox-grid label` are both flex, which
   silently broke the substrate search filter and the b-input toggle. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.5;
}

#main-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: calc(var(--space) * 2) calc(var(--space) * 1.5);
}

.grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 6fr); gap: calc(var(--space) * 2); align-items: start; }
.grid > .left { display: flex; flex-direction: column; gap: calc(var(--space) * 2); min-width: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: calc(var(--space) * 2); align-items: start; }

@media (max-width: 1180px) { .grid { grid-template-columns: 1fr; } }
@media (max-width: 720px)  { .row  { grid-template-columns: 1fr; } #main-container { padding: var(--space); } }

/* Panels are defined by space, not boxes. Only the display panel keeps a
   hairline, because the plots need an edge to sit against. */
.card { background: none; border: 0; padding: 0; }
.card + .card { margin-top: calc(var(--space) * 2); }
.right {
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: calc(var(--space) * 1.25);
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.011em; margin: 0; }
h1 { font-size: var(--step-3); line-height: 1.2; }
h2 { font-size: var(--step-1); margin-bottom: calc(var(--space) * 0.75); }
h3 {
  font-size: var(--step--1); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin: calc(var(--space) * 1.5) 0 calc(var(--space) * 0.5);
}
#header h3 { font-size: var(--step-0); text-transform: none; letter-spacing: normal;
             color: var(--ink-secondary); font-weight: 400; margin: 0.35em 0 0.6em; }
p { margin: 0.35em 0; color: var(--ink-secondary); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.modal-link { color: var(--accent); cursor: pointer; text-decoration: none; }
.modal-link:hover { text-decoration: underline; }

.readout {
  border: 0;
  border-left: 2px solid var(--hairline);
  padding: 0.15rem 0 0.15rem 0.7rem;
  margin: 0 0 var(--space);
  font-size: var(--step--1);
  color: var(--ink-secondary);
  max-height: 5.5em; overflow-y: auto;
}

/* Sliders */
input[type="range"] {
  width: 100%; margin: 0.3rem 0 0; accent-color: var(--accent);
  background: none;
}
.slider-marks {
  display: flex; justify-content: space-between;
  font-size: var(--step--1); color: var(--ink-muted);
}

/* Table */
.table-wrap { overflow: auto; max-height: 22rem; margin-top: 0.25rem; }
#matches-table {
  width: 100%; border-collapse: collapse;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}
#matches-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  text-align: right; font-weight: 600; color: var(--ink-muted);
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
#matches-table th:first-child, #matches-table td:first-child { text-align: left; }
#matches-table td {
  padding: 0.35rem 0.6rem; text-align: right;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
}
#matches-table tbody tr:hover td { background: var(--accent-wash); }
/* A colour chip carries substrate identity beside the name, so the plots and
   the table agree without the text itself wearing a series colour. */
.chip {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin-right: 0.5rem; vertical-align: baseline;
  outline: 1px solid rgba(11, 11, 11, 0.12); outline-offset: -1px;
}
.table-foot {
  display: flex; align-items: center; gap: 0.6rem;
  margin-top: 0.6rem; font-size: var(--step--1); color: var(--ink-muted);
}
#page-status { flex: 1; font-variant-numeric: tabular-nums; }

/* Controls */
.field { display: flex; align-items: center; gap: 0.6rem; margin: 0.4rem 0; }
.field label { width: 4em; font-size: var(--step--1); color: var(--ink-secondary); }
.radio-row { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: var(--step--1); margin: 0.4rem 0; }
.radio-row label { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); margin: 0; }

input[type="number"], input[type="text"], input[type="search"] {
  font: inherit; font-size: var(--step--1);
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--hairline); border-radius: 4px;
  background: var(--raised); color: var(--ink);
  min-width: 0;
}
input:focus-visible, button:focus-visible, [type="range"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn, .btn-sm {
  font: inherit; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--raised); color: var(--ink);
  transition: background 120ms ease, border-color 120ms ease;
}
.btn { padding: 0.45rem 0.9rem; font-size: var(--step--1); }
.btn-sm { padding: 0.2rem 0.55rem; font-size: var(--step--1); }
.btn:hover, .btn-sm:hover:not(:disabled) { background: var(--accent-wash); border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #256abf; border-color: #256abf; }
.btn-sm:disabled { color: var(--ink-muted); cursor: default; opacity: 0.55; }

.note { font-size: var(--step--1); color: var(--ink-muted); margin: 0.5rem 0 0; }
.graph { width: 100%; }

/* Legend for the map: identity is never colour alone. */
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin: 0.6rem 0 0; font-size: var(--step--1); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--ink-secondary); }

/* Fieldsets: hairline rule + a quiet label, replacing the black pill */
fieldset { border: 0; border-top: 1px solid var(--hairline); padding: 0; margin: calc(var(--space) * 1.5) 0 0; }
legend {
  padding: 0 0.6rem 0 0; font-size: var(--step--1); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted);
}
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem 1.2rem; margin-top: 0.6rem; }
.filter-grid label { display: block; font-size: var(--step--1); color: var(--ink-secondary); margin-bottom: 0.2rem; }
.filter-grid input { width: 100%; }
@media (max-width: 700px) { .filter-grid { grid-template-columns: 1fr; } }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; font-size: var(--step--1); }
.chip-row label, .plane-row label { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.plane-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem 0.9rem; margin: 0.45rem 0; font-size: var(--step--1); }
.plane-row > strong { min-width: 7.5em; font-weight: 600; color: var(--ink-secondary); }

.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.15rem 1rem; max-height: 46vh; overflow-y: auto;
  border: 1px solid var(--hairline); border-radius: 4px;
  padding: 0.7rem; font-size: var(--step--1);
}
.checkbox-grid label { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; padding: 0.1rem 0; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(11, 11, 11, 0.32);
  display: flex; align-items: center; justify-content: center; padding: var(--space);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--raised); border-radius: var(--radius);
  max-width: 820px; width: 100%; max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 48px rgba(11, 11, 11, 0.16);
}
.modal > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space) calc(var(--space) * 1.25);
  border-bottom: 1px solid var(--hairline);
}
.modal > header h2 { margin: 0; }
.modal-close {
  background: none; border: 0; font-size: 1.5rem; line-height: 1;
  cursor: pointer; color: var(--ink-muted); padding: 0 0.2rem;
}
.modal-close:hover { color: var(--ink); }
.modal-body { padding: var(--space) calc(var(--space) * 1.25); overflow-y: auto; }
.modal-body h3 { margin-top: calc(var(--space) * 1.25); }
.modal > footer {
  padding: var(--space) calc(var(--space) * 1.25);
  border-top: 1px solid var(--hairline); text-align: right;
}
.modal-actions { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.7rem; }
.modal-actions input[type="search"] { flex: 1; }

#loading {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--ink-muted);
}
#loading[hidden] { display: none; }
#loading.error { color: #d03b3b; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
