/* Indexing demo layout. Colours and controls come from ../shared/theme.css. */

html,
body { height: 100%; overflow: hidden; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 2;
}

.home {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px 4px 2px;
  border-radius: 6px;
}
.home:hover { color: var(--ink); background: var(--panel-2); }

.title {
  margin: 0 6px 0 0;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.group { display: flex; align-items: center; gap: 6px; }
.tools { display: flex; gap: 2px; margin-left: auto; }

.sql { font: 700 14px var(--mono); color: var(--muted); }
.val-input { width: 96px; font: 600 15px var(--mono); }
.val-input.flash { animation: flash 0.6s; }
#colSelect { font: 600 14px var(--mono); }

.limit-switch { margin-left: 6px; }
.limit-switch .sql { color: var(--muted); transition: color 0.15s; }
.limit-switch input:checked ~ .sql { color: var(--accent); }

.seg-method { height: 36px; align-items: stretch; }
.seg-method button { font-size: 14px; padding: 0 12px; }
.seg-method button[data-v="scan"].on { color: var(--orange); }
.seg-method button[data-v="index"].on { color: var(--violet); }

@keyframes flash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30% { box-shadow: 0 0 0 4px var(--accent-soft); border-color: var(--accent); }
}

/* ---------- Main area ---------- */

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}
body.no-sidebar .main { grid-template-columns: minmax(0, 1fr) 0; }
body.no-sidebar .sidebar { display: none; }

.stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.canvas-wrap {
  --watermark-bottom: 172px; /* sit above the scan progress rows */
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-height: 300px;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Caption (current step explanation) ---------- */

.caption {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 14px 10px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  pointer-events: none;
  transition: border-color 0.25s;
}
.caption[data-status="success"] { border-left-color: var(--good); }
.caption[data-status="warn"] { border-left-color: var(--warn); }
.caption[data-status="error"] { border-left-color: var(--bad); }

.caption-text {
  flex: 1 1 420px;
  margin: 0;
  font-size: 17px;
  font-weight: 550;
  line-height: 1.4;
  min-height: 2.8em;
}

.rules { display: flex; flex-wrap: wrap; gap: 6px; }
.rules span {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rules span b { color: var(--ink); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 120px;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--panel);
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow);
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Scoreboard ---------- */

.board {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 4px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.board.spot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }

.lane {
  --lane: var(--orange);
  --lane-soft: var(--orange-soft);
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) 92px 128px 128px minmax(140px, 2fr);
  align-items: center;
  gap: 14px;
  padding: 4px 8px;
  border-radius: 9px;
  transition: background 0.2s, opacity 0.2s;
}
.lane[data-lane="index"] { --lane: var(--violet); --lane-soft: var(--violet-soft); }
.lane.active { background: var(--lane-soft); }
.lane.empty { opacity: 0.55; }

.lane-name { display: flex; align-items: center; gap: 9px; min-width: 0; }
.lane-name b { display: block; font-size: 15px; color: var(--lane); white-space: nowrap; }
.lane-name small { display: block; font: 600 12px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane-name > div { min-width: 0; }
.dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--lane); }
.lane.active .dot { animation: blink 0.9s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.lane-num { display: flex; flex-direction: column; line-height: 1.15; }
.lane-num b { font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lane-num span { font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.lane-time b { color: var(--lane); }

.lane-bar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lane-bar .track { position: relative; flex: 1; height: 14px; border-radius: 7px; background: var(--line); overflow: hidden; }
.lane-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 7px; background: var(--lane); }
.lane-bar em {
  flex: none;
  font-style: normal;
  font-size: 13px;
  font-weight: 750;
  color: var(--good);
  white-space: nowrap;
}
.lane-bar em:empty { display: none; }

/* ---------- Player ---------- */

.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.transport { display: flex; align-items: center; gap: 6px; }
.transport .btn { width: 40px; height: 40px; }
.transport .play { width: 48px; height: 48px; border-radius: 50%; }
.transport .play .icon { width: 22px; height: 22px; }

.progress { flex: 1 1 220px; min-width: 180px; }
.progress-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
}
.progress-label span { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.progress-label .queue { color: var(--accent); font-weight: 600; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#progressFill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.3s; }

.speed { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.speed input { width: 110px; accent-color: var(--accent); }
.speed output { width: 40px; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------- Sidebar ---------- */

.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.panel h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel h2 span { text-transform: none; letter-spacing: 0; color: var(--ink); margin-left: 4px; }

.step-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 30vh;
  overflow-y: auto;
  counter-reset: step;
}
.step-log li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ink-2);
  cursor: pointer;
}
.step-log li::before {
  counter-increment: step;
  content: counter(step);
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.step-log li:hover { background: var(--panel-2); }
.step-log li.current { background: var(--accent-soft); color: var(--ink); }
.step-log li.current::before { color: var(--accent); }
.step-log li.s-success::before { color: var(--good); }
.step-log li.s-warn::before { color: var(--warn); }
.step-log li.k-read::before { color: var(--warn); }

.pseudo {
  margin: 0;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font: 12.5px/1.6 var(--mono);
}
.pseudo .ln {
  padding: 1px 10px 1px calc(9px + var(--indent, 0ch) + 2ch);
  text-indent: -2ch;
  border-left: 3px solid transparent;
  color: var(--ink-2);
}
.pseudo .ln.on { background: var(--accent-soft); border-left-color: var(--accent); color: var(--ink); font-weight: 650; }
.pseudo .ln .cm { color: var(--muted); font-weight: 400; }
.pseudo .empty { margin: 0; padding: 4px 12px; font-family: var(--font); font-size: 13px; color: var(--muted); }

.note { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.note:last-child { margin: 10px 0 0; }
.note b { color: var(--ink-2); }

.scale-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; font-weight: 600; }
.scale-label output { font-size: 15px; font-weight: 750; color: var(--accent); }
.scale-range { width: 100%; margin: 6px 0 10px; accent-color: var(--accent); }

.scale { display: grid; gap: 8px; }
.sc-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.sc-row .sc-name { font-weight: 700; }
.sc-row .sc-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.sc-row .sc-val b { color: var(--ink); }
.sc-row .sc-bar { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.sc-row .sc-bar i { display: block; height: 100%; min-width: 3px; border-radius: 5px; }
.sc-scan .sc-name { color: var(--orange); }
.sc-scan .sc-bar i { background: var(--orange); }
.sc-index .sc-name { color: var(--violet); }
.sc-index .sc-bar i { background: var(--violet); }
.scale-verdict { margin: 10px 0 0; font-size: 14px; font-weight: 700; color: var(--good); }
.scale-verdict.warn { color: var(--warn); }

.setting { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 12px; }
.setting:first-of-type { margin-top: 0; }
.setting-label { font-size: 13.5px; font-weight: 600; }
.setting-label small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.setting .switch { font-size: 13.5px; }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.sw { width: 20px; height: 16px; border-radius: 4px; flex: none; border: 1.5px solid var(--line-strong); background: var(--panel); }
.sw-data { background: linear-gradient(var(--accent-soft) 45%, var(--panel) 45%); }
.sw-index { background: linear-gradient(var(--violet-soft) 45%, var(--panel) 45%); }
.sw-reading { border: 2.5px solid var(--warn); }
.sw-visited { background: linear-gradient(var(--warn-soft) 45%, var(--panel) 45%); }
.sw-ram { position: relative; }
.sw-ram::after { content: ""; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sw-match { background: var(--good-soft); border-color: var(--good); }
.sw-nomatch { background: var(--panel-2); opacity: 0.55; }
.sw-compare { background: var(--warn-soft); border-color: var(--warn); }
.sw-ptr { border: 2.5px dashed var(--violet); background: transparent; }
.sw-free { border: 1.5px dashed var(--line-strong); background: var(--panel-2); }

/* ---------- Help modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 14, 22, 0.45);
}
.modal-card {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px 28px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 12px; font-size: 20px; }
.modal-card h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.modal-card ul { margin: 0; padding-left: 18px; }
.modal-card li { margin: 4px 0; font-size: 14px; }
.modal-card code { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.modal-close { position: absolute; top: 14px; right: 14px; }
.help-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 0 32px; }
.credit { margin: 20px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.credit b { color: var(--ink-2); }
.keys { border-collapse: collapse; font-size: 14px; }
.keys td { padding: 4px 12px 4px 0; }
.keys td:first-child { white-space: nowrap; }

/* ---------- Smaller screens ---------- */

@media (max-width: 1240px) {
  .lane { grid-template-columns: minmax(130px, 1fr) 80px 112px 112px minmax(100px, 1.4fr); gap: 10px; }
}

@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .main { grid-template-columns: 1fr; }
  body.no-sidebar .main { grid-template-columns: 1fr; }
  .canvas-wrap { height: 82vh; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .help-grid { grid-template-columns: 1fr; }
  .caption-text { font-size: 15px; flex-basis: 100%; }
  .group { flex-wrap: wrap; }
  .query { flex: 1 1 100%; min-width: 0; }
  .val-input { flex: 1; width: 0; min-width: 60px; }
  .lane { grid-template-columns: 1fr auto auto; gap: 4px 12px; }
  .lane-name { grid-column: 1 / -1; }
  .lane-num:nth-child(3) { display: none; }
  .lane-bar { grid-column: 1 / -1; }
  .lane-num b { font-size: 17px; }
}
