/* VaultX folder tree, folder cards, breadcrumb trail, folder menu and folder drag & drop.
   Owned by the folders workstream. Colors come only from the design tokens in app.css. */

/* Tree geometry. The indentation of a level is min(depth × 14px, 40px + depth × 6px, 100px): full steps for
   the first five levels, then smaller ones, capped so deep folders keep room for their name. folder-tools.js
   uses the same formula (folderIndentPx) to draw drop lines. */
:root { --folder-indent: 14px; --folder-pad: 10px; --folder-toggle: 18px; }

/* ---------------------------------------------------------------- sidebar tree */

#folder-nav { position: relative; }
.folder-tree { display: flex; flex-direction: column; padding: 1px 0 6px; }
.folder-group { display: flex; flex-direction: column; }

.folder-row {
  --depth: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 32px;
  padding: 0 4px 0 calc(var(--folder-pad) + min(var(--depth) * var(--folder-indent), 40px + var(--depth) * 6px, 100px));
  border-radius: var(--radius-sm, 8px);
  color: var(--muted, #9aa1ad);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background-color .12s, color .12s, opacity .12s;
}
.folder-row:hover { background: var(--hover, rgba(255, 255, 255, .05)); color: var(--text, #eceef2); }
.folder-row.active { background: var(--accent-soft, rgba(117, 145, 255, .14)); color: var(--text, #eceef2); }
.folder-row:focus { outline: none; }
.folder-row:focus-visible { outline: 2px solid var(--focus-ring, #7591ff); outline-offset: -2px; }

/* Thin guide lines show the nesting (drawn from each child row's indentation). */
.folder-group { position: relative; }
.folder-group::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: calc(var(--folder-pad) + var(--folder-toggle) / 2 + min(var(--group-depth, 0) * var(--folder-indent), 40px + var(--group-depth, 0) * 6px, 100px));
  width: 1px;
  background: var(--line-soft, #1f2229);
  pointer-events: none;
}
.folder-tree:hover .folder-group::before { background: var(--line, #2a2e37); }

/* Drag grip: at the left edge, shown on hover. */
.folder-grip {
  position: absolute;
  left: 0;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 10px;
  height: 22px;
  transform: translateY(-50%);
  color: var(--text-soft, #737a86);
  opacity: 0;
  cursor: grab;
  touch-action: none;
  transition: opacity .12s;
}
.folder-grip .icon { width: 11px; height: 15px; }
.folder-row:hover > .folder-grip { opacity: .75; }

.folder-svg.is-filled { fill: currentColor; stroke: none; }

.folder-toggle {
  display: flex;
  flex: 0 0 var(--folder-toggle);
  align-items: center;
  justify-content: center;
  width: var(--folder-toggle);
  height: 22px;
  border-radius: var(--radius-xs, 6px);
  color: var(--text-soft, #737a86);
}
.folder-toggle[data-folder-toggle] { cursor: pointer; }
.folder-toggle[data-folder-toggle]:hover { background: var(--active, rgba(255, 255, 255, .08)); color: var(--text, #eceef2); }
.folder-toggle .icon { width: 13px; height: 13px; stroke-width: 2.2; transition: transform .15s var(--ease, ease-out); }
.folder-row.is-expanded .folder-toggle .icon { transform: rotate(90deg); }

.folder-row-icon { display: flex; flex: 0 0 auto; margin-right: 4px; color: var(--muted, #9aa1ad); }
.folder-row-icon .icon { width: 17px; height: 17px; }
.folder-row:hover .folder-row-icon { color: var(--text, #eceef2); }
.folder-row.active .folder-row-icon { color: var(--accent, #7591ff); }

.folder-row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }

/* Count and ⋯ share one fixed slot at the right edge, so hovering never shifts the layout. */
.folder-row-count {
  flex: 0 0 auto;
  min-width: 26px;
  padding-right: 4px;
  text-align: right;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft, #737a86);
  font-variant-numeric: tabular-nums;
}
.folder-row.active .folder-row-count { color: var(--accent, #7591ff); }
.folder-more {
  position: absolute;
  right: 3px;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  transform: translateY(-50%);
  border-radius: var(--radius-xs, 6px);
  background: transparent;
  color: var(--muted, #9aa1ad);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s, background-color .12s;
}
.folder-more .icon { width: 16px; height: 16px; }
.folder-more:hover { background: var(--active, rgba(255, 255, 255, .08)); color: var(--text, #eceef2); }
.folder-row:hover > .folder-more,
.folder-row:focus-within > .folder-more,
.folder-row.active > .folder-more,
.folder-row.folder-menu-open > .folder-more { opacity: 1; pointer-events: auto; }
.folder-row:hover > .folder-row-count,
.folder-row:focus-within > .folder-row-count,
.folder-row.active > .folder-row-count,
.folder-row.folder-menu-open > .folder-row-count { visibility: hidden; }
.folder-row.folder-menu-open { background: var(--hover, rgba(255, 255, 255, .05)); color: var(--text, #eceef2); }
.folder-row.folder-menu-open.active { background: var(--accent-soft, rgba(117, 145, 255, .14)); }

.folder-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 8px 10px; font-size: 13px; color: var(--text-soft, #737a86); }
.folder-empty-create {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px;
  border: 1px dashed var(--line, #2a2e37); border-radius: var(--radius-sm, 8px);
  background: transparent; color: var(--muted, #9aa1ad); font-size: 13px; font-weight: 500;
}
.folder-empty-create:hover { border-color: var(--accent, #7591ff); color: var(--text, #eceef2); background: var(--accent-soft, rgba(117, 145, 255, .14)); }
.folder-empty-create .icon { width: 16px; height: 16px; }

/* ------------------------------------------------------------- folder cards */

.folder-section { margin-bottom: 24px; }
.folder-section-heading h2 { display: flex; align-items: baseline; gap: 6px; }
.folder-section-count { font-weight: 500; color: var(--text-soft, #737a86); font-variant-numeric: tabular-nums; }
.folder-section-heading > .folder-section-hint { font-size: 12px; color: var(--text-soft, #737a86); }
.folder-hint-touch { display: none; }

.folder-section .folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 12px;
  margin: 0;
}
.folder-section .folder-card {
  position: relative;
  display: block;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line, #2a2e37);
  border-radius: var(--radius, 12px);
  background: var(--surface, #15171c);
  color: var(--text, #eceef2);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: border-color .12s, background-color .12s, box-shadow .12s, opacity .12s, transform .2s;
}
.folder-section .folder-card:hover { border-color: var(--line-strong, #3a3f4a); background: var(--surface2, #1b1e24); }
.folder-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 12px 40px 12px 12px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
.folder-card-main:focus { outline: none; }
.folder-card-main:focus-visible { outline: 2px solid var(--focus-ring, #7591ff); outline-offset: 2px; }
.folder-card-icon {
  display: flex; flex: 0 0 36px; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm, 8px);
  background: var(--accent-soft, rgba(117, 145, 255, .14)); color: var(--accent, #7591ff);
}
.folder-card-icon .icon { width: 19px; height: 19px; }
.folder-card-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.folder-card-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 600; color: var(--text, #eceef2); }
.folder-card-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted, #9aa1ad); }
.folder-card-grip { left: 1px; height: 28px; }
.folder-section .folder-card:hover .folder-card-grip { opacity: .7; }
.folder-card-more {
  position: absolute; right: 8px; top: 50%;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  transform: translateY(-50%);
  border: 0; border-radius: var(--radius-xs, 6px);
  background: transparent; color: var(--muted, #9aa1ad);
  opacity: .55;
  transition: opacity .12s, background-color .12s;
}
.folder-card-more .icon { width: 16px; height: 16px; }
.folder-section .folder-card:hover .folder-card-more,
.folder-card-more:focus-visible,
.folder-card.folder-menu-open .folder-card-more { opacity: 1; }
.folder-card-more:hover { background: var(--active, rgba(255, 255, 255, .08)); color: var(--text, #eceef2); }
.folder-section .folder-card.folder-menu-open { border-color: var(--line-strong, #3a3f4a); }

/* ---------------------------------------------------------------- breadcrumb */

/* The trail is as wide as the heading column (contain: its own length never widens the column), ancestor
   crumbs keep their capped width and the current folder ellipsizes. When the ancestors do not fit,
   folder-tools.js collapses the oldest ones into a "…" crumb, so nothing ever shrinks to a sliver. */
/* One row height for both modes (view label and folder trail; trail crumbs are 24px tall), so the page title
   does not jump when a folder opens. */
#breadcrumb { min-height: 24px; line-height: 24px; }
.page-heading-text:has(> #breadcrumb.has-folder-trail) { flex: 1 1 auto; }
#breadcrumb.has-folder-trail { contain: inline-size; overflow: visible; letter-spacing: normal; text-transform: none; font-size: 13px; font-weight: 400; color: var(--muted, #9aa1ad); }
.folder-trail { flex: 1 1 auto; min-width: 0; max-width: 100%; }
.folder-trail ol { display: flex; align-items: center; min-width: 0; margin: 0; padding: 0; overflow: hidden; list-style: none; }
.folder-trail li { display: flex; flex: 0 0 auto; align-items: center; min-width: 0; }
.folder-trail li.folder-trail-last { flex: 0 1 auto; }
.folder-trail-link,
.folder-trail-text,
.folder-trail-current {
  display: inline-block; flex: 0 1 auto; min-width: 0; max-width: 220px;
  height: 24px; padding: 0 6px; border-radius: var(--radius-xs, 6px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 24px;
}
.folder-trail-link { min-width: 24px; border: 0; background: transparent; color: var(--muted, #9aa1ad); font: inherit; text-align: center; cursor: pointer; }
.folder-trail-link:hover,
.folder-trail-more[aria-expanded="true"] { background: var(--hover, rgba(255, 255, 255, .05)); color: var(--text, #eceef2); }
.folder-trail-link:focus { outline: none; }
.folder-trail-link:focus-visible { outline: 2px solid var(--focus-ring, #7591ff); outline-offset: -2px; }
.folder-trail-root { display: inline-flex; align-items: center; gap: 6px; margin-left: -6px; }
.folder-trail-root span { overflow: hidden; text-overflow: ellipsis; }
.folder-trail.is-compact .folder-trail-root span { display: none; }
.folder-trail-link .icon { width: 14px; height: 14px; flex: 0 0 auto; }
.folder-trail-more { padding: 0 8px; font-weight: 600; letter-spacing: .06em; }
.folder-trail-text { color: var(--text-soft, #737a86); }
.folder-trail-current { max-width: 100%; color: var(--text, #eceef2); font-weight: 500; }
.folder-trail-sep { display: flex; flex: 0 0 auto; color: var(--text-soft, #737a86); }
.folder-trail-sep .icon { width: 12px; height: 12px; stroke-width: 2; }

/* "…" crumb menu: the hidden parent folders, indented like a path. */
.folder-trail-menu { min-width: 200px; max-width: min(320px, calc(100vw - 16px)); }
.folder-trail-menu .menu-action { --depth: 0; padding-left: calc(10px + var(--depth) * 10px); }

/* ------------------------------------------------------------- folder menu */

.folder-menu { min-width: 236px; }
.folder-menu:focus { outline: none; }
.folder-menu .context-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.folder-menu .context-title span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.folder-menu .context-title .icon { width: 14px; height: 14px; flex: 0 0 auto; color: var(--accent, #7591ff); }
.folder-menu .menu-action .icon { flex: 0 0 auto; }
.folder-menu-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.folder-menu-key { margin-left: auto; padding-left: 16px; font-size: 12px; color: var(--text-soft, #737a86); font-variant-numeric: tabular-nums; }
.folder-menu-separator { height: 1px; margin: 4px -4px; background: var(--line, #2a2e37); }
.folder-menu .menu-action:disabled { opacity: .45; cursor: default; background: transparent; }

/* ------------------------------------------------------------------ dialogs */

.folder-dialog-lead { margin: 0 0 12px; font-size: 14px; color: var(--text, #eceef2); overflow-wrap: anywhere; }
.folder-dialog-note { display: flex; align-items: center; gap: 8px; margin: -6px 0 16px; font-size: 12px; color: var(--muted, #9aa1ad); overflow-wrap: anywhere; }
.folder-dialog-note .icon { width: 14px; height: 14px; flex: 0 0 auto; }
.folder-dialog-note strong { font-weight: 600; color: var(--text, #eceef2); }

.folder-move-list {
  display: flex; flex-direction: column; gap: 1px;
  max-height: min(340px, 48vh); overflow-y: auto; margin: 0 0 16px; padding: 4px;
  border: 1px solid var(--line, #2a2e37); border-radius: var(--radius-sm, 8px);
  background: var(--input-bg, var(--surface, #15171c));
  scrollbar-width: thin;
}
.folder-move-option {
  --depth: 0;
  display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 32px;
  padding: 4px 8px 4px calc(8px + min(var(--depth) * 16px, 48px + var(--depth) * 6px, 120px));
  border-radius: var(--radius-xs, 6px);
  color: var(--text, #eceef2); font-size: 13px; cursor: pointer;
}
.folder-move-option:hover { background: var(--hover, rgba(255, 255, 255, .05)); }
.folder-move-option:has(input:checked) { background: var(--accent-soft, rgba(117, 145, 255, .14)); }
.folder-move-option:has(input:focus-visible) { outline: 2px solid var(--focus-ring, #7591ff); outline-offset: -2px; }
.folder-move-option input { flex: 0 0 auto; width: 14px; height: 14px; margin: 0; accent-color: var(--accent, #7591ff); }
.folder-move-option .icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--muted, #9aa1ad); }
.folder-move-option:has(input:checked) .icon { color: var(--accent, #7591ff); }
.folder-move-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-move-option small { flex: 0 0 auto; font-size: 11px; color: var(--text-soft, #737a86); }

.folder-delete-facts { display: flex; flex-direction: column; gap: 6px; margin: 0 0 18px; padding: 12px 14px 12px 30px; border-radius: var(--radius-sm, 8px); background: var(--surface2, #1b1e24); font-size: 13px; color: var(--muted, #9aa1ad); }
.folder-delete-facts strong { color: var(--text, #eceef2); font-weight: 600; }
.folder-delete-facts li:last-child { color: var(--text, #eceef2); }

/* --------------------------------------------------------------- drag & drop */

body.folder-drag-active,
body.folder-drag-active * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }
body.folder-drag-active.folder-drag-invalid,
body.folder-drag-active.folder-drag-invalid * { cursor: not-allowed !important; }
body.folder-busy #folder-nav { cursor: progress; }

.folder-row.is-drag-source,
.folder-card.is-drag-source { opacity: .38; }
.folder-row.is-drag-source:hover { background: transparent; }
.folder-row.is-drag-source > .folder-grip,
.folder-row.is-drag-source > .folder-more { opacity: 0; }
.folder-row.is-drag-source > .folder-row-count { visibility: visible; }

/* Nest highlight: drop inside this folder. */
.folder-drop-into,
.folder-section .folder-card.folder-drop-into,
#sidebar .nav-item.folder-drop-into {
  background: var(--accent-soft, rgba(117, 145, 255, .14)) !important;
  outline: 1px solid var(--accent, #7591ff) !important;
  outline-offset: -1px;
  color: var(--text, #eceef2);
}
.folder-section .folder-card.folder-drop-into { border-color: var(--accent, #7591ff); }

/* Insertion line: before/after a row (horizontal) or a card (vertical). */
.folder-drop-line {
  position: fixed;
  z-index: 260;
  height: 2px;
  border-radius: 2px;
  background: var(--accent, #7591ff);
  pointer-events: none;
}
.folder-drop-line::before {
  content: "";
  position: absolute;
  left: -6px;
  top: -3px;
  width: 4px;
  height: 4px;
  border: 2px solid var(--accent, #7591ff);
  border-radius: 50%;
  background: var(--sidebar-bg, var(--bg, #0f1115));
}
.folder-drop-line.is-vertical { width: 2px; }
.folder-drop-line.is-vertical::before { left: -3px; top: -6px; }
.folder-drop-line[hidden] { display: none; }

/* Floating chip that follows the pointer. */
.folder-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 270;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  height: 34px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line-strong, #3a3f4a);
  border-radius: var(--radius-sm, 8px);
  background: var(--raised, var(--surface3, #23262e));
  box-shadow: var(--shadow-lg, 0 4px 12px rgba(0, 0, 0, .3), 0 24px 64px rgba(0, 0, 0, .5));
  color: var(--text, #eceef2);
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  will-change: transform;
}
.folder-drag-ghost .icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--accent, #7591ff); }
.folder-drag-ghost span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-drag-ghost small { flex: 0 0 auto; padding: 1px 6px; border-radius: 10px; background: var(--accent-soft, rgba(117, 145, 255, .14)); color: var(--accent, #7591ff); font-size: 11px; font-weight: 600; }

/* Touch long-press: press-in while waiting, a small lift once the folder is picked up. */
.folder-row.is-pressing,
.folder-card.is-pressing { transform: scale(.97); transition: transform .35s ease-in, background-color .12s; }
.folder-row.is-armed,
.folder-card.is-armed { transform: scale(1.02); background: var(--active, rgba(255, 255, 255, .08)); box-shadow: var(--shadow-md, 0 8px 24px rgba(0, 0, 0, .3)); transition: transform .12s ease-out; }

/* Short highlight on the folder that just moved. */
@keyframes folder-moved { from { background-color: var(--accent-soft, rgba(117, 145, 255, .14)); box-shadow: inset 0 0 0 1px var(--accent, #7591ff); } to { box-shadow: inset 0 0 0 1px transparent; } }
.folder-row.is-moved,
.folder-section .folder-card.is-moved { animation: folder-moved 1.1s ease-out; }

/* ---------------------------------------------------------- touch & small */

@media (hover: none) {
  /* Bigger expand/collapse target (26 × 36 px), clear of the 14 px drag grip at the left edge. */
  :root { --folder-pad: 14px; --folder-toggle: 26px; }
  .folder-toggle { height: 36px; }
  .folder-row { height: 40px; font-size: 14px; }
  .folder-row > .folder-grip { opacity: .45; width: 14px; }
  .folder-row-count { min-width: 0; padding-right: 2px; }
  .folder-more { position: static; flex: 0 0 34px; width: 34px; height: 34px; transform: none; opacity: .8; pointer-events: auto; }
  .folder-row:hover > .folder-row-count,
  .folder-row:focus-within > .folder-row-count,
  .folder-row.active > .folder-row-count,
  .folder-row.folder-menu-open > .folder-row-count { visibility: visible; }
  .folder-card-more { opacity: .85; width: 34px; height: 34px; right: 4px; }
  .folder-section .folder-card:hover { background: var(--surface, #15171c); border-color: var(--line, #2a2e37); }
  .folder-card-grip { display: none; }
  .folder-hint-pointer { display: none; }
  .folder-menu-key { display: none; }
  .folder-hint-touch { display: inline; }
}

@media (max-width: 800px) {
  .folder-section .folder-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .folder-card-main { padding: 10px 38px 10px 10px; gap: 10px; }
  .folder-card-icon { flex-basis: 32px; width: 32px; height: 32px; }
  .folder-trail-link, .folder-trail-text { max-width: 140px; }
}
@media (max-width: 480px) {
  .folder-section-heading > .folder-section-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .folder-row, .folder-card, .folder-toggle .icon, .folder-more, .folder-grip { transition: none !important; }
  .folder-row.is-moved, .folder-section .folder-card.is-moved { animation: none; }
  .folder-row.is-pressing, .folder-card.is-pressing, .folder-row.is-armed, .folder-card.is-armed { transform: none; }
}
