/* ── Files management page ─────────────────────────────────────────
   Two-pane layout: folder nav rail + sortable file table. Built entirely
   from tokens.css variables — no new colors introduced here. */

.fm-body {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.fm-nav-rail {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: .75rem;
}
.fm-nav-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .4rem;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-3);
}

.fm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: .75rem 1rem;
}

.fm-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.fm-toolbar-spacer { flex: 1; }
.fm-search {
  flex: 0 0 240px;
  padding: .4rem .6rem;
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
}

/* Always occupies its space (min-height + visibility, not display:none) so
   selecting/deselecting files never reflows the table beneath it — a real
   problem mid-drag, where the table shifting under the cursor while you're
   still selecting is disorienting. Hidden state is also non-interactive
   (visibility:hidden blocks clicks/focus), so an empty bar can't be clicked. */
.fm-bulk-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  background: var(--blue-dim);
  border-radius: var(--r-sm);
  font-size: .82rem;
  margin-bottom: .5rem;
  min-height: 2.8rem; /* matches the populated (select + buttons) height exactly — measured, not guessed, since the hidden state clears innerHTML and relies entirely on this floor to avoid a reflow */
  visibility: hidden;
}
.fm-bulk-bar.visible { visibility: visible; }

/* Horizontal padding leaves a permanent blank margin on both sides of the
   table — a marquee-select drag can start here at any scroll position, not
   just below the last row, matching the Explorer/Nautilus convention. */
.fm-table-wrap { flex: 1; overflow-y: auto; padding: 0 .5rem; }
.fm-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.fm-table thead th {
  text-align: left;
  padding: .4rem .6rem;
  color: var(--text-3);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.fm-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.fm-table tbody tr:hover { background: var(--hover); }
.fm-table tbody tr.selected { background: var(--blue-dim); }
.fm-table tbody tr.disabled { opacity: .38; }
.fm-table td { padding: .4rem .6rem; }

@media (max-width: 800px) {
  .fm-body { flex-direction: column; height: auto; }
  .fm-nav-rail { display: none; }
  /* The toolbar is one non-wrapping flex row at desktop width, holding the
     folder select + search + 2 filter selects + 2 date inputs + Import +
     Sync. That is far wider than a phone viewport, and .fm-main is
     overflow:hidden — so without these two rules the overflow is CLIPPED
     rather than scrollable and the Import/Sync buttons become physically
     unreachable on mobile. Wrap onto multiple lines instead, and let the
     search box shrink (it is flex: 0 0 240px at desktop width). */
  .fm-toolbar { flex-wrap: wrap; }
  .fm-search { flex: 1 1 160px; }
  .fm-mobile-folder-select {
    display: block !important;
    padding: .4rem .6rem;
    border: 1px solid var(--border-md);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: .85rem;
  }
}

.fm-nav-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .5rem;
  border-radius: var(--r-sm);
  font-size: .82rem;
  color: var(--text-2);
  cursor: pointer;
}
.fm-nav-item:hover { background: var(--hover); }
.fm-nav-item.active { background: var(--blue-dim); color: var(--text); font-weight: 600; }
.fm-nav-item.disabled { opacity: .55; }
.fm-nav-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fm-filter {
  padding: .35rem .5rem;
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: .8rem;
}

.fm-bulk-bar select {
  padding: .3rem .5rem;
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .8rem;
}

.fm-nav-item.drop-over { outline: 2px dashed var(--accent); outline-offset: -2px; }

.fm-status-badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: var(--r-pill);
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.fm-status-enabled  { background: var(--green-dim); color: var(--green); }
.fm-status-disabled { background: var(--hover);      color: var(--text-3); }
.fm-status-disabled-folder { background: var(--amber-dim); color: var(--amber); }
.fm-table tbody tr.dragging { opacity: .35; }

.fm-import-wrap {
  position: relative;
  display: inline-block;
}

.fm-import-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: .25rem;
  background: var(--surface-s);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-sm);
  z-index: 10;
  min-width: 180px;
}
.fm-import-item {
  padding: .5rem .75rem;
  font-size: .82rem;
  color: var(--text);
  cursor: pointer;
}
.fm-import-item:hover { background: var(--hover); }
