/* ShareBox — Frazil-branded theme.
   Two modes: light (default) and dark.
   Toggle by setting <html data-theme="dark">. Theme.js does this from
   localStorage before paint to avoid flash.

   Palette anchors:
     #0059a9  Frazil brand blue (accent in both modes)
     #1d3050  Frazil deep navy (dark surface + light-mode body text)

   Aesthetic: flat icons, clean panels, Lato everywhere. */

/* Lato is self-hosted (vendored) rather than loaded from Google Fonts: no
   third-party request per page load, works on the corporate network / VPN
   and offline, and keeps the CSP at font-src 'self'. woff2 files (latin
   subset, the 4 weights used) live in /static/fonts. See
   docs/frazil-design-system.md. */
@font-face {
  font-family: 'Lato'; font-style: normal; font-weight: 300;
  font-display: swap; src: url('/static/fonts/lato-300.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato'; font-style: normal; font-weight: 400;
  font-display: swap; src: url('/static/fonts/lato-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato'; font-style: normal; font-weight: 700;
  font-display: swap; src: url('/static/fonts/lato-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Lato'; font-style: normal; font-weight: 900;
  font-display: swap; src: url('/static/fonts/lato-900.woff2') format('woff2');
}

/* ===== Light theme (default) ===== */
:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --surface-2: #f1f4f9;
  --surface-3: #e6ecf3;
  --border:    #e2e8f0;
  --border-strong: #cdd5e0;

  --text:      #1d3050;
  --text-muted:#5a6b85;
  --text-dim:  #8a9bb3;

  --accent:    #0059a9;
  --accent-hi: #0072d6;
  --accent-lo: #003e7a;
  --accent-soft: rgba(0, 89, 169, 0.10);
  /* Readable accent-text tokens. In light mode they equal --accent/--accent-hi
     so link and accent-text colour is unchanged; dark mode overrides them to a
     lightened value that clears WCAG AA (see the dark block). */
  --accent-fg: #0059a9;
  --accent-fg-hi: #0072d6;

  --success:   #2a9d5e;
  --warn:      #c08020;
  --warn-soft: rgba(192, 128, 32, 0.12);
  --danger:    #c03030;
  --danger-soft: rgba(192, 48, 48, 0.10);

  --font-body: 'Lato', system-ui, -apple-system, sans-serif;

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);

  --logo-filter: none;  /* logo renders as-is in light mode */
}

/* ===== Dark theme ===== */
[data-theme="dark"] {
  /* Neutrals desaturated to near-grey (SB-DARK-1). Lightness held exactly so
     the elevation ladder bg<surface<surface-2<surface-3 is unchanged; only the
     blue saturation is pulled out so the accent has a neutral ground to stand
     against. Old values were s42-s55 in the accent's own hue. */
  --bg:        #191D24;
  --surface:   #222730;
  --surface-2: #2C333F;
  --surface-3: #394251;
  --border:    #404754;
  --border-strong: #515967;

  --text:      #F3F4F6;
  --text-muted:#ABB0BA;
  --text-dim:  #737E91;

  --accent:    #0059a9;
  --accent-hi: #2576c7;
  --accent-lo: #003e7a;
  --accent-soft: rgba(37, 118, 199, 0.18);
  /* Lightened accent-text tokens for dark surfaces. The light-mode brand blue
     #0059a9 gives only 2.49:1 on the dark bg; these clear AA (accent-fg 6.00:1
     on --bg, 5.32:1 on --surface). --accent itself stays the saturated fill/
     border/ring colour it is elsewhere. */
  --accent-fg: #5c9fdd;
  --accent-fg-hi: #7db4e8;

  --success:   #4ec07a;
  --warn:      #e8b870;
  --warn-soft: rgba(232, 184, 112, 0.18);
  --danger:    #e36363;
  --danger-soft: rgba(227, 99, 99, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:    0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);

  /* The logo is a blue-on-transparent PNG; it reads OK on dark navy too,
     but a touch of brightness helps it pop. */
  --logo-filter: brightness(1.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.18s ease, color 0.18s ease;
}

a { color: var(--accent-fg); text-decoration: none; }
a:hover { color: var(--accent-fg-hi); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ============ Layout ============ */
.app {
  display: grid;
  /* Three columns: sidebar | main | rail. The preview panel is now an
     absolute-positioned overlay (see .preview below) so opening it
     doesn't reflow the main column — file rows stay at their original
     widths instead of word-wrapping or truncating mid-interaction.
     The rail stays in its grid cell at the right edge; when the panel
     opens we shift the rail leftward via transform so it visually
     docks against the panel's left edge without disturbing the grid. */
  grid-template-columns: 220px 1fr 44px;
  /* Topbar row sized by its content (.topbar has min-height: 64px). The
     1fr below fills the rest of the viewport. */
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar  topbar topbar"
    "sidebar main   rail";
  height: 100vh;
  overflow: hidden;
  /* `.preview` is absolute-positioned and anchors to this container
     via `right: 0; top: 64px; bottom: 0`. Without explicit position
     here, it would anchor to the nearest positioned ancestor — most
     likely `<body>`, which gives the same result today but is
     fragile if anyone wraps `.app` in another container later. */
  position: relative;
}
/* When the preview is open: shift the rail left by the panel width so
   it docks to the left edge of the floating panel; pad the main
   header's right side so toolbar buttons (Upload, New folder) don't
   end up hidden behind the overlay. The main listing stays
   full-width — file rows on the right side may be partially obscured
   while the panel is open, which is the trade we make in exchange
   for not having every file row reflow on every panel open/close. */
.app.preview-open .preview-rail {
  transform: translateX(-480px);
}
.app.preview-open .main-header {
  padding-right: 504px;        /* 480 panel + 24 breathing room  */
}

/* When search is active (dropdown open OR on the dedicated /search
   page), hide the right rail and any open preview panel so the
   listing area gets the freed space. The LEFT sidebar always stays
   visible on desktop — desktop users rely on it for scope/team
   switching, and the listing area still has plenty of room with
   just the right rail hidden.
   EXCEPTION: when the user clicks a search result row, openPreview
   adds .preview-open to the app root. We allow that combination
   (.search-active + .preview-open) to show the preview anyway —
   that's the user's explicit "show me this file" click and we
   shouldn't fight it. The :not(.preview-open) selector below
   threads the needle so dropdown-while-typing still hides the
   panel, but click-a-result-from-search-page reveals it. */
/* When search is active, hide the preview PANEL but keep the RAIL
   (the narrow icon strip). The rail is only ~48px wide so it
   doesn't crowd the listing, and keeping it visible means the user
   can re-open the preview pane immediately after closing the search
   without having to re-click a file row. The earlier version of
   this rule hid the rail too, which was overly aggressive — losing
   ~48px of width didn't meaningfully help the listing, and it made
   the preview-pane reopen affordance disappear during search. */
.app.search-active:not(.preview-open) .preview {
  display: none !important;
}
/* Earlier rule explicitly zeroed .main-header's right-padding while
   search was active without an open preview, on the theory that the
   504px padding-right (used to clear the preview pane) needed to be
   reset. But that rule overrode the BASE 28px padding too — so when
   search opened on a state with NO preview ever open, the buttons
   in the toolbar (filter, new folder, upload) shifted by 28px,
   reading as a layout glitch.
   The rule is unnecessary: the .app.preview-open .main-header rule
   only applies while .preview-open is set on the app root, so when
   closePreview() removes that class, the 504px override naturally
   stops applying and the base 28px takes over. No explicit reset
   needed here. */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  /* Compact topbar, sized just enough to host the composite mark with
     small margins. Frazil inscription on the cube starts to smudge at
     this size but is still recognizable as a wordmark; below this we
     lose it entirely. */
  min-height: 64px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-mark {
  /* Composite ShareBox cube (kept for any legacy references). */
  height: 60px;
  width: 60px;
  display: block;
  flex-shrink: 0;
}
.brand-lockup {
  /* Horizontal cube + "ShareBox" lockup. The SVG viewBox is 280x64, so
     setting height to 60 gives an effective width of ~262px, fitting
     comfortably inside the 64px-tall topbar with 2px breathing room
     above and below. The cube portion of the lockup matches the prior
     standalone cube size, so visual continuity is preserved. */
  height: 60px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.brand-app {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.search-wrap {
  /* Now sits in the right-side topbar cluster alongside logout + user chip.
     Fixed width — wide enough for typical names and inline snippets, but
     not so wide it crowds out the user chip on smaller screens. */
  width: 320px;
  position: relative;
}
.search-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 8px 36px;
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  /* contenteditable-specific: minimum height matches what the input
     element provided, line-height keeps single-line typing tidy. */
  min-height: 18px;
  line-height: 18px;
  cursor: text;
  /* Prevent contenteditable's default behavior of word-wrapping into
     a multi-line box when text exceeds container width. We want a
     single-line input feel, with overflow scrolling left/right. */
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
}
/* Placeholder for contenteditable: rendered via ::before when empty.
   `data-placeholder` on the element holds the text. The pseudo-
   element is positioned in normal flow so caret placement is correct
   when the user clicks before typing. */
.search-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}
.search-input::placeholder { color: var(--text-dim); }
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  width: 16px;
  height: 16px;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  /* Anchor to the right edge of the input (since the input now sits at the
     right side of the topbar) and let the dropdown extend to the LEFT.
     This keeps the dropdown from overflowing off-screen. */
  right: 0;
  min-width: 100%;
  width: 480px;
  max-width: 90vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}
.search-results.show { display: block; }
.search-result {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.search-result:hover { background: var(--surface-2); }
.search-result:last-child { border-bottom: none; }
.search-snippet {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
  font-style: italic;
  /* Snippet may include <mark> tags from the API; mark inherits default
     browser styling (yellow background) which we override below. */
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-snippet mark {
  background: var(--accent-soft);
  color: var(--accent-fg);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 700;
  font-style: normal;
}

/* "See all results" footer link in the search dropdown. Visually
   distinct from the result rows so the user reads it as an action,
   not another match. Sits at the bottom of the dropdown and navigates
   to the dedicated /search page. */
.search-result.search-see-all {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--accent-fg);
  font-size: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  border-bottom: none;
}
.search-result.search-see-all:hover {
  background: var(--accent-soft);
}

/* Search-results page (#/search). Renders a row per match with the
   highlighted excerpt below the filename. The .search-snippet-row
   class is the page variant of .search-snippet (the dropdown one);
   page rows have more horizontal room so the snippet can wrap to two
   lines instead of being clamped to one. */
.filetable.search-table .search-snippet-row {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  margin-left: 28px;  /* aligns with name text after the file icon */
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.filetable.search-table .search-snippet-row mark {
  background: var(--accent-soft);
  color: var(--accent-fg);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 700;
  font-style: normal;
}
/* Search rows are clickable just like favorites/recent (open the
   preview on click). Override the trash-table style that disables
   row interaction. */
.filetable.search-table tbody tr[data-search-file-id] {
  cursor: pointer;
}
.filetable.search-table tbody tr[data-search-file-id]:hover {
  background: var(--surface-2);
}

/* ---------------------------------------------------------------------------
 * Uploads tray — toolbar button + dropdown panel
 * ---------------------------------------------------------------------------
 * The button sits between the search bar and the user chip. Always visible
 * (option 3 — "always show, dropdown reveals state"). The spinning ring
 * around the icon appears only while there are active uploads; idle button
 * is a clean upload-arrow. Click anywhere on the button to toggle the
 * dropdown panel that lists active and recent uploads.
 *
 * Per-upload progress lives inside the panel (a row per file with a small
 * progress bar). The button itself uses an indeterminate spinner because
 * trying to communicate per-file progress in a 24px target is a losing
 * battle.
 */
.uploads-tray {
  position: relative;
  display: flex;
  align-items: center;
}
.uploads-btn {
  /* Match the visual weight of nearby toolbar elements without copying the
     pill border of the user chip — that'd compete visually. Uses a
     transparent background, surface-2 on hover, accent ring while active. */
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  flex-shrink: 0;
}
.uploads-btn:hover {
  background: var(--surface-2);
}
.uploads-btn[aria-expanded="true"] {
  background: var(--surface-2);
  border-color: var(--border);
}
.uploads-icon {
  width: 18px;
  height: 18px;
  position: relative;
  z-index: 1;
}
/* Spinning ring — appears only when the button has class .is-active.
   We use a conic-gradient on a pseudo-element rather than an SVG <circle>
   with stroke-dashoffset because the conic approach gives a clean
   3/4-circle "loading" arc that animates by rotation alone, with no
   per-frame stroke math. */
.uploads-spinner {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) 0deg,
    var(--accent) 270deg,
    transparent 270deg,
    transparent 360deg
  );
  -webkit-mask: radial-gradient(circle, transparent 11px, black 12px);
  mask: radial-gradient(circle, transparent 11px, black 12px);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
.uploads-btn.is-active .uploads-spinner {
  opacity: 1;
  animation: uploads-spin 1s linear infinite;
}
@keyframes uploads-spin {
  to { transform: rotate(360deg); }
}

/* Dropdown panel. Anchored to the right edge of the button so it doesn't
   spill off-screen on narrow viewports. min-width prevents it from looking
   silly when only one upload is listed; max-width/max-height keep it
   bounded for many simultaneous uploads. */
.uploads-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  min-width: 360px;
  max-width: 460px;
  max-height: 480px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* The HTML hidden attribute should always hide the panel, but our
   .uploads-panel { display: flex } rule above otherwise wins via
   selector specificity (class beats attribute). Force it. */
.uploads-panel[hidden] { display: none; }
.uploads-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.uploads-panel-list {
  overflow-y: auto;
  padding: 6px 0;
  min-height: 60px;
  flex: 1 1 auto;
}
.uploads-panel-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.uploads-panel-footer {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

/* Per-upload row inside the uploads tray panel. Layout:
   [icon]  [filename / status]              [progress% or icon]
            [progress bar (active only)]
   ALL rules in this block are scoped under .uploads-panel so they
   don't fight with the older `.upload-queue .upload-row` rules used
   by the request-link / public-upload page (which has a different
   4-column grid layout). Without this scoping, source-order
   specificity meant the older 4-column rule clobbered our 3-column
   layout, producing visibly mis-aligned filenames in the tray. */
.uploads-panel .upload-row {
  display: grid;
  /* 4 columns: icon, body, pctRight (sometimes empty), dismiss× (only
     on terminal rows). Auto cols collapse to 0 when empty, so active
     rows keep the original 3-col look without rule changes. */
  grid-template-columns: 22px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
}
.uploads-panel .upload-row + .upload-row {
  border-top: 1px solid var(--border);
}
/* Completed rows get a clickable affordance — cursor + subtle hover
   background to match other clickable list patterns in the app. The
   .is-clickable class is added by _renderRow only when the entry has
   nav data populated (status='done' AND we successfully parsed the
   FileDetail response). Failed rows and uploading rows are NOT
   clickable: there's nothing to navigate to. */
.uploads-panel .upload-row.is-clickable {
  cursor: pointer;
}
.uploads-panel .upload-row.is-clickable:hover {
  background: var(--surface-2);
}
.uploads-panel .upload-row.is-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.uploads-panel .upload-row-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.uploads-panel .upload-row-icon svg { width: 18px; height: 18px; }
.uploads-panel .upload-row.is-failed .upload-row-icon { color: var(--danger); }
.uploads-panel .upload-row.is-done .upload-row-icon { color: var(--success, #0a7d2c); }
.uploads-panel .upload-row-body {
  min-width: 0;
}
.uploads-panel .upload-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.uploads-panel .upload-row-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
/* On terminal rows (done/failed), let the status line wrap up to a
   few lines so longer messages — like the "Scanner limit exceeded
   (MaxFileSize): file too complex..." text — stay fully readable
   instead of getting cut off with an ellipsis. Active rows keep
   the single-line clip because their text changes rapidly during
   upload and a multi-line wrap would feel busy. */
.uploads-panel .upload-row.is-failed .upload-row-status,
.uploads-panel .upload-row.is-done .upload-row-status {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  /* Standard line-clamp is the modern equivalent; both kept for
     broad browser support. Chrome/Edge/Safari honor the webkit one;
     Firefox honors `line-clamp`. */
  line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.uploads-panel .upload-row.is-failed .upload-row-status { color: var(--danger); }
.uploads-panel .upload-row-progress {
  /* Progress bar rendered as a single track with a fill div positioned
     by inline width%. Hidden on done/failed rows since it's at 100%/0%
     and adds noise. */
  margin-top: 6px;
  height: 4px;
  width: 100%;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.uploads-panel .upload-row-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.15s ease-out;
}
/* Indeterminate variant — used during the 'scanning' phase of an
   async upload, where we don't know how far through the scan we
   are. A linear-gradient stripe slides across the track on a
   2-second loop. The fill div has 100% width so the gradient
   masks the entire track surface; the visual motion comes from
   shifting the gradient position rather than width animation. */
.uploads-panel .upload-row-progress-fill.is-indeterminate {
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--surface-3) 0%,
    var(--accent) 50%,
    var(--surface-3) 100%
  );
  background-size: 200% 100%;
  animation: upload-row-indeterminate 1.6s linear infinite;
  transition: none;
}
@keyframes upload-row-indeterminate {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.uploads-panel .upload-row-pct {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}

/* Per-row dismiss × button — only present on terminal (done/failed)
   rows. Sits in the 4th grid column. Subtle by default, color
   intensifies on hover. The button itself stops propagation in JS
   so clicking × on a clickable done-row doesn't also navigate to
   the file. */
.uploads-panel .upload-row-dismiss {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px;
  margin: 0;
  cursor: pointer;
  color: var(--text-dim);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.uploads-panel .upload-row-dismiss svg {
  width: 14px;
  height: 14px;
}
.uploads-panel .upload-row-dismiss:hover {
  opacity: 1;
  background: var(--surface-3);
  color: var(--text);
}
.uploads-panel .upload-row-dismiss:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  opacity: 1;
}

/* Footer can now hold either:
     1. A "Keep tab open" warning (when active uploads exist)
     2. A "Clear all" button (when any terminal entries exist)
     3. Both, stacked.
   The flex column gives them consistent spacing without a separator. */
.uploads-panel-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.uploads-panel-footer-note {
  font-size: 12px;
  color: var(--text-dim);
}
.uploads-panel-clear-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  align-self: flex-end;
  transition: background 0.12s, border-color 0.12s;
}
.uploads-panel-clear-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}
.uploads-panel-clear-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.user-chip {
  /* Outer pill — the visual container. The two child buttons are flat;
     this element provides the rounded background and border so the two
     regions read as one unit even when only one is hovered. */
  display: flex;
  align-items: stretch;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.user-chip:hover { border-color: var(--border-strong); }

.user-chip-main,
.user-chip-caret {
  /* Both buttons reset to transparent on the pill background. They light
     up independently on hover so the user can see which region they're
     about to click. */
  background: transparent;
  border: none;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.user-chip-main {
  gap: 10px;
  padding: 4px 10px 4px 4px;
}
.user-chip-main:hover { background: var(--surface-3); }

.user-chip-caret {
  /* Thin caret region. The 1px left border is the visual separator
     hinting at "two regions". Width is generous enough for a comfortable
     click target without dominating the chip. */
  padding: 0 10px;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
}
.user-chip-caret:hover {
  background: var(--surface-3);
  color: var(--text);
}
.user-chip-caret svg { width: 12px; height: 12px; }
.user-chip-caret[aria-expanded="true"] {
  background: var(--surface-3);
  color: var(--text);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.user-name { font-size: 13px; color: var(--text); font-weight: 700; }
.user-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-fg);
  font-weight: 700;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* Theme toggle button — visually identical to icon-btn but sized for top bar */
.theme-toggle { /* alias kept for clarity in markup */ }
.theme-toggle .sun, .theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: inline-block; }
:root:not([data-theme="dark"]) .theme-toggle .moon { display: inline-block; }

/* Floating theme toggle for pages without a topbar (login, share) */
.theme-toggle-fixed {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  z-index: 10;
}
.theme-toggle-fixed:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle-fixed svg { width: 14px; height: 14px; }

/* ============ Sidebar ============ */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  /* Two-region layout: a scrolling scope tree on top, a pinned footer
     (Trash) at the bottom. min-height:0 lets the flex child actually
     scroll; without it the inner overflow:auto is ignored because the
     flex item would grow indefinitely to fit its content. */
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
/* Scope tree — Company / Teams / Personal / per-user expansions. Takes
   all remaining space above the footer and scrolls when content
   overflows (e.g. when an admin expands "Show All" on a large team). */
.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0;
}
/* Footer slot — currently just Trash. Pinned at the bottom regardless
   of how tall the scope list grows. The top border separates it from
   the scrolling content above so the user reads it as "this is a
   different kind of thing". padding mirrors .sidebar-scroll's so the
   row's left/right rhythm doesn't shift across the boundary. */
.sidebar-footer {
  flex: 0 0 auto;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-section { padding: 0 12px 6px; }
.sidebar-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 10px 8px 4px;
  font-weight: 700;
}
/* Variant of the section label that hosts a pill button on the right
   (used for the admin-only "Show All / Hide All" toggle next to
   "Personal"). The pill is small, low-contrast, and only visible on
   admin sessions. */
.sidebar-label-with-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-pill {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  margin-right: 12px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-pill:hover {
  background: var(--accent-soft);
  color: var(--accent-fg);
  border-color: var(--accent);
}
/* The very first label inside the sidebar sits flush with the top edge so
   the "TOP-LEVEL" line aligns vertically with the middle pane's
   breadcrumb. Offsets:
     .sidebar padding-top: 8px
   + .sidebar-label padding-top (default 10px) overridden to 4px
   = 12px from the panel's top edge — which matches the .main-header
     padding-top of 12px and the .preview-header padding-top of 12px.
   Without this override the first label sat 18px down and read as
   misaligned.

   Note: the first sidebar label is rendered as a DIRECT child of
   #sidebar (not wrapped in a .sidebar-section), so the selector targets
   the first .sidebar-label child directly. */
.sidebar-scroll > .sidebar-label:first-child {
  padding-top: 4px;
}
.tree-node {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
  font-weight: 400;
}
/* Name span — flexes to fill row width. Targeted by class rather than
   :last-child so additional siblings (like the trash count badge) can
   be appended without losing the ellipsis behavior on long names. */
.tree-node-name {
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-node:hover { background: var(--surface-2); }
.tree-node.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.tree-node.active .scope-icon { color: #fff; }

/* Trash count badge — small pill on the right side of the Trash sidebar
   row when there's anything in trash. Hidden by default; .show is added
   via JS when the count is > 0. flex-shrink:0 keeps it from getting
   squashed when the row also holds a long-name truncation. */
.trash-count {
  display: none;
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 16px;
  min-width: 18px;
  text-align: center;
}
.trash-count.show { display: inline-block; }
.tree-node.active .trash-count {
  /* On the active (selected) row, the row background is the accent
     color and text is white. Re-tint the badge so it stays readable. */
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* Trash table — same chrome as the regular file table, but rows aren't
   clickable as a unit (the per-row buttons are the explicit actions).
   Override the cursor and hover-bg so the row doesn't visually lie. */
.filetable.trash-table tbody tr { cursor: default; }
.filetable.trash-table tbody tr:hover { background: transparent; }
.filetable.trash-table .actions-cell { white-space: nowrap; }
.filetable.trash-table .actions-cell .btn + .btn { margin-left: 6px; }

/* Quick Access (Favorites / Recent) day-bucket header rows. The
   Recent view groups entries by Today / Yesterday / This week /
   Earlier; these are non-clickable header rows that span all columns
   and visually separate each group. */
.filetable .quick-access-bucket-row td {
  padding: 14px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: none;
  background: transparent;
  cursor: default;
}
.filetable.trash-table tbody tr[data-qa-id] {
  /* Quick Access rows are clickable (open preview on row click).
     Override the trash-table cursor:default override above. */
  cursor: pointer;
}
.filetable.trash-table tbody tr[data-qa-id]:hover {
  background: var(--surface-2);
}
.scope-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

/* ============ Collapsible sidebar (desktop icon-rail) ============
   The left sidebar collapses to an icon-only rail. State is the
   `data-sidebar-collapsed` attribute on <html> (set pre-paint by
   theme.js to avoid a flash, toggled by the button on the Quick Access
   header). Every collapsed-state rule below is gated to desktop widths:
   on mobile (<=768px) the sidebar is an off-canvas drawer that must
   always show full labels, so the attribute is inert there. */

/* Animate the grid column so the rail slides rather than snaps. Modern
   engines (Chrome 107+, Firefox 66+, Safari 16+) interpolate
   grid-template-columns; older ones jump, which is an acceptable
   degradation. */
.app { transition: grid-template-columns 180ms ease; }

.sidebar-qa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
/* Collapse toggle on the Quick Access header. Sized as a 22px hit
   target with a 15px glyph, low-contrast until hover — it shouldn't
   compete with the scope rows for attention. */
.sidebar-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  padding: 0;
  margin-right: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sidebar-collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.sidebar-collapse-btn svg { width: 15px; height: 15px; }

@media (min-width: 769px) {
  :root[data-sidebar-collapsed="1"] .app {
    /* Rail wide enough to center a 16px icon with breathing room. */
    grid-template-columns: 56px 1fr 44px;
  }
  /* Drop row labels and every section header except the Quick Access
     header (which still hosts the toggle). */
  :root[data-sidebar-collapsed="1"] .sidebar .tree-node-name,
  :root[data-sidebar-collapsed="1"] .sidebar .sidebar-label:not(.sidebar-qa-header) {
    display: none;
  }
  /* The admin "Show All" pill and the peer/oversight rows it reveals are
     not part of the rail — the rail shows only the user's own scopes. */
  :root[data-sidebar-collapsed="1"] .sidebar .sidebar-pill,
  :root[data-sidebar-collapsed="1"] .sidebar .tree-node--peer {
    display: none;
  }
  /* Center each icon in the narrow rail; the peer-row indent no longer
     applies (inline padding-left is overridden here). */
  :root[data-sidebar-collapsed="1"] .sidebar .tree-node {
    justify-content: center;
    gap: 0;
    padding: 8px 0 !important;
    position: relative;
  }
  /* Quick Access header collapses to just the centered toggle button —
     it reads as the top icon of the rail. */
  :root[data-sidebar-collapsed="1"] .sidebar-qa-header {
    justify-content: center;
    padding: 4px 0 6px;
  }
  :root[data-sidebar-collapsed="1"] .sidebar-qa-text { display: none; }
  :root[data-sidebar-collapsed="1"] .sidebar-collapse-btn { margin-right: 0; }
  /* Trash count rides as a small corner bubble on the icon instead of a
     trailing pill (there's no row width for a pill in the rail). */
  :root[data-sidebar-collapsed="1"] .trash-count.show {
    position: absolute;
    top: 2px;
    right: 8px;
    min-width: 15px;
    padding: 0 4px;
    font-size: 9px;
    line-height: 15px;
  }
}

/* ============ Main ============ */
.main {
  grid-area: main;
  /* Two-region layout: a non-shrinking header (breadcrumb + toolbar)
     and a scrollable listing below. The previous design scrolled the
     entire main panel together, which pushed the +New folder / Upload
     buttons off the top of the viewport when a folder had many files.
     Splitting the regions parks the controls in place. */
  display: flex;
  flex-direction: column;
  min-height: 0;            /* allow the inner overflow:auto to actually scroll */
  background: var(--bg);
  overflow: hidden;         /* the child .main-listing handles scroll */
  position: relative;       /* anchor for the drag-and-drop overlay */
}
.main-header {
  flex: 0 0 auto;            /* never shrink, never grow */
  /* Padding values chosen so the listing title (h1 inside .toolbar)
     lands at roughly the same y-coordinate as the right pane's
     .preview-title. That alignment is what makes the two panel headers
     read as "the same header line" across the divider. */
  padding: 12px 28px 14px;
  background: var(--bg);
  /* Single thin separator below the entire header. The .toolbar inside
     used to draw its own bottom border for the old single-scroll
     layout; now the .main-header owns that separator instead, and the
     toolbar's own border has been removed (see .toolbar below). */
  border-bottom: 1px solid var(--border);
  /* Pinned to the same height as .preview-header so the bottom border
     of each panel header aligns across the divider. */
  min-height: 73px;
  box-sizing: border-box;
}
.main-listing {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 28px 20px;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.breadcrumb-sep { color: var(--text-dim); }
.breadcrumb-item { cursor: pointer; }
.breadcrumb-item:hover { color: var(--text); }
.breadcrumb-item.current { color: var(--text); font-weight: 700; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* No bottom border / padding / margin here — the wrapping
     .main-header owns the separator and the listing's own padding-top
     handles the gap above the file rows. */
}
.toolbar-left h1 {
  /* Sized to match .preview-title on the right pane (16px / weight 900)
     so when both panes are open, the two headlines read as visual
     peers at the same baseline. The previous 24px made the middle
     pane's title significantly larger and pushed its baseline well
     below the right pane's title. */
  font-size: 16px;
  font-weight: 900;
  margin: 0 0 2px 0;
  letter-spacing: -0.01em;
  color: var(--text);
}
.toolbar-left .meta {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}
.toolbar-right { display: flex; gap: 8px; }

/* ============ List controls (filter + sort) ============ */
/* Sit at the left edge of the listing-actions toolbar group, before
   the scope-action buttons (Upload / New Folder / Empty Trash). The
   1px divider visually separates "narrow this list" from "act on
   this scope" so the eye groups them correctly. */
.list-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.list-controls-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 6px;
  display: inline-block;
}

/* When the preview pane is open the toolbar is narrower (the preview
   claims ~480px on desktop), but the action buttons collapse to icon-only
   here (see .toolbar-action), which frees the room the filter needs. So
   clicking the funnel still opens the input — just a touch narrower to
   respect the tighter column. (This used to force width:0, which meant the
   input never appeared while the panel was open.) */
.app.preview-open .list-filter-input.is-open {
  width: 150px;
}

/* Right panel open → the listing column narrows and the scope-action
   buttons slide left. Collapse them (New folder / Upload folder / Upload)
   to icon-only so they stay on one tidy row; the label returns on hover
   (title=) and in full when the panel closes. Desktop only — on mobile the
   preview is a full-screen drawer, not a side column, so there's no squeeze. */
@media (min-width: 769px) {
  .app.preview-open .toolbar-action span { display: none; }
  .app.preview-open .toolbar-action {
    padding-left: 9px;
    padding-right: 9px;
    gap: 0;
  }

  /* Reserve the panel's width on the listing (mirrors the header's
     padding-right) so the table reflows INTO the visible area instead of
     sliding its right columns (Size/Modified/actions) behind the floating
     overlay. This is a deliberate change from the original trade ("leave
     the listing full-width, accept obscured columns, avoid reflow") — the
     rows now reflow on panel open/close, which is what keeps Modified
     visible. */
  .app.preview-open .main-listing {
    padding-right: 504px;   /* 480 panel + 24 breathing room, matches header */
  }

  /* With the area reserved, the widest column ("Uploaded By", col 5, a
     fixed 200px) no longer fits — drop it so Name / Type / Size / Modified
     sit comfortably. Mirrors the mobile hide of the same column. Normal
     browse table only; trash/search variants have different columns. */
  .app.preview-open .filetable:not(.trash-table):not(.search-table) th:nth-child(5),
  .app.preview-open .filetable:not(.trash-table):not(.search-table) td:nth-child(5) {
    display: none;
  }
}

/* Filter: icon button + collapsible inline input + clear-X. The input
   is `width: 0` when collapsed so the toolbar feels minimal at rest;
   gains a fixed width on .is-open so typing has room to breathe. */
.list-filter-wrap {
  display: inline-flex;
  align-items: center;
  position: relative;
}
.list-filter-btn.is-active {
  /* Subtle accent dot when a filter is active, so the user knows the
     list is currently narrowed even if the input is collapsed. */
  color: var(--accent-fg);
  background: var(--accent-soft);
}
.list-filter-input {
  width: 0;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  border-radius: var(--radius-sm);
  outline: none;
  transition: width 160ms ease, padding 160ms ease, border-color 160ms ease,
              background 160ms ease, margin 160ms ease;
  margin: 0;
}
.list-filter-input.is-open {
  width: 200px;
  padding: 6px 28px 6px 10px;
  margin: 0 2px;
  border-color: var(--border);
  background: var(--surface);
}
.list-filter-input.is-open:focus {
  border-color: var(--accent);
}
.list-filter-clear {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  display: none;
  color: var(--text-dim);
}
.list-filter-clear.is-visible { display: inline-flex; }
.list-filter-clear svg { width: 12px; height: 12px; }

/* Sort popover. Anchored under the sort button, right-aligned to it.
   The list of sort keys uses the same .popover-item style as the
   user-menu popover so the visual grammar is consistent. */
.list-sort-popover {
  min-width: 220px;
  z-index: 1500;
}
.list-sort-popover .popover-item {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.list-sort-popover .popover-item.is-selected {
  font-weight: 700;
  color: var(--accent-fg);
}
.list-sort-popover .sort-check {
  width: 14px;
  display: inline-flex;
  justify-content: center;
  color: var(--accent-fg);
}

/* In-header sort button. Lives in the rightmost <th> cell on desktop
   instead of the toolbar — closer to the data it acts on. The cell
   itself is right-aligned to match the actions-cell below; we don't
   add extra padding on the th so the sort button's right edge sits
   at the same column position as the kebab buttons in each row.
   The button's interior padding mirrors the kebab's (.btn-ghost has
   .btn's 7px 14px) so the icon's center falls in the same horizontal
   spot as a kebab's dots — no jagged left/right offset between the
   header and the rows. */
.filetable thead th.th-actions {
  text-align: right;
}
.icon-btn.header-sort-btn {
  padding: 7px 14px;
  height: auto;
  width: auto;
  min-width: 0;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
}
.icon-btn.header-sort-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}
.icon-btn.header-sort-btn svg {
  width: 14px;
  height: 14px;
}

.btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  font-weight: 700;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
  color: #fff;
}
.btn-danger {
  color: var(--danger);
  border-color: var(--border);
  background: var(--surface);
}
.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); }

/* ============ File table ============ */
.filetable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.filetable th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.filetable td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.filetable tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.filetable tbody tr:hover { background: var(--surface-2); }
.filetable tbody tr.selected {
  background: var(--accent-soft);
}
.filetable .name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  /* Give the file name room to breathe: ellipsize rather than wrap
     mid-name, and reserve a generous right-side gutter so the next
     column doesn't crowd the last visible character. min-width:0 lets
     the text node actually shrink inside the flex parent (default
     flex behavior would let it overflow). */
  min-width: 0;
  padding-right: 24px;
}
.filetable .name-cell > .name-text {
  /* Truncate with ellipsis instead of wrapping; the title attribute
     on the span lets users hover for the full name. min-width:0 lets
     the text shrink inside its flex parent (default flex behavior
     would let it overflow rather than truncate). */
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filetable .file-icon,
.filetable .folder-icon {
  /* The contained SVG governs sizing internally via viewBox. We size
     the wrapper so the icon takes a predictable amount of horizontal
     space in the name column regardless of content. */
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.filetable .file-icon svg,
.filetable .folder-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
/* Generic file icons (no recognized type) inherit a muted color via
   currentColor; type-specific icons set their own fills inline so this
   rule doesn't reach them. */
.filetable .file-icon { color: var(--text-muted); }
.filetable .folder-icon { color: var(--accent-fg); }
.filetable td.mono {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.filetable .actions-cell {
  text-align: right;
  white-space: nowrap;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  margin-top: 24px;
  transition: all 0.2s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-fg);
}

/* ============ Preview pane ============ */
.preview {
  /* Floating overlay anchored to the right edge of the viewport,
     starting just below the topbar. Sliding in/out via transform
     instead of grid-column animation so the underlying main panel
     never has its width changed — file rows keep their stable layout
     regardless of panel state.

     z-index sits above the main panel but well below modals (modal-
     backdrop is 1000). The left-edge shadow gives a subtle elevation
     cue distinguishing the floating panel from the main surface. */
  position: absolute;
  top: 64px;                 /* equal to .topbar min-height */
  right: 0;
  bottom: 0;
  width: 480px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 50;
  /* Hidden state: parked off-screen to the right. pointer-events
     turned off so it doesn't catch clicks landing on the area where
     it would be visible if shown. */
  transform: translateX(100%);
  pointer-events: none;
  transition: transform 0.25s ease;
}
[data-theme="dark"] .preview {
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
}
.app.preview-open .preview {
  transform: translateX(0);
  pointer-events: auto;
}
/* Rail has its own slide so the 0.25s panel transition feels unified. */
.preview-rail {
  transition: transform 0.25s ease;
}
/* main-header slides its right padding too — keeps toolbar buttons
   easing toward their visible position instead of jumping. */
.main-header {
  transition: padding-right 0.25s ease;
}
.preview-header {
  /* Total header height tuned to match .main-header so the two panel
     headers align bottom-to-bottom across the divider. The middle pane
     has two lines (breadcrumb + title); the right pane has two lines
     (title + meta). Each panel's content is allowed to flow naturally
     within the same overall band. */
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  min-height: 73px;
  box-sizing: border-box;
}
.preview-title {
  font-size: 16px;
  font-weight: 900;
  margin: 0 0 4px 0;
  word-break: break-all;
  color: var(--text);
  letter-spacing: -0.01em;
}
.preview-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.preview-rail {
  /* Persistent vertical icon strip on the right edge of the app. Always
     visible, runs floor-to-ceiling under the topbar. Buttons appear
     disabled when no file is selected so the strip doesn't look like
     dead UI. */
  grid-area: rail;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  gap: 2px;
}
.preview-rail-btn {
  width: 36px;
  height: 36px;
  margin: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.preview-rail-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.preview-rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.preview-rail-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.preview-rail-btn svg {
  width: 18px;
  height: 18px;
}

/* Star toggle on the rail. Hollow by default (rendered via stroke
   only); fills with the accent color when .is-fav is set. The star
   icon's SVG uses fill="currentColor" so simply changing the color
   via the .is-fav class fills it. */
.preview-rail-btn.rail-star {
  color: var(--text-dim);
}
.preview-rail-btn.rail-star.is-fav {
  color: var(--warn);  /* gold-ish star feel — matches the badge palette */
}
.preview-rail-btn.rail-star.is-fav:hover:not(:disabled) {
  color: var(--warn);
}
/* Hollow-vs-filled effect: when not favorited, render the star outline
   only (no fill). When favorited, fill normally. We fake this by
   targeting the SVG's fill attribute via CSS — works because the icon's
   SVG uses fill="currentColor". The :not selector ensures only the
   non-favorite state gets the transparent fill. */
.preview-rail-btn.rail-star:not(.is-fav) svg polygon {
  fill: transparent;
  stroke: currentColor;
  stroke-width: 2;
}
.rail-divider {
  width: 60%;
  height: 1px;
  margin: 4px auto;
  background: var(--border);
}
.preview-body {
  padding: 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ============ Inline file viewer ============ */
/* When .viewer-mode is on, the preview body fills edge-to-edge (no padding)
   so PDFs / images / video can use the full pane. The flex:1 above already
   makes it fill remaining vertical space within .preview. */
.preview-body.viewer-mode {
  padding: 0;
  overflow: hidden;
}
.viewer-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}
.viewer-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: auto;
  background: var(--bg);
}
.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.viewer-stage-audio {
  align-content: center;
}
.viewer-stage audio {
  width: 100%;
  max-width: 380px;
}
.viewer-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  background: var(--bg);
}

/* ========== Office preview (docx/xlsx/pptx → PDF) ==========
   The iframe is hidden until the converted-PDF blob is ready, so the
   user sees a "Generating preview…" spinner instead of a flash of
   empty white. Same dimensions/positioning as the regular .viewer-frame
   so swapping in is seamless. */
.viewer-office-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
  background: var(--bg);
}
.viewer-office-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  background: var(--bg);
}
.viewer-office-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
}
.viewer-office-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.viewer-office-hint {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 280px;
  text-align: center;
  margin-top: 4px;
}
.viewer-office-fallback {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  text-align: center;
}
.viewer-office-fallback-msg {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 360px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.detail-row:last-child { border: none; }
.detail-key {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 2px;
  font-weight: 700;
}
.detail-val { color: var(--text); word-break: break-all; }

/* Folder inspector (Info panel) — adaptive confidential indicator and
   inline explanatory notes. The lock glyph inherits currentColor. */
.folder-info-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}
.folder-info-note.warn {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--warn);
}
.folder-info-note svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  margin-top: 1px;
}

/* Folder Access (permissions) panel */
.perm-team {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
}
.perm-team svg { width: 18px; height: 18px; flex: 0 0 auto; }
.perm-group { margin-bottom: 16px; }
.perm-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.perm-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-dim);
}
.perm-summary { font-size: 13px; color: var(--text); }
.perm-summary.perm-none { color: var(--text-dim); font-style: italic; }
.perm-members { display: flex; flex-direction: column; gap: 6px; }
.perm-member { display: flex; align-items: center; gap: 9px; }
.perm-avatar {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent, #0059a9);
  color: #fff;
}
.perm-name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.perm-manage-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ============ Versions list (Details panel) ============ */
.versions-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.version-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-radius: var(--radius);
  position: relative;
}
.version-row:hover {
  background: var(--surface-2);
}
.version-star {
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.version-star svg { width: 16px; height: 16px; }
/* Empty placeholder so non-primary rows align with primary rows. */
.version-star-empty {
  width: 16px;
  height: 16px;
  display: inline-block;
}
.version-meta { min-width: 0; }
.version-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Small "PRIMARY" pill next to the version number for the active row. */
.version-pill {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  background: var(--accent-soft);
  color: var(--accent-fg);
  border-radius: 999px;
  text-transform: uppercase;
}
.version-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  /* Truncate if uploader email is long; details still readable as
     tooltip via the title attribute we don't currently set, but the
     visible truncation keeps the layout stable. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.version-menu-btn {
  /* Reuse .icon-btn styles (transparent + border on hover). */
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.audit-entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
.audit-entry .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.audit-entry .actor { color: var(--text); font-weight: 700; }
.audit-entry .ts {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.audit-entry .event-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 8px;
}
.audit-entry .event-tag.viewed { color: var(--accent-fg); background: var(--accent-soft); }
.audit-entry .event-tag.downloaded { color: var(--success); background: rgba(42, 157, 94, 0.10); }
.audit-entry .event-tag.shared { color: var(--accent-fg); background: var(--accent-soft); }
[data-theme="dark"] .audit-entry .event-tag.downloaded { background: rgba(78, 192, 122, 0.14); }
.audit-entry .detail {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============ Notes panel (preview pane) ============
   iMessage-style chat bubbles. Self bubbles right-aligned in the
   accent color; other-author bubbles left-aligned in a soft surface
   color. The panel itself is a flex column: scrolling list on top,
   composer pinned to the bottom.

   When the notes panel is rendered we override .preview-body's normal
   20px padding + scroll behaviour via the .notes-mode class so the
   composer can sit flush against the panel's bottom edge. The notes
   list inside scrolls instead. */
.preview-body.notes-mode {
  padding: 0;
  overflow: hidden;
  display: flex;
}
.notes-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.notes-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.notes-empty {
  margin: 40px auto;
  text-align: center;
  color: var(--text-muted);
}
.notes-empty svg {
  width: 32px; height: 32px;
  opacity: 0.5;
}
.note-row {
  display: flex;
  width: 100%;
}
.note-row.self  { justify-content: flex-end;   }
.note-row.other { justify-content: flex-start; }
.note-bubble {
  max-width: 78%;
  padding: 8px 12px 9px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.note-bubble-self {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.note-bubble-other {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  margin-bottom: 3px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.note-bubble-self .note-meta {
  color: rgba(255, 255, 255, 0.85);
  justify-content: flex-end;
}
.note-bubble-other .note-meta {
  color: var(--text-muted);
}
.note-author { font-weight: 700; }
.note-ts {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.note-bubble-self  .note-ts { color: rgba(255, 255, 255, 0.7); }
.note-bubble-other .note-ts { color: var(--text-dim); }
.note-content {
  white-space: pre-wrap;       /* preserve paragraph breaks */
  font-size: 13px;
}
/* Inline delete affordance — small, low-contrast until hover so it
   doesn't compete with the note text itself. */
.note-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  width: 14px;
  height: 14px;
  opacity: 0.55;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.note-delete:hover { opacity: 1; }
.note-delete svg { width: 12px; height: 12px; }
.note-bubble-self  .note-delete       { color: rgba(255,255,255,0.85); }
.note-bubble-other .note-delete       { color: var(--text-muted);     }

/* Composer — sticky bottom strip with a multi-line textarea and a
   send button. The textarea grows to ~3 lines max before scrolling
   internally, so a long note doesn't push the bubble list off-screen. */
.note-composer {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: flex-end;
}
.note-composer-readonly {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  display: block;
}
.note-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  max-height: 80px;
  line-height: 1.4;
}
.note-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.note-composer .btn {
  padding: 8px 12px;
  flex-shrink: 0;
}
.note-composer .btn svg { width: 14px; height: 14px; }

/* Share list item */
.share-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.share-item.expired { opacity: 0.55; }
.share-item .share-url {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.share-item .share-url input,
.share-item .share-url .share-url-text {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 11px;
  color: var(--text);
  /* The text variant (replaced from input) is keyboard-selectable
     and click-truncates with ellipsis when the URL is long. The
     Copy button next to it is the canonical copy affordance, but
     Cmd-A on a focused span still works in modern browsers. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
  user-select: all;  /* triple-click → select all */
  cursor: text;
}
.share-item .share-meta {
  display: flex;
  gap: 12px;
  color: var(--text-muted);
  font-size: 11px;
  flex-wrap: wrap;
  align-items: center;
}
.share-item .share-meta .pill {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  font-weight: 700;
}
.share-item .share-meta .pill.warn { background: rgba(192, 128, 32, 0.12); color: var(--warn); }
.share-item .share-meta .pill.danger { background: var(--danger-soft); color: var(--danger); }
.share-item .share-meta .pill.ok { background: rgba(42, 157, 94, 0.12); color: var(--success); }
[data-theme="dark"] .share-item .share-meta .pill.warn { background: rgba(232, 184, 112, 0.14); }
[data-theme="dark"] .share-item .share-meta .pill.ok { background: rgba(78, 192, 122, 0.14); }

/* ============ Existing-links chooser ============
   Shown when the user clicks "Create share link" / "Create request
   link" on a target that already has active links. Each row is a
   reusable card surfacing URL, expiry, usage count, and password
   indicator with Copy + Revoke buttons. */
.existing-link-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}
.existing-link-row:last-child { margin-bottom: 0; }
.existing-link-url {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.existing-link-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-muted);
}
.existing-link-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  font-weight: 700;
}
.existing-link-pill-pw {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
/* "Never expires" pill — uses a warning-tinted palette to draw the
   eye, since these links are a more sensitive class that benefits
   from being visually distinct in any list. */
.existing-link-pill-warn {
  background: rgba(245, 158, 11, 0.15);
  color: rgb(180, 83, 9);
  font-weight: 700;
}
[data-theme="dark"] .existing-link-pill-warn {
  background: rgba(245, 158, 11, 0.2);
  color: rgb(252, 211, 77);
}
.existing-link-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.existing-link-actions .btn {
  /* Slightly more breathing room than the default since these are
     primary actions in the modal. */
  padding: 6px 14px;
}

/* Subscribers panel inside an existing-link-row. Renders below the
   action buttons when expanded; collapsed by default. Visually
   nested into the row via a soft-tinted background and subtle
   left-edge accent. */
.existing-link-subs {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.existing-link-subs-loading,
.existing-link-subs-empty,
.existing-link-subs-error {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}
.existing-link-subs-error { color: var(--danger); }
.subs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.subs-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.subs-name {
  font-weight: 600;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.subs-email {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.subs-creator-pill,
.subs-me-pill {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.subs-creator-pill {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.subs-me-pill {
  background: var(--surface-3);
  color: var(--text-dim);
}
/* Muted pill: shown next to the creator's row when they've used the
   "Notify me" toggle to silence themselves on this specific link.
   Helps anyone viewing the subscribers list see at a glance that the
   creator opted out (so subscribers know they're now the only ears
   on this link). */
.subs-muted-pill {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  color: rgb(180, 83, 9);
}
[data-theme="dark"] .subs-muted-pill {
  background: rgba(245, 158, 11, 0.2);
  color: rgb(252, 211, 77);
}
.subs-remove-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.subs-remove-btn:hover {
  background: var(--danger);
  color: white;
}
.subs-self-toggle {
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.subs-self-toggle .check-row {
  margin-bottom: 0;
}

/* Bell popover anchored to the share/request bell button. Wider than
   a regular kebab popover because it embeds the subscribers list. */
.popover.bell-popover {
  width: 280px;
  max-width: 90vw;
  padding: 0;
}
.popover.bell-popover .subs-list {
  margin: 0;
  padding: 12px;
}
.popover.bell-popover .subs-self-toggle {
  padding: 12px;
  background: var(--surface-2);
}
.share-bell {
  padding: 4px 8px !important;
}

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
[data-theme="dark"] .modal-backdrop { background: rgba(8, 14, 24, 0.7); }
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  /* The modal is a flex column so its body can scroll while the
     header (incl. settings tabs) and footer stay parked. Previously
     `overflow:auto` on the modal itself scrolled the whole thing as a
     unit, which carried the Close button off-screen on the Users /
     Teams admin tabs. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Wider variant used by the admin settings modal so tables (Users, Teams,
   Audit Log) have room to breathe. The non-admin Account tab still
   centers comfortably inside this width — no special-casing needed. */
.modal.modal-wide {
  max-width: 980px;
}
/* Tall variant for the move-folder picker. The folder tree wants
   vertical real estate so users can see several levels without
   scrolling; the body itself scrolls if the tree gets long. */
.modal.modal-tall {
  max-width: 540px;
  height: 75vh;
}
.modal-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 2px;
}

/* Move modal — the destination tree and supporting bits. */
.move-current {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 14px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.move-tree-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1;
  overflow-y: auto;
  background: var(--surface);
  min-height: 200px;
}
.move-tree {
  padding: 6px 0;
}
.move-tree-node {
  /* --depth is set inline via JS (renderMoveTreeNode). Rows indent
     by 18px per depth level — matches the caret column width so
     subfolder labels visually nest under their parent's icon. */
}
.move-tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px calc(12px + var(--depth, 0) * 18px);
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 0 4px;
  font-size: 13px;
  outline: none;
}
.move-tree-row:hover { background: var(--surface-2); }
.move-tree-row:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.move-tree-row.is-picked {
  background: var(--accent-soft);
  color: var(--accent-fg);
  font-weight: 700;
}
/* Marks the file's current location. Distinct from .is-picked (which
   is the user's chosen destination): a small "current" pill plus muted
   bg reads as "you are here" without competing with the picked-state
   accent. If the user picks the current folder, .is-picked wins
   visually and the pill is hidden so the row's appearance reflects
   the current selection state cleanly. */
.move-tree-row.is-current {
  background: var(--surface-2);
}
.move-tree-current-pill {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  flex-shrink: 0;
}
.move-tree-row.is-picked .move-tree-current-pill {
  display: none;
}
.move-tree-caret {
  width: 14px;
  font-size: 10px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  justify-content: center;
}
.move-tree-icon {
  display: inline-flex;
  align-items: center;
  width: 18px;
}
.move-tree-icon svg { width: 16px; height: 16px; color: var(--text-dim); }
.move-tree-row.is-picked .move-tree-icon svg { color: var(--accent-fg); }
.move-tree-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.move-tree-loading,
.move-tree-error,
.move-tree-empty {
  padding: 6px 12px 6px calc(30px + var(--depth, 0) * 18px);
  font-size: 12px;
  color: var(--text-dim);
}
.move-tree-error { color: var(--danger); }

/* Selection bar — appears above the listing when one or more files
   are checked. Sits flush below the toolbar; "X selected" on the left,
   bulk action buttons on the right. The element is created/destroyed
   on demand by renderSelectionBar(). */
.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.selection-count {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-fg);
}
.selection-actions {
  display: flex;
  gap: 8px;
}

/* File rows that are part of an active multi-select. Distinct from
   `.selected` (which marks the currently-previewed file) — a row can
   theoretically be both, though in practice clicking to select clears
   the preview-selection. The ring on the left edge gives a clear "this
   is in your selection set" cue. */
.filetable .file-row.is-selected {
  background: var(--accent-soft);
}
.filetable .file-row.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
.filetable .file-row.is-selected:hover {
  background: var(--accent-soft);
}

/* When ANY file row is selected (i.e. the bulk-action bar is showing),
   Confidential file rows in the same listing get a greyed-out look to
   communicate "you can't include these in this bulk action."
   #app.has-selection is added by renderSelectionBar() when the
   selection set becomes non-empty. The hover state intentionally
   matches the dimmed look so hovering a Confidential row doesn't
   tease an interaction that isn't available. */
#app.has-selection .filetable .file-row.is-confidential {
  opacity: 0.45;
  cursor: not-allowed;
}
#app.has-selection .filetable .file-row.is-confidential:hover {
  background: inherit;
  opacity: 0.45;
}

/* Settings tabs (Account / Users / Teams / Audit Log) sit just below the
   modal title and above the body. Same visual language as the old
   .admin-tabs strip but tightened to fit inside the modal chrome. */
.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  background: var(--surface);
  flex-shrink: 0;
}
.settings-tab {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
  color: var(--accent-fg);
  border-bottom-color: var(--accent);
}
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-title {
  font-size: 18px;
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.01em;
}
.modal-body {
  padding: 20px;
  /* Body is the only scrolling region inside the modal. min-height:0 is
     needed for flex children to honour overflow on smaller viewports. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface);
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
}
.field textarea {
  resize: vertical;
  min-height: 64px;
  font-family: inherit;
}
/* Inline checkbox + label pairing used for opt-in switches inside form
   fields (never-expire, notify-me). Reads as a single line, distinct
   from the uppercase label-on-top pattern of the rest of the form. */
.field label.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 0;
  cursor: pointer;
}
.field label.check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}
[data-theme="dark"] .field input,
[data-theme="dark"] .field select,
[data-theme="dark"] .field textarea {
  background: var(--surface-2);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ============ Login page ============ */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  background: var(--bg);
}
[data-theme="dark"] .auth-wrap {
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 118, 199, 0.10), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 89, 169, 0.08), transparent 50%),
    var(--bg);
}
:root:not([data-theme="dark"]) .auth-wrap {
  background:
    radial-gradient(circle at 20% 20%, rgba(0, 89, 169, 0.05), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 89, 169, 0.04), transparent 50%),
    var(--bg);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
.auth-logo img {
  /* The composite ShareBox cube is square (1:1). 200px matches the
     size used on the recipient landing pages — the two
     "first-impression" surfaces feel cohesive. With nothing else
     visually competing on the login surface, the cube earns the
     space, and the Frazil inscription on the right face reads
     clearly at this size.

     No filter applied — the cube's colors and the embedded Frazil PNG
     are designed to look identical in light and dark themes. */
  width: 200px;
  height: 200px;
  display: block;
}
.auth-app {
  /* Legacy text wordmark. Kept for any non-image fallback contexts;
     the login page now uses .auth-wordmark with an SVG image. */
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 8px;
}
.auth-wordmark {
  /* SVG wordmark beneath the 200px cube. The isometric projection
     leaves ~30px of empty space at the bottom of the cube box, so
     a slight negative margin-top closes the visual gap without
     crashing the wordmark into the cube. -16px matches the external
     landing pages (share / request) — same restraint, "let the lockup
     breathe a little" rather than the tighter -36px we had before.
     Wordmark width still matches the landing pages at 140px. */
  display: flex;
  justify-content: center;
  margin-top: -16px;
  margin-bottom: 0;
}
.auth-wordmark img {
  width: 140px;
  height: auto;
  display: block;
}
.auth-tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
  margin-bottom: 16px;
  letter-spacing: 0.04em;
}
.auth-error {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 16px;
  display: none;
}
.auth-error.show { display: block; }

/* "Forgot password?" link below the sign-in button. Quiet text-link
   style; the primary action stays the Sign in button. */
.auth-aux {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
}
.auth-aux a {
  color: var(--text-muted);
  text-decoration: none;
}
.auth-aux a:hover {
  color: var(--accent-fg);
  text-decoration: underline;
}

/* Forgot-password dialog. Inline overlay rather than a modal route
   so the existing login page captures the email already typed.
   Uses the same auth-card visual language as the login form. */
.auth-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.auth-dialog[hidden] { display: none; }
.auth-dialog-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-strong);
}
.auth-dialog-help {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 16px;
}
.auth-success {
  background: var(--success-soft, rgba(34, 197, 94, 0.1));
  border: 1px solid var(--success, #22c55e);
  color: var(--success-text, #16a34a);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
[data-theme="dark"] .auth-success {
  color: #4ade80;
}

/* ============ Public share pages ============ */
.share-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
  position: relative;
  background: var(--bg);
}
[data-theme="dark"] .share-page {
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 118, 199, 0.10), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 89, 169, 0.08), transparent 50%),
    var(--bg);
}
:root:not([data-theme="dark"]) .share-page {
  background:
    radial-gradient(circle at 20% 20%, rgba(0, 89, 169, 0.05), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 89, 169, 0.04), transparent 50%),
    var(--bg);
}
.share-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.share-card .share-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 0;
}
.share-card .share-logo img {
  /* Composite ShareBox cube — square (1:1). Sized large because the
     recipient landing pages are otherwise sparse; the cube anchors the
     page visually. With the previous sub-icon (download/upload glyph)
     removed, the cube is now the sole visual element above the file
     name, so we let it occupy more of the card. 200px on a 480px card
     leaves comfortable margins without crowding the headline below. */
  width: 200px;
  height: 200px;
  /* No filter — the cube's colors and embedded Frazil PNG are designed
     to look identical in light and dark themes; the previous logo-filter
     was for inverting the standalone Frazil PNG. */
}
.share-card .share-wordmark {
  /* Wordmark beneath the cube on recipient landing pages. The wordmark
     renders smaller here than on the login card — the recipient cards
     are wider (480px vs 380px) and have additional content (filename,
     buttons), so the wordmark needs to be more restrained to keep the
     cube as the dominant brand element. Negative margin-top pulls the
     wordmark up into the cube's bottom whitespace (the isometric
     projection leaves ~30px empty at the bottom of the 200x200 cube),
     but only partway — recipient pages have more visual real estate
     than the login card, so we let the lockup breathe a little. */
  display: flex;
  justify-content: center;
  margin-top: -16px;
  margin-bottom: 20px;
}
.share-card .share-wordmark img {
  width: 140px;
  height: auto;
  display: block;
}
.share-card .file-glyph {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: var(--accent);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #fff;
}
.share-card .file-glyph svg { width: 28px; height: 28px; }
.share-card .success-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--success);
  margin: 4px 0 0;
}
.share-card .success-pip {
  width: 20px;
  height: 20px;
  background: var(--success);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.share-card .success-pip svg {
  width: 12px !important;
  height: 12px !important;
}
.share-card h2 {
  font-size: 20px;
  font-weight: 900;
  margin: 0 0 6px;
  word-break: break-all;
  letter-spacing: -0.01em;
}
.share-card .meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 24px;
  font-variant-numeric: tabular-nums;
}
.share-card .lede {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.invalid-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  background: var(--danger-soft);
  border-radius: 50%;
  color: var(--danger);
}
.invalid-icon svg { width: 28px; height: 28px; }

.share-error {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 16px;
  text-align: left;
}

/* ============ Request (upload) page ============ */
.request-card { max-width: 540px; }
.request-card .upload-glyph { background: var(--accent); }

.request-note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 16px 0 20px;
  text-align: left;
}
.request-note-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 4px;
}
.request-note-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;       /* preserve sender's line breaks */
  word-break: break-word;
}

.request-dropzone {
  margin-top: 0;
  padding: 24px;
}

.progress-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.15s ease;
}

/* Multi-file upload queue (request landing page).
   Each row: filename · size · status · ×-remove. The status column
   handles four states: queued, uploading (with embedded progress
   bar), ok, failed/skipped. The list is reset list — bullets/padding
   stripped. */
.upload-queue {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-height: 240px;
  overflow-y: auto;
}
.upload-row {
  display: grid;
  grid-template-columns: 1fr auto 110px 24px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.upload-row:last-child { border-bottom: none; }
.upload-row-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.upload-row-size {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.upload-queue .upload-row-statuswrap { text-align: right; }
/* Scoped to `.upload-queue` (the public request-landing upload list).
   Without the scope, the unscoped `.upload-row-status` rule's
   `text-transform: uppercase` bleeds into the in-app uploads tray
   (which uses the same class name under `.uploads-panel`) and
   renders the tray's status text in ALL CAPS — visible as
   "UPLOADED" / "UPLOADING… X / Y MB" / "SCANNING FOR VIRUSES…"
   despite the tray's own scoped rules NOT specifying uppercase.
   This was the long-standing all-caps bug from the backlog. */
.upload-queue .upload-row-status {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-queued {
  background: var(--surface-3);
  color: var(--text-dim);
}
.status-ok {
  background: rgba(34, 197, 94, 0.15);
  color: rgb(21, 128, 61);
}
[data-theme="dark"] .status-ok {
  background: rgba(34, 197, 94, 0.2);
  color: rgb(134, 239, 172);
}
.status-failed {
  background: rgba(239, 68, 68, 0.15);
  color: rgb(185, 28, 28);
  cursor: help;
}
[data-theme="dark"] .status-failed {
  background: rgba(239, 68, 68, 0.2);
  color: rgb(252, 165, 165);
}
.status-skipped {
  background: rgba(245, 158, 11, 0.15);
  color: rgb(180, 83, 9);
  cursor: help;
}
[data-theme="dark"] .status-skipped {
  background: rgba(245, 158, 11, 0.2);
  color: rgb(252, 211, 77);
}
.upload-row-progress {
  display: flex;
  align-items: center;
  gap: 6px;
}
.upload-row-progress .progress-track {
  flex: 1;
  height: 5px;
}
.upload-row-progress .status-pct {
  font-variant-numeric: tabular-nums;
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
  min-width: 32px;
  text-align: right;
}
.upload-row-remove {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.upload-row-remove:hover {
  background: var(--surface-2);
  color: var(--danger);
}

/* Summary list shown after a multi-file upload batch completes.
   Mirrors the queue but with terminal states only — no progress
   bars, no remove buttons. */
.upload-summary {
  list-style: none;
  margin: 12px 0 14px;
  padding: 0;
  text-align: left;
  font-size: 12px;
}
.upload-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.upload-summary-row:last-child { border-bottom: none; }
.upload-summary-row .summary-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.upload-summary-row .summary-tag {
  flex-shrink: 0;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.upload-summary-row.ok .summary-tag { color: rgb(21, 128, 61); }
[data-theme="dark"] .upload-summary-row.ok .summary-tag { color: rgb(134, 239, 172); }
.upload-summary-row.failed .summary-tag { color: rgb(185, 28, 28); }
[data-theme="dark"] .upload-summary-row.failed .summary-tag { color: rgb(252, 165, 165); }
.upload-summary-row.skipped .summary-tag { color: rgb(180, 83, 9); }
[data-theme="dark"] .upload-summary-row.skipped .summary-tag { color: rgb(252, 211, 77); }

/* ============ Admin page ============ */
.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.admin-tab {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.admin-tab.active {
  color: var(--accent-fg);
  border-bottom-color: var(--accent);
}

/* ============ Helpers ============ */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty .empty-icon {
  margin: 0 auto 8px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
}
.empty .empty-icon svg { width: 44px; height: 44px; }

/* Drag-and-drop overlay. Shown only while the user is dragging files
   over the main listing — covers the entire scrollable area with a
   translucent panel and a centered "Drop to upload" prompt. The overlay
   sits inside #main-listing (which is set to position:relative when the
   overlay is created) so it inherits the scroll area's bounds without
   needing to track scroll offsets. pointer-events stay enabled so the
   browser delivers drop events to the overlay (and we forward them to
   the main panel via event bubbling).

   The dashed accent border + accent-tinted backdrop reads as "active
   drop target" without overpowering the file rows underneath. */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface) 88%);
  border: 2px dashed var(--accent);
  border-radius: 10px;
  z-index: 30;
  pointer-events: none;  /* let drag events fall through to main-listing */
}
.drop-overlay.show {
  display: grid;
  place-items: center;
  /* Subtle entrance — fade and slight scale-in. */
  animation: drop-overlay-in 120ms ease-out;
}
@keyframes drop-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.drop-overlay-inner {
  text-align: center;
  color: var(--accent-fg);
}
.drop-overlay-icon {
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.drop-overlay-icon svg { width: 30px; height: 30px; color: var(--accent-fg); }
.drop-overlay-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.drop-overlay-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}
[data-theme="dark"] .drop-overlay {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface) 82%);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-host {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* The host is a positioned container that exists at all times, even
     when there are no toasts. Without this, the empty container can
     sit invisibly over part of the page and eat clicks intended for
     the content underneath. The actual .toast children opt back in
     to pointer events so users can dismiss them. */
  pointer-events: none;
}
.toast { pointer-events: auto; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  min-width: 240px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  color: var(--text);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
/* Warning: partial-failure cases (e.g. bulk delete where some files
   succeeded and some hit a Protect flag). Yellow accent reads as
   "look at this" without the alarm-red of error. */
.toast.warning { border-left-color: var(--warn, #b88500); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
/* Toasts that carry an action button get a row layout so the message
   and button sit side-by-side. .toast-msg keeps the existing font;
   .toast-action renders as a small accent button. The button's hit
   target is generous (10/6 padding) since these toasts auto-dismiss
   in ~9s and you don't want to miss the click. */
.toast:has(.toast-action) {
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast .toast-msg { flex: 1; min-width: 0; }
.toast .toast-action {
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.toast .toast-action:hover { background: var(--accent-hi); }
.toast .toast-action:active { background: var(--accent-lo); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 10px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============ Popover menu (⋯ on file rows) ============ */
.popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: 4px;
  z-index: 1500;
  animation: popover-in 0.12s ease;
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}
.popover-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-weight: 400;
}
.popover-item:hover { background: var(--surface-2); }
.popover-item.danger { color: var(--danger); }
.popover-item.danger:hover { background: var(--danger-soft); }
.popover-item svg { width: 14px; height: 14px; flex-shrink: 0; }
/* Notification-style red bubble inside a popover row, used for the
   "Notifications" entry in the user menu to mirror the avatar badge.
   Auto-margin pushes it to the right edge of the row. */
.popover-item-badge {
  margin-left: auto;
  /* Match the avatar's notification badge color (var(--warn) yellow)
     so users connect "this row caused the bubble I saw on my avatar."
     Using var(--danger) red was visually loud and didn't match. */
  background: var(--warn);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.popover-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Segmented theme control (Account Settings modal) */
.theme-seg {
  background: transparent;
  border: none;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}
.theme-seg:hover { color: var(--text); }
.theme-seg.active {
  background: var(--surface);
  color: var(--accent-fg);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
[data-theme="dark"] .theme-seg.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: none;
}

/* =============================================================== */
/* Notifications                                                   */
/* =============================================================== */

/* Wrapper around the avatar provides positioning context for the
   notification badge. Without this wrapper the badge would have to
   anchor to the whole user-chip, which leaves it floating in margin
   space rather than tied to the visual identity of "you". */
.user-avatar-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

/* Notification badge — sits on the top-right corner of the user
   avatar, like a standard mobile-app icon badge. Slight overhang on
   the corner ensures it reads even when the count grows ('9+' is
   wider than the single-digit form). The 2px ring (via box-shadow)
   visually punches the badge out of the avatar so the two shapes
   don't visually merge. */
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--warn);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  letter-spacing: 0.02em;
  /* Ring against the topbar background so the badge is clearly
     "above" the avatar rather than overlapping it. The topbar's
     background is var(--surface). */
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
  /* Hidden by default; JS adds .show when unread > 0. */
  display: none;
}
.notif-badge.show { display: inline-block; }
[data-theme="dark"] .notif-badge {
  box-shadow: 0 0 0 2px var(--bg);
}
.user-chip { position: relative; }

/* Generic modal X-close button (used in notifications modal). Accounts
   for browsers' default <button> styling that would otherwise leave a
   visible border around the bare × character. */
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: all 120ms;
}
.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Notifications modal — same width as the Settings modal so it sits
   in the same visual class. */
#notifications-modal .modal { max-width: 720px; }

#notifications-modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#notifications-modal .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#notifications-modal .mark-all-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms;
}
#notifications-modal .mark-all-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
#notifications-modal .mark-all-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#notifications-modal .notif-list {
  /* Scrollable. Max height keeps very long lists from making the
     modal taller than the viewport. */
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 0;
}
#notifications-modal .notif-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
  font-size: 13px;
}

/* Each notification row. Click → navigate (handled by JS). Hover
   reveals the "Mark unread" button on the right. */
.notif-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 120ms;
  position: relative;
}
.notif-row:hover { background: var(--surface-2); }
.notif-row:last-child { border-bottom: none; }

.notif-row .notif-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  margin-top: 2px;
}
.notif-row .notif-icon svg { width: 16px; height: 16px; }
.notif-row .notif-icon.download {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.notif-row .notif-icon.upload {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.notif-row .notif-icon.expired {
  background: var(--warn-soft);
  color: var(--warn);
}
/* Retention warnings: red tint conveys urgency. The calendar icon
   inside follows currentColor so the SVG inherits this red. Same
   palette as the listing-row red calendar badge to keep the visual
   language consistent: red calendar = "this file is on a deletion
   timer." */
.notif-row .notif-icon.retention {
  background: rgba(197, 40, 40, 0.10);
  color: var(--danger, #c52828);
}
/* Mentioned: same accent treatment as download/upload — informational
   rather than alarming. Distinct icon (ICON.clock by default) is fine
   since the dispatch falls through. */
.notif-row .notif-icon.mentioned {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
/* Malware detected: same red treatment as retention warnings but more
   intense — solid red bg + white icon — so it stands out in the
   notification list as "do something about this NOW." */
.notif-row .notif-icon.danger {
  background: var(--danger, #c52828);
  color: #ffffff;
}

.notif-row .notif-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.notif-row .notif-msg {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  /* Long filenames shouldn't push the row absurdly wide. */
  word-break: break-word;
}
.notif-row.unread .notif-msg {
  font-weight: 700;
}
.notif-row .notif-coalesce {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 1px 6px;
  border-radius: 999px;
  vertical-align: middle;
}
.notif-row .notif-meta {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

/* "Mark unread" button — only visible on read rows on hover, since
   it's the only mark-as-action available there (and unread rows
   become read on click anyway, no separate button needed). */
.notif-row .notif-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 120ms;
}
.notif-row:hover .notif-actions { opacity: 1; }
.notif-row .notif-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms;
}
.notif-row .notif-action-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Unread row gets a subtle left accent bar so the bold message has
   a peer signal — keeps the design readable for users who don't
   immediately notice typeface weight. */
.notif-row.unread {
  background: var(--warn-soft);
}
.notif-row.unread:hover {
  /* Slightly darker on hover so the row still gives feedback even
     though it already has a tinted background. */
  background: color-mix(in srgb, var(--warn-soft) 60%, var(--surface-2));
}

/* Settings modal: notifications section */
.settings-section .digest-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--border);
}
.settings-section .digest-toggle-row .digest-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.settings-section .digest-toggle-row .digest-help {
  font-size: 11px;
  color: var(--text-muted);
}

/* Native checkbox-as-pill toggle, matches the visual weight of the
   theme toggle pills already in the modal. */
.toggle-pill {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-pill input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-pill .toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: 200ms;
}
.toggle-pill .toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  top: 2px;
  background: var(--surface);
  border-radius: 50%;
  transition: 200ms;
  box-shadow: var(--shadow-sm);
}
.toggle-pill input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-pill input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: #fff;
}

/* Admin-only digest-time row in the admin tab */
.admin-digest-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.admin-digest-row .digest-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.admin-digest-row .digest-help {
  font-size: 11px;
  color: var(--text-muted);
}
.admin-digest-row select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

/* =============================================================== */
/* OCR queue admin page                                            */
/* =============================================================== */

/* Status filter tabs at the top of the table */
.ocr-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.ocr-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 120ms;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ocr-tab:hover { color: var(--text); }
.ocr-tab.active {
  color: var(--accent-fg);
  border-bottom-color: var(--accent);
}
.ocr-tab .count {
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.ocr-tab.active .count {
  background: var(--accent-soft);
  color: var(--accent-fg);
}

/* Status pill — color-coded by job state */
.ocr-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ocr-status-pending {
  background: var(--surface-2);
  color: var(--text-muted);
}
.ocr-status-running {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.ocr-status-done {
  background: rgba(42, 157, 94, 0.12);
  color: var(--success);
}
.ocr-status-failed {
  background: var(--danger-soft);
  color: var(--danger);
}
.ocr-status-skipped {
  background: var(--warn-soft);
  color: var(--warn);
}
[data-theme="dark"] .ocr-status-done {
  background: rgba(78, 192, 122, 0.18);
}

/* Small button variant — used for inline retry buttons in tables */
.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* =========================================================================
   MOBILE LAYOUT
   =========================================================================
   Everything below 768px lives inside this single block. The contract:
   nothing in this section is allowed to bleed into desktop layout. Every
   rule is gated by the @media query, and any new mobile-only DOM elements
   default to display:none in their base styles (above) so desktop never
   sees them.

   The base layout is a 3-column grid (sidebar / main / preview rail).
   On mobile we collapse to a single column with:

     - Topbar gets a hamburger button on the left and a search icon on
       the right; the desktop search input is hidden.
     - Sidebar becomes an off-canvas drawer that slides in from the
       left when the hamburger is tapped. A scrim covers the rest of
       the page so taps outside the drawer close it.
     - Main listing fills the entire viewport.
     - Preview pane becomes a full-screen overlay when opened (via
       file row tap or rail icon). A close X in the top-right exits
       back to the listing.
     - Right rail (View/Details/Share/Notes/Audit) repositions to a
       horizontal bottom bar inside the preview overlay, putting
       file-specific actions where the user's thumbs are.

   Tap targets are bumped to 44x44 minimum (Apple HIG / Android MD spec).
   Modals go full-viewport so the user isn't fighting backdrops.
   ========================================================================= */

/* Default state for mobile-only DOM elements when desktop is active.
   Toggled to a flex/block display inside the media query below. These
   live OUTSIDE the media query so they're hidden on desktop regardless
   of viewport width. */
.mobile-only { display: none; }
.mobile-scrim { display: none; }
.mobile-preview-close { display: none; }
.mobile-icon-btn {
  /* Base styles for the hamburger / search / preview-close icon
     buttons. The buttons themselves are display:none on desktop via
     .mobile-only, so these properties only apply when shown on mobile.
     The display value is set inside the media query (where .mobile-only
     becomes `display: flex`) — defining it here would override the
     desktop hide because `.mobile-icon-btn` comes later in source. */
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}
.mobile-icon-btn svg { width: 22px; height: 22px; }
.mobile-icon-btn:hover { background: var(--surface-2); }
.mobile-icon-btn:active { background: var(--surface-2); }

@media (max-width: 768px) {
  /* ---- Top-level grid → single column flow ---- */
  /* Desktop has a 3-column grid (sidebar / main / rail). On mobile we
     collapse to a single column where the main listing fills available
     space; sidebar becomes off-canvas (positioned absolute and slid
     in/out via transform), preview becomes a full-screen overlay. */
  .app {
    grid-template-columns: 0 1fr 0;
    grid-template-areas:
      "topbar topbar topbar"
      "main   main   main";
  }

  /* ---- Topbar ---- */
  .topbar {
    padding: 0 8px;
    gap: 4px;
  }
  .mobile-only { display: flex; }
  /* Lockup shrinks on mobile so it doesn't crowd the topbar. The
     wordmark is the readable part — keeping it visible matters more
     than the cube being prominent. */
  .brand-lockup { height: 28px; }
  /* Desktop search input is hidden on mobile; replaced by the icon
     button + an overlay (handled in JS). */
  .search-wrap { display: none; }
  /* User chip on mobile: avatar + caret only, no name/role text. The
     full name takes too much horizontal space on a 375px viewport,
     and the avatar's initials already identify the user. */
  .user-chip-main > div:last-child { display: none; }
  .user-chip-main { padding: 4px; }
  .user-chip-caret { padding: 4px 6px; }

  /* ---- Sidebar drawer ---- */
  /* The desktop collapse toggle has no meaning in the drawer (which is
     already a show/hide affordance via the hamburger), so hide it. */
  .sidebar-collapse-btn { display: none; }
  .sidebar {
    /* Take it out of the grid and overlay it on top of main. Slid
       off-screen by default; the .open class slides it in. The
       drawer width is 280px which fits comfortably on 375px viewport
       while leaving a sliver of main content visible. */
    position: fixed;
    top: 56px;          /* below the topbar */
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms ease-out;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.12);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  /* Scrim — covers the rest of the page when drawer is open. Tap
     anywhere on it (handled in JS) to close. */
  .mobile-scrim {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 40;
  }
  .mobile-scrim.show {
    display: block;
  }

  /* ---- Topbar height tightening so it eats less vertical space ---- */
  .topbar {
    height: 56px;
    min-height: 56px;
  }
  /* Adjust the .main grid row offset to match the smaller topbar. */
  .app {
    grid-template-rows: 56px 1fr;
  }

  /* ---- Main listing area ---- */
  .main-header {
    padding: 8px 12px 10px;
    min-height: auto;
  }
  .main-listing { padding: 8px 12px 12px; }
  .breadcrumb { font-size: 12px; }
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .toolbar-left { min-width: 0; flex: 1 1 100%; }
  .toolbar-left h1 {
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .toolbar-right {
    flex: 1 1 100%;
    justify-content: flex-end;
  }
  .toolbar-right .btn { font-size: 13px; padding: 8px 12px; }
  .toolbar-right .btn span { display: inline; }

  /* ---- File listing → card-style ---- */
  /* The 6-column desktop table doesn't fit. On mobile we stack each
     row's cells vertically, using CSS to repurpose <tr> as a card and
     hide the now-redundant <th> row. Each row shows: name+icon (line 1),
     small-print meta line (size · modified · uploader). The actions
     column (a kebab on most lists) is repositioned to the top-LEFT of
     the card so it's near the user's thumb at the natural scroll-rest
     position — bottom-right used to put it under the next card on
     long lists, which made tapping ambiguous. */
  .filetable thead { display: none; }
  .filetable, .filetable tbody, .filetable tr, .filetable td {
    display: block;
    width: 100%;
  }
  .filetable tbody tr {
    border-bottom: 1px solid var(--border);
    padding: 10px 4px;
    position: relative;
  }
  .filetable td {
    border-bottom: none;
    padding: 2px 0;
  }
  .filetable td:first-child {
    /* The name cell — primary visual element of each card. */
    font-size: 15px;
    font-weight: 600;
    padding-bottom: 4px;
  }
  /* Style the meta cells (type/size/modified/uploader) as a small
     muted line. They wrap together visually rather than stacking. */
  .filetable td.mono,
  .filetable td:not(:first-child):not(.actions-cell) {
    font-size: 12px;
    color: var(--text-muted);
    display: inline-block;
    padding-right: 8px;
  }
  /* Hide some columns on mobile to keep cards readable. The "Uploaded
     By" column is the most cuttable since the row is usually the
     current user's own files anyway. */
  .filetable td:nth-child(5) { display: none; }
  /* Default actions-cell: block-level, right-aligned (used by trash
     Restore/Delete, eSign Activity "Open signed" labeled button, and
     any other multi-or-labeled-button rows). */
  .filetable .actions-cell {
    display: block;
    text-align: right;
    padding-top: 4px;
  }
  .filetable.trash-table .actions-cell .btn { font-size: 12px; }

  /* Single-icon "kebab" rows — pin the ellipsis to the top-LEFT of the
     card so it's where the thumb naturally lands when scrolling the
     list. Bottom-right used to make the kebab visually merge with the
     next card's name on long lists. Scoped via :has() to the three
     kebab patterns (Favorites/Recent, search, browse). Modern mobile
     browsers (Safari 15.4+, Chrome 105+) support :has(); older
     browsers silently fall back to the default bottom-right layout
     above, which is a fine degradation. */
  .filetable tbody tr:has(.actions-cell .qa-kebab),
  .filetable tbody tr:has(.actions-cell .search-kebab),
  .filetable tbody tr:has(.actions-cell [data-action="row-menu"]) {
    padding-left: 44px;
  }
  .filetable .actions-cell:has(.qa-kebab),
  .filetable .actions-cell:has(.search-kebab),
  .filetable .actions-cell:has([data-action="row-menu"]) {
    position: absolute;
    top: 4px;
    left: 0;
    width: 40px;
    padding: 0;
    text-align: center;
    display: block;
  }
  .filetable .actions-cell:has(.qa-kebab) .btn,
  .filetable .actions-cell:has(.search-kebab) .btn,
  .filetable .actions-cell:has([data-action="row-menu"]) .btn {
    padding: 8px 10px;
    line-height: 1;
  }

  /* ---- Preview overlay ---- */
  /* On desktop, .preview is positioned absolute right of the main
     panel and slides in via transform. On mobile we make it a
     full-screen overlay anchored to the viewport. */
  .preview {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 60;
    /* Above the topbar — preview fully takes over. */
    transform: translateX(100%);
    transition: transform 200ms ease-out;
    /* Belt-and-braces: explicitly suppress pointer events when closed.
       The desktop rule above already does this, but redeclaring here
       ensures the mobile fixed-positioned full-viewport overlay can't
       intercept taps on the listing if any browser/mobile quirk allows
       a translated-out element to still hit-test. */
    pointer-events: none;
  }
  .app.preview-open .preview {
    transform: translateX(0);
    pointer-events: auto;
  }
  /* The floating top-right close button defined in the template is
     redundant — the preview header already renders a #close-preview
     X inline next to the title (the same one used on desktop), which
     fits naturally into the top row without claiming its own block.
     Keep .mobile-preview-close hidden on mobile to reclaim the ~50px
     of vertical space it would otherwise eat. */
  .mobile-preview-close { display: none; }

  /* ---- Right rail → bottom action bar inside preview ---- */
  /* On desktop the rail is a vertical strip to the right of the main
     panel. On mobile we want file-specific actions to live where the
     user's thumbs are: a horizontal bar at the bottom of the preview
     overlay. We reposition it absolutely; rail JS doesn't change. */
  .preview-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: 56px;
    z-index: 65;
    /* Only visible when preview is open. */
    display: none;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-left: none;
    padding: 0 8px;
  }
  .app.preview-open .preview-rail {
    display: flex;
  }
  /* Reset desktop's vertical-stack rail-button styling. The buttons
     use the same .preview-rail-btn class but live in a horizontal bar now. */
  .preview-rail .preview-rail-btn {
    flex: 1;
    margin: 0;
    width: auto;
    height: 44px;
  }
  /* Rail divider — vertical on mobile (between buttons in a row). */
  .preview-rail .rail-divider {
    width: 1px;
    height: 60%;
    margin: auto 0;
  }
  /* Account for the bottom bar so preview body content isn't hidden
     under it. */
  .preview-body {
    padding-bottom: 64px;
  }

  /* Modals → full-viewport */
  /* Desktop modals are typically centered cards (e.g. 980px wide for
     Settings). On mobile we let them fill the viewport so every
     control is reachable without horizontal scroll. */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    margin: 0;
  }
  .modal-backdrop { padding: 0; }
  /* Settings tabs strip — let it scroll horizontally if the tab
     count exceeds viewport width. The wrapping behavior on desktop
     is fine but cramped at 375px; horizontal scroll keeps the labels
     legible without truncation. */
  .settings-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 0 12px;
  }
  .settings-tabs::-webkit-scrollbar { display: none; }

  /* User dropdown menu — anchor to viewport bottom (action sheet
     style) instead of dropping down from the chip. The menu element
     uses the .popover class with #user-menu-popover ID; we override
     the desktop's absolute positioning here. JS skips its inline
     top/left assignment on mobile so this CSS isn't fighting it. */
  #user-menu-popover {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100%;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  }
  #user-menu-popover .popover-item {
    padding: 14px 18px;
    font-size: 15px;
  }

  /* Mobile search overlay — the desktop search-wrap is hidden, and
     when the user taps the search icon, JS adds .show to this overlay.
     The overlay is a full-width input bar pinned below the topbar. */
  .mobile-search-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 45;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }
  .mobile-search-overlay.show {
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .mobile-search-overlay input {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
  }
  .mobile-search-overlay .mobile-search-results {
    position: fixed;
    top: 112px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 112px);
    overflow-y: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  /* Hide the drag-drop overlay on mobile entirely — touch devices
     don't have drag affordances, so showing the overlay would be
     dead weight. JS also bails on isMobile() but this CSS is a
     defensive fallback. */
  .drop-overlay { display: none !important; }

  /* Tap target sizing — bump buttons to 44x44 minimum where they're
     not already there. Most desktop buttons are 32-36 high, which
     fingers can hit but feels cramped. */
  .btn {
    min-height: 40px;
    padding: 10px 14px;
  }
  .btn.btn-sm { min-height: 32px; }

  /* Toast positioning — on desktop toasts pin to the top-right;
     on mobile they need to sit at the bottom centered and clear of
     any system UI. Reset the desktop `top: 70px` so the host doesn't
     stretch the full viewport height (with both top and bottom set
     on a position:fixed element, the box fills the gap between them
     and intercepts clicks even when empty). */
  .toast-host {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
  .toast { width: 100%; }

  /* Notes / details panel padding tuning — tighter horizontal so the
     content uses available width instead of feeling marooned. */
  .preview-body { padding: 12px 14px 64px; }
  .preview-header { padding: 10px 56px 10px 14px; }

  /* iOS safe-area insets — keep the bottom rail and toasts above the
     home indicator. env(safe-area-inset-bottom) returns 0 on browsers
     that don't support it, so this is a clean upgrade for iOS. */
  .preview-rail {
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .toast-host {
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* List filter / sort controls on mobile. The toolbar is tight, so
     we give the filter input a smaller width when expanded and pin
     the wrap so it doesn't overflow into action buttons. The icons
     themselves stay 32px and reachable. */
  .list-filter-input.is-open {
    width: 140px;
  }
  .list-controls-divider {
    margin: 0 2px;
  }
  .list-controls {
    gap: 2px;
  }
  /* When the side drawer is open, hide the list-controls (filter
     funnel and clear-X). The drawer pushes the topbar's effective
     workspace narrower, and the filter input would otherwise jumble
     up against the title and action buttons. The user can re-open
     the filter after closing the drawer; the drawer is a navigation
     surface, not a place to be filtering. */
  .app.drawer-open .list-controls {
    display: none;
  }
}

/* =============================================================
   Admin shell (/admin) — full-page SPA, left rail + main content
   ============================================================= */
body.admin-page {
  background: var(--bg);
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.admin-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  /* Drop-shadow on scroll keeps the rail/content combo from looking
     glued to the topbar — small visual separation. */
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.admin-brand {
  flex: 0 0 auto;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  /* Logo gets a subtle hover state so admins know it's clickable
     for Home — primary navigation back to ShareBox. */
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.15s ease;
}
.admin-brand:hover { background: var(--surface-2); }
.admin-brand .brand-lockup { height: 28px; }
.admin-title-wrap {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.admin-title-wrap #admin-page-title { color: var(--text); }
.admin-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-topbar .user-chip {
  cursor: default;  /* No menu yet on admin page; chip is informational. */
}
/* Admin Guide download pill - matches the theme-toggle pill styling so the
   topbar reads as one set of controls. */
.admin-guide-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  cursor: pointer;
}
.admin-guide-btn:hover { background: var(--surface-2); color: var(--text); }
.admin-guide-btn svg { width: 14px; height: 14px; }
/* On narrow screens, keep just the icon to save room. */
@media (max-width: 640px) {
  .admin-guide-btn span { display: none; }
  .admin-guide-btn { padding: 6px; }
}
.admin-topbar .avatar-bubble {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

/* Layout: left rail fixed-width, main scrollable. The topbar above
   stays sticky; the rail is sticky too so it stays in view as the
   main content scrolls. */
.admin-shell {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}
.admin-rail {
  flex: 0 0 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 8px;
  position: sticky;
  top: 49px;  /* below topbar */
  height: calc(100vh - 49px);
  overflow-y: auto;
}
.admin-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.admin-nav-item:hover { background: var(--surface-2); }
.admin-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.admin-nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.admin-nav-item span:first-of-type { flex: 1; }
.admin-nav-count {
  font-size: 10px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.admin-nav-item.active .admin-nav-count {
  background: var(--accent);
  color: white;
}

.admin-main {
  flex: 1 1 auto;
  padding: 28px 32px;
  overflow-x: auto;
  min-width: 0;
}

/* Tab content scaffolding */
.admin-tab-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
}
.admin-tab-header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.admin-tab-actions {
  display: flex;
  gap: 8px;
}
.admin-tab-blurb {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
  max-width: 720px;
}
.admin-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.admin-search {
  flex: 1 1 280px;
  min-width: 240px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.admin-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.admin-result-count {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Table layout — scrollable container, sticky header. */
.admin-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  overflow-x: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table thead th {
  text-align: left;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 700;
  white-space: nowrap;
}
.admin-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-th-actions { text-align: right; }
.admin-row-actions {
  text-align: right;
  white-space: nowrap;
}
.admin-row-actions .btn { margin-left: 4px; }

/* Checkbox column — narrow, centered. Used by Active Links bulk
   revoke; pattern reusable for any future bulk-action tab. */
.admin-th-checkbox,
.admin-td-checkbox {
  width: 32px;
  text-align: center;
  padding-left: 8px !important;
  padding-right: 4px !important;
}
.admin-th-checkbox input,
.admin-td-checkbox input {
  cursor: pointer;
  margin: 0;
  vertical-align: middle;
}

/* Clickable rows in admin tables — used in the Archive tab for
   user/folder navigation. Hover state already comes from the
   existing tr:hover rule; this just adds the cursor cue. */
.admin-clickable-row {
  cursor: pointer;
}

/* Breadcrumb in archive folder navigation. Subtle, clear hierarchy
   marker; current segment renders bold without a link cursor. */
.admin-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--surface-2, #f6f7f9);
  border-radius: 6px;
  font-size: 13px;
}
.admin-breadcrumb a {
  color: var(--accent, #1f5fc7);
  text-decoration: none;
}
.admin-breadcrumb a:hover { text-decoration: underline; }
.admin-breadcrumb-current {
  font-weight: 600;
  color: var(--text);
}
.admin-breadcrumb-sep {
  color: var(--text-dim);
}
.admin-detail-cell {
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
  font-size: 12px;
}
.admin-empty-row {
  text-align: center;
  color: var(--text-dim);
  font-style: italic;
  padding: 32px 14px !important;
}

/* Pills used in admin table cells */
.admin-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-3);
  color: var(--text-dim);
}
.admin-pill.ok { background: rgba(34,197,94,0.15); color: rgb(21,128,61); }
[data-theme="dark"] .admin-pill.ok { background: rgba(34,197,94,0.2); color: rgb(134,239,172); }
.admin-pill.warn { background: rgba(245,158,11,0.15); color: rgb(180,83,9); }
[data-theme="dark"] .admin-pill.warn { background: rgba(245,158,11,0.2); color: rgb(252,211,77); }
.admin-pill.danger { background: rgba(239,68,68,0.15); color: rgb(185,28,28); }
[data-theme="dark"] .admin-pill.danger { background: rgba(239,68,68,0.2); color: rgb(252,165,165); }
.admin-pill.subtle { background: var(--surface-3); color: var(--text-dim); }
.admin-pill.role-admin { background: rgba(168,85,247,0.15); color: rgb(126,34,206); }
[data-theme="dark"] .admin-pill.role-admin { background: rgba(168,85,247,0.2); color: rgb(216,180,254); }
.admin-pill.role-user { background: rgba(59,130,246,0.15); color: rgb(29,78,216); }
[data-theme="dark"] .admin-pill.role-user { background: rgba(59,130,246,0.2); color: rgb(147,197,253); }
.admin-pill.role-guest { background: var(--surface-3); color: var(--text-dim); }

/* Sections + cards (used by Operations, Settings, Integrations) */
.admin-section { margin-bottom: 32px; }
.admin-section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 700;
}
.admin-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}
.admin-card .field { margin-bottom: 14px; }
.admin-card .field:last-of-type { margin-bottom: 16px; }
.admin-card-status {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
}
.admin-card-status.ok { color: rgb(21,128,61); }
[data-theme="dark"] .admin-card-status.ok { color: rgb(134,239,172); }
.admin-card-status.warn { color: rgb(180,83,9); }
[data-theme="dark"] .admin-card-status.warn { color: rgb(252,211,77); }
.admin-card-status.danger { color: rgb(185,28,28); }
[data-theme="dark"] .admin-card-status.danger { color: rgb(252,165,165); }
.admin-card-detail {
  color: var(--text-dim);
  font-size: 12px;
}
.admin-placeholder {
  color: var(--text-dim);
  font-size: 13px;
}
.admin-bullets {
  margin: 8px 0 12px 18px;
  padding: 0;
}
.admin-bullets li {
  margin-bottom: 4px;
}

/* Manage-team modal mini-list (members inside a modal body) */
.admin-mini-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-height: 280px;
  overflow-y: auto;
}
.admin-mini-row {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.admin-mini-row:last-child { border-bottom: none; }
.admin-mini-name { flex: 1; }
.admin-mini-email {
  color: var(--text-dim);
  font-size: 11px;
  margin-left: 6px;
}

/* Loading + error states */
.admin-loading {
  padding: 60px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.admin-error {
  padding: 14px;
  border: 1px solid var(--danger);
  background: rgba(239,68,68,0.08);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
}
.admin-empty {
  padding: 60px 32px;
  text-align: center;
  color: var(--text-dim);
}
.admin-modal-error {
  padding: 10px 12px;
  background: rgba(239,68,68,0.08);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 12px;
  margin-bottom: 12px;
}

/* Small-button modifier used heavily in admin row actions. */
.btn.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}
.btn.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn.btn-ghost:hover {
  background: var(--surface-2);
}

.dim { color: var(--text-dim); font-style: italic; font-size: 12px; }

/* Responsive: stack rail above content on narrow screens.
   The rail collapses into a horizontal scroll strip on mobile so
   admins can still navigate without a hamburger menu. */
@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .admin-rail {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .admin-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .admin-nav-item {
    white-space: nowrap;
    padding: 8px 12px;
  }
  .admin-main { padding: 16px; }
  .admin-tab-header { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* Operations dashboard — grid of cards.
   Two cards per row at typical widths; collapses to one on mobile.
   Each card carries a single metric or grouping. Title is small caps. */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.ops-card-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 700;
  margin: 0 0 10px;
}
.ops-stat-big {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  color: var(--text);
}
.ops-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.ops-stat-grid > div {
  display: flex;
  flex-direction: column;
}
.ops-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.ops-stat-num {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Storage breakdown bars — one row per scope, label left, bar
   middle, value right. Bars are width-proportional to the largest
   slice so the smallest is still visible. */
.ops-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.ops-bar-row {
  display: grid;
  grid-template-columns: 64px 1fr 80px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.ops-bar-label {
  text-transform: capitalize;
  color: var(--text-dim);
}
.ops-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.ops-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.ops-bar-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

/* Background-job heartbeats — label/value pair, dim if stale */
.ops-hb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ops-hb-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.ops-hb-row:last-child { border-bottom: none; }
.ops-hb-row.stale { color: rgb(180,83,9); }
[data-theme="dark"] .ops-hb-row.stale { color: rgb(252,211,77); }

/* OCR error rows */
.ops-err-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ops-err-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.ops-err-msg {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
}

/* Segmented method-picker (e.g. cert vs secret in M365 admin form).
   Two-button toggle styled as a single pill-shape with the active
   state having the accent color. Plain button bg + accent for active. */
.seg-group {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}
.seg-group .seg-btn {
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}
.seg-group .seg-btn:hover {
  color: var(--text);
}
.seg-group .seg-btn.active {
  background: var(--accent);
  color: white;
}

/* OneDrive integration view (Phase 2).
   The view reuses .filetable for the listing so styling stays
   consistent with ShareBox's normal browse view. We only need a
   handful of view-specific tweaks here. */
.onedrive-search-header {
  padding: 0 0 14px 0;
}
.onedrive-search-input {
  width: 100%;
  max-width: 540px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}
.onedrive-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* Search results: show the parent path under the file name so users
   can tell where the hit lives in their OneDrive tree. */
.onedrive-row-path {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
/* OneDrive Load More: the wrapper div IS the button. We removed the
   nested <button class="btn"> because the base .btn flex layout was
   creating subtle hit-testing gaps where the visible rectangle was
   bigger than the actual button element. Now there's exactly one
   element, exactly one click target, exactly one rectangle. */
.onedrive-more {
  display: block;
  width: 100%;
  margin: 14px 0;
  padding: 14px 14px;
  box-sizing: border-box;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background .15s, border-color .15s;
}
.onedrive-more:hover {
  background: var(--surface-3, var(--surface-2));
  border-color: var(--border-strong, var(--border));
}
.onedrive-more:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.onedrive-more[data-loading="1"] {
  opacity: 0.65;
  cursor: wait;
}
.onedrive-more-label {
  pointer-events: none;
  display: inline-block;
}

/* OneDrive row action — bare share icon. No button chrome (no border,
   no background, no padding). The icon sizes to match the surrounding
   row text height so the row stays uniform on scroll. Hover lights
   up the icon color to signal interactivity; that's enough cue. */
.onedrive-share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s;
  vertical-align: middle;
}
.onedrive-share-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}
.onedrive-share-btn:hover {
  background: transparent;
  color: var(--accent-fg);
}
.onedrive-share-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Star toggle button. Same visual rhythm as .onedrive-share-btn —
   tiny inline icon, transparent background, dim default color
   that wakes up on hover. The favorited state fills the star with
   the gold-ish accent so a glance at the row tells you "starred."
   Hollow outline is the default (unfavorited). */
.onedrive-star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  margin-right: 4px;     /* small gap before the share button */
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s;
  vertical-align: middle;
}
.onedrive-star-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}
.onedrive-star-btn:hover {
  /* On hover, dim outline brightens to accent — readable affordance
     for "click me." Color matches hover style of .onedrive-share-btn
     for visual coherence. */
  color: var(--accent-fg);
}
.onedrive-star-btn.is-favorited {
  /* Filled gold for favorited state. Standard "starred" affordance
     across most apps; users will read it correctly without needing
     a tooltip. Keeps the same color-on-hover so the active state
     stays visually stable. */
  color: #f59e0b;        /* warm gold, readable on light + dark */
}
[data-theme="dark"] .onedrive-star-btn.is-favorited {
  color: #fbbf24;        /* slightly brighter for dark mode */
}
.onedrive-star-btn.is-favorited:hover {
  /* Hover on a favorited star — dim slightly to hint "click to
     unstar" (the action is destructive-ish so a darker shade
     reads as a warning rather than the "click me" brightening
     of the unfavorited state). */
  color: #d97706;
}
.onedrive-star-btn.is-stale {
  /* Stale favorite: item moved/deleted in OneDrive. Render the
     star muted-amber so the user notices it differs from healthy
     favorites; tooltip explains the state. */
  color: var(--text-dim);
  opacity: 0.6;
}
.onedrive-star-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* OneDrive table actions column: just enough room for the icon and
   a small right margin. Browsers compute the rest of the columns
   naturally based on content, which keeps the Name column from
   feeling padded with empty space on wide viewports. */
.onedrive-table .filetable-col-actions {
  /* Was 36px when only a share button lived here. Now we have a
     star + a share button, each ~18px wide with a 4px gap and
     8px right padding — bumped to 64px to accommodate both
     without crowding. Folder rows render the star but no share
     button (folders aren't shareable through the existing copy-
     and-share flow), so the column has a small dead space on
     folder rows; that's preferable to the column dynamically
     resizing per-row. */
  width: 64px;
  text-align: right;
  padding-right: 8px;
}
.onedrive-table {
  width: 100%;
}
.onedrive-table thead th {
  text-align: left;
}
/* Long names truncate cleanly via the inner flex+ellipsis in the
   name cell. The cell itself just needs nowrap so a multi-line
   name doesn't make the row tall. */
.onedrive-table td.name-cell {
  white-space: nowrap;
}

/* ===========================================================================
   Phase 2 notes — @mention chips, edit affordance, autocomplete popup
   ========================================================================= */

/* Inline @mention chip rendered inside note bodies. Same accent color
   regardless of bubble side; readable on both backgrounds. */
.mention-chip {
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--accent-bg, rgba(63, 122, 255, 0.18));
  color: var(--accent, #2160e6);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.note-bubble-self .mention-chip {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.mention-chip:hover { filter: brightness(1.05); }
.mention-chip-removed {
  background: rgba(127,127,127,0.2);
  color: var(--text-dim);
  cursor: default;
}

/* Team mention chip — visually distinct from user chips so a glance
   tells you whether a note pings one person vs an entire team. We
   use a warmer hue (amber-ish) to signal "louder" without being
   alarming; user chips stay on the cool accent color. Keep the same
   shape, padding, and font-weight so chips align in the same line. */
.mention-chip-team {
  background: rgba(245, 158, 11, 0.18);  /* amber-500 @ ~18% */
  color: #b45309;                         /* amber-700 — readable on both light & dark surfaces */
}
.note-bubble-self .mention-chip-team {
  background: rgba(255, 220, 130, 0.30);
  color: #fff;
}

/* "(edited)" indicator next to the timestamp on edited bubbles. */
.note-edited {
  font-style: italic;
  margin-left: 4px;
  opacity: 0.7;
}

/* Edit pencil button — sits between author/time and delete. */
/* Edit pencil button — sits between author/time and delete.
   Hidden by default and revealed on bubble hover so it doesn't
   clutter the chat layout — same pattern most chat UIs use. */
.note-edit {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 120ms;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.note-edit svg { width: 12px; height: 12px; }
.note-row:hover .note-edit,
.note-edit:focus { opacity: 0.85; }
.note-row:hover .note-edit:hover { opacity: 1; }
.note-bubble-self  .note-edit { color: rgba(255,255,255,0.85); }
.note-bubble-other .note-edit { color: var(--text-muted); }

/* Same hover-reveal for the delete button (cleaner than always-visible). */
.note-row .note-delete {
  opacity: 0;
  transition: opacity 120ms;
}
.note-row:hover .note-delete,
.note-delete:focus { opacity: 0.65; }
.note-row:hover .note-delete:hover { opacity: 1; }

/* Inline edit textarea (replaces the bubble's content during edit). */
.note-edit-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.note-bubble-self .note-edit-input {
  background: rgba(255,255,255,0.95);
  color: var(--text);
}

/* @-autocomplete popup — floats above the composer textarea. */
.mention-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 60px;  /* leave room for the send button */
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  margin-bottom: 4px;
  z-index: 10;
}
.mention-popup-item {
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
}
.mention-popup-item.active,
.mention-popup-item:hover {
  background: var(--accent-bg, rgba(63,122,255,0.12));
}
/* Team rows in the autocomplete popup get a small left accent bar in
   the same amber as the team chip, plus a slightly different active
   tint, so users can see at a glance "this option pings the whole
   team" before clicking. */
.mention-popup-team {
  border-left: 3px solid rgba(245, 158, 11, 0.6);
  padding-left: 7px;  /* compensate so text alignment matches non-team rows */
}
.mention-popup-team.active,
.mention-popup-team:hover {
  background: rgba(245, 158, 11, 0.10);
}
.mention-popup-email {
  color: var(--text-dim);
  font-size: 11px;
}
.mention-popup-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Mention chip popover (clicking a chip shows user info). */
.mention-popover {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 10px 14px;
  z-index: 1000;
  font-size: 12px;
  min-width: 160px;
  max-width: 280px;
}

/* ---------------------------------------------------------------------
   Phantom rows — in-flight uploads rendered in the destination folder's
   listing so the user sees where their file is landing. Visually
   distinguished from real rows (dimmed background, italic name, no
   hover affordance) so they don't get mistaken for a real file at a
   glance. Pinned to the top of the file list by render order, not by
   CSS — keeps things simple.
   --------------------------------------------------------------------- */
.filetable tr.phantom-row {
  background: var(--accent-soft);
  cursor: default;
}
.filetable tr.phantom-row:hover {
  /* Override the default row-hover highlight — phantoms aren't clickable. */
  background: var(--accent-soft);
}
.filetable tr.phantom-row td {
  /* Match the natural padding of a real file row — the only extra
     content in the name cell is the 4px progress bar (with a 4px
     margin), so the row reads as the same height as a normal row.
     vertical-align:top keeps the name + bar visually anchored under
     the other columns' single line of text. */
  vertical-align: top;
}
.filetable tr.phantom-row .name-text {
  /* Italic + slightly dimmed name so the eye reads it as "not yet
     a real file." Pairs with the tinted background. */
  font-style: italic;
  color: var(--text);
  opacity: 0.92;
}
.filetable tr.phantom-row .phantom-file-icon {
  /* Same icon as a normal file row, painted in the brand accent so
     the row's leading visual matches the tinted background. */
  display: inline-flex;
  align-items: center;
  width: 18px;
  height: 18px;
  color: var(--accent-fg);
  margin-right: 6px;
  flex-shrink: 0;
}
.filetable tr.phantom-row .phantom-name-cell {
  display: flex;
  align-items: center;
  min-width: 0;
}
.filetable tr.phantom-row .phantom-progress {
  margin-top: 4px;
  height: 4px;
  width: 100%;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.filetable tr.phantom-row .phantom-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.15s ease-out;
}
.filetable tr.phantom-row .phantom-progress-fill.is-indeterminate {
  /* Reuses the same moving-stripe keyframe as the tray's scanning
     indicator (defined up around L654) so the two surfaces stay
     visually synced. */
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--surface-3) 0%,
    var(--accent) 50%,
    var(--surface-3) 100%
  );
  background-size: 200% 100%;
  animation: upload-row-indeterminate 1.6s linear infinite;
  transition: none;
}
