/* Datasets manager — two-pane body inside the modal shell (spec §05 → Layout). */

.manager {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
  height: 100%;
}

/* --- List pane --- */
.listPane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: var(--border-width) solid var(--border);
}

/* A shared primary Button (lg); locally just pinned with a margin. */
.newButton {
  flex: 0 0 auto;
  margin: var(--space-4);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border-top: var(--border-width) solid var(--border);
}

.empty {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
  padding: var(--space-5) var(--space-4);
}

.item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  border-left: 2px solid transparent;
  transition: background var(--dur-fast) var(--ease);
}

.item + .item {
  border-top: var(--border-width) solid var(--border);
}

.item:hover {
  background: var(--layer-01);
}

.itemActive {
  background: var(--layer-01);
  border-left-color: var(--accent);
}

.itemMain {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  appearance: none;
  border: none;
  background: none;
  padding: var(--space-3) 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.itemName {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.itemMeta {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Usage badge — count of referencing snippets (spec §05 → List item). */
.badge {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--layer-02);
  border-radius: var(--radius);
}

/* --- Detail pane --- */
.detailPane {
  min-height: 0;
  overflow: auto;
}

.detailEmpty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 14px;
  padding: var(--space-6);
  text-align: center;
}

.detail,
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
}

.detailHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.detailName {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.detailActions,
.formActions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.formActions {
  justify-content: flex-end;
}

/* Actions are shared Buttons (secondary / primary / danger-outline). */

.comment {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* URL dataset provenance: the source address + last-fetched time (spec §05). */
.sourceMeta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.sourceLink {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.sourceLink:hover {
  text-decoration: underline;
}

.sourceLink:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.sectionTitle {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--space-4);
  margin: 0;
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stats dt {
  font-size: 11px;
  color: var(--text-secondary);
}

.stats dd {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* Two-up multi-column flow (min 220px per column, so a narrow pane falls back
   to one): a wide schema reads down-then-over and a 25-field dataset no longer
   buries the preview table below a full-screen scroll (NN/g #8;
   docs/ux-second-pass.md resolution 2026-06-13). */
.columns {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 220px 2;
  column-gap: 0;
  column-rule: var(--border-width) solid var(--border);
  border: var(--border-width) solid var(--border);
}

.column {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  break-inside: avoid;
  /* Hairline between rows; the negative margin tucks each column's first border
     under the container border (a `+`-sibling border would double there). */
  border-top: var(--border-width) solid var(--border);
  margin-top: calc(-1 * var(--border-width));
}

.columnName {
  font-size: 13px;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.columnType {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--layer-01);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
}

.timestamps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: 11px;
  color: var(--text-secondary);
}

.preview {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  padding: var(--space-3);
  background: var(--layer-01);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

/* Tabular preview — a scrollable grid with a sticky header (spec §05 → Preview). */
.previewTableWrap {
  max-height: 260px;
  overflow: auto;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
}

.previewTable {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

.previewTable th,
.previewTable td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width) solid var(--border);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.previewTable thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--layer-01);
  font-weight: 600;
  color: var(--text-secondary);
}

.previewTable tbody tr:last-child td {
  border-bottom: none;
}

.muted {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.linked {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.linkButton {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}

.linkButton:hover {
  text-decoration: underline;
}

.linkButton:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Create / edit form --- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input,
.textarea {
  width: 100%;
  padding: var(--space-3);
  font-size: 13px;
}

.textarea {
  font-family: var(--font-mono);
  resize: vertical;
  min-height: 160px;
}

.detected {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: calc(-1 * var(--space-2));
}

.detectedBadge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--layer-02);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius);
}

.detectedHint {
  font-size: 11px;
  color: var(--text-secondary);
}

.formError {
  margin: 0;
  font-size: 13px;
  color: var(--support-error);
}

/* The inline-fallback recovery under a failed URL fetch — left-aligned, not
   stretched, so it reads as a secondary recovery beneath the error message. */
.fallback {
  align-self: flex-start;
  margin-top: calc(-1 * var(--space-2));
}
