/* /tools/sql-formatter and its dialect pages - formatter-only rules on top of
   tools.css. Site tokens (tokens.css) for surfaces and text; the syntax colors
   are DESIGN.md's syntax roles (theme.rs), with the number role swapped for
   the site's --amber-ink in light mode because DESIGN.md's #ca8a04 is under
   3:1 on a white card. No shadows, hairline borders. */

.fmt {
    --fmt-kw: #b45309;
    --fmt-str: #15803d;
    --fmt-com: #6b7280;
    --fmt-num: var(--amber-ink);
    --fmt-fn: #2563eb;
    --fmt-err: #c62828;
    --fmt-add: var(--green-soft);
    --fmt-del: var(--pink-wash);
}
:root[data-theme="dark"] .fmt {
    --fmt-kw: #fbbf24;
    --fmt-str: #4ade80;
    --fmt-com: #9ca3af;
    --fmt-num: #facc15;
    --fmt-fn: #60a5fa;
    --fmt-err: #f87171;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .fmt {
        --fmt-kw: #fbbf24;
        --fmt-str: #4ade80;
        --fmt-com: #9ca3af;
        --fmt-num: #facc15;
        --fmt-fn: #60a5fa;
        --fmt-err: #f87171;
    }
}

.fmt-readas { color: var(--muted); font-size: .95rem; margin: 10px 0 0; }

/* ---------- Options bar + Advanced panel ---------- */
.fmt-adv-toggle { margin-left: auto; }
.fmt-adv-count:not(:empty) {
    display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 999px;
    background: var(--blue-soft); color: var(--blue-on-soft); font-size: .78rem; line-height: 1.6;
}
.fmt-advanced { border: 1px solid var(--line); border-radius: 14px; background: var(--card); padding: 18px 20px; margin: 0 0 18px; }
.fmt-adv-head { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.fmt-adv-head p { margin: 0; color: var(--muted); font-size: .92rem; max-width: 64ch; }
.fmt-adv-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.fmt-adv-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 26px; }
.fmt-adv-group { border: 0; margin: 0; padding: 12px 0 4px; min-width: 0; }
.fmt-adv-group legend { font-family: "JetBrains Mono", monospace; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0; margin-bottom: 6px; }
.fmt-field { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; font-size: .9rem; color: var(--ink); }
.fmt-field > span { font-weight: 600; color: var(--heading); }
.fmt-field select, .fmt-field input[type="number"], .fmt-field input[type="text"] { padding: 7px 10px; font-size: .9rem; width: 100%; border-radius: 8px; }
.fmt-field.is-toggle { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; min-height: 36px; cursor: pointer; }
.fmt-field.is-toggle > span { font-weight: 400; color: var(--ink); }
.fmt-field.is-toggle input { width: 18px; height: 18px; flex: none; accent-color: var(--blue-bright); }
.fmt-field small { color: var(--muted); font-size: .8rem; line-height: 1.4; }
.fmt-field.is-changed > span::after { content: " • changed"; color: var(--blue-lift); font-weight: 600; font-size: .78rem; }
.fmt-field.is-disabled { opacity: .55; }

/* ---------- Panes ---------- */
.fmt-pane-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-height: 32px; }
.fmt-count { font-family: "JetBrains Mono", monospace; font-size: .76rem; color: var(--muted); }
.fmt-pane-tools { display: inline-flex; gap: 6px; margin-left: auto; }
.fmt-tool-btn {
    font: inherit; font-size: .82rem; color: var(--heading); background: var(--card);
    border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; min-height: 32px; cursor: pointer;
}
.fmt-tool-btn:hover:not([disabled]) { border-color: var(--blue-bright); }
.fmt-tool-btn[disabled] { opacity: .55; cursor: not-allowed; }
.fmt-tool-btn[aria-pressed="true"] { background: var(--blue-soft); border-color: var(--blue-bright); color: var(--blue-on-soft); }
.fmt-pane-in.is-dragging textarea { border-color: var(--blue-bright); border-style: dashed; }
.fmt-drop-hint { margin: 0; font-size: .8rem; color: var(--muted); }

.fmt-out {
    position: relative;
    min-height: 380px;
    max-height: 640px;
    overflow: auto;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
    font-size: .9rem;
    line-height: 1.55;
    font-variant-ligatures: none;
    tab-size: 4;
}
.fmt-out:focus-visible { outline: 2px solid var(--blue-bright); outline-offset: 2px; }
.fmt-out-code { margin: 0; padding: 13px 16px; white-space: pre; color: var(--ink); font: inherit; background: none; }
.fmt-out-empty { padding: 13px 16px; color: var(--muted); }
/* Line numbers: a sticky gutter column the selection never picks up. */
.fmt-lines { display: grid; grid-template-columns: auto 1fr; min-width: max-content; }
.fmt-gutter {
    position: sticky; left: 0; z-index: 1;
    margin: 0; padding: 13px 10px 13px 12px; text-align: right; white-space: pre;
    color: var(--muted); background: var(--card); border-right: 1px solid var(--line);
    user-select: none; -webkit-user-select: none; font: inherit;
}
.fmt-lines .fmt-out-code { padding-left: 14px; }

/* Syntax roles (classes match report::Class in client/apps/sqlformat-wasm). */
.t-k { color: var(--fmt-kw); }
.t-s { color: var(--fmt-str); }
.t-n { color: var(--fmt-num); }
.t-c { color: var(--fmt-com); font-style: italic; }
.t-f { color: var(--fmt-fn); }
.t-p { color: var(--fmt-kw); font-style: italic; }
.t-o { color: var(--muted); }
.t-q { color: var(--ink); }

/* Changes view: unified line diff. */
.fmt-diff { margin: 0; padding: 8px 0; white-space: pre; font: inherit; min-width: max-content; }
.fmt-diff span { display: block; padding: 0 16px 0 10px; }
.fmt-diff .d-add { background: var(--fmt-add); color: var(--green-on-soft); }
.fmt-diff .d-del { background: var(--fmt-del); color: var(--pink-ink); }
.fmt-diff .d-same { color: var(--muted); }
.fmt-diff-note { padding: 13px 16px; color: var(--muted); font-family: inherit; }

/* ---------- Actions + status ---------- */
.fmt-actions .fmt-check { margin-left: auto; }
.fmt-status { margin: 12px 0 0; min-height: 1.5em; }
.fmt-declined { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; margin: 14px 0 0; }
.fmt-declined p { margin: 0; flex: 1 1 280px; }

/* ---------- Dialect links ---------- */
.fmt-dialect-links { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 22px; }
.fmt-dialect-links a { font-weight: 600; }

@media (max-width: 820px) {
    .fmt-out { min-height: 240px; max-height: 480px; }
    .fmt-adv-toggle { margin-left: 0; width: 100%; justify-content: center; }
    .fmt-actions .fmt-check { margin-left: 0; }
    .fmt-actions .btn { flex: 1 1 140px; justify-content: center; }
}
