/* CSV to JSON Converter: CSV input and reading options, output options and JSON,
   the column editor and the row preview. Colours come from the shared tokens, so
   the panel follows the light and dark themes. */
.c2j {
  display: grid;
  gap: 1.25rem;
  min-width: 0;
  padding: clamp(16px, 2.4vw, 32px);
  text-align: left;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--shade);
}
.c2j *, .c2j *::before, .c2j *::after { box-sizing: border-box; }
.c2j [hidden] { display: none !important; }
.c2j h2 { margin: 0 0 .35rem; font-size: 1.45rem; letter-spacing: -.02em; }
.c2j h3 { margin: 0; font-size: 1.1rem; }
.c2j h3 label { display: inline; font: inherit; }
.c2j p { margin: 0; color: var(--ink-soft); }
.c2j-head p { max-width: 76ch; }
.c2j-sub { font-size: .85rem; overflow-wrap: anywhere; }
.c2j-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Two panes side by side on wide screens, stacked below 1000 px. */
.c2j-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
@media (min-width: 1000px) { .c2j-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.c2j-pane { display: flex; flex-direction: column; gap: .8rem; min-width: 0; padding: 1rem; border: 2px solid var(--line); border-radius: 10px; }
.c2j-csv { background: var(--blue-tint); }
.c2j-csv.is-dragging { outline: 3px dashed var(--action); outline-offset: -9px; }
.c2j-json { background: var(--paper-3); }
.c2j-pane-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; }
.c2j-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* Fields and controls (42 px minimum height). */
.c2j label { display: grid; gap: .3rem; min-width: 0; font-size: .85rem; font-weight: 650; }
.c2j textarea, .c2j select, .c2j input[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .5rem .6rem;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--border-soft);
  border-radius: 6px;
}
.c2j textarea { flex: 1 1 auto; font-family: var(--font-mono); font-size: .86rem; line-height: 1.5; white-space: pre; overflow: auto; resize: vertical; tab-size: 4; }
.c2j-csv textarea { min-height: 16rem; }
.c2j-json textarea { min-height: 21rem; }
.c2j select:disabled, .c2j input:disabled { opacity: .55; cursor: not-allowed; }
.c2j :is(input, textarea, select, button, summary, a, [tabindex]):focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.c2j button, .c2j .c2j-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .5rem .95rem;
  font: inherit;
  font-size: .92rem;
  font-weight: 650;
  color: var(--ink);
  text-decoration: none;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.c2j button:disabled { opacity: .5; cursor: default; }
.c2j .c2j-primary { color: var(--on-action); background: var(--action); box-shadow: 3px 3px 0 var(--shade); }
.c2j .c2j-primary:hover:not(:disabled) { background: var(--primary-dark); }
.c2j .c2j-file-button { position: relative; display: inline-flex; }
.c2j .c2j-file-button input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.c2j .c2j-file-button:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.c2j .c2j-check { display: flex; align-items: center; gap: .55rem; min-height: 42px; font-size: .92rem; font-weight: 500; }
.c2j .c2j-check input { flex: none; width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--action); }
.c2j fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.c2j legend { margin-bottom: .45rem; padding: 0; font-size: .95rem; font-weight: 700; }
.c2j-group { display: grid; gap: .35rem; padding-top: .8rem; border-top: 1.5px solid var(--border-soft); }
.c2j-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .75rem; align-items: end; }
.c2j-row.c2j-wide { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.c2j-file { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; font-weight: 600; color: var(--ink) !important; overflow-wrap: anywhere; }

/* Output shape pills. */
.c2j-shapes { display: flex; flex-wrap: wrap; gap: .5rem; }
.c2j-shapes legend { width: 100%; }
.c2j-shapes label { position: relative; display: inline-flex; align-items: center; min-height: 42px; padding: .45rem .9rem; font-size: .92rem; background: var(--bg-2); border: 2px solid var(--line); border-radius: 999px; cursor: pointer; }
.c2j-shapes input { position: absolute; opacity: 0; pointer-events: none; }
.c2j-shapes label:has(input:checked) { color: var(--on-action); background: var(--action); box-shadow: 2px 2px 0 var(--shade); }
.c2j-shapes label:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Status, warnings and counts. */
.c2j-status { min-height: 1.4em; font-weight: 600; color: var(--ink) !important; overflow-wrap: anywhere; }
.c2j-status[data-kind="error"] { padding: .5rem .75rem; background: var(--error-soft); border-left: 4px solid var(--error); border-radius: 6px; }
.c2j-notes { display: grid; gap: .55rem; padding: .55rem .75rem; color: var(--ink); background: var(--warning-soft); border-left: 4px solid var(--warning); border-radius: 6px; }
.c2j-notes ul { display: grid; gap: .3rem; margin: 0; padding-left: 1.1rem; font-size: .88rem; overflow-wrap: anywhere; }
.c2j-counts { font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.c2j-action { font-size: .85rem; font-weight: 600; color: var(--ink); }

/* Column editor and preview. */
.c2j details { min-width: 0; padding: .8rem 1rem; border: 2px solid var(--line); border-radius: 10px; }
.c2j summary { font-size: 1.05rem; font-weight: 700; cursor: pointer; }
.c2j details[open] > summary { margin-bottom: .5rem; }
.c2j-cols { display: grid; gap: .5rem; margin: .7rem 0 0; padding: 0; list-style: none; }
.c2j-cols.is-long { max-height: 32rem; padding: 0 .3rem .3rem 0; overflow: auto; }
.c2j-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .75rem; padding: .6rem .75rem; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 8px; }
.c2j-col-head { grid-column: 1 / -1; }
@media (min-width: 760px) {
  .c2j-col { grid-template-columns: minmax(0, 1.5fr) minmax(9rem, 1fr) minmax(9rem, 13rem); gap: .5rem .9rem; align-items: center; }
  .c2j-col-head { grid-column: auto; }
}
.c2j-col.is-off { background: var(--paper-3); border-style: dashed; }
.c2j-col.is-off .c2j-col-title { text-decoration: line-through; }
.c2j-col-head { display: grid; gap: .1rem; min-width: 0; }
.c2j-col .c2j-col-include { min-height: 36px; }
.c2j-col-title { font-weight: 700; overflow-wrap: anywhere; }
.c2j-col-meta { font-size: .8rem; color: var(--ink-soft); overflow-wrap: anywhere; }
.c2j .c2j-col-field { font-size: .78rem; }
.c2j-table-wrap { max-height: 28rem; margin-top: .6rem; overflow: auto; background: var(--field); border: 1.5px solid var(--border-soft); border-radius: 8px; }
.c2j table { min-width: 100%; border-collapse: collapse; font-size: .84rem; }
.c2j th, .c2j td { padding: .4rem .65rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border-faint); overflow-wrap: break-word; }
.c2j td { font-family: var(--font-mono); white-space: pre; }
.c2j td.c2j-long { min-width: 14rem; white-space: pre-wrap; }
.c2j thead th { position: sticky; top: 0; z-index: 1; min-width: 6rem; background: var(--paper-3); }
.c2j thead th:first-child { min-width: 0; }
.c2j tbody th { font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.c2j tr[data-uneven="true"] th { box-shadow: inset 4px 0 0 var(--warning); }
.c2j-key { display: block; font-family: var(--font-mono); font-size: .82rem; }
.c2j-type, .c2j-tag { display: inline-block; padding: 0 .45rem; font-family: var(--font-body); font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--ink); border: 1.5px solid var(--line); border-radius: 999px; }
.c2j-type { margin-top: .25rem; }
.c2j-tag { margin-left: .35rem; background: var(--warning-soft); }
.c2j-type[data-type="number"] { background: var(--pastel-blue); }
.c2j-type[data-type="boolean"] { background: var(--pastel-green); }
.c2j-type[data-type="text"], .c2j-type[data-type="empty"] { background: var(--yellow-tint); }
.c2j-type[data-type="off"] { background: var(--bg-2); border-style: dashed; }
.c2j thead th.is-off .c2j-key { text-decoration: line-through; }
.c2j-foot { font-size: .85rem; }

/* Space the page holds for this view until it mounts (see .tool-view-placeholder in _workspace.css).
   Each height is a little under the space the view takes at that width, measured as how far the
   content below moves when the view replaces the placeholder, so nothing below it moves. Re-measure
   after changing the view's layout: node scripts/measure-tool-views.js --apply csv-to-json. */
.tool-view-placeholder[data-tool="csv-to-json"] { min-height: 2544px; }
@media (max-width: 1000px) { .tool-view-placeholder[data-tool="csv-to-json"] { min-height: 2736px; } }
@media (max-width: 760px) { .tool-view-placeholder[data-tool="csv-to-json"] { min-height: 3391px; } }
@media (max-width: 544px) { .tool-view-placeholder[data-tool="csv-to-json"] { min-height: 4219px; } }
