/* SQL track: the query workbench and the result grid.
 *
 * Only what the workbench needs. The page shell, the two-column reading
 * measure, the typography and the difficulty badges all come from core.css and
 * judge.css, and nothing here restates them -- a second copy of a token is a
 * second thing to change when the design moves.
 *
 * Every colour is a Design_Token. No literal hex, so dark mode needs no second
 * ruleset: the tokens already flip. */

/* ---------------------------------------------------------------------------
   THE PROBLEM IDE'S SQL-SPECIFIC PARTS.

   `_layouts/sqlp.html` is the DSA judge's shell, so `assets/css/judge.css`
   already styles the panes, the tabs, the divider, the console and the two
   buttons. Nothing of that is restated here -- a second copy of a token is a
   second thing to change when the design moves, which is this file's own
   opening rule.

   What is here is only what SQL adds: the dialect badge and the status line in
   the editor bar, the left pane's panels, the schema tab's tables, and the
   submissions list.
   --------------------------------------------------------------------------- */

/* ---- editor bar ---------------------------------------------------------- */

/* The dialect, in the slot the judge's language `<select>` occupies. A badge
   rather than a control because there is nothing to choose: Requirement 3
   criterion 13 is one dialect across the whole track. */
.lc-editor-bar .sqlw-badge {
  flex: none;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.6875rem;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
}

/* The one place engine state is shown, and a live region, so it must not
   reflow the bar as the text changes -- the bar's height is what the editor
   pane's is computed against, and a status that wrapped would push the console
   off the bottom. It takes the slack and ellipsizes instead.

   Colour carries the state. The WORDING is where the actionable difference
   lives, and every state a reader has to act on also renders in the Result
   tab below. */
.lc-editor-bar .sqlw-status {
  flex: 1 1 10rem;
  min-width: 0;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sqlw-status[data-state="ready"] { color: var(--easy, var(--success)); }
.sqlw-status[data-state="loading"],
.sqlw-status[data-state="initialising"],
.sqlw-status[data-state="busy"] { color: var(--medium, var(--warning)); }
/* Unsupported, offline and unavailable share one treatment on purpose: all
   three mean "no query will run", and distinguishing them by colour would
   imply a difference the reader cannot act on. */
.sqlw-status[data-state="unsupported"],
.sqlw-status[data-state="offline-incomplete"],
.sqlw-status[data-state="unavailable"] { color: var(--hard, var(--error)); }

/* Below the pane breakpoint the bar has no room for prose beside two buttons
   and an icon, so the status drops to its own line and is free to wrap there --
   an error is worth two lines on a phone. */
@media (max-width: 860px) {
  .lc-editor-bar { flex-wrap: wrap; height: auto; padding-bottom: 0.4rem; }
  .lc-editor-bar .sqlw-status { flex-basis: 100%; white-space: normal; overflow: visible; }
}

/* ---- left pane panels ---------------------------------------------------- */

/* Siblings shown and hidden by ide-shell.js. `hidden` is the attribute, and
   this makes sure nothing in judge.css re-displays it. */
.sqlp-panel[hidden] { display: none; }

/* The lessons a problem is drawn from, as the description pane's footer. */
.sqlp-lessons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.sqlp-lessons-label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sqlp-lesson-chip {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
}
.sqlp-lesson-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---- schema tab ---------------------------------------------------------- */

.sqlp-cpanel[hidden] { display: none; }
.sqlp-table + .sqlp-table { margin-top: 1.1rem; }
.sqlp-table-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.sqlp-table-name { font-size: 0.85rem; color: var(--accent); }
.sqlp-table-rows { font-size: 0.72rem; color: var(--text-muted); }
/* The column type under its name, so the header carries both without a second
   row -- Requirement 6 criterion 7 wants names AND types presented. */
.sqlp-coltype {
  display: block;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.65rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}
.sqlp-table-note { margin: 0.35rem 0 0; font-size: 0.72rem; color: var(--text-muted); }

/* ---- submissions tab ----------------------------------------------------- */

.sqlp-subs-empty { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }
.sqlp-sub-list { list-style: none; margin: 0; padding: 0; }
.sqlp-sub {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.sqlp-sub-verdict { font-weight: 600; color: var(--hard, var(--error)); }
.sqlp-sub[data-ok="true"] .sqlp-sub-verdict { color: var(--easy, var(--success)); }
.sqlp-sub-lang { color: var(--text-muted); font-size: 0.72rem; }
.sqlp-sub-when { margin-left: auto; color: var(--text-muted); font-size: 0.72rem; }

/* ---- editor -------------------------------------------------------------- */

/* `#sql-editor` IS the right pane's editor slot, carrying judge.css's
   `.lc-editor-wrap`, so it is already sized and already scrolls. All SQL adds
   is making CodeMirror fill it: `height: 100%` instead of the `height: auto`
   plus `min-height` the old inline block needed, because here there is a box to
   fill rather than content to grow around. */
#sql-editor .CodeMirror { height: 100%; font-size: 0.9rem; }
/* The textarea fallback, for a reader whose network blocks cdnjs. Styled to be
   usable rather than to match CodeMirror, because pretending to be the editor
   it is not would be worse than looking plain. */
.sqlw-fallback {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 9rem;
  padding: 0.6rem;
  border: 0;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
}

/* ---- output -------------------------------------------------------------- */

/* `#sql-out` is the console's Result tab. It must NOT collapse when empty the
   way the old inline block did -- the tab would then have no body and the
   console would look broken before the first Run -- so it carries its own
   empty-state message instead. */
#sql-out:empty::before {
  content: "Press Run to execute your query. Results appear here.";
  color: var(--text-muted);
  font-size: 0.85rem;
}
.sqlw-note { margin: 0.4rem 0; font-size: 0.875rem; color: var(--text-muted); }

.sqlw-verdict {
  margin: 0 0 0.6rem;
  font-weight: 650;
  font-size: 1rem;
}
.sqlw-verdict[data-v="accepted"] { color: var(--easy); }
.sqlw-verdict[data-v="wrong-answer"] { color: var(--hard); }
.sqlw-verdict[data-v="query-error"],
.sqlw-verdict[data-v="timeout"] { color: var(--medium); }
/* An engine failure is OURS, so it is muted rather than alarming: the reader
   has done nothing wrong and a red banner tells them they have. */
.sqlw-verdict[data-v="engine-unavailable"] { color: var(--text-muted); }

/* ---- result grid --------------------------------------------------------- */

.sqlg { margin: 0.8rem 0; }
.sqlg-cap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.sqlg-count { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Horizontal scroll on the WRAPPER, never on the page. A wide result set is
   normal -- SELECT * over a seeded table is the first thing a reader types --
   and a page that scrolls sideways because of it is a broken page. */
.sqlg-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.sqlg table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.sqlg th, .sqlg td {
  padding: 0.35rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.sqlg thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2, var(--surface));
  font-weight: 600;
}
.sqlg tbody tr:last-child td { border-bottom: 0; }
/* Numbers right-aligned and tabular, so a column of salaries can be compared
   by eye against the expected column. */
.sqlg-num { text-align: right; font-variant-numeric: tabular-nums; }
/* NULL must be visibly different from the empty string. Both render as nothing
   by default, and telling them apart is the single most common thing a reader
   needs from a result grid. */
.sqlg-null span {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  color: var(--text-muted);
  background: var(--border);
}
.sqlg-empty td { color: var(--text-muted); font-style: italic; white-space: normal; }

/* ---- errors and mismatches ---------------------------------------------- */

.sqlg-err, .sqlg-miss, .sqlg-dead {
  margin: 0.6rem 0;
  padding: 0.7rem 0.85rem;
  border-radius: 6px;
  border-left: 3px solid var(--border);
  background: var(--surface);
}
.sqlg-err { border-left-color: var(--medium); }
.sqlg-miss { border-left-color: var(--hard); }
.sqlg-dead { border-left-color: var(--text-muted); }
.sqlg-err-head { margin: 0 0 0.4rem; font-weight: 600; font-size: 0.9375rem; }
.sqlg-err-body {
  margin: 0;
  padding: 0.5rem 0.6rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  border-radius: 4px;
  background: var(--surface-2, var(--border));
  white-space: pre-wrap;
}

/* Row counts first, side by side, because a count difference is the fastest
   thing a reader can act on. */
.sqlg-counts {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.15rem 0.75rem;
  justify-content: start;
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}
.sqlg-counts dt { color: var(--text-muted); }
.sqlg-counts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

.sqlg-pair { width: 100%; margin: 0.5rem 0 0; border-collapse: collapse; font-size: 0.8125rem; }
.sqlg-pair caption { text-align: left; color: var(--text-muted); padding-bottom: 0.2rem; }
.sqlg-pair th { width: 8.5rem; text-align: left; color: var(--text-muted); font-weight: 500; padding: 0.2rem 0.5rem 0.2rem 0; }
.sqlg-pair td { padding: 0.2rem 0; }
.sqlg-pair code { white-space: pre-wrap; word-break: break-word; }

.sqlg-names { margin: 0.5rem 0; font-size: 0.8125rem; color: var(--text-muted); }
.sqlg-names summary { cursor: pointer; }

/* ---- schema panel -------------------------------------------------------- */

.sqlg-tbl { margin: 1rem 0; }
.sqlg-tbl h3 { margin: 0 0 0.35rem; font-size: 0.9375rem; }
.sqlg-cols {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
}
.sqlg-type { color: var(--text-muted); }

@media (max-width: 640px) {
  /* The panel's padding moved to its parts, so this tightens those instead. */
  .sqlw { border-radius: 8px; }
  .sqlg th, .sqlg td { padding: 0.3rem 0.45rem; }
}
