/*
 * EncodeLabel kit: datalists (goes with assets/js/kit-data.js).
 *
 * Only what is special to adding and editing a list lives here. Buttons,
 * boxes, tables, pop-ups and the dropzone come from site.css, and every
 * colour is one of its tokens, so the light and dark themes both work.
 *
 *   .kd            the "Add your list" pop-up (steps, add screen, reading screen, check screen)
 *   .kd-map        the column dropdowns (EL.kit.data.mapper)
 *   .kd-grid       the light table (EL.kit.data.grid)
 */

/* ---- The pop-up: the two steps across the top -------------------------------- */
.kd-steps {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 18px; padding: 0; list-style: none;
  color: var(--muted); font-size: .9rem; font-weight: 600;
}
.kd-steps li { display: inline-flex; align-items: center; gap: 8px; }
.kd-steps li + li::before { content: ""; width: 28px; height: 1px; margin-right: 6px; background: var(--field-line); }
.kd-steps .step-number { background: none; color: var(--muted); box-shadow: inset 0 0 0 1px var(--field-line); }
.kd-steps [aria-current] { color: var(--ink); }
.kd-steps [aria-current] .step-number { background: var(--ink); color: var(--paper); box-shadow: none; }
.kd-screen:focus { outline: none; }
.kd-icon { display: inline-flex; flex: none; }

/* ---- Step 1: drop a file, or paste ----------------------------------------- */
.kd-error strong { display: block; margin-bottom: 2px; overflow-wrap: anywhere; }
.kd-error p { margin: 0; }
.kd-add { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 0 20px; align-items: stretch; }
.kd-drop { justify-content: center; min-height: 236px; margin: 0; padding: 28px 20px; }
.kd-drop .kd-icon .icon { width: 32px; height: 32px; }
.kd-choose { margin-top: 12px; pointer-events: none; } /* the whole zone is the button; this only shows where to press */
/* There is nothing to drag on a phone, so the zone says "Add" there. */
.kd-if-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .kd-if-mouse { display: none; }
  .kd-if-touch { display: inline; }
}
.kd-drop:hover .kd-choose { border-color: var(--ink); }
.kd-drop input:focus-visible ~ .kd-choose { outline: 3px solid var(--focus); outline-offset: 2px; }
.kd-or { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.kd-or::before, .kd-or::after { content: ""; flex: 1; width: 1px; background: var(--line); }
.kd-paste { display: flex; flex-direction: column; margin: 0; }
.kd-paste textarea { flex: 1 1 auto; min-height: 132px; resize: none; white-space: pre; overflow: auto; }
.kd-paste-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px 14px; margin-top: 10px; }
.kd-paste-foot .hint { flex: 1 1 0; margin: 0; }
.kd-paste-foot .btn { flex: none; }
.kd-sample {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.kd-sample p { margin: 0 4px 0 0; color: var(--muted); font-size: .92rem; }
.kd-private { display: flex; align-items: flex-start; gap: 8px; margin: 16px 0 0; }
.kd-private .icon { width: 1.15em; height: 1.15em; margin-top: .1em; }

/* Saved datalists (people who are logged in). */
.kd-saved { margin-top: 20px; }
.kd-saved h3 { margin: 0 0 8px; font-size: 1rem; }
.kd-saved-list {
  max-height: 228px; margin: 0; padding: 0; overflow-y: auto; list-style: none;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.kd-saved-list li + li { border-top: 1px solid var(--line); }
.kd-saved-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px 8px 14px;
  border: 0; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.kd-saved-item:hover { background: var(--soft); }
.kd-saved-item:focus-visible { outline-offset: -3px; }
.kd-saved-item[aria-busy="true"] { opacity: .6; cursor: progress; }
.kd-saved-item > .kd-icon { color: var(--muted); }
.kd-saved-text { display: grid; flex: 1 1 auto; min-width: 0; }
.kd-saved-text strong { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.kd-saved-text span { color: var(--muted); font-size: .85rem; }
.kd-saved-wait { display: grid; gap: 8px; padding: 14px; }
.kd-saved-wait .skeleton { width: 60%; height: 12px; min-height: 0; }
.kd-saved-wait .skeleton + .skeleton { width: 35%; }
.kd-saved .status-line:empty { display: none; }
.kd-saved .status-line .link-button { margin-left: 4px; font-weight: 400; }

/* ---- Reading a file -------------------------------------------------------- */
.kd-reading { display: grid; justify-items: center; gap: 6px; padding: 64px 16px 72px; text-align: center; }
.kd-reading[hidden] { display: none; }
.kd-reading .spinner { margin-bottom: 10px; font-size: 1.7rem; color: var(--brand); }
.kd-reading p { margin: 0; overflow-wrap: anywhere; }
.kd-reading-title { font-size: 1.05rem; font-weight: 650; }
.kd-reading .btn { margin-top: 14px; }

/* ---- Step 2: check it ------------------------------------------------------- */
.kd-source {
  display: flex; align-items: center; gap: 12px; margin: 0 0 16px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-small);
  background: color-mix(in srgb, var(--ink) 3%, var(--card));
}
.kd-source > .kd-icon { color: var(--muted); }
.kd-source-text { display: grid; min-width: 0; }
.kd-source-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kd-source-text span { color: var(--muted); font-size: .85rem; }
.kd-options { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 20px; margin: 0 0 14px; }
.kd-options[hidden] { display: none; }
.kd-options .field { flex: 0 1 260px; min-width: 180px; margin: 0; }

/* The first rows. The table scrolls sideways inside its own box. */
.kd-preview { margin: 0 0 6px; }
.kd-preview th, .kd-preview td { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kd-preview thead th { vertical-align: bottom; }
.kd-preview .kd-num, .kd-grid-table .kd-grid-num {
  width: 1%; min-width: 40px; padding-right: 8px; padding-left: 10px;
  color: var(--muted); font-size: .8rem; font-weight: 400; font-variant-numeric: tabular-nums; letter-spacing: 0; text-align: right;
}
.kd-col { display: block; overflow: hidden; text-overflow: ellipsis; }
.kd-role {
  display: inline-block; max-width: 100%; margin-top: 5px; padding: 1px 7px; overflow: hidden; border-radius: 3px;
  background: var(--soft); color: var(--link); font-size: .72rem; font-weight: 600; letter-spacing: 0;
  text-overflow: ellipsis; text-transform: none; vertical-align: top;
}
.kd-none { padding: 18px 12px; color: var(--muted); text-align: center; }
.kd-preview-note { margin: 0; }

.kd-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.kd-section[hidden] { display: none; }
.kd-section > h3 { margin: 0 0 4px; font-size: 1.02rem; }
.kd-section > h3 + p { margin: 0 0 14px; }
.kd-type { max-width: 420px; margin: 10px 0 14px; }

/* What was repaired and what still looks wrong, one box per finding. */
.kd-lines { display: grid; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.kd-line {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; padding: 10px 14px 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--card);
}
.kd-line > .kd-icon { margin-top: .12em; color: var(--muted); }
.kd-line.is-ok > .kd-icon { color: var(--ok); }
.kd-line.is-warn { border-color: transparent; background: var(--warn-soft); }
.kd-line.is-warn > .kd-icon { color: var(--warn); }
.kd-line p { margin: 0; }
.kd-line-text { font-weight: 600; }
.kd-line-note { margin-top: 3px !important; font-size: .88rem; }
.kd-line:not(.is-warn) .kd-line-note { color: var(--muted); }
.kd-line-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.kd-lines + .fine-print { margin: 10px 0 0; }

/* The pop-up's bottom bar on step 2. */
.kd-foot[hidden] { display: none; }
.kd-foot-info {
  display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: center; align-self: center; gap: 2px 16px; margin: 0;
  color: var(--muted); font-size: .9rem;
}
.kd-foot-info[hidden] { display: none; }
.kd-foot-info .link-button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; color: var(--ink); font-weight: 600; }
.kd-foot-info .link-button .kd-icon { color: var(--warn); }
.kd-section:focus { outline: none; }

/* ---- The column dropdowns -------------------------------------------------- */
/* Three across in the pop-up, two on a phone or in a narrow side panel. */
.kd-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(max(150px, 30%), 1fr)); gap: 0 14px; }
.kd-map .field { min-width: 0; margin: 0 0 12px; }
.kd-map .hint { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- The light table ------------------------------------------------------- */
.kd-grid-wrap { max-height: min(62vh, 560px); margin: 0; overflow: auto; overscroll-behavior: contain; }
/* Separate borders, so the heading row keeps its line while the rows scroll under it. */
.kd-grid-table { border-collapse: separate; border-spacing: 0; }
.kd-grid-table th, .kd-grid-table td { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kd-grid-table thead th { position: sticky; top: 0; z-index: 2; }
.kd-grid-table tbody th { position: sticky; left: 0; z-index: 1; background: color-mix(in srgb, var(--ink) 3%, var(--card)); }
.kd-grid-table thead th.kd-grid-num { left: 0; z-index: 3; }
.kd-grid-table tbody tr:hover > td { background: color-mix(in srgb, var(--ink) 3%, var(--card)); }
.kd-grid-table td { height: 40px; background: var(--card); }
.kd-grid.is-editable td[data-kd="cell"] { cursor: text; scroll-margin: 44px 48px 4px 48px; }
.kd-grid.is-editable td[data-kd="cell"]:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.kd-grid-table td.is-editing { min-width: 11rem; padding: 2px; overflow: visible; }
.kd-grid-input, textarea.kd-grid-input { min-height: 36px; padding: 5px 9px; border-color: var(--focus); }
textarea.kd-grid-input { min-height: 84px; resize: vertical; }
.kd-grid-table .kd-grid-act { position: sticky; right: 0; width: 1%; padding: 2px 4px; }
.kd-grid-table td.kd-grid-act { box-shadow: -1px 0 0 var(--line); }
.kd-grid-bin {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: var(--radius-small); background: none; color: var(--muted); cursor: pointer;
}
.kd-grid-bin:hover { background: var(--error-soft); color: var(--error); }
.kd-grid-bin:focus-visible { outline-offset: -3px; color: var(--error); }
.kd-grid-gap td {
  position: sticky; left: 0; height: auto; padding: 8px 12px;
  background: color-mix(in srgb, var(--ink) 3%, var(--card)); color: var(--muted); font-size: .9rem;
}
.kd-grid-gap .btn { margin-left: 12px; }
.kd-grid-none { position: sticky; left: 0; margin: 0; padding: 26px 16px; color: var(--muted); text-align: center; }
.kd-grid-none[hidden] { display: none; }
.kd-grid-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 10px 0 0; }
.kd-grid-said { display: flex; flex: 1 1 12rem; align-items: baseline; gap: 10px; min-width: 0; }
.kd-grid-said .status-line { min-height: 0; margin: 0; }
.kd-grid-total { margin: 0 0 0 auto; color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* Fingers need room. */
@media (pointer: coarse) {
  .kd-grid-table td { height: 44px; }
  .kd-grid-bin { width: 44px; height: 44px; }
  .kd-grid-input { min-height: 40px; }
  .kd-saved .status-line .link-button, .kd-grid-said .link-button { min-height: 44px; }
}

/* ---- Phones and narrow pop-ups --------------------------------------------- */
@media (max-width: 720px) {
  .kd-add { grid-template-columns: minmax(0, 1fr); }
  .kd-drop { min-height: 0; padding: 22px 16px; }
  .kd-or { flex-direction: row; margin: 14px 0; }
  .kd-or::before, .kd-or::after { width: auto; height: 1px; }
  .kd-paste textarea { flex: none; height: 116px; min-height: 116px; }
}
@media (max-width: 560px) {
  .kd-steps { margin-bottom: 14px; }
  .kd-steps li + li::before { width: 16px; margin-right: 2px; }
  .kd-options .field { flex: 1 1 100%; }
  .kd-paste-foot { flex-direction: column; align-items: stretch; }
  .kd-foot-info { flex: 1 1 100%; justify-content: space-between; }
  .kd-line-actions .btn { flex: 1 1 auto; }
  .kd-grid-wrap { max-height: 58vh; }
  .kd-grid-table th, .kd-grid-table td { max-width: 12rem; }
  .kd-grid-table .kd-grid-num { min-width: 30px; padding-right: 6px; padding-left: 6px; }
}
