/* ============================================================
   File surface — responsive grid + row layouts
   ============================================================ */

/* Default file grid — a vertical list of rows. Each row lays out its own
   columns internally; the container only stacks them. Card mode (multi-column)
   is opt-in via [data-columns]. */
.ds-file-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ds-file-grid:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); border-radius: var(--r-2); }

/* Listing wrapper holds the optional filter + sort header above the grid. */
.ds-file-listing { display: flex; flex-direction: column; gap: var(--space-2); min-height: 0; }
/* The quick filter is a compact control, not a full-width form row - a giant
   input above the grid reads as a search page and costs fold height. */
/* The filter is now an inline item in the single .ds-file-controls toolbar row
   (the standalone right-aligned .ds-file-filter strip was removed). */
.ds-file-filter-input {
  width: min(280px, 100%); padding: var(--space-1-75) var(--space-2-75); font-size: var(--fs-sm);
  background: var(--bg); color: var(--fg);
  border: var(--bw-hair) solid var(--rule); border-radius: var(--r-1);
}
.ds-file-controls .ds-file-filter-wrap { flex: 0 1 220px; display: contents; }
.ds-file-controls .ds-file-filter-wrap .ds-file-filter-input { flex: 0 1 220px; }
.ds-file-filter-input:focus-visible { outline: none; box-shadow: var(--focus-ring-inset); }
.ds-file-sort { display: flex; gap: var(--space-2); padding: 0 var(--space-2) var(--space-1); }
.ds-file-sort-btn {
  font-size: var(--fs-tiny); font-family: var(--ff-mono); color: var(--fg-3);
  background: none; border: none; cursor: pointer; padding: var(--space-hair) var(--space-1); border-radius: var(--r-1);
}
.ds-file-sort-btn:hover { color: var(--fg-2); background: var(--bg-2); }
.ds-file-sort-btn.active { color: var(--accent-ink); }
.ds-file-sort-btn:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }

/* Skeleton shimmer rows shown while a directory loads. */
.ds-file-row-skeleton { cursor: default; pointer-events: none; }
/* In-place refresh: dim the populated grid instead of swapping it for shimmer
   rows (the rows stay; the round-trip reads as a settle, not a reload). */
.ds-file-grid.is-refreshing { opacity: .6; }
@media (prefers-reduced-motion: no-preference) {
  .ds-file-grid { transition: opacity .15s var(--ease); }
}
/* EventList loading skeleton (shares the .ds-skel shimmer base above). */
.ds-event-row-skeleton { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2-75) var(--space-3); pointer-events: none; }
.ds-skel-rank { height: 12px; width: 2.5ch; }
.ds-event-state { padding: var(--space-2) var(--space-3); }
.ds-skel { display: inline-block; border-radius: var(--r-1); background: var(--bg-2); position: relative; overflow: hidden; }
.ds-skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--bg-3), transparent);
  transform: translateX(-100%); animation: ds-skel-shimmer 1.2s infinite;
}
.ds-skel-icon { width: 22px; height: 22px; }
.ds-skel-title { height: 12px; width: 60%; }
.ds-skel-meta { height: 10px; width: 64px; margin-left: auto; }
@keyframes ds-skel-shimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .ds-skel::after { animation: none; } }

/* File row — linear layout (checkbox? · open-button[code · icon · title · meta] · actions).
   The row is a flex strip; the open <button> is the stretching member and lays
   out the entry's own columns. It needs a full reset (UA button chrome off)
   because FileRow wraps the row content in a real button for native keyboard
   semantics. */
.ds-file-row {
  display: flex; align-items: center; gap: var(--space-2-5);
  /* 11px vertical is an optical half-step between --space-2-5 (10) and
     --space-2-75 (12), deliberately off-scale: with the 26px .ds-file-icon
     and the hairline borders it lands the row at ~50px, comfortably over the
     44px touch floor without the 52px a 12px pad would give. Snapping either
     way visibly re-pitches every row in a long listing. */
  padding: 11px var(--space-3); background: var(--bg);
  border: var(--bw-hair) solid transparent;
  border-radius: var(--r-2); color: var(--fg);
  cursor: pointer;
  transition: background var(--dur-snap) var(--ease),
              border-color var(--dur-snap) var(--ease),
              transform var(--dur-snap) var(--ease);
}
.ds-file-open {
  display: flex; align-items: center; gap: var(--space-2-75);
  flex: 1 1 auto; min-width: 0;
  background: none; border: 0; padding: 0; margin: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.ds-file-open[disabled] { cursor: default; }
.ds-file-open:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); border-radius: var(--r-1); }
.ds-file-row:hover {
  background: var(--bg-2);
  border-color: var(--rule);
}
.ds-file-row:active { transform: translateY(1px); }
.ds-file-row.active { background: var(--accent-tint); border-color: var(--accent); }
.ds-file-row[data-file-type="dir"]      { border-left-width: 3px; border-left-color: var(--accent); }
.ds-file-row[data-file-type="image"],
.ds-file-row[data-file-type="video"],
.ds-file-row[data-file-type="audio"],
.ds-file-row[data-file-type="code"],
.ds-file-row[data-file-type="text"],
.ds-file-row[data-file-type="archive"],
.ds-file-row[data-file-type="document"],
.ds-file-row[data-file-type="symlink"],
.ds-file-row[data-file-type="other"]    { border-left-width: 3px; border-left-color: var(--rule); }

/* Row internals — these are the classes FileRow actually renders. */
.ds-file-row .title {
  font-weight: 500; font-size: var(--fs-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; flex: 1 1 auto;
}
.ds-file-row .code {
  font-family: var(--ff-mono); font-size: var(--fs-micro);
  color: var(--fg-3);
}
.ds-file-row .ds-file-meta {
  font-family: var(--ff-mono); font-size: var(--fs-xs);
  color: var(--fg-3); white-space: nowrap;
  /* Never shrink below content: a flex sibling with white-space:nowrap and
     the default flex-shrink:1 silently overflows its own box (no ellipsis)
     when the row runs out of width, painting the date/size over the title
     and action icons at mobile widths. Fixed-size the meta column instead
     and let .title (flex:1, min-width:0, ellipsis) absorb the squeeze. */
  flex-shrink: 0;
}

/* File icon — glyph chip, tinted per type. */
.ds-file-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; font-size: var(--fs-sm); line-height: 1;
  color: var(--fg-2);
}
.ds-file-row[data-file-type="dir"]      .ds-file-icon { color: var(--accent-ink); }
.ds-file-row[data-file-type="image"]    .ds-file-icon { color: var(--mascot); }
.ds-file-row[data-file-type="video"]    .ds-file-icon { color: var(--purple-2); }
.ds-file-row[data-file-type="audio"]    .ds-file-icon { color: var(--sky); }
.ds-file-row[data-file-type="code"]     .ds-file-icon { color: var(--green-2); }
.ds-file-row[data-file-type="archive"]  .ds-file-icon { color: var(--flame); }
.ds-file-row[data-file-type="document"] .ds-file-icon { color: var(--amber, var(--sun)); }

/* Row actions — a faint baseline keeps them discoverable at rest (not fully
   hidden, which left mouse/trackpad users unable to find rename/move/delete
   without accidentally hovering a row), full opacity on hover/focus. */
.ds-file-actions {
  display: inline-flex; gap: var(--space-hair); align-items: center;
  opacity: 0.35; transition: opacity var(--dur-base) var(--ease);
}
.ds-file-row:hover .ds-file-actions,
.ds-file-row:focus-within .ds-file-actions { opacity: 1; }
.ds-file-act {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  background: transparent; border: 0; border-radius: var(--r-1);
  color: var(--fg-3); font-size: var(--fs-xs); cursor: pointer;
  transition: background var(--dur-snap) var(--ease), color var(--dur-snap) var(--ease);
}
.ds-file-act:hover { background: var(--bg-3); color: var(--fg); }
.ds-file-act-warn:hover { background: color-mix(in oklab, var(--warn) 18%, var(--bg)); color: var(--warn); }

/* Multi-select — per-row checkbox, header tri-state, bulk action strip. */
/* CSS-drawn multi-select checkbox: a bordered box that fills with the accent +
   a border-drawn tick when its parent button is .is-marked or aria-checked.
   Shared by FileRow/FileCell (.is-marked) and the file/session select-all +
   SessionCard select (aria-checked true/mixed) since the bundle concatenates
   all CSS. Replaces the old [x]/[ ] bracket text - no glyphs, AT keeps the
   role=checkbox/aria-checked name+state.
   See also .ds-check in editor-primitives.css — a separate native-input
   checkbox family for form/settings contexts; intentionally distinct
   rendering (native vs CSS-drawn), do not let one drift toward the other
   by accident. */
.ds-check-box {
  width: 15px; height: 15px; box-sizing: border-box; flex: 0 0 auto; position: relative;
  border: 1.5px solid var(--fg-3); border-radius: var(--r-0);
  transition: background var(--dur-snap) var(--ease), border-color var(--dur-snap) var(--ease);
}
.is-marked > .ds-check-box,
[aria-checked="true"] > .ds-check-box { background: var(--fg); border-color: var(--fg); }
.is-marked > .ds-check-box::after,
[aria-checked="true"] > .ds-check-box::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid var(--bg); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}
[aria-checked="mixed"] > .ds-check-box { background: var(--fg); border-color: var(--fg); }
[aria-checked="mixed"] > .ds-check-box::after {
  content: ""; position: absolute; left: 3px; right: 3px; top: 6px; height: 2px; background: var(--bg); border-radius: var(--r-hair);
}

.ds-file-check {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 var(--space-1);
  background: transparent; border: 0; border-radius: var(--r-1);
  color: var(--fg-3);
  cursor: pointer;
  transition: background var(--dur-snap) var(--ease), color var(--dur-snap) var(--ease);
}
.ds-file-check:hover { background: var(--bg-3); color: var(--fg); }
.ds-file-check.is-marked { color: var(--accent-ink); }
.ds-file-check:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }
.ds-file-check[disabled] { opacity: 0.4; cursor: default; }
.ds-file-row.is-marked { background: var(--accent-tint); border-color: var(--accent); }
.ds-file-selectall {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--ff-mono); font-size: var(--fs-tiny); color: var(--fg-2);
  cursor: pointer; background: none; border: none;
  padding: var(--space-1); border-radius: var(--r-1);
}
.ds-file-selectall:hover { background: var(--bg-2); color: var(--fg); }
.ds-file-selectall:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }
.ds-file-controls { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2) var(--space-1); flex-wrap: wrap; }
.ds-file-controls .spread { flex: 1 1 auto; }
.ds-file-controls .ds-file-sort { padding: 0; }
.ds-bulkbar {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  padding: var(--space-1) var(--space-2);
  background: var(--bg-2); border: var(--bw-hair) solid var(--rule); border-radius: var(--r-2);
}
.ds-bulkbar-count { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-2); }
/* BulkBar is a toolbar (it even declares role=toolbar): compact rect buttons,
   quiet destructive outline - the app arm-confirms destructive bulk actions
   via ConfirmDialog, so the strip never needs a loud CTA. */
.ds-bulkbar .btn, .ds-bulkbar .btn-primary {
  padding: var(--space-1-5) var(--space-2-75); min-height: 32px; border-radius: var(--r-1); font-weight: 500;
}
.ds-bulkbar .btn { background: transparent; border: var(--bw-hair) solid var(--rule); color: var(--fg-2); }
.ds-bulkbar .btn:hover { background: var(--bg-2); color: var(--fg); }
.ds-bulkbar .btn-primary.danger { background: transparent; color: var(--warn); border: var(--bw-hair) solid var(--warn); }
.ds-bulkbar .btn-primary.danger:hover { background: color-mix(in oklab, var(--warn) 12%, transparent); color: var(--warn); }
@media (pointer: coarse) {
  .ds-bulkbar .btn, .ds-bulkbar .btn-primary { min-height: 44px; }
}

/* Density picker — list / compact / thumbnails. */
.ds-density {
  display: inline-flex; gap: var(--space-hair); padding: var(--space-hair);
  background: var(--bg-2); border: var(--bw-hair) solid var(--rule); border-radius: var(--r-1);
}
.ds-density-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; color: var(--fg-2);
  background: none; border: none; cursor: pointer;
  padding: 0; border-radius: calc(var(--r-1) - 2px);
  transition: background var(--dur-snap) var(--ease), color var(--dur-snap) var(--ease);
}
.ds-density-btn:hover { color: var(--fg); }
.ds-density-btn.active { background: var(--accent-tint); color: var(--fg); }
.ds-density-btn:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }

/* Compact density — tighter rows for long listings. */
.ds-file-grid[data-density="compact"] { gap: var(--space-hair); }
.ds-file-grid[data-density="compact"] .ds-file-row { padding: var(--space-1-5) var(--space-2-75); gap: var(--space-2-5); }
.ds-file-grid[data-density="compact"] .ds-file-row .title { font-size: var(--fs-xs); }
.ds-file-grid[data-density="compact"] .ds-file-row .ds-file-meta { font-size: var(--fs-micro); }
.ds-file-grid[data-density="compact"] .ds-file-icon { width: 20px; height: 20px; font-size: var(--fs-tiny); }

/* Thumbnail density — tile grid; image entries carry a real lazy thumbnail. */
.ds-file-grid-thumb {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: var(--space-3); align-items: start;
}
.ds-file-cell {
  position: relative;
  background: var(--bg); border: var(--bw-hair) solid var(--rule); border-radius: var(--r-2);
  overflow: hidden;
  transition: border-color var(--dur-snap) var(--ease), background var(--dur-snap) var(--ease);
}
.ds-file-cell:hover { border-color: var(--fg-3); }
.ds-file-cell.active { border-color: var(--accent); background: var(--accent-tint); }
.ds-file-cell.is-marked { border-color: var(--accent); background: var(--accent-tint); }
.ds-file-cell.is-locked { opacity: 0.6; }
.ds-file-row.is-locked { opacity: 0.6; }
.ds-file-row.is-restricted .title { color: var(--fg-2); }
/* 1px vertical pad is deliberately below --space-hair (2px): this mono tag
   sits inline in a file row and must not add height to it; --space-hair would
   double the vertical pad and push the tag past the row cap height.
   A fourth, deliberately bordered/mono tag variant for file-permission tags
   specifically (distinct from .ds-badge for numeric counts and .chip for
   status/label words) - is-noaccess reuses the shared --flame tone token
   so 'no access' reads the same red as chip.tone-error/miss elsewhere. */
.ds-file-perm-tag { font-family: var(--ff-mono); font-size: var(--fs-micro); color: var(--fg-3); padding: 1px var(--space-1-75); border: var(--bw-hair) solid var(--rule); border-radius: var(--r-1); white-space: nowrap; }
.ds-file-perm-tag.is-noaccess { color: var(--flame); border-color: var(--flame); }
.ds-file-cell-open {
  display: flex; flex-direction: column; align-items: stretch; gap: var(--space-1);
  width: 100%; padding: var(--space-1); margin: 0;
  background: none; border: none; cursor: pointer; color: var(--fg);
}
.ds-file-cell-open[disabled] { cursor: default; }
.ds-file-cell-open:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: -2px; border-radius: var(--r-2); }
.ds-file-cell-media {
  display: flex; align-items: center; justify-content: center;
  width: 100%; aspect-ratio: 4 / 3;
  background: var(--bg-2); border-radius: var(--r-1); overflow: hidden;
}
/* 24px is the ICON size inside a 34px chip, not a type tier — it is matched to
   the chip box, not to the text scale (the --fs-* rungs jump 21px -> fluid
   heading clamps, so neither substitutes without resizing the icon). Same
   reasoning for the other four .ds-*-glyph rules in this sheet. */
.ds-file-cell-media .ds-file-icon { width: 34px; height: 34px; font-size: 24px; }
.ds-file-cell-thumb { width: 100%; height: 100%; object-fit: cover; }
/* Per-type icon tints on thumb tiles so the grid keeps the colour-coding the
   list rows already carry (mirrors .ds-file-row[data-file-type] .ds-file-icon). */
.ds-file-cell[data-file-type="dir"]      .ds-file-icon { color: var(--accent-ink); }
.ds-file-cell[data-file-type="image"]    .ds-file-icon { color: var(--mascot); }
.ds-file-cell[data-file-type="video"]    .ds-file-icon { color: var(--purple-2); }
.ds-file-cell[data-file-type="audio"]    .ds-file-icon { color: var(--sky); }
.ds-file-cell[data-file-type="code"]     .ds-file-icon { color: var(--green-2); }
.ds-file-cell[data-file-type="archive"]  .ds-file-icon { color: var(--flame); }
.ds-file-cell[data-file-type="document"] .ds-file-icon { color: var(--amber); }
.ds-file-cell[data-file-type="symlink"]  .ds-file-icon { color: var(--purple); }
.ds-file-cell-name {
  font-size: var(--fs-tiny); text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ds-file-cell-meta { font-family: var(--ff-mono); font-size: var(--fs-micro); color: var(--fg-3); text-align: left; }
.ds-file-cell-check {
  position: absolute; top: 4px; left: 4px; z-index: var(--z-raised);
  background: color-mix(in oklab, var(--bg) 78%, transparent);
}

/* ============================================================
   File browser surface — stage, toolbar, breadcrumb, dropzone,
   upload progress, empty state, modals, preview. Authored for
   fsbrowse but lives in the shared kit under .ds-247420 scope.
   ============================================================ */

/* Stage — the scrollable content column. */
.ds-file-stage {
  display: flex; flex-direction: column; gap: var(--space-3);
  width: 100%; max-width: var(--measure-wide); margin: 0 auto;
  padding: var(--space-2) var(--space-3) var(--space-4);
}
/* When the stage is the app-main child, the shell already supplies top
   padding — collapse the stage's own so content isn't pushed down. */
.app-main > div > .ds-file-stage,
.app-main .ds-file-stage { padding-top: 0; }

/* Full-width files stack: the stage's space-3 vertical beat without its
   --measure-wide cap/auto-margins, so the roots / toolbar / bulkbar / uploads / grid
   bands keep one consistent rhythm instead of touching edge-to-edge. Carries
   the same side/bottom padding as .ds-file-stage (top collapses the same way
   when mounted directly under .app-main, which already supplies top padding)
   so switching a consumer from the capped stage to this full-width stack is a
   pure width change, not a spacing regression. */
.ds-files-stack {
  display: flex; flex-direction: column; gap: var(--space-3); min-height: 0;
  padding: 0 var(--space-3) var(--space-4);
}
.app-main > div > .ds-files-stack,
.app-main .ds-files-stack { padding-top: 0; }

/* Breadcrumb path */
.ds-crumb-path {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-hair);
  font-size: var(--fs-sm);
}
.ds-crumb-seg {
  background: transparent; border: 0; cursor: pointer;
  padding: var(--space-1) var(--space-2); border-radius: var(--r-1);
  color: var(--fg-3); font-family: inherit; font-size: var(--fs-sm);
  transition: background var(--dur-snap) var(--ease), color var(--dur-snap) var(--ease);
  /* A single long unbroken segment (hash-named dir) must never force the
     whole path past the viewport. */
  max-width: min(40vw, 220px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ds-crumb-seg:hover { background: var(--bg-2); color: var(--fg); }
.ds-crumb-seg.leaf { color: var(--fg); font-weight: 600; }
.ds-crumb-sep { color: var(--fg-3); opacity: 0.6; user-select: none; }

/* Toolbar */
.ds-file-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); flex-wrap: wrap;
}
/* Dense page header: one row, small heading, single-line muted lede. The
   working surfaces (files, live, history, settings) lead with content, not a
   display H1 + paragraph that costs the first 150px of every fold. */
.ds-page-header-dense { margin: 0 0 var(--space-3); }
.ds-page-header-dense-row { display: flex; align-items: baseline; gap: var(--space-3); min-width: 0; }
.ds-page-header-dense-row h1 {
  margin: 0; font-size: var(--fs-lg); line-height: 1.3; font-weight: 600;
  letter-spacing: normal; flex: 0 0 auto;
}
.ds-page-header-dense-lede {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-sm); color: var(--fg-3);
}
.ds-page-header-dense .ds-page-header-right { flex: 0 0 auto; margin-left: auto; }
/* Below ~480px the single-line ellipsis truncates the majority of the lede
   text with no way to recover it (no title attr, no expand) - let the row
   wrap and the lede break onto its own line instead of clipping. */
@media (max-width: 480px) {
  .ds-page-header-dense-row { flex-wrap: wrap; }
  .ds-page-header-dense-lede {
    flex-basis: 100%; overflow: visible; text-overflow: clip; white-space: normal;
  }
}
.ds-file-toolbar-left,
.ds-file-toolbar-right {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
/* Toolbar-scoped buttons: quiet, compact, rectangular - a toolbar is chrome,
   not a CTA row; the stadium pill stays for real page-level actions. */
.ds-file-toolbar .btn, .ds-file-toolbar .btn-ghost {
  padding: var(--space-1-5) var(--space-2-75); min-height: 32px;
  border-radius: var(--r-1);
  font-weight: 500;
  background: transparent;
  border: var(--bw-hair) solid var(--rule); color: var(--fg-2);
}
.ds-file-toolbar .btn:hover, .ds-file-toolbar .btn-ghost:hover { background: var(--bg-2); color: var(--fg); }
@media (pointer: coarse) {
  .ds-file-toolbar .btn, .ds-file-toolbar .btn-ghost { min-height: 44px; }
}
.ds-meta-mono {
  font-family: var(--ff-mono); font-size: var(--fs-xs);
  color: var(--fg-3); letter-spacing: var(--tr-caps);
}

/* Error banner — dismissible toast row. */
.ds-error-banner {
  padding: var(--space-2-5) var(--space-2-75); border-radius: var(--r-2);
  background: color-mix(in oklab, var(--warn) 14%, var(--bg));
  border: var(--bw-hair) solid color-mix(in oklab, var(--warn) 40%, transparent);
  color: var(--warn); font-size: var(--fs-sm); cursor: pointer;
}
.ds-error-banner:hover { background: color-mix(in oklab, var(--warn) 20%, var(--bg)); }

/* Dropzone */
.ds-dropzone {
  border: var(--bw-rule) dashed var(--rule);
  border-radius: var(--r-3); background: var(--bg);
  transition: border-color var(--dur-base) var(--ease), background var(--dur-base) var(--ease);
}
.ds-dropzone-inner {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-2); flex-wrap: wrap;
  padding: var(--space-4) var(--space-3); text-align: center;
}
/* Icon size, not type — see .ds-file-cell-media .ds-file-icon above. */
.ds-dropzone-glyph { font-size: 22px; color: var(--fg-3); }
.ds-dropzone-label { font-size: var(--fs-sm); color: var(--fg-3); }
.ds-dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-tint);
}
@media (prefers-reduced-motion: no-preference) {
  .ds-dropzone.dragover { animation: ds-dropzone-pulse 1.1s var(--ease) infinite; }
}
.ds-dropzone.dragover .ds-dropzone-glyph,
.ds-dropzone.dragover .ds-dropzone-label { color: var(--accent-ink); }
@keyframes ds-dropzone-pulse {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: color-mix(in oklab, var(--accent) 45%, transparent); }
}
/* Wrapper form (has children): no permanent chrome - the content renders as if
   the zone were not there, and the dashed affordance overlays it ONLY while a
   drag is in flight. */
.ds-dropzone--wrap { position: relative; border: none; border-radius: 0; background: transparent; }
.ds-dropzone--wrap > .ds-dropzone-inner { display: none; }
.ds-dropzone--wrap.dragover > .ds-dropzone-inner {
  display: flex; position: absolute; inset: 0; z-index: var(--z-raised);
  margin: 0; padding: var(--space-3);
  align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  outline: var(--bw-rule) dashed var(--accent); outline-offset: -6px;
  border-radius: var(--r-3);
}
.ds-dropzone--wrap.dragover { animation: none; }
/* Touch devices can never fire dragover — keep the pick-files affordance
   visible as a compact static row so upload stays reachable in wrap mode. */
@media (hover: none) and (pointer: coarse) {
  .ds-dropzone--wrap > .ds-dropzone-inner {
    display: flex; position: static; padding: var(--space-2);
    outline: none; background: transparent;
  }
}

/* Upload progress */
.ds-upload-progress { display: flex; flex-direction: column; gap: var(--space-1-75); }
.ds-upload-item {
  display: grid; grid-template-columns: minmax(0, 1fr) 120px 44px;
  gap: var(--space-2); align-items: center;
  padding: var(--space-2) var(--space-2-75); border-radius: var(--r-2);
  background: var(--bg-2); font-size: var(--fs-xs);
}
.ds-upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-upload-bar {
  height: 6px; border-radius: var(--r-pill);
  background: var(--bg-3); overflow: hidden;
}
.ds-upload-fill {
  display: block; height: 100%; width: 0;
  background: var(--fg-3); border-radius: var(--r-pill);
  transition: width var(--dur-base) var(--ease);
}
.ds-upload-fill.is-active { background: var(--accent); }
/* Indeterminate: percent is unknown mid-transfer (fetch gives no chunk-level
   progress) — a sliding marquee bar reads as "working", not stuck at 0%. */
.ds-upload-bar.indeterminate .ds-upload-fill {
  width: 40%; transition: none;
  animation: ds-upload-marquee 1.1s ease-in-out infinite;
}
@keyframes ds-upload-marquee {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
  .ds-upload-bar.indeterminate .ds-upload-fill { animation: none; width: 100%; opacity: 0.5; }
}
.ds-upload-pct {
  font-family: var(--ff-mono); font-size: var(--fs-micro);
  color: var(--fg-3); text-align: right;
}
.ds-upload-item.done .ds-upload-fill { background: var(--success); }
.ds-upload-item.done .ds-upload-pct { color: var(--green); }
.ds-upload-item.error .ds-upload-fill { background: var(--warn); }
.ds-upload-item.error .ds-upload-pct { color: var(--warn); }
/* Per-row upload recovery actions (replace / dismiss) — error rows are not dead ends. */
.ds-upload-item { grid-template-columns: minmax(0, 1fr) minmax(60px, 120px) 44px auto; }
@media (max-width: 480px) {
  .ds-upload-item { grid-template-columns: minmax(0, 1fr) 44px; }
  .ds-upload-bar { grid-column: 1 / -1; order: 3; }
  .ds-upload-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
.ds-upload-actions { display: inline-flex; gap: var(--space-1); justify-content: flex-end; }
.ds-upload-act {
  padding: var(--space-hair) var(--space-2-5); min-height: 24px; cursor: pointer;
  background: var(--bg); border: var(--bw-hair) solid var(--rule); border-radius: var(--r-1);
  color: var(--fg-2); font-family: var(--ff-body); font-size: var(--fs-micro);
}
.ds-upload-act:hover { background: var(--bg-3); color: var(--fg); }
.ds-upload-act:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }
@media (hover: none), (pointer: coarse) {
  .ds-upload-act { min-height: 44px; min-width: 44px; }
  /* 44px floor for file controls on ANY touch device, not only narrow ones
     (the width-based mobile block misses wide touch tablets). */
  .ds-file-act, .ds-file-sort-btn, .ds-crumb-seg, .ds-file-filter-input { min-height: 44px; }
  .ds-file-act { min-width: 44px; }
  .ds-file-check, .ds-file-selectall, .ds-density-btn { min-height: 44px; min-width: 44px; }
}

/* Empty state */
.ds-file-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2); padding: var(--space-6) var(--space-3);
  color: var(--fg-3); text-align: center;
}
/* Icon size, not type — see .ds-file-cell-media .ds-file-icon above. */
.ds-file-empty-glyph { font-size: 34px; opacity: 0.55; }
.ds-file-empty-text { font-size: var(--fs-sm); }

/* -- Modals ------------------------------------------------- */
.ds-modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  /* Notch/home-indicator safe: near-fullscreen modals must not slide under. */
  padding: max(var(--space-3), env(safe-area-inset-top))
           max(var(--space-3), env(safe-area-inset-right))
           max(var(--space-3), env(safe-area-inset-bottom))
           max(var(--space-3), env(safe-area-inset-left));
  background: color-mix(in oklab, var(--ink) 55%, transparent);
}
@media (prefers-reduced-motion: no-preference) {
  .ds-modal-backdrop { animation: ds-modal-fade var(--dur-base) var(--ease); }
}
@keyframes ds-modal-fade { from { opacity: 0; } to { opacity: 1; } }
.ds-modal {
  display: flex; flex-direction: column;
  width: 100%; max-width: 460px;
  max-height: calc(100vh - 2 * var(--space-4));
  max-height: calc(100dvh - 2 * var(--space-4));
  background: var(--bg); color: var(--fg);
  border: var(--bw-hair) solid var(--rule);
  border-radius: var(--r-3); box-shadow: var(--shadow-3);
  overflow: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  .ds-modal { animation: ds-modal-rise var(--dur-base) var(--ease); }
}
@keyframes ds-modal-rise {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.ds-modal-small { max-width: 380px; }
.ds-modal-preview { max-width: 880px; }
.ds-modal-head {
  padding: var(--space-3) var(--space-4);
  font-weight: 600; font-size: var(--fs-body);
  border-bottom: var(--bw-hair) solid var(--rule);
}
.ds-modal-body { padding: var(--space-4); overflow: auto; font-size: var(--fs-sm); }
.ds-modal-actions {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: var(--bw-hair) solid var(--rule);
}
.ds-modal-input {
  width: 100%; padding: var(--space-2-5) var(--space-2-75);
  background: var(--bg-2); border: var(--bw-hair) solid var(--rule);
  border-radius: var(--r-2); color: var(--fg);
  font-family: inherit; font-size: var(--fs-sm);
}
.ds-modal-input:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }
/* iOS auto-zooms inputs under 16px on focus, breaking the modal layout.
   Deliberately a literal, NOT var(--fs-body): --fs-body is re-declared to
   15px under [data-typescale="sm"], which would silently drop this input back
   under the zoom threshold on any density-reduced page. The 16px here is a
   platform constant, not a point on the type scale. */
@media (hover: none), (pointer: coarse) {
  .ds-modal-input { font-size: 16px; min-height: 44px; }
}
/* PromptDialog's optional roots-chip row (destination-path prompts with more
   than one allowed root) - same chip idiom the cwd editor's roots row uses. */
.ds-prompt-roots { display: flex; align-items: center; gap: var(--space-1-75); flex-wrap: wrap; margin-top: var(--space-2); }
.ds-prompt-root-chip {
  background: var(--bg-2); border: var(--bw-hair) solid var(--rule); color: var(--fg-2);
  border-radius: var(--r-pill); padding: var(--space-half) var(--space-2-5); font: inherit; font-size: var(--fs-tiny);
  cursor: pointer;
}
.ds-prompt-root-chip:hover { border-color: var(--accent); color: var(--fg); }
.ds-prompt-root-chip:focus-visible { outline: var(--focus-w) solid var(--focus-color); outline-offset: var(--focus-offset); }
@media (pointer: coarse) { .ds-prompt-root-chip { min-height: 44px; } }
/* In-body modal error (role=alert): mutation failures (409/403) surface INSIDE
   the dialog, not behind the fixed overlay. */
.ds-modal-error {
  margin: var(--space-2) 0 0; padding: var(--space-2) var(--space-2-5);
  border: var(--bw-hair) solid var(--flame); border-radius: var(--r-2);
  background: color-mix(in oklab, var(--flame) 12%, var(--bg));
  color: var(--flame); font-size: var(--fs-xs);
}
/* --ink, not --on-color: --on-color is a fixed #fff, which reads fine on a dark
   fill but measures 3.07:1 on --warn (#FF5A52, a light red) -- below the 4.5:1
   floor. --ink on the same fill measures 6.27:1. Same principle as the
   --accent/--accent-ink split the token layer documents: a light saturated fill
   takes the dark text tone. Measured in a live browser. */
.btn-primary.danger {
  background: var(--warn);
  border-color: var(--warn);
  color: var(--ink);
}
.btn-primary.danger:hover { filter: brightness(0.92); border-color: var(--warn); }

/* -- Preview ------------------------------------------------ */
.ds-preview-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--bw-hair) solid var(--rule);
}
.ds-preview-name {
  font-weight: 600; font-size: var(--fs-body);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
  flex: 1 1 auto;
}
.ds-preview-meta {
  font-family: var(--ff-mono); font-size: var(--fs-xs);
  color: var(--fg-3); white-space: nowrap;
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.ds-preview-actions { display: inline-flex; gap: var(--space-hair); margin-left: auto; }
.ds-preview-body {
  flex: 1; min-height: 0; overflow: auto;
  padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column;
}
.ds-preview-media {
  max-width: 100%;
  max-height: 70vh; max-height: 70dvh;
  margin: 0 auto;
  border-radius: var(--r-2); object-fit: contain;
}
.ds-preview-audio { width: 100%; }
.ds-preview-code,
.ds-preview-text {
  margin: 0; flex: 1; min-height: 0; overflow: auto;
  padding: var(--space-3);
  background: var(--ink); color: var(--paper);
  border-radius: var(--r-2);
  font-family: var(--ff-mono); font-size: var(--fs-xs); line-height: var(--lh-base);
  white-space: pre; tab-size: 2;
}
.ds-preview-text { white-space: pre-wrap; word-break: break-word; }
.ds-preview-code code, .ds-preview-text code { font: inherit; color: inherit; background: none; }
/* wrap-lines toggle (ported from pi-web's DisplayMode word-wrap control) */
.ds-preview-code.is-wrapped { white-space: pre-wrap; overflow-wrap: anywhere; }
.ds-preview-wrap-toggle.active { color: var(--paper); background: color-mix(in oklab, var(--paper) 18%, transparent); }
/* source/preview mode switch (ported from pi-web's markdown/HTML DisplayMode
   tabs) — the host supplies already-rendered, already-sanitized HTML via
   `previewHtml`; this component only toggles visibility. */
.ds-preview-mode-switch { display: inline-flex; gap: var(--space-1); margin-right: var(--space-1); }
.ds-preview-mode-btn {
  font-family: var(--ff-mono); font-size: var(--fs-micro);
  padding: var(--space-1) var(--space-2); border-radius: var(--r-1);
  color: var(--paper-3); background: none; border: none; cursor: pointer;
}
.ds-preview-mode-btn.active { color: var(--paper); background: color-mix(in oklab, var(--paper) 18%, transparent); }
.ds-preview-html {
  flex: 1; min-height: 0; overflow: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-0); border-radius: var(--r-2);
}
.ds-preview-truncated {
  margin-top: var(--space-2); padding-top: var(--space-2);
  border-top: var(--bw-hair) solid color-mix(in oklab, var(--paper) 20%, transparent);
  color: var(--paper-3); font-size: var(--fs-micro);
}
.ds-preview-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2); padding: var(--space-6); color: var(--fg-3);
}
/* Icon size, not type — see .ds-file-cell-media .ds-file-icon above. */
.ds-preview-glyph { font-size: 34px; opacity: 0.6; }

/* Thin scrollbars inside preview bodies. */
.ds-preview-code, .ds-preview-text, .ds-modal-body, .ds-preview-body {
  scrollbar-width: thin;
}
.ds-preview-code::-webkit-scrollbar,
.ds-preview-text::-webkit-scrollbar,
.ds-preview-body::-webkit-scrollbar,
.ds-modal-body::-webkit-scrollbar { width: 10px; height: 10px; }
.ds-preview-code::-webkit-scrollbar-thumb,
.ds-preview-text::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--paper) 28%, transparent);
  border-radius: var(--r-pill); border: 2px solid transparent; background-clip: padding-box;
}
.ds-preview-body::-webkit-scrollbar-thumb,
.ds-modal-body::-webkit-scrollbar-thumb {
  background: var(--bg-3); border-radius: var(--r-pill);
}

/* Mobile — modals go near-fullscreen, preview media shrinks. */
@media (max-width: 560px) {
  .ds-modal {
    max-width: 100%;
    max-height: calc(100vh - 2 * var(--space-3));
    max-height: calc(100dvh - 2 * var(--space-3));
  }
  .ds-modal-preview {
    width: 100%; max-height: none;
    height: calc(100vh - 2 * var(--space-3));
    height: calc(100dvh - 2 * var(--space-3));
  }
  .ds-preview-media { max-height: 50vh; max-height: 50dvh; }
  .ds-file-stage { padding: var(--space-3) var(--space-2); }
  /* Preview head: let it wrap and drop the nowrap meta (duplicated in body)
     so the close button can never be pushed past the modal edge. */
  .ds-preview-head { flex-wrap: wrap; row-gap: var(--space-1); }
  .ds-preview-meta { display: none; }
}
