/* Data sources & table picker styles — owned by the data-sources slice.
   Built on the shared design tokens (--surface, --ink-*, --rule-*, --accent). */

.ds-narrow { max-width: 640px; }

/* ---- Index list ---------------------------------------------------------- */
.ds-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}
.ds-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  box-shadow: var(--shadow-1);
  text-decoration: none;
  color: inherit;
  position: relative;
}
/* Hover tint + lift-shadow crossfade via opacity (compositor) instead of
   background/box-shadow (paint). Border color snaps. */
.ds-row::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--surface-2); box-shadow: var(--shadow-2);
  opacity: 0; transition: opacity .12s ease; pointer-events: none; z-index: -1;
}
.ds-row:hover::after { opacity: 1; }
.ds-row:hover {
  border-color: var(--rule-3);
}
.ds-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent-edge);
}
.ds-row:hover .ds-row-icon { color: var(--accent-ink); border-color: var(--accent-edge); }
.ds-row-icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--ink-3);
  flex: 0 0 auto;
}
.ds-row-main { min-width: 0; flex: 1; }
.ds-row-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500; color: var(--ink);
}
.ds-row-sub {
  font-size: 12px; color: var(--ink-4); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ds-row-meta {
  display: flex; align-items: center; gap: 12px;
  flex: 0 0 auto; color: var(--ink-4); font-size: 12px;
}
.ds-chip {
  font-size: 11px; padding: 2px 8px;
  border-radius: 20px; background: var(--surface-2);
  border: 1px solid var(--rule-2); color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.ds-when { white-space: nowrap; font-variant-numeric: tabular-nums; }

.ds-empty {
  margin-top: 24px; align-items: center; text-align: center;
  background: var(--surface);
  border: 1px solid var(--rule-2); border-radius: 10px;
  box-shadow: var(--shadow-1);
}
.ds-empty svg { margin-bottom: 4px; color: var(--ink-5); }
.ds-empty .hint { font-size: 12.5px; color: var(--ink-4); }

/* ---- Form ---------------------------------------------------------------- */
.ds-form-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  align-items: center;
}
.ds-form-note {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 14px 0 0;
  font-size: 12px; color: var(--ink-4); line-height: 1.5;
}
.ds-form-note .ds-note-ic { flex: 0 0 auto; margin-top: 1px; color: var(--ok-ink); }

/* ---- Show: layout -------------------------------------------------------- */
.ds-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
  margin-top: 6px;
}
@media (max-width: 900px) {
  .ds-grid { grid-template-columns: 1fr; }
}

.ds-status {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 14px;
}
.ds-status-msg {
  font-size: 12px; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
.ds-status-msg.bad {
  color: var(--bad-ink);
  /* keep a long connection error from blowing out the narrow left column */
  overflow-wrap: anywhere;
}

.ds-dl { margin: 0; display: flex; flex-direction: column; gap: 0; }
.ds-dl > div {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--rule-2);
}
.ds-dl > div:last-child { border-bottom: none; }
.ds-dl dt { font-size: 12px; color: var(--ink-4); }
.ds-dl dd {
  margin: 0; font-size: 12.5px; color: var(--ink-2);
  text-align: right; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.ds-secret { color: var(--ink-4); font-style: italic; }

.ds-linked { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule-2); }
.ds-linked-h {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); margin-bottom: 8px; font-family: var(--mono);
}
.ds-linked-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 8px; margin: 0 -8px; border-radius: 5px;
  font-size: 13px;
  text-decoration: none; color: var(--ink-2); position: relative;
}
/* Hover tint via opacity crossfade (compositor) instead of background (paint). */
.ds-linked-row::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--surface-2); opacity: 0; transition: opacity .1s ease; pointer-events: none; z-index: -1; }
.ds-linked-row:hover::after { opacity: 1; }
.ds-linked-row:hover { color: var(--ink); }
.ds-linked-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  color: var(--ink);
}
.pill.sm { height: 17px; font-size: 10.5px; padding: 0 7px; }
.ds-readonly-pill { gap: 4px; color: var(--ink-3); }
.ds-readonly-pill svg { opacity: .8; }

/* ---- Table picker -------------------------------------------------------- */
.ds-picker { overflow: hidden; }
/* the design-system .btn has no focus ring; give the picker's controls one so
   the whole tables → columns → preview flow is keyboard-navigable */
.ds-picker .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ds-picker-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 240px;
}
.ds-picker-col { display: flex; flex-direction: column; min-width: 0; }
.ds-picker-col.ds-picker-tables { border-right: 1px solid var(--rule-2); }
.ds-picker-col-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); font-family: var(--mono);
  border-bottom: 1px solid var(--rule-2);
}
.ds-picker-scroll {
  flex: 1; overflow-y: auto; max-height: 320px;
  padding: 6px;
}
.ds-picker-hint {
  padding: 14px; font-size: 12.5px; color: var(--ink-4);
  display: flex; align-items: center; gap: 8px; line-height: 1.4;
}
.ds-picker-hint .ic { flex: 0 0 auto; color: var(--ink-5); }

.ds-tablelist, .ds-columnlist { list-style: none; margin: 0; padding: 0; }

.ds-table-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 7px 9px; border-radius: 6px;
  background: transparent; border: 1px solid transparent;
  color: var(--ink-2); font: inherit; font-size: 13px;
  cursor: pointer; position: relative;
}
/* Hover/selected fill crossfades via opacity (compositor) instead of background
   (paint); the variant sets --ti-bg. Border/text color snap. */
.ds-table-item::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--ti-bg, var(--surface-2)); opacity: 0; transition: opacity .1s ease; pointer-events: none; z-index: -1; }
.ds-table-item:hover::after { opacity: 1; }
.ds-table-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.ds-table-item.on {
  border-color: var(--accent-edge, var(--rule-3));
  color: var(--accent-ink, var(--ink)); font-weight: 500;
  --ti-bg: var(--accent-soft, var(--surface-2));
}
.ds-table-item.on::after { opacity: 1; }
.ds-table-item.on .ic { color: var(--accent-ink); }
.ds-table-item .ic { color: var(--ink-4); flex: 0 0 auto; }
.ds-table-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-table-tag {
  margin-left: auto; font-size: 10px; color: var(--ink-4);
  font-family: var(--mono); text-transform: uppercase;
}

.ds-column-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 9px; border-radius: 6px;
  border: 1px solid transparent; position: relative;
}
/* Hover/picked fill crossfades via opacity (compositor) instead of background
   (paint); the state sets --ci-bg. Border color snaps. */
.ds-column-item::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--ci-bg, var(--surface-2)); opacity: 0; transition: opacity .1s ease; pointer-events: none; z-index: -1; }
.ds-column-item:hover::after { opacity: 1; }
.ds-column-item.picked-value { border-color: var(--ok); --ci-bg: var(--ok-soft); }
.ds-column-item.picked-value::after { opacity: 1; }
.ds-column-item.picked-date { border-color: var(--warn); --ci-bg: var(--warn-soft); }
.ds-column-item.picked-date::after { opacity: 1; }
.ds-column-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ds-column-name > span:first-child {
  font-size: 13px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ds-column-type {
  font-size: 10.5px; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
/* the introspection partial tags numeric/temporal columns — give them a quiet
   affordance so the eligible "value"/"period" picks read at a glance */
.ds-column-item.is-numeric  .ds-column-type { color: var(--accent-ink); }
.ds-column-item.is-temporal .ds-column-type { color: var(--warn-ink); }
.ds-column-pick { display: flex; gap: 4px; flex: 0 0 auto; }
.ds-column-pick .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Preview ------------------------------------------------------------- */
.ds-preview { border-top: 1px solid var(--rule-2); }
.ds-preview-h {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); font-family: var(--mono);
}
.ds-preview-h .sp { flex: 1; }
.ds-preview-controls { padding: 0 14px 8px; }
.ds-preview-bind {
  font-size: 12px; color: var(--ink-3);
  background: var(--surface-2); padding: 4px 8px; border-radius: 5px;
  display: inline-block;
}
.ds-preview-out { padding: 4px 14px 14px; }

.ds-preview-table-wrap { overflow-x: auto; border: 1px solid var(--rule-2); border-radius: 6px; }
.ds-preview-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ds-preview-table th, .ds-preview-table td {
  text-align: left; padding: 6px 10px;
  border-bottom: 1px solid var(--rule-2);
  white-space: nowrap;
}
.ds-preview-table th {
  font-weight: 500; color: var(--ink-4);
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-2);
}
.ds-preview-table tbody tr:hover { background: var(--surface-2); }
.ds-preview-table tr:last-child td { border-bottom: none; }
.ds-preview-table td {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.ds-preview-foot {
  margin-top: 6px; font-size: 11.5px; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

.ds-picker-error {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 14px; margin: 4px;
  font-size: 12.5px; line-height: 1.45; color: var(--bad-ink);
  background: var(--bad-soft);
  border: 1px solid var(--bad); border-radius: 6px;
  overflow-wrap: anywhere;
}
/* the icon ships only with the server partial; the JS-injected variant is a
   bare <div><span>…</span></div>, so this layout must read well without it */
.ds-picker-error .ic { flex: 0 0 auto; margin-top: 1px; }

/* spinner used by injected fragments */
.ds-spin {
  width: 11px; height: 11px; display: inline-block;
  border: 1.5px solid var(--rule-3); border-top-color: var(--ink-3);
  border-radius: 50%; animation: ds-spin .7s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

.mono { font-family: var(--mono); }

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .ds-row,
  .ds-row-icon,
  .ds-linked-row,
  .ds-table-item,
  .ds-table-item .ic,
  .ds-column-item,
  .ds-preview-table tbody tr {
    transition: none;
  }
  /* keep the spinner readable without spinning — a static ring still signals
     "working" while respecting the user's motion preference */
  .ds-spin { animation: none; }
}
