/* /tools/query-generator - page-specific rules ONLY. Shared primitives
   (tokens, buttons, cards, notices, form controls) come from tokens.css /
   site.css and tools.css. No new colors: every value here is a site token.
   Mono is for identifiers and generated SQL only. */

/* ---------- Tool area: full viewport width ---------- */
.qg-tool { padding: 32px 0 clamp(48px, 6vw, 72px); }
.qg-full { padding: 0 clamp(16px, 2vw, 32px); }

/* Builder on the left, the SQL it produces on the right. The output pane is
   sticky, so every change is visible without scrolling. Below 1100px the
   panes stack and a jump link leads to the SQL. */
.qg-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; align-items: start; }
.qg-builder, .qg-output { min-width: 0; }
@media (min-width: 1100px) {
    .qg-layout { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(28px, 2.4vw, 48px); }
    .qg-output { position: sticky; top: 88px; }
    #qg-sql { max-height: calc(100vh - 260px); }
    .qg-jump { display: none; }
}

.qg-jump {
    display: inline-block; margin-bottom: 16px; font-size: .92rem; font-weight: 600; color: var(--link);
    text-underline-offset: 3px; min-height: 24px;
}
.qg-jump:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }

/* ---------- Controls ---------- */
.qg-bar { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; margin-bottom: 24px; }
.qg-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.qg-field label { font-size: .86rem; font-weight: 600; color: var(--heading); }
.qg-field select, .qg-field input { padding: 9px 12px; font-size: .95rem; min-width: 0; }
.qg-field input { width: 9em; font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-variant-ligatures: none; }

.qg-group { margin: 0 0 28px; }
.qg-h { font-size: 1.05rem; margin: 0 0 10px; color: var(--heading); }
.qg-rows { display: grid; gap: 10px; margin-bottom: 10px; }
.qg-rows:empty { display: none; }
.qg-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.qg-row select, .qg-row input { padding: 8px 10px; font-size: .9rem; min-width: 0; }
.qg-row input { font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-variant-ligatures: none; }
.qg-row input::placeholder, #qg-ddl::placeholder { color: var(--muted); opacity: 1; }
.qg-col-name { min-width: 15em; }
.qg-agg { min-width: 12em; }
.qg-alias { width: 12em; }
.qg-value { width: 15em; }
.qg-op { min-width: 9em; }
.qg-on { min-width: 12em; }
.qg-eq { color: var(--muted); font-family: "JetBrains Mono", monospace; }
.qg-combine { min-width: 6em; }
.qg-dir { min-width: 7em; }

.qg-group-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

.qg-add, .qg-remove {
    background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
    padding: 6px 14px; font: inherit; font-size: .86rem; cursor: pointer; min-height: 36px;
}
.qg-remove { display: inline-flex; align-items: center; justify-content: center; padding: 0; width: 36px; margin-left: auto; }
.qg-add:hover, .qg-remove:hover { border-color: var(--link); color: var(--heading); }
.qg-add:focus-visible, .qg-remove:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.qg-clear { margin-left: auto; }

.qg-check { display: inline-flex; align-items: center; gap: 10px; font-size: .92rem; color: var(--ink); cursor: pointer; min-height: 36px; }
.qg-check input { width: 18px; height: 18px; accent-color: var(--blue-bright); }

/* ---------- Output pane ---------- */
.qg-sql-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 12px; }
.qg-sql-title { margin: 0 auto 8px 0; font-size: 1.2rem; }
.qg-engine { flex-direction: row; align-items: center; gap: 10px; }
.qg-engine select { min-width: 10em; }
/* A working control, not a call to action: drop the colored glow the shared
   .btn-primary carries. */
.qg-tool .btn-primary { box-shadow: none; }
#qg-sql { max-height: 480px; overflow: auto; }
#qg-sql:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.qg-sr {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Your own schema ---------- */
.qg-schema { border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 12px 14px; }
.qg-schema summary { cursor: pointer; margin: 0; min-height: 24px; }
.qg-schema summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.qg-schema[open] summary { margin-bottom: 10px; }
.qg-note { font-size: .9rem; color: var(--ink); max-width: 72ch; margin: 0 0 12px; text-wrap: pretty; }
.qg-schema .qg-label-text { display: block; font-size: .86rem; font-weight: 600; color: var(--heading); margin-bottom: 6px; }
#qg-ddl {
    width: 100%; min-height: 200px; resize: vertical; background: var(--cream);
    font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-size: .85rem; line-height: 1.5;
    font-variant-ligatures: none; white-space: pre; overflow: auto;
}
.qg-ddl-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.qg-status { font-size: .9rem; color: var(--muted); margin: 12px 0 0; max-width: 72ch; }
.qg-status:empty { display: none; }
.qg-status.is-warning { color: var(--amber-ink); }

/* ---------- Reading measure for the prose around the tool ---------- */
/* em, not ch: ch is the width of a zero, wider than an average letter, so
   68ch still ran to ~90 characters a line. 36em lands near 75. */
.qg-head .lede, .qg-prose .tools-intro { max-width: 36em; text-wrap: pretty; }
.qg-prose .tools-points, .qg-prose .tools-faq { max-width: 38em; }
.qg-prose .tools-points li, .qg-prose .tools-faq p { text-wrap: pretty; }

/* ---------- Phones ---------- */
@media (max-width: 640px) {
    /* Rows become a grid: the AND/OR picker and the remove button share the
       top line, every other control takes a full-width line of its own. */
    .qg-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
    .qg-row > * { grid-column: 1 / -1; width: 100%; min-width: 0; }
    .qg-row > :first-child { grid-column: 1; }
    .qg-row > .qg-combine { width: auto; justify-self: start; }
    .qg-row > .qg-remove { grid-row: 1; grid-column: 2; width: 36px; justify-self: end; margin: 0; }
    .qg-row > .qg-eq { font-size: .82rem; }
    .qg-field, .qg-field input { width: 100%; }
    .qg-engine { flex-direction: column; align-items: stretch; }
    .qg-clear { margin-left: 0; }
    .qg-sql-head .qg-copy { width: 100%; }
}
