/* Production Fidelity FI-01..FI-07 — Files owns its complete visual grammar. */
.files-section {
  min-width: 0;
  margin-top: 0;
}

.files-section.active {
  display: flex;
  flex-direction: column;
}

.files-heading-copy {
  display: grid;
}

.files-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.files-actions .files-header-control,
.files-actions > .button {
  width: auto;
  min-width: 0;
  min-height: 2.3rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--ui-line);
  border-radius: 0.36rem;
  background: var(--ui-panel);
  color: var(--ui-text-soft);
  font: 600 0.75rem/1 system-ui, sans-serif;
}

.files-actions .files-header-control:hover,
.files-actions .files-header-control[aria-checked="true"] {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}

.files-actions > .button.primary {
  border-color: var(--ui-primary);
  background: var(--ui-primary);
  color: var(--ui-primary-text);
}

.files-actions .files-header-control svg,
.file-action-icon svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.files-actions #files-refresh {
  width: 2.3rem;
  padding: 0;
}

.files-actions #files-refresh span:last-child {
  display: none;
}

.files-pane {
  position: relative;
  min-width: 0;
  min-height: 26rem;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ui-line);
  border-radius: 0.55rem;
  background: var(--ui-panel);
  box-shadow: 0 0.75rem 2rem color-mix(in srgb, var(--ui-bg) 45%, transparent);
  transition: border-color 150ms, background 150ms;
}

.files-pane.dragging {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
}

.files-pane.dragging::after {
  content: "Drop files — they'll land in _Intake for filing";
  position: absolute;
  z-index: 30;
  inset: 0.65rem;
  display: grid;
  place-items: center;
  border: 2px dashed var(--ui-accent);
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--ui-panel) 94%, transparent);
  color: var(--ui-accent);
  font-weight: 650;
}

.files-split {
  --files-tree-width: 13.5rem;
  /* T315: preview chrome is two equal path-row strips; tree toolbar matches. */
  --files-path-row-height: 2.5rem; /* T315: even px at 16root → clean searchCenter */
  --files-top-row-height: var(--files-path-row-height);
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
}

.files-tree-pane {
  min-width: 0;
  min-height: 0;
  flex: 0 0 var(--files-tree-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ui-panel);
}

.file-tree-label {
  flex: 0 0 auto;
  padding: 0.7rem 0.75rem 0.35rem;
  color: var(--ui-muted);
  font: 500 0.65rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.freshness-key {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  margin: 0 0.75rem;
  padding: 0.7rem 0 0.75rem;
  border-top: 1px solid var(--ui-line);
  color: var(--ui-muted);
  font: 0.62rem/1 ui-monospace, Menlo, monospace;
}

.freshness-key span {
  display: flex;
  align-content: center;
  gap: 0.25rem;
}

.files-tree-toolbar {
  position: relative;
  /* T315: align with tabs+path both at --files-path-row-height. */
  min-height: calc(var(--files-path-row-height) + var(--files-path-row-height));
  flex: 0 0 calc(var(--files-path-row-height) + var(--files-path-row-height));
  display: grid;
  align-items: center;
  grid-template-columns: minmax(8rem, 1fr);
  gap: 0;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--ui-line);
}

.files-tree-toolbar:has(.files-tree-controls:empty) {
  min-height: calc(var(--files-path-row-height) + var(--files-path-row-height));
}

.files-search-field {
  /* Flex-center avoids translateY(-50%) half-pixel drift vs toolbar mid-line. */
  position:absolute; inset-block:0; right:.75rem; left:.75rem; min-width:0;
  display:flex; align-items:center;
}

.files-tree-search {
  width: 100%;
  min-width: 0;
  height: 2.25rem;
  padding: 0 2rem 0 0.7rem;
  border: 1px solid var(--ui-line);
  border-radius: 0.36rem;
  color: var(--ui-text);
  font: 500 0.78rem/1 system-ui, sans-serif;
}

.files-tree-search::placeholder {
  color: var(--ui-muted);
}

.files-tree-search:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

.files-search-spinner {
  position: absolute;
  top: 50%;
  right: 0.65rem;
  width: 0.75rem;
  height: 0.75rem;
  margin-top: -0.375rem;
  border: 2px solid var(--ui-line);
  border-top-color: var(--ui-accent);
  border-radius: 50%;
  animation: files-search-spin 650ms linear infinite;
  pointer-events: none;
}

.files-search-spinner[hidden],
.files-search-results[hidden] {
  display: none;
}

@keyframes files-search-spin {
  to { transform: rotate(360deg); }
}

.files-search-results {
  position: absolute;
  z-index: 70;
  /* Anchor to the search input's bottom edge (field is vertically centered),
     not the padded toolbar box — keeps the first result ~6–8px under the input. */
  top: calc(50% + (2.25rem / 2) + 0.4rem);
  right: 0.75rem;
  left: 0.75rem;
  max-height: 17.5rem;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid color-mix(in srgb, var(--ui-accent) 40%, var(--ui-line));
  border-radius: 0 0 0.45rem 0.45rem;
  background: var(--ui-raised);
  box-shadow: var(--ui-shadow);
}

.files-index-health {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.55rem;
  padding: 0.25rem 0.75rem;
  border-bottom: 1px solid var(--ui-line);
  color: var(--ui-muted);
  font: 600 0.66rem/1.2 system-ui, sans-serif;
}

.files-index-health[data-status="ready"] { color: var(--ui-ok, #2f7d4a); }
.files-index-health[data-status="needs_attention"] { color: var(--ui-warn, #a15c12); }
.files-index-health[data-status="unavailable"] { color: var(--ui-muted); }

#files-index-health-dot {
  width: 0.42rem;
  height: 0.42rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.files-search-group + .files-search-group {
  margin-top: 0.35rem;
  border-top: 1px solid var(--ui-line);
  padding-top: 0.25rem;
}

.files-search-group-title {
  margin: 0;
  padding: 0.35rem 0.5rem 0.2rem;
  color: var(--ui-muted);
  font: 700 0.64rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.files-search-copy {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  gap: 0.12rem;
}

.files-search-snippet {
  overflow: hidden;
  color: var(--ui-muted);
  font: 0.68rem/1.3 system-ui, sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-search-summary {
  padding: 0.45rem 0.5rem 0.25rem;
  color: var(--ui-muted);
  font: 0.68rem/1.2 ui-monospace, Menlo, monospace;
}

.files-search-more {
  width: 100%;
  margin-top: 0.2rem;
}

.files-search-option {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: var(--ui-text);
  font-size: 0.75rem;
  text-align: left;
}

.files-search-option:hover,
.files-search-option.active {
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}

.files-search-icon {
  flex: 0 0 auto;
  color: var(--ui-muted);
}

.files-search-name {
  flex: 0 0 auto;
  max-width: 46%;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-search-parent {
  min-width: 0;
  overflow: hidden;
  color: var(--ui-muted);
  font: 0.7rem/1.3 ui-monospace, Menlo, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-search-freshness {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.files-search-freshness--fresh {
  color: color-mix(in srgb, var(--ui-ok, #2f7d4a) 85%, var(--ui-text));
  background: color-mix(in srgb, var(--ui-ok, #2f7d4a) 16%, transparent);
}

.files-search-freshness--stale {
  color: color-mix(in srgb, var(--ui-warn, #a15c12) 90%, var(--ui-text));
  background: color-mix(in srgb, var(--ui-warn, #a15c12) 18%, transparent);
}

.files-search-empty,
.files-search-note {
  padding: 0.55rem;
  color: var(--ui-muted);
  font-size: 0.75rem;
}

.files-search-pending {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.files-search-pending::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--ui-accent);
}

.files-tree-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.files-tree-controls:empty {
  display: none;
}

.files-tree-control {
  min-width: 0;
  min-height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--ui-line);
  border-radius: 0.36rem;
  background: transparent;
  color: var(--ui-text-soft);
  font: 600 0.75rem/1 system-ui, sans-serif;
}

.files-tree-control:hover,
.files-tree-control[aria-checked="true"] {
  border-color: color-mix(in srgb, var(--ui-accent) 45%, var(--ui-line));
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}

.files-tree-control-upload {
  margin-left: auto;
}

#upload-progress {
  position: absolute;
  z-index: 1;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  accent-color: var(--ui-accent);
}

.files-tree {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 0.45rem;
  list-style: none;
}

.file-children {
  padding-left: 1rem;
  list-style: none;
}

.file-entry-row {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
}

.file-entry {
  min-width: 0;
  min-height: 2rem;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.35rem 3.8rem 0.35rem 0.45rem;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--ui-text-soft);
  font: 500 0.75rem/1.25 system-ui, sans-serif;
  text-align: left;
}

.file-entry:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

.file-entry.selected {
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}

.file-entry:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: -2px;
}

.file-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-synced-badge {
  flex: 0 0 auto;
  color: var(--ui-accent);
  font: 600 0.65rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.file-time,
.file-size {
  flex: 0 0 auto;
  color: var(--ui-muted);
  font: 0.68rem/1 ui-monospace, Menlo, monospace;
  white-space: nowrap;
}

.file-time-absent {
  opacity: 0.55; font-style: italic;
}

.file-actions-trigger {
  position: absolute;
  z-index: 2;
  right: 0.2rem;
  width: 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: var(--ui-panel);
  color: var(--ui-muted);
  font-size: 0.95rem;
  opacity: 0;
}

.file-entry-row:hover .file-actions-trigger,
.file-entry-row:focus-within .file-actions-trigger,
.file-actions-trigger[aria-expanded="true"] {
  opacity: 1;
}

.file-actions-trigger:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

.file-actions-menu {
  position: absolute;
  z-index: 72;
  top: 2rem;
  right: 0.2rem;
  width: 15.25rem;
  display: grid;
  gap: 0.15rem;
  padding: 0.35rem;
  border: 1px solid var(--ui-line);
  border-radius: 0.45rem;
  background: var(--ui-raised);
  box-shadow: var(--ui-shadow);
}

.file-actions-menu[hidden] {
  display: none;
}

.file-actions-menu.context-positioned {
  position: fixed;
  right: auto;
  bottom: auto;
}

.file-actions-menu :is(a, button) {
  width: 100%;
  padding: 0.55rem;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: var(--ui-text);
  font: 500 0.75rem/1.25 system-ui, sans-serif;
  text-align: left;
  text-decoration: none;
}

.file-actions-menu :is(a, button):hover:not(:disabled),
.file-actions-menu :is(a, button):focus-visible {
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}

.file-actions-menu button:disabled {
  color: var(--ui-muted);
}

.file-actions-menu .file-action-delete {
  color: var(--ui-danger);
}

.file-actions-divider {
  height: 1px;
  margin: 0.2rem 0.4rem;
  background: var(--ui-line);
}

.freshness-dot {
  width: 0.45rem;
  height: 0.45rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--ui-muted);
}

.freshness-hour {
  background: var(--ui-success);
  box-shadow: 0 0 0.45rem color-mix(in srgb, var(--ui-success) 55%, transparent);
}

.freshness-day {
  background: var(--ui-accent);
}

.freshness-week {
  background: var(--ui-muted);
  opacity: 0.65;
}

.file-node.file-reveal-flash > .file-entry-row {
  border-radius: 0.35rem;
  animation: file-reveal-flash 1.6s ease-out;
}

@keyframes file-reveal-flash {
  0%, 35% { background: color-mix(in srgb, var(--ui-accent) 18%, transparent); }
  100% { background: transparent; }
}

.system-directory-health {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ui-warning) 40%, transparent);
  background: var(--ui-warning-soft);
  color: var(--ui-warning);
  font-size: 0.75rem;
}

.system-directory-health-copy {
  min-width: 0;
  flex: 1;
  line-height: 1.35;
}

.system-directory-health-copy strong {
  display: block;
  color: var(--ui-text);
}

.system-directory-health code {
  color: var(--ui-text-soft);
  font-size: 0.7rem;
}

.system-directory-health .button {
  flex: 0 0 auto;
  font-size: 0.75rem;
}

.connected-storage-directory > .file-entry-row {
  border-radius: 0.35rem;
  background: color-mix(in srgb, var(--ui-accent) 4.5%, transparent);
}

/* T313 favorite folders */
.file-favorite-star {
  position: absolute;
  z-index: 2;
  right: 2.05rem;
  width: 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--ui-muted);
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
}

.file-entry-row:hover .file-favorite-star,
.file-entry-row:focus-within .file-favorite-star,
.file-favorite-star.is-favorite,
.file-favorite-star:focus-visible {
  opacity: 1;
}

.file-favorite-star.is-favorite {
  color: var(--ui-accent);
}

.file-favorite-star:hover,
.file-favorite-star:focus-visible {
  background: var(--ui-hover);
  color: var(--ui-text);
}

.file-entry {
  padding-right: 5.4rem;
}

.files-pinned {
  margin: 0 0 0.35rem;
  padding: 0.35rem 0.45rem 0.45rem;
  border-bottom: 1px solid var(--ui-border);
}

.files-pinned-heading {
  margin: 0 0 0.2rem;
  color: var(--ui-muted);
  font: 600 0.68rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.files-pinned-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.files-pinned-item {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
}

.files-pinned-open {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0.25rem 0.4rem;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--ui-text-soft);
  font: 500 0.75rem/1.25 system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
}

.files-pinned-open:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

.files-pinned-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-pinned-missing {
  flex: 0 0 auto;
  color: var(--ui-muted);
  font: 600 0.65rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.files-pinned-item.is-missing .files-pinned-open {
  opacity: 0.55;
}

.files-pinned-item .file-favorite-star {
  position: static;
  opacity: 1;
  flex: 0 0 auto;
}

.file-reference-pinned-group {
  border-bottom: 1px solid var(--ui-border);
  margin-bottom: 0.25rem;
  padding-bottom: 0.25rem;
}

.file-reference-pinned-label {
  padding: 0.35rem 0.65rem 0.15rem;
  color: var(--ui-muted);
  font: 600 0.68rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.file-reference-pinned-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

@media (max-width: 820px) {
  #files-legacy-tab > .page-header {
    margin-bottom: 0;
  }
  #files-legacy-tab .files-heading-copy {
    flex: 0 0 auto;
  }
  #files-legacy-tab .files-actions {
    min-width: 0;
  }
  #files-legacy-tab .files-actions > .files-tree-controls {
    flex: 0 0 auto;
    overflow-x: visible;
  }

  #files-legacy-tab .files-index-health {
    flex: 0 0 auto;
    min-height: 24px;
    padding: 0.2rem 0.5rem;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: var(--ui-panel-soft);
    white-space: nowrap;
  }

  #files-legacy-tab .files-tree-toolbar {
    min-height: 51px;
    height: 51px;
    flex: 0 0 51px;
    padding: 0.25rem 0.5rem;
  }

  #files-legacy-tab .files-tree-toolbar:has(.files-tree-controls:empty) {
    min-height: 51px;
  }

  #files-legacy-tab .files-search-field {
    inset-block: 0;
    right: 0.5rem;
    left: 0.5rem;
  }

  #files-legacy-tab .files-tree-search,
  #files-legacy-tab #files-search {
    width: 100%;
    min-height: 44px;
    height: 44px;
  }

  #files-legacy-tab .files-search-results {
    top: calc(50% + 22px + 0.25rem);
    right: 0.5rem;
    left: 0.5rem;
  }

  .file-favorite-star {
    opacity: 1;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    right: 2.4rem;
  }

  .files-pinned-item .file-favorite-star,
  .files-pinned-open {
    min-width: 44px;
    min-height: 44px;
  }

  /* T319: flat list rows (no nested tree children); 56px hits. */
  .files-phone-stack .file-node > .file-children {
    display: none !important;
  }

  .files-phone-stack .file-entry-row,
  .files-phone-stack .files-pinned-item {
    min-height: 56px;
  }

  .files-phone-stack .file-entry {
    min-height: 56px;
    padding-block: 0.65rem;
    font-size: 0.9rem;
  }

  .files-phone-stack .files-pinned-open {
    min-height: 56px;
    flex: 1 1 auto;
    justify-content: flex-start;
    text-align: left;
  }

  .files-phone-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex: 0 0 auto;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--ui-line);
    color: var(--ui-muted);
    font: 500 0.75rem/1.2 system-ui, sans-serif;
    -webkit-overflow-scrolling: touch;
  }

  .files-phone-breadcrumb[hidden] {
    display: none !important;
  }

  .files-phone-crumb {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 0.35rem;
    border: 0;
    border-radius: 0.3rem;
    background: transparent;
    color: var(--ui-accent);
    font: inherit;
    cursor: pointer;
  }

  .files-phone-crumb:last-of-type {
    color: var(--ui-text);
    font-weight: 650;
  }

  .files-phone-crumb-sep {
    flex: 0 0 auto;
    opacity: 0.55;
  }

  .files-phone-stack {
    overflow-x: hidden;
  }

  /* Files phone law pass (post-T319): styling adaptation only — 44px floors,
     contained overflow, visible row actions, honest empty/loading rhythm. */
  .files-phone-stack .files-tree-search,
  .files-phone-stack #files-search {
    min-height: 44px;
    height: 44px;
    box-sizing: border-box;
  }

  .files-phone-stack .files-tree-control {
    min-width: 44px;
    min-height: 44px;
    height: auto;
    box-sizing: border-box;
    padding-inline: 0.7rem;
  }

  .files-phone-stack .file-actions-trigger {
    opacity: 1;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    right: 0.15rem;
  }

  .files-phone-stack .file-actions-menu :is(a, button) {
    min-height: 44px;
    box-sizing: border-box;
  }

  .files-phone-stack .files-tree-retry,
  .files-phone-stack .files-search-retry,
  .files-tree-failure .files-tree-retry {
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    padding-inline: 0.75rem;
  }

  .files-phone-stack .files-tree-skeleton {
    height: 44px;
    min-height: 44px;
  }

  .files-phone-stack .files-search-empty,
  .files-phone-stack .files-search-note,
  .files-phone-stack .empty-state {
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.85rem 0.75rem;
    overflow-wrap: anywhere;
  }

  .files-phone-stack .files-actions .button {
    min-height: 44px;
    box-sizing: border-box;
  }
}

@media (min-width: 821px) {
  .files-phone-breadcrumb,
  .files-phone-back {
    display: none !important;
  }
}
