/* The page around the grid. The grid brings its own stylesheet and themes. */

:root {
  color-scheme: light;
  --ground: #ffffff;
  --surface: #f6f7f9;
  --ink: #16191d;
  --ink-2: #4d5761;
  --ink-3: #6b7580;
  --rule: #dfe3e7;
  --accent: #1a6bc7;
  --accent-ink: #ffffff;
  --meter: #1a6bc7;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0f1319;
  --surface: #171c24;
  --ink: #eaeef3;
  --ink-2: #b4bdc8;
  --ink-3: #8f9aa7;
  --rule: #2b333d;
  --accent: #5aa2f0;
  --accent-ink: #0b1118;
  --meter: #5aa2f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.loading { max-width: 640px; margin: 18vh auto; padding: 0 20px; text-align: center; }
.loading h1 { font-size: 1.5rem; margin: 0 0 10px; }
.loading-message { color: var(--ink-2); margin: 6px 0; }

/* -------------------------------------------------------- masthead */

.masthead { border-bottom: 1px solid var(--rule); padding-bottom: 14px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.masthead h1 {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
}
.lede { margin: 0; color: var(--ink-2); max-width: 82ch; }
.theme-toggle {
  font: 13px var(--sans);
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  align-self: flex-start;
}
.theme-toggle:hover { border-color: var(--accent); }

/* --------------------------------------------------------- controls */

.controls { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.row-label { font-size: 13px; color: var(--ink-2); min-width: 64px; }
.group-label { margin-left: 18px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }

.chip {
  font: 13px var(--sans);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--ground);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-clear { font-size: 13px; padding: 5px 8px; border: 0; background: none; color: var(--accent); cursor: pointer; }
.chip:focus-visible, .chip-clear:focus-visible, .theme-toggle:focus-visible, .search:focus-visible, .select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.search, .select {
  font: 13px var(--sans);
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--ground);
  color: var(--ink);
}
.search { width: 280px; max-width: 100%; }

/* ------------------------------------------------------------ stats */

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.stat {
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--surface);
  padding: 10px 14px;
  min-width: 0;
}
.stat-label { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 1.45rem; line-height: 1.3; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.meter { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin-top: 6px; }
.meter-fill { height: 100%; background: var(--meter); border-radius: 3px; transition: width 0.3s; }

/* ------------------------------------------------------- grid + map */

.window-hint { margin: 0; font-size: 13px; color: var(--ink-2); }
.split { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 14px; }
.pane { border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; height: 620px; min-width: 0; background: var(--surface); }
.grid-host, .map-host { height: 100%; width: 100%; }
.map-note { padding: 16px; color: var(--ink-2); font-size: 13px; }

/* ----------------------------------------------------------- queries */

.queries { border: 1px solid var(--rule); border-radius: 9px; background: var(--surface); padding: 10px 14px; }
.queries summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.query-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.q-time { font: 12px var(--mono); color: var(--ink-3); }
.q-sql {
  margin: 2px 0 0; padding: 8px 10px; border-radius: 7px; background: var(--ground); border: 1px solid var(--rule);
  font: 12px/1.5 var(--mono); color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 120px; overflow: auto;
}

/* -------------------------------------------------------- colophon */

.colophon { font-size: 12.5px; color: var(--ink-3); border-top: 1px solid var(--rule); padding-top: 12px; max-width: 110ch; }
.colophon p { margin: 0; }
.colophon a { color: var(--accent); }

/* ----------------------------------------------------------- narrow */

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat[data-stat="fetched"], .stat[data-stat="matches"], .stat[data-stat="partitions"] { grid-column: 1 / -1; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .pane { height: 480px; }
}
@media (max-width: 560px) {
  .app { padding: 16px 12px 40px; }
  .title-row { align-items: flex-start; }
  .group-label { margin-left: 0; }
  .search { width: 100%; }
  .row-label { min-width: 0; width: 100%; }
}

/* The status line (spinner, words, bar) and the cover over a panel that is still waiting. */
.spinner {
  display: inline-block;
  flex: none;
  width: 22px;
  height: 22px;
  border: 3px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.load-status {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--surface);
  padding: 14px 16px;
  text-align: left;
}
.load-status[hidden], .panel-loading[hidden], .load-bar[hidden] { display: none; }
.load-text { margin: 0; color: var(--ink); font-size: 14.5px; }
.load-bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--rule); overflow: hidden; }
.load-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.25s ease-out; }
.loading .load-status { margin-top: 22px; }
.panel-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 14px;
  text-align: center;
}
.panel-loading p { margin: 0; }

/* The wrapper that carries a panel's cover: it must not change the panel's size. */
.slot { position: relative; min-width: 0; }
.pane > .slot { height: 100%; width: 100%; }
.slot > .stats { min-height: 84px; }
