/* /tools/csv-to-sql - page-specific rules ONLY. Shared primitives (tokens,
   buttons, cards, notices, pills, tables, form controls) come from tokens.css /
   site.css and tools.css. No new colors: every value here is a site token.
   Mono is for data and SQL only.

   Layout: the converter spans the viewport (it does not sit in the 1140px
   .wrap). Wide screens get two columns - data, its parsed preview and the
   source options on the left, the SQL and its options on the right - and
   below 820px (the breakpoint tools.css uses) everything stacks. */

.csv-tool { padding: 28px 0 clamp(48px, 6vw, 72px); }
.csv-tool-inner { padding: 0 clamp(16px, 2vw, 32px); }
.csv code { font-family: "JetBrains Mono", monospace; font-size: .88em; overflow-wrap: anywhere; }
.csv-sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

.csv-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "source sql" "preview sql";
    grid-template-rows: auto 1fr;
    gap: 22px clamp(18px, 2vw, 32px);
    align-items: start;
}
.csv-pane-source { grid-area: source; }
.csv-preview { grid-area: preview; min-width: 0; }
.csv-pane-sql { grid-area: sql; }
.csv-pane { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* ---------- Pane header: name, privacy promise, live summary ---------- */
.csv-pane-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; min-height: 32px; }
.csv-pane-label { font-family: "Fredoka", "Inter", sans-serif; font-size: 1.2rem; font-weight: 600; color: var(--heading); }
.csv-privacy {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 999px;
    background: var(--green-soft); color: var(--green-on-soft);
    font-size: .82rem; font-weight: 600;
}
.csv-privacy svg { flex: none; }
.csv-summary { font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Toolbars ---------- */
/* Top-aligned so a note under one field does not push its neighbours down;
   controls without a label above them are dropped by one label line. */
.csv-toolbar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-start; }
.csv-toolbar > .csv-check, .csv-toolbar > .csv-file-opt, .csv-toolbar > .csv-chip { margin-top: 26px; }
.csv-opt.csv-opt-wide { flex-basis: 250px; max-width: 320px; }
.csv-opt { display: flex; flex-direction: column; gap: 6px; flex: 1 1 150px; max-width: 280px; font-size: .86rem; font-weight: 600; color: var(--heading); }
.csv-opt select, .csv-opt input { width: 100%; padding: 9px 12px; font-size: .95rem; min-height: 44px; }
.csv-opt select:disabled { opacity: .6; cursor: not-allowed; }
.csv-opt[hidden] { display: none; }
.csv-opt-note { font-size: .8rem; font-weight: 400; color: var(--muted); }
.csv-opt-note[hidden] { display: none; }
.csv-check { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; color: var(--ink); min-height: 44px; cursor: pointer; }
.csv-check input { width: 18px; height: 18px; accent-color: var(--blue-bright); flex: none; margin: 0; }
.csv-check input:focus-visible { outline: 2px solid var(--blue-bright); outline-offset: 2px; }
.csv-check:has(input:disabled) { color: var(--muted); cursor: not-allowed; }

/* The native file control is hidden behind a pill that is its label; the input
   itself stays focusable, and its focus ring is drawn on the pill. */
.csv-file-opt { position: relative; flex: 0 0 auto; }
.csv-file-opt label {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 20px; border-radius: 999px;
    background: var(--card); color: var(--heading); border: 1.5px solid var(--line);
    font-size: .92rem; font-weight: 600; cursor: pointer;
    transition: border-color .15s ease;
}
.csv-file-opt label:hover { border-color: var(--blue-bright); }
.csv-file-opt input[type="file"] {
    position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; padding: 0;
    opacity: 0; cursor: pointer; font-size: 0;
}
.csv-file-opt:focus-within label { outline: 2px solid var(--blue-bright); outline-offset: 2px; }

.csv-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
    min-height: 44px; padding: 4px 4px 4px 14px; border-radius: 999px;
    background: var(--blue-soft); color: var(--blue-on-soft); font-size: .86rem; font-weight: 600;
}
.csv-chip[hidden] { display: none; }
.csv-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.csv-chip-x {
    display: inline-grid; place-items: center; flex: none;
    width: 36px; height: 36px; border-radius: 999px; border: none;
    background: transparent; color: inherit; cursor: pointer;
}
.csv-chip-x:hover { background: var(--card); }

/* ---------- Text areas ---------- */
.csv-drop { position: relative; }
.csv textarea {
    display: block; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
    font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-size: .86rem; line-height: 1.55;
    color: var(--ink); font-variant-ligatures: none; tab-size: 4; resize: vertical;
    white-space: pre; overflow: auto;
}
.csv textarea::placeholder { color: var(--muted); opacity: 1; }
.csv textarea:focus { outline: 2px solid var(--blue-bright); outline-offset: -1px; }
#csv-input { height: clamp(260px, 46vh, 720px); background: var(--cream); }
#csv-input[readonly] { cursor: default; }
#csv-output { height: clamp(320px, 64vh, 1000px); background: var(--card); }
#csv-output.is-wrapped { white-space: pre-wrap; overflow-wrap: anywhere; }
.csv.is-busy textarea { cursor: progress; }

.csv-drop-overlay {
    position: absolute; inset: 0; display: none; place-items: center; padding: 24px; text-align: center;
    border: 2px dashed var(--blue-bright); border-radius: 10px;
    background: var(--blue-soft); color: var(--blue-on-soft); font-weight: 600; pointer-events: none;
}
.csv-pane-source.is-dragover .csv-drop-overlay { display: grid; }

.csv-pane-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.csv .btn-sm { padding: 10px 20px; font-size: .92rem; min-height: 44px; gap: 8px; }
.csv .btn[hidden] { display: none; }
.csv .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.csv-kbd { font-size: .82rem; color: var(--muted); }
.csv-check-sm { margin-left: auto; font-size: .88rem; }
.csv-hint { font-size: .86rem; color: var(--muted); margin: 0; max-width: 64ch; }

/* ---------- Status, errors, warnings ---------- */
.csv-status { font-size: .9rem; color: var(--muted); margin: 0; }
.csv-status:empty { display: none; }
.csv-status.is-error { color: var(--pink-ink); font-weight: 600; }
.csv-status[hidden] { display: none; }
.csv-warnings { margin: 0; font-size: .9rem; }
.csv-warnings ul { margin: 0; padding-left: 18px; }
.csv-warnings li + li { margin-top: 4px; }

/* ---------- More options ---------- */
.csv-more { border-top: 1px solid var(--line); }
.csv-more summary {
    display: flex; align-items: center; gap: 10px; min-height: 44px;
    font-weight: 600; color: var(--heading); cursor: pointer; list-style: none;
}
.csv-more summary::-webkit-details-marker { display: none; }
.csv-more summary::before,
.csv-faq-item summary::after {
    content: ""; flex: none; width: 8px; height: 8px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(-45deg); transition: transform .2s cubic-bezier(.16, 1, .3, 1);
}
.csv-more[open] summary::before { transform: rotate(45deg); }
.csv-more-body { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px; padding: 2px 0 8px; }
.csv-more-body .csv-opt-note { flex-basis: 100%; margin: 0; }
.csv-opt-inline { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 10px; max-width: none; }
.csv-opt-inline input { width: 96px; }
.csv-opt-inline input:disabled { opacity: .6; }

/* ---------- Parsed preview ---------- */
.csv-preview[hidden] { display: none; }
.csv-preview-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 10px; }
.csv-preview-title { font-size: 1.2rem; margin: 0; }
.csv-preview-count { font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.csv-preview-stale { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--amber-soft); color: var(--amber-ink); }
.csv-preview-stale[hidden] { display: none; }
.csv-preview.is-stale .csv-grid-wrap { opacity: .5; }
.csv-grid-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.csv-grid-wrap:focus-visible, .csv-quote-wrap:focus-visible { outline: 2px solid var(--blue-bright); outline-offset: 2px; }
.csv-grid { border-collapse: separate; border-spacing: 0; font-size: .86rem; min-width: 100%; }
.csv-grid th, .csv-grid td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.csv-grid tbody tr:last-child td { border-bottom: none; }
.csv-grid th { position: sticky; top: 0; z-index: 1; background: var(--card); font-weight: 600; color: var(--heading); vertical-align: top; }
.csv-grid td { font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-variant-ligatures: none; font-variant-numeric: tabular-nums; }
.csv-grid td.csv-null { color: var(--muted); font-style: italic; }
.csv-col-name { margin-bottom: 6px; }
.csv-col-sqltype { margin-top: 6px; font-family: "JetBrains Mono", monospace; font-size: .74rem; font-weight: 400; color: var(--muted); }
.csv-type { font-size: .82rem; padding: 4px 8px; min-height: 36px; font-weight: 400; max-width: 170px; }

/* ---------- Prose below the tool ---------- */
.csv-prose .tools-intro { max-width: 60ch; }
.csv-prose .tools-points { max-width: 64ch; }
.csv-head .lede { max-width: 60ch; }
/* The shared "Related on SQLly" list, on this page only. */
.tools-xref, .tools-xref-also { max-width: 64ch; }
.csv-prose .fmt-example-label { text-transform: none; letter-spacing: 0; font-size: .82rem; }
.csv-quote-wrap { overflow-x: auto; }
.csv-quote { border-collapse: collapse; font-size: .92rem; min-width: min(100%, 720px); }
.csv-quote th, .csv-quote td { padding: 10px 14px; border: 1px solid var(--line); text-align: left; }
.csv-quote th { background: var(--card); color: var(--heading); font-weight: 600; }
.csv-quote tbody th { background: transparent; }

.csv-faq { max-width: 64ch; gap: 12px; }
.csv-faq-item { padding: 0; }
.csv-faq-item summary {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 44px; padding: 18px 22px; cursor: pointer; list-style: none;
}
.csv-faq-item summary::-webkit-details-marker { display: none; }
.csv-faq-item summary::after { transform: rotate(45deg); margin-top: -4px; }
.csv-faq-item[open] summary::after { transform: rotate(-135deg); margin-top: 4px; }
.tools-faq .csv-faq-item h3 { margin: 0; font-size: 1.1rem; }
.tools-faq .csv-faq-item p { padding: 0 22px 20px; }

/* The shared CTA paragraph is 4.3:1 on the lighter end of its gradient; this
   is the lighter strip text already used by .tools-cta, which clears AA. */
.csv-cta p { color: #cfe0ff; }
.csv-cta .btn svg { flex: none; }

@media (max-width: 820px) {
    .csv-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "source" "preview" "sql"; grid-template-rows: none; }
    .csv-opt { max-width: none; }
    .csv-check-sm { margin-left: 0; }
    #csv-output { height: clamp(260px, 56vh, 640px); }
}

/* Touch screens: 16px text so iOS does not zoom on focus, 44px targets. */
@media (pointer: coarse) {
    .csv textarea, .csv-opt select, .csv-opt input, .csv-type { font-size: 16px; }
    .csv-type { min-height: 44px; }
    .csv-chip-x { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .csv .btn, .csv-cta .btn, .csv-file-opt label, .csv-more summary::before, .csv-faq-item summary::after { transition: none; }
    .csv .btn:hover, .csv .btn:active, .csv-cta .btn:hover, .csv-cta .btn:active { transform: none; }
}
