/* sql.css — SQL editor, result panels and time-limit controls (stream A5, main §5.6).
   First version from WP0c: the sort buttons of _result_grid.phtml. A5 owns it afterwards.
   The shared editor chrome (textarea.sql, .sql-toolbar, .tier-*, .result, .result-export) lives in the frozen
   app.css; only what A5 adds is here. templates/sql_fatal.phtml loads app.css alone, so it needs nothing here. */

.result-grid th .th-sort {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  gap: .35rem;
}

/* Editor chrome (sql-editor.md §5.6b, §5.6c) */
.editor-form .hint { margin: .3rem 0 0; font-size: 12px; color: var(--muted); }
.sql-status { font-size: 12px; min-height: 1em; color: var(--muted); }
#sql-timeout-warning { margin: .6rem 0 0; }
#sql-mode-help { margin: .5rem 0 0; }

/* Result panels (§5.6a) */
.result .badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .2rem .55rem;
  border-radius: 99px;
}
.result .badge-refused { background: var(--bad-soft); color: var(--bad); }
.result .callout p { margin: .15rem 0; }
.result .error-title { font-weight: 600; }
.result .result-footer .callout { flex: 1 1 100%; }
.result-wrap { max-height: 55vh; }
pre.excerpt,
.db-error-excerpt {
  margin: .4rem 0 0;
  padding: .5rem .7rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre;
  overflow-x: auto;
}

/* Explain output and A5's own dialogs (§5.6b) */
.explain-output { margin-top: 1rem; }
.explain-output:empty { display: none; }
.explain-plan h3 {
  margin: .75rem 0 .4rem;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--fg-soft);
}
.explain-json {
  max-height: 24rem;
  overflow: auto;
  padding: .65rem .85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.db-error p { margin: .15rem 0; }
.stmt-notes { margin: .2rem 0 0 1rem; font-size: 12px; color: var(--muted); }
.sql-dialog .stmts { max-height: 50vh; overflow: auto; }

/* Simulate (stream B1, sql-editor.md §4.5.4) */
.sql-toolbar button[aria-disabled="true"],
.sim-footer button[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.sql-simulate-reason { font-size: 12px; }
.sim-panel { margin-top: 1.25rem; }
.sim-title { margin: 0 0 .5rem; font-size: 15px; }
.sim-refusals, .sim-ack-lines { margin: .5rem 0; padding-left: 1.1rem; }
.sim-refusals li { margin: .4rem 0; }
.sim-refusals pre.sql, .sql-dialog .sim-refused-sql { display: block; margin: .25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.sim-footer { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; margin-top: 1rem; }
.sim-changed { font-size: 12px; }
/* Each statement's SQL shows its first 6 lines; sql.js adds [Show all SQL] to a longer one (§4.5.4 "expandable"). */
.sim-panel .report-item > pre.sql { max-height: calc(6 * 1.5em + 1.3rem + 2px); overflow: auto; }
.sim-panel .report-item > pre.sql.sim-sql-open { max-height: none; }
.sim-sql-toggle { font-size: 12px; margin-top: .25rem; }
.sql-dialog .report-triggers { font-size: 12.5px; }
.sql-dialog .sim-ack-lines { max-width: 60ch; }

/* Keyboard ergonomics and session notes (B2, §5.6b) */
.editor-form .sql-esc-hint { color: var(--fg); font-weight: 600; }
#sql-mode-help [data-mode-help][hidden] { display: none; }
.result .stmt-set-local { margin: .4rem 0; }

/* === Query history and snippets drawer (stream B3, main §5.8) ===
   Every selector is scoped under .sql-library or a .sql-lib-* class: B6's inspector also carries the spec's `drawer`
   class, so no bare .drawer rule is written here (contract map C-21). A right-hand panel below the sticky header,
   a full-width sheet under 720 px. The toolbar pair sits in its own span, so the toolbar's direct <button> children
   stay A5's and B1's [Explain] [Simulate] [Run] (B1's C-14 order test reads exactly those). */
.sql-lib-toolbar { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
.sql-lib-flash { flex: 1 1 12rem; min-width: 0; font-size: 12px; color: var(--fg-soft); overflow-wrap: anywhere; }
.sql-lib-flash.sql-lib-bad { color: var(--bad); }
.sql-library {
  position: fixed;
  top: var(--sticky-top, var(--header-h));
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(30rem, 100vw);
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding: .9rem 1rem 1rem;
  background: var(--panel-alt);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.sql-library .sql-lib-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.sql-library .sql-lib-tabs { display: flex; gap: .25rem; }
.sql-library .sql-lib-tab { padding: .4rem .9rem; font-size: 13px; }
.sql-library .sql-lib-tab[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sql-library .sql-lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; }
.sql-library .sql-lib-filter {
  flex: 1 1 100%;
  width: 100%;
  padding: .45rem .7rem;
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.sql-library .sql-lib-alldbs { display: inline-flex; align-items: center; gap: .35rem; margin: 0; font-size: 13px;
  text-transform: none; letter-spacing: 0; color: var(--fg-soft); }
.sql-library .sql-lib-count { margin: 0 0 0 auto; font-size: 12px; }
.sql-library .sql-lib-panel { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.sql-library .sql-lib-list { list-style: none; margin: 0; padding: 0; }
.sql-library .sql-lib-item { border-bottom: 1px solid var(--line); padding: .45rem 0; }
.sql-library .sql-lib-load {
  display: block;
  width: 100%;
  padding: .35rem .5rem;
  text-align: left;
  font-weight: 400;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.sql-library .sql-lib-load:hover { background: var(--panel); border-color: var(--line); }
.sql-library .sql-lib-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; font-size: 12px;
  color: var(--fg-soft); }
.sql-library .sql-lib-meta .tier { margin-right: 0; }
.sql-library .sql-lib-name { color: var(--fg); font-size: 13px; }
.sql-library .sql-lib-db,
.sql-library .sql-lib-badge { padding: .05rem .45rem; border: 1px solid var(--line-strong); border-radius: 99px; font-size: 11px; }
.sql-library .sql-lib-st-error, .sql-library .sql-lib-st-unknown { color: var(--bad); }
.sql-library .sql-lib-st-partial, .sql-library .sql-lib-st-running { color: var(--warn); }
.sql-library .sql-lib-st-ok { color: var(--ok); }
.sql-library .sql-lib-sql {
  display: block;
  margin-top: .3rem;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--fg);
}
.sql-library .sql-lib-note { display: block; margin-top: .2rem; font-size: 12px; color: var(--warn); }
.sql-library .sql-lib-actions { display: flex; gap: .25rem; margin-top: .2rem; }
.sql-library .sql-lib-actions button,
.sql-library .sql-lib-rename-row button { padding: .2rem .6rem; font-size: 12px; }
.sql-library .sql-lib-rename-row { display: flex; gap: .35rem; align-items: center; }
.sql-library .sql-lib-rename { flex: 1 1 auto; min-width: 0; }
.sql-library .sql-lib-status { margin: 0; min-height: 1em; font-size: 12px; color: var(--fg-soft); }
.sql-library .sql-lib-status.sql-lib-bad { color: var(--bad); }
.sql-library .sql-lib-foot { margin: .6rem 0 0; }
.sql-library [aria-busy="true"] { opacity: .6; cursor: progress; }
.sql-library .sql-lib-unlock { display: grid; gap: .35rem; margin-top: .6rem; }
.sql-library .sql-lib-unlock-nopw { display: inline-flex; align-items: center; gap: .35rem; margin: 0; font-size: 13px;
  text-transform: none; letter-spacing: 0; }
.sql-library .sql-lib-unlock-error { margin: 0; color: var(--bad); font-size: 12px; }
.sql-lib-modal .sql-lib-field { display: grid; gap: .3rem; }
.sql-lib-modal .sql-lib-scope { display: grid; gap: .3rem; margin: .8rem 0 0; border: 0; padding: 0; }
.sql-lib-modal .sql-lib-scope label { display: inline-flex; gap: .4rem; align-items: center; text-transform: none;
  letter-spacing: 0; }

@media (max-width: 720px) {
  .sql-library { left: 0; width: auto; border-left: 0; }
}
