:root {
  --bg: #f5f6f5;
  --surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sidebar: #0C2A4A;
  --sidebar-fg: #f1f3f2;
  --sidebar-fg-muted: #aeb8c4;   /* cool grey — was grey-green #b8bdba */
  --sidebar-border: #081f38;     /* darker navy divider / pressed btn — was grey-green #3a3f3c */
  --sidebar-hover: #173a5e;      /* lighter navy hover — was grey-green #5a615c */
  --fg: #1a1a1a;
  --fg-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #0C2A4A;
  --accent-fg: #ffffff;
  --hover: #eef0f3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);

  --sidebar-w: 240px;
  --topbar-h: 64px;
  --footer-h: 42px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  letter-spacing: -0.005em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Full-page loader — shown on first paint, fades out on window load.
   Emulates the ECI_NEXUS_v2 loader: a centred, icon-only spinner (the brand
   star mark rendered in the primary colour via CSS mask) with a smooth
   opacity fade-out (the loader node is removed on transitionend — see the
   inline script before </body>). */
#page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#page-loader.fade-out {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.page-loader-spinner {
  width: 44px;
  height: 44px;
  background: var(--accent);
  -webkit-mask: url("../img/logo_light_icon.png") center / contain no-repeat;
          mask: url("../img/logo_light_icon.png") center / contain no-repeat;
  animation: page-loader-spin 2.5s linear infinite;
}
@keyframes page-loader-spin {
  to { transform: rotate(360deg); }
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr var(--footer-h);
  grid-template-areas:
    "sidebar topbar"
    "sidebar main"
    "sidebar footer";
  /* Pin to viewport height so the `1fr` middle row resolves to a fixed
     size — `.main`'s existing `overflow-y: auto` then scrolls inside
     the row, and the document page's flex/grid children stop growing
     with their content (search card + PDF viewer stay rooted). */
  height: 100vh;
  /* Animate the collapse/expand of the sidebar rail (browsers that don't
     support animating grid tracks just snap — harmless). */
  transition: grid-template-columns 160ms ease;
}

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  color: var(--sidebar-fg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--sidebar-border);
}

/* Safety clamp — nothing in the brand header can overflow, whatever the
   per-image rules resolve to (guards against a stale-CSS/HTML mismatch). */
.sidebar-logo img { max-width: 100%; max-height: 52px; }

/* Expanded: the full wordmark (logo_light_full). Collapsed: swapped for the
   square icon-only mark (logo_light_icon). */
.sidebar-logo .logo-full {
  height: 39px;
  width: auto;
  display: block;
  object-fit: contain;
}

.sidebar-logo .logo-icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  flex-shrink: 0;
  display: none;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav .nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--sidebar-fg-muted);
  padding: 10px 12px 6px;
  font-weight: 600;
}

.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--sidebar-fg-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-fg);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;
  font-weight: 600;
}

.sidebar-nav .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-nav a.active .nav-icon { opacity: 1; }

/* ── Collapsed sidebar (icon-only rail) ──────────────────────────────────────
   Toggled by `.sidebar-collapsed` on <html> (persisted in localStorage, applied
   pre-paint by the head script). Narrowing `--sidebar-w` shrinks the grid
   column; the full wordmark swaps out for the square icon mark, labels hide,
   and icons centre. Native `title` tooltips (set in JS) stand in for labels. */
html.sidebar-collapsed { --sidebar-w: 66px; }
html.sidebar-collapsed .sidebar-logo { gap: 0; padding-left: 0; padding-right: 0; }
html.sidebar-collapsed .sidebar-logo .logo-full { display: none; }
html.sidebar-collapsed .sidebar-logo .logo-icon { display: block; }
html.sidebar-collapsed .sidebar-nav { padding-left: 8px; padding-right: 8px; }
html.sidebar-collapsed .sidebar-nav a {
  justify-content: center;
  gap: 0;
  padding-left: 0;
  padding-right: 0;
}
html.sidebar-collapsed .sidebar-nav a > span { display: none; }

/* Topbar */
.topbar {
  grid-area: topbar;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Left cluster: sidebar toggle + optional page title. */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* Sidebar collapse toggle. Always visible so a collapsed rail can be reopened. */
.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--fg-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.sidebar-toggle:hover {
  background: var(--bg-elevated);
  color: var(--fg);
  border-color: var(--fg-muted);
}
.sidebar-toggle svg { width: 18px; height: 18px; }

.topbar-title {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.005em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Right cluster: page actions + the logged-in user chip. */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-user-wrap { position: relative; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 9px;
  border: none;
  border-radius: 20px;
  background: var(--hover);          /* always highlighted — reads as a card */
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.topbar-user:hover,
.topbar-user[aria-expanded="true"] {
  background: var(--border);
}
.topbar-user-caret {
  width: 16px;
  height: 16px;
  color: var(--fg-muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.topbar-user[aria-expanded="true"] .topbar-user-caret { transform: rotate(180deg); }

/* Dropdown card (Sign out lives here now — moved out of the sidebar). */
.topbar-user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 200;
}
.topbar-user-menu[hidden] { display: none; }
.topbar-user-menu-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.topbar-user-menu-name { font-size: 13px; font-weight: 600; color: var(--fg); }
.topbar-user-menu-role { font-size: 11px; color: var(--fg-muted); }
.topbar-user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  transition: background-color 0.12s ease;
}
.topbar-user-menu-item:hover { background: var(--hover); }
.topbar-user-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.topbar-user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
}
.topbar-user-avatar svg { width: 18px; height: 18px; }
.topbar-user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;   /* both lines start at the left, right of the avatar */
  gap: 3px;                  /* breathing room between name and role */
  line-height: 1.2;
  text-align: left;
}
.topbar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.topbar-user-role {
  font-size: 11px;
  color: var(--fg-muted);
}

/* Main */
.main {
  grid-area: main;
  padding: 24px;
  overflow-y: auto;
}

/* Files: search + tabs */
.files-search {
  margin: 0;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  max-width: 580px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 150ms ease, border-color 150ms ease;
}

.search-bar:hover {
  box-shadow: 0 1px 6px rgba(32, 33, 36, 0.12);
}

.search-bar:focus-within {
  border-color: transparent;
  box-shadow: 0 1px 8px rgba(32, 33, 36, 0.18);
}

.search-bar .search-icon {
  width: 18px;
  height: 18px;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.search-bar input[type="search"] {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  padding: 4px 0;
}

.search-bar input[type="search"]::placeholder {
  color: var(--fg-muted);
}

.search-bar input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search-tabs {
  display: flex;
  gap: 24px;
  margin-top: 16px;
  padding: 0 4px;
  border-bottom: 1px solid var(--border);
}

/* Analytics card (left) + results (right). The meta lines sit above this,
   with a gap so the columns get breathing room beneath them. */
.search-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  margin-top: 18px;
}
.search-main { flex: 1; min-width: 0; }              /* ~col-8/9 */
.search-facets {
  flex: 0 0 300px;                                    /* ~col-3/4 */
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.facet-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}
/* Sections inside the single analytics card, separated by a divider line. */
.facet-section + .facet-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.facet-card-head { margin-bottom: 14px; }
.facet-card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.facet-card-empty {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted);
}

/* Whole-card empty state (no analytics for the result set). */
.facet-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  text-align: center;
}
.facet-empty-icon {
  width: 28px;
  height: 28px;
  color: var(--fg-muted);
  opacity: 0.6;
}
.facet-empty-text {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted);
}

/* Date histogram: flex columns, bars grown from the bottom. Drag across to
   select a month range. */
.facet-hist {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  cursor: crosshair;
  user-select: none;
}
.facet-hist-col {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  text-decoration: none;
}
.facet-hist-bar {
  width: 100%;
  min-height: 2px;
  background: rgba(12, 42, 74, 0.30);   /* muted by default */
  border-radius: 2px 2px 0 0;
  transition: background 120ms ease;
}
.facet-hist-col:hover .facet-hist-bar { background: rgba(12, 42, 74, 0.5); }
/* Highlight the live drag selection and the applied range in full accent. */
.facet-hist-col.is-selecting .facet-hist-bar,
.facet-hist-col.is-active .facet-hist-bar { background: var(--accent); }
.facet-hist-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--fg-muted);
}

/* Top companies / collections list. */
.facet-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.facet-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 6px;
  margin: 0 -6px;                 /* bleed into card padding for full-width hover */
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.facet-list-item:hover { background: var(--hover); text-decoration: none; }
/* Selected facet row — accent tint + an inset accent bar so the active filter
   reads clearly and stays on-brand (tracks --accent, incl. custom branding). */
.facet-list-item.is-active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: inset 2px 0 0 var(--accent);
}
.facet-list-item.is-active:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.facet-list-item.is-active .facet-list-name { font-weight: 600; color: var(--accent); }
.facet-list-item.is-active .facet-list-count { color: var(--accent); }

/* Facet list rows past the first 5 stay hidden until "Show more" expands them. */
.facet-row-hidden { display: none; }
.facet-section.is-expanded .facet-row-hidden { display: block; }

.facet-more {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  margin-left: -6px;
  padding: 4px 6px;
  background: none;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background 120ms ease;
}
.facet-more:hover { background: var(--hover); }
.facet-more-caret { width: 14px; height: 14px; transition: transform 150ms ease; }
.facet-section.is-expanded .facet-more-caret { transform: rotate(180deg); }
.facet-more-close { display: none; }
.facet-section.is-expanded .facet-more-open { display: none; }
.facet-section.is-expanded .facet-more-close { display: inline; }

/* Active filters block above the analytics card — a labelled header with a
   Clear-all, then the chips. */
.facet-active {
  margin-bottom: 14px;
}
.facet-active-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.facet-active-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.facet-active-clearall {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.facet-active-clearall:hover { text-decoration: underline; }
.facet-active-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.facet-active-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.facet-active-ico { width: 16px; height: 16px; border-radius: 3px; object-fit: cover; }
.facet-active-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-active-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--accent-fg);
  text-decoration: none;
  opacity: 0.75;
  flex-shrink: 0;
  transition: opacity 120ms ease, background 120ms ease;
}
.facet-active-clear svg { width: 11px; height: 11px; }
.facet-active-clear:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.22);
  text-decoration: none;
}

/* Professional empty state when a query has no results. */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 72px 24px;
  text-align: center;
}
.search-empty-icon {
  width: 40px;
  height: 40px;
  color: var(--fg-muted);
  opacity: 0.7;
}
.search-empty-text {
  margin: 0;
  font-size: 14px;
  color: var(--fg-muted);
}
.facet-list-ico {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--accent);
  overflow: hidden;
}
.facet-list-ico img { width: 100%; height: 100%; object-fit: cover; }
/* Type-logo icons (pdf/word/excel/…) are contained, not cropped like the
   mailbox favicons above; slight padding keeps the glyph off the edges. */
.facet-list-ico img.facet-list-ico-img { object-fit: contain; padding: 2px; }
.facet-list-ico svg { width: 13px; height: 13px; }
.facet-list-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}
.facet-list-count {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
}

@media (max-width: 860px) {
  .search-layout { flex-direction: column; }
  .search-facets { flex-basis: auto; width: 100%; position: static; }
}

.search-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 2px;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
}

.search-tabs a:hover {
  color: var(--fg);
  text-decoration: none;
}

.search-tabs a.active {
  color: var(--bg-sidebar);
  border-bottom-color: var(--bg-sidebar);
  font-weight: 600;
}

.search-tabs .tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Home dashboard (/) */
.dashboard-header {
  margin-bottom: 20px;
}

.dashboard-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.dashboard-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--fg-muted);
}

/* Home dashboard chart row — 12-col grid so cards can span 4 / 8. */
.dash-charts {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
  align-items: stretch;
}

.dash-charts .col-4 { grid-column: span 4; }
.dash-charts .col-8 { grid-column: span 8; }

@media (max-width: 900px) {
  .dash-charts .col-4,
  .dash-charts .col-8 { grid-column: 1 / -1; }
}

.chart-donut {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
}

/* Files overview — no-query state */
.files-overview {
  margin-top: 28px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  /* Simple horizontal card: icon on the left, count + label stacked beside it. */
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-card-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 9px;
  background: rgba(12, 42, 74, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-card-icon svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.stat-card-body {
  min-width: 0;
}

.stat-card-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.stat-card-label {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
}

/* Ingestion chart */
.chart-card {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 14px 8px;
  box-shadow: var(--shadow);
}

.chart-card-header {
  margin-bottom: 8px;
}

.chart-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-muted);
}

.line-chart {
  display: block;
  overflow: visible;
}

.chart-card--muted {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  color: var(--fg-muted);
  font-size: 12px;
  font-style: italic;
}

/* Empty state */
.files-empty {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.files-empty svg {
  width: 36px;
  height: 36px;
  color: var(--fg-muted);
  opacity: 0.5;
  margin-bottom: 4px;
}

.files-empty p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-muted);
}

.files-empty-hint {
  font-size: 12px !important;
  font-weight: 400 !important;
}

/* Search results */
.search-meta {
  margin-top: 18px;
  color: var(--fg-muted);
  font-size: 12px;
}

/* Meta line (left) + sort control (right). */
.search-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.search-meta-row .search-meta { margin-top: 0; }

.search-sort {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-sort-label {
  font-size: 12px;
  color: var(--fg-muted);
}
.search-sort-select {
  font: inherit;
  font-size: 13px;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
    no-repeat right 9px center;
  color: var(--fg);
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  transition: border-color 140ms ease;
}
.search-sort-select:hover { border-color: rgba(12, 42, 74, 0.35); }
.search-sort-select:focus {
  outline: none;
  border-color: var(--bg-sidebar);
  box-shadow: 0 0 0 3px rgba(12, 42, 74, 0.12);
}

.search-results {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  max-width: 760px;
}

.result {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.result:last-child { border-bottom: 0; }

.result-preview-link {
  display: block;
  flex-shrink: 0;
  width: 96px;
  aspect-ratio: 3 / 4;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 4px 12px -4px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.result-preview-link:hover {
  transform: translateY(-1px);
  border-color: rgba(12, 42, 74, 0.3);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.05),
    0 8px 18px -6px rgba(0, 0, 0, 0.14);
}

.result-preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}

/* Word / PowerPoint results re-use the preview slot but show a static type
   icon, so contain + pad it (centred) instead of cover-cropping like a real
   page preview. */
.result-preview--icon {
  object-fit: contain;
  object-position: center;
  padding: 16px;
}

/* Audio results re-use the preview slot but the waveform PNG is
   wider-than-tall, so we override the 3/4 aspect ratio + the
   cover/top alignment to give it more horizontal room. */
.result-preview-link--audio {
  aspect-ratio: 5 / 3;
  width: 160px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Anchor for the absolute-positioned play overlay. */
  position: relative;
}

.result-preview-link--audio:hover {
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

.result-preview--waveform {
  object-fit: contain;
  object-position: center;
}

/* Play-triangle overlay on the audio waveform thumbnail. Hidden by
   default on pointer devices — fades in on hover/focus to advertise
   that the chart is the click target. On touch devices (where hover
   is meaningless) we keep it permanently visible so the affordance
   isn't lost. `pointer-events: none` so the overlay never steals
   clicks from the link itself. */
.result-preview-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 140ms ease;
  pointer-events: none;
}

.result-preview-link--audio:hover .result-preview-play,
.result-preview-link--audio:focus-visible .result-preview-play {
  opacity: 1;
}

@media (hover: none) {
  .result-preview-play { opacity: 1; }
}

.result-preview-play-circle {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Subtle scale-on-hover to mirror the chart's interactivity feel. */
  transition: transform 140ms ease, background 140ms ease;
}

.result-preview-link--audio:hover .result-preview-play-circle {
  background: rgba(0, 0, 0, 0.72);
  transform: scale(1.04);
}

.result-body {
  flex: 1;
  min-width: 0;
}

.result-meta {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 2px;
  word-break: break-all;
}

.result-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--bg-sidebar);
  letter-spacing: -0.005em;
  line-height: 1.35;
}

.result-title-link {
  color: inherit;
  text-decoration: none;
}

.result-title-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.result-page {
  color: var(--fg-muted);
  font-weight: 400;
  font-size: 13px;
  margin-left: 4px;
}

.result-snippet {
  margin: 4px 0 0;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.55;
}

.result-modified {
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-muted);
}

.result-snippet mark {
  background: rgba(12, 42, 74, 0.14);
  color: inherit;
  font-weight: 600;
  padding: 0 1px;
  border-radius: 2px;
}

.search-meta-paging {
  margin-top: 8px;
  font-size: 11px;
}

.search-pager {
  margin: 28px auto 8px;
  max-width: 760px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
}

.search-pager-numbers {
  list-style: none;
  margin: 0 4px;
  padding: 0;
  display: flex;
  gap: 4px;
}

.search-pager-num,
.search-pager-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.search-pager-arrow svg {
  width: 14px;
  height: 14px;
}

.search-pager-num:hover,
.search-pager-arrow:not(.is-disabled):hover {
  background: var(--hover);
  border-color: rgba(12, 42, 74, 0.35);
  color: var(--fg);
  text-decoration: none;
}

.search-pager-num.is-current {
  background: var(--bg-sidebar);
  border-color: var(--bg-sidebar);
  color: #ffffff;
  cursor: default;
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.12);
}

.search-pager-arrow.is-disabled {
  color: var(--fg-muted);
  opacity: 0.4;
  cursor: not-allowed;
}

.search-pager-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 32px;
  color: var(--fg-muted);
  font-size: 13px;
  user-select: none;
}

/* Document page */
.doc-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.doc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.doc-header-text { min-width: 0; }

.doc-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.doc-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--bg-sidebar);
  letter-spacing: -0.01em;
  word-break: break-all;
}

.doc-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.doc-meta-sep { color: var(--border); }

/* Clickable file-location path under the document title (company / collection
   / folder…), each segment linking to that level in the Files page. */
.doc-path {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
}
.doc-path-seg {
  color: var(--fg-muted);
  text-decoration: none;
  border-radius: 4px;
}
.doc-path-seg:hover { color: var(--accent); text-decoration: underline; }
.doc-path-sep { color: var(--border); }

/* 2-col / 2-row layout:
   row 1 = tabs nav (col 1 only — col 2 stays empty so the search card's
   top edge aligns with the PDF viewer, not the tabs).
   row 2 = active panel (col 1, fills) + search card (col 2, same height).
   `minmax(0, 1fr)` on row 2 pins both items to the container height
   instead of growing to fit content. */
.doc-body {
  display: grid;
  grid-template-columns: 8fr 4fr;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px 16px;
  flex: 1;
  min-height: 0;
}

.doc-body.is-fullwidth { grid-template-columns: 1fr; }

.doc-body > .doc-tabs {
  /* Span full row so the underline runs the whole width below the
     tabs (col-12 visually). Tab buttons stay left-aligned. */
  grid-column: 1 / -1;
  grid-row: 1;
}

.doc-body-main {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.doc-search-card {
  grid-column: 2;
  grid-row: 2;
}

@media (max-width: 1100px) {
  .doc-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .doc-body > .doc-tabs   { grid-column: 1; grid-row: 1; }
  .doc-body-main          { grid-column: 1; grid-row: 2; }
  .doc-search-card        { grid-column: 1; grid-row: 3; }
}

/* In-document search card */
.doc-search-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

/* Override `display: flex` so the [hidden] attribute actually hides it
   when JS swaps tabs (PDF-tab-only). */
.doc-search-card[hidden] { display: none; }

/* ── Card tabs (Search / Chat) ── */
.doc-card-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
.doc-card-tab {
  background: none;
  border: 0;
  padding: 8px 12px;
  margin-bottom: -1px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.doc-card-tab:hover { color: var(--fg); }
.doc-card-tab.active { color: var(--fg); border-bottom-color: var(--accent); }

.doc-card-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.doc-card-panel[hidden] { display: none; }

/* ── Audio statistics panel (talk-time, speaking rate, …) ── */
.doc-stats {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-stats-title {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}
.doc-stats-title:first-child { margin-top: 0; }

/* Headline counters — 2×2 grid of icon cards. */
.doc-stats-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.doc-stat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  min-width: 0;
}
.doc-stat-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(12, 42, 74, 0.08);
  color: #0C2A4A;
}
.doc-stat-icon svg { width: 18px; height: 18px; }
.doc-stat-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-stat-val {
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.doc-stat-key {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}
/* Fixed-height box so the Chart.js canvas (responsive, no aspect ratio) has a
   stable size to fill. */
.doc-stats-chart {
  position: relative;
  height: 200px;
  flex-shrink: 0;
}
.doc-stats-empty {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--fg-muted);
}

/* Audio card sizing: Statistics tab sizes to its content (card ends below the
   chart); the Chat tab adds `.is-fill` to stretch the card to the full column
   height. Scoped to `--audio` so the PDF/email Search+Chat card is unaffected. */
.doc-search-card--audio { align-self: start; }
.doc-search-card--audio.is-fill { align-self: stretch; height: 100%; }

/* ── Document chat ── */
.doc-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.doc-chat-empty { margin: 0; font-size: 13px; color: var(--fg-muted); }

.doc-chat-bubble { display: flex; flex-direction: column; }
.doc-chat-bubble--user { align-items: flex-end; }
.doc-chat-bubble--assistant { align-items: flex-start; }
.doc-chat-text {
  max-width: 90%;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.55;
}
.doc-chat-bubble--user .doc-chat-text {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 12px 12px 2px 12px;
}
.doc-chat-bubble--assistant .doc-chat-text {
  background: var(--bg);
  color: var(--fg);
  border-radius: 12px 12px 12px 2px;
}
.doc-chat-bubble.is-error .doc-chat-text { color: #b54343; background: transparent; }
.doc-chat-text p { margin: 0 0 8px; }
.doc-chat-text p:last-child { margin-bottom: 0; }
.doc-chat-text ul, .doc-chat-text ol { margin: 0 0 8px; padding-left: 18px; }
.doc-chat-text a { color: var(--accent); }
.doc-chat-typing { color: var(--fg-muted); }

.doc-chat-cites {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.doc-chat-cite {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
}
.doc-chat-cite:hover { border-color: rgba(12, 42, 74, 0.4); }

/* Model picker row above the composer (reuses the /chat `.chat-dd` widget). */
.doc-chat-toolbar {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.doc-chat-model.chat-dd { max-width: 100%; }
/* The step trace (`.chat-activity`) is appended into `.doc-chat-messages`; it
   already carries its own styling — just keep it from stretching full-width. */
.doc-chat-messages .chat-activity { align-self: flex-start; max-width: 100%; }

.doc-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.doc-chat-form:focus-within { border-color: rgba(12, 42, 74, 0.4); }
.doc-chat-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
}
.doc-chat-send {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.doc-chat-send svg { width: 15px; height: 15px; }
.doc-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

.doc-search-card-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.doc-search-form {
  position: relative;
  display: flex;
  align-items: center;
}

.doc-search-form-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--fg-muted);
  pointer-events: none;
}

.doc-search-form input[type="search"] {
  flex: 1;
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
}

.doc-search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--bg-sidebar);
  background: var(--surface);
}

.doc-search-form input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.doc-search-meta {
  font-size: 11px;
  color: var(--fg-muted);
}

.doc-search-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
}

.doc-search-status {
  margin: 0;
  color: var(--fg-muted);
  font-size: 12px;
  font-style: italic;
}

.doc-search-status.is-error {
  color: #b54343;
  font-style: normal;
}

.doc-search-result {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 12px 4px;
  cursor: pointer;
  font: inherit;
  color: var(--fg);
  transition: background 100ms ease;
}

.doc-search-result:last-child { border-bottom: 0; }

.doc-search-result:hover {
  background: var(--hover);
}

.doc-search-result-page {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 8px;
  background: rgba(12, 42, 74, 0.1);
  color: var(--bg-sidebar);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.doc-search-result-snippet {
  font-size: 12px;
  line-height: 1.55;
  color: var(--fg);
  word-break: break-word;
}

.doc-search-result-snippet mark {
  background: rgba(12, 42, 74, 0.18);
  color: inherit;
  font-weight: 600;
  padding: 0 1px;
  border-radius: 2px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--bg-sidebar);
  color: #ffffff;
  border: 1px solid var(--bg-sidebar);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.005em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.08);
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.btn-primary:hover {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-hover);
  color: #ffffff;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(26, 26, 26, 0.14);
}

.btn-primary:active {
  background: var(--sidebar-border);
  border-color: var(--sidebar-border);
}

.btn-primary .btn-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.doc-tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
}

.doc-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  padding: 10px 2px;
  margin-bottom: -1px;
  color: var(--fg-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 120ms ease, border-color 120ms ease;
}

.doc-tab .tab-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.85;
}

.doc-tab:hover { color: var(--fg); }

.doc-tab.active {
  color: var(--bg-sidebar);
  border-bottom-color: var(--bg-sidebar);
  font-weight: 600;
}

.doc-tab.active .tab-icon { opacity: 1; }

.doc-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.doc-panel[hidden] { display: none; }

.doc-pdf {
  flex: 1;
  min-height: 600px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

/* Spreadsheet viewer — fills the panel like the PDF embed does. Sheet strip on
   top, one scroll container holding the grid, truncation note underneath. The
   workbook is parsed client-side (SheetJS); see document.html. */
.doc-sheet {
  flex: 1;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Worksheet strip — only rendered for a multi-sheet workbook. Scrolls
   horizontally rather than wrapping, so a 20-sheet file can't push the grid
   down the page. */
.doc-sheet-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 6px;
  scrollbar-width: thin;
}

.doc-sheet-tab {
  flex: 0 0 auto;
  padding: 5px 12px;
  font-size: 12px;
  font-family: inherit;
  color: var(--fg-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  border-bottom-color: transparent;
  cursor: pointer;
  white-space: nowrap;
}

.doc-sheet-tab:hover { color: var(--fg); background: var(--surface); }

.doc-sheet-tab.active {
  color: var(--fg);
  background: var(--surface);
  border-bottom-color: var(--surface);
  font-weight: 600;
}

/* The grid scrolls in BOTH directions inside its own box — a wide sheet must
   never make the whole document page scroll sideways. */
.doc-sheet-scroll {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.doc-sheet-table {
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.doc-sheet-table th,
.doc-sheet-table td {
  border: 1px solid var(--border);
  padding: 4px 10px;
  text-align: left;
  max-width: 420px;          /* a prose-filled cell can't blow out the column */
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-sheet-table td.is-num { text-align: right; }

/* Column letters (thead) and row numbers (.doc-sheet-gutter) both stick, so the
   references stay on screen while scrolling a long or wide sheet. */
.doc-sheet-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  color: var(--fg-muted);
  font-weight: 600;
  text-align: center;
}

.doc-sheet-table .doc-sheet-gutter {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg);
  color: var(--fg-muted);
  font-weight: 500;
  text-align: right;
  min-width: 44px;
}

/* The top-left corner cell overlaps both sticky axes. */
.doc-sheet-table thead .doc-sheet-gutter { z-index: 3; }

.doc-sheet-note {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--fg-muted);
}

/* Audio player wrapper — fills the panel like the PDF embed does.
   WaveSurfer waveform on top, scrolling karaoke transcript underneath. */
.doc-audio-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 16px 16px 0;
  min-height: 0;
  position: relative;   /* anchor for the floating "jump to current" button */
}

/* Floating pill, bottom-right of the audio/karaoke card. Toggled via the
   `hidden` attribute from JS (only visible when the playing line is off-screen). */
.doc-transcript-jump {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--bg-sidebar);   /* #0C2A4A */
  border-radius: 999px;
  background: var(--bg-sidebar);         /* #0C2A4A */
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 120ms ease, border-color 120ms ease;
}
.doc-transcript-jump:hover {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-hover);
}
.doc-transcript-jump svg { width: 15px; height: 15px; flex-shrink: 0; }
.doc-transcript-jump[hidden] { display: none; }

.doc-audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.doc-audio-play {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  background: #0C2A4A;
  color: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.doc-audio-play:hover {
  background: #3d423f;
  transform: scale(1.04);
}

.doc-audio-play-icon {
  width: 16px;
  height: 16px;
}

/* The button always carries one of `data-state="paused"` /
   `data-state="playing"`. The matching icon stays visible; the other
   collapses to `display: none`. Both icons remain in the DOM
   (stacked) so swapping doesn't reflow the button or the row. */
.doc-audio-play[data-state="paused"] [data-audio="pause-icon"],
.doc-audio-play[data-state="playing"] [data-audio="play-icon"] {
  display: none;
}

.doc-audio-wave {
  flex: 1;
  min-width: 0;
}

.doc-audio-time {
  flex-shrink: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  min-width: 78px;
  text-align: right;
}

/* Skip-back / skip-forward — flank the play button. The step size
   ("10") sits over the double-chevron icon. */
.doc-audio-skip {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--fg-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.doc-audio-skip:hover {
  background: var(--hover);
  color: var(--fg);
}

.doc-audio-skip-icon {
  width: 20px;
  height: 20px;
}

.doc-audio-skip-num {
  position: absolute;
  bottom: 3px;
  right: 3px;
  font-size: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: var(--surface);
  border-radius: 2px;
  padding: 1px;
}

/* Mirror the rewind badge to the outer (left) edge so the badge isn't
   sitting in the gap between back and play — that asymmetry made the
   forward button look farther from play than the back one. Now both
   badges hug the outer edges and the inner gaps read symmetrically. */
.doc-audio-skip[data-audio="back"] .doc-audio-skip-num {
  right: auto;
  left: 3px;
}

/* Playback-speed cycle button — sits after the time label. */
.doc-audio-rate {
  flex-shrink: 0;
  min-width: 44px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.doc-audio-rate:hover {
  background: var(--hover);
  border-color: var(--fg-muted);
}

/* Waveform skeleton — a soft shimmer fills the wave area between
   render and WaveSurfer's `ready` event so a long file over a slow
   CDN doesn't look broken. JS strips `.is-loading` on ready. */
.doc-audio-wave.is-loading {
  height: 56px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--hover) 25%,
    rgba(12, 42, 74, 0.12) 37%,
    var(--hover) 63%
  );
  background-size: 400% 100%;
  animation: doc-audio-shimmer 1.4s ease infinite;
}

@keyframes doc-audio-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Karaoke transcript — one row per Whisper segment, click to seek,
   active row scrolls into view, active word highlights inside a row. */
.doc-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 0 16px;
  scroll-padding-top: 24px;
  scroll-padding-bottom: 24px;
}

.doc-transcript-row {
  display: flex;
  gap: 14px;
  padding: 10px 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  color: var(--fg-muted);
}

.doc-transcript-row:hover {
  background: var(--hover);
  color: var(--fg);
}

.doc-transcript-row.is-current {
  color: var(--fg);
  background: rgba(12, 42, 74, 0.06);
}

.doc-transcript-time {
  flex-shrink: 0;
  width: 44px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--fg-muted);
  padding-top: 2px;
}

.doc-transcript-row.is-current .doc-transcript-time {
  color: #0C2A4A;
  font-weight: 600;
}

.doc-transcript-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.doc-transcript-word {
  transition: color 80ms ease, background 80ms ease;
  border-radius: 2px;
  padding: 0 1px;
}

.doc-transcript-row.is-current .doc-transcript-word.is-current {
  color: #ffffff;
  background: #0C2A4A;
}

/* A word attributed to a different speaker than its turn (a boundary word that
   belongs to the other speaker): tint it + underline in that speaker's colour
   so the exact speaker is visible per word. `--speaker-color` is set inline
   from GBFSSpeakers.color(). The karaoke `.is-current` rule above still wins
   while the word is playing (later + more specific), so the highlight reads. */
.doc-transcript-word--offspeaker {
  color: var(--speaker-color, var(--fg));
  box-shadow: inset 0 -2px 0 var(--speaker-color, transparent);
}

/* ── Speaker turns (diarization) ── */
/* A turn header: a coloured user-avatar + the speaker label, shown once above
   the first row of each turn. Replaces the old per-row left line. */
.doc-transcript-speaker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 8px 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
}
.doc-transcript-speaker:first-child {
  margin-top: 4px;
}
.doc-speaker-avatar {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--speaker-color, var(--fg-muted));
  color: #fff;
}
.doc-speaker-avatar svg {
  width: 14px;
  height: 14px;
}
.doc-speaker-label {
  letter-spacing: 0.01em;
}

/* ── Inline transcript find ── */
.doc-transcript-find {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.doc-transcript-find:focus-within {
  border-color: var(--fg-muted);
}

.doc-transcript-find-icon {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  color: var(--fg-muted);
}

.doc-transcript-find-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  outline: none;
}

.doc-transcript-find-count {
  flex-shrink: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
}

.doc-transcript-find-nav {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--fg);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease;
}

.doc-transcript-find-nav:hover:not(:disabled) {
  background: var(--hover);
}

.doc-transcript-find-nav:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Substring hit inside a flat (no word-timestamp) transcript row.
   Matches the karaoke active-word pill — dark sidebar grey, white text. */
.doc-find-mark {
  background: #0C2A4A;
  color: #ffffff;
  border-radius: 2px;
}

/* Whole-word hit inside a karaoke row (word <span>s we can't split). */
.doc-transcript-word.is-find {
  background: #0C2A4A;
  color: #ffffff;
  border-radius: 2px;
}

/* The match the find-nav is currently focused on. */
.doc-transcript-row.is-find-current {
  background: rgba(12, 42, 74, 0.12);
}

.doc-pager {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 12px;
  font-size: 13px;
  color: var(--fg-muted);
}

.doc-pager-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.doc-pager-btn:hover:not(:disabled) {
  background: var(--hover);
  border-color: rgba(12, 42, 74, 0.3);
}

.doc-pager-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.doc-pager-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.doc-pager-jump-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.doc-pager-input {
  width: 3.5em;
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: border-color 120ms ease;
}

.doc-pager-input:focus {
  outline: none;
  border-color: rgba(12, 42, 74, 0.5);
}

/* Hide the native number spinners — Prev/Next already cover stepping. */
.doc-pager-input::-webkit-outer-spin-button,
.doc-pager-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.doc-pager-input {
  -moz-appearance: textfield;
  appearance: textfield;
}

.doc-panel[data-panel="text"] {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.doc-panel[data-panel="text"][hidden] { display: none; }

.doc-pager {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--fg-muted);
}

.doc-text-page {
  max-width: 70ch;
  margin: 0 auto;
  padding: 40px 24px 56px;
  transition: opacity 120ms ease;
}

.doc-text-page.is-loading { opacity: 0.55; }

.doc-text-page-heading {
  margin: 0 0 28px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--fg-muted);
}

.doc-text-page-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--fg);
}

.doc-text-page-body p {
  margin: 0 0 1.05em;
  word-break: break-word;
}

.doc-text-page-body p:last-child { margin-bottom: 0; }

.doc-text-status {
  color: var(--fg-muted);
  font-size: 13px;
  margin: 0;
  font-style: italic;
}

.doc-text-status.is-error {
  color: #b54343;
  font-style: normal;
}

/* Metadata panel */
.doc-panel[data-panel="metadata"] {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.doc-panel[data-panel="metadata"][hidden] { display: none; }

.doc-metadata-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
}

.doc-metadata {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(180px, 220px) 1fr;
  row-gap: 0;
  column-gap: 24px;
  font-size: 13px;
}

.doc-metadata-row {
  display: contents;
}

.doc-metadata-row dt,
.doc-metadata-row dd {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.doc-metadata-row:last-child dt,
.doc-metadata-row:last-child dd {
  border-bottom: 0;
}

.doc-metadata-row dt {
  color: var(--fg-muted);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.01em;
}

.doc-metadata-row dd {
  color: var(--fg);
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* 404 page — no card, monochrome (sidebar grey, not the blue accent) */
.error-page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  text-align: center;
}

.error-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
  border-radius: 50%;
  background: var(--hover);
  color: var(--bg-sidebar);
}
.error-badge svg { width: 34px; height: 34px; }

.error-code {
  font-size: 88px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--bg-sidebar);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.error-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--fg);
}

.error-detail {
  margin: 0 0 24px;
  max-width: 480px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.55;
}

.error-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.error-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.error-btn svg { width: 16px; height: 16px; }
a.error-btn:hover { text-decoration: none; }

.error-btn--ghost {
  background: var(--surface);
  color: var(--fg);
}
.error-btn--ghost:hover {
  background: var(--hover);
  border-color: var(--fg-muted);
}

.error-btn--primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.error-btn--primary:hover {
  background: #3f4541;
  border-color: #3f4541;
}

/* Login page */
/* Split sign-in: full-bleed image on the left, form panel on the right. */
.login-body {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}

.login-media {
  flex: 1 1 0;
  min-width: 0;
  background: url("../img/lugano.avif") center / cover no-repeat;
}

.login-panel {
  flex: 0 0 clamp(360px, 34vw, 520px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg-sidebar);   /* navy */
}

.login-wrap {
  width: 100%;
  max-width: 340px;
}

/* Narrow screens: drop the image, let the form span the viewport. */
@media (max-width: 768px) {
  .login-media { display: none; }
  .login-panel { flex: 1 1 auto; }
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.login-logo img {
  width: 82%;          /* a touch narrower than the inputs, centred */
  height: auto;
  object-fit: contain;
}

.login-error {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(181, 67, 67, 0.08);
  border: 1px solid rgba(181, 67, 67, 0.25);
  border-radius: 6px;
  font-size: 13px;
  color: #b54343;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-label {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.72);
}

.login-input {
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: #ffffff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.login-input:focus {
  outline: none;
  border-color: #2d7ff9;                       /* blue */
  box-shadow: 0 0 0 3px rgba(45, 127, 249, 0.35);
}

.login-submit {
  margin-top: 4px;
  padding: 10px;
  background: #2d7ff9;                          /* blue */
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease;
}

.login-submit:hover { background: #1e6fe0; }
.login-submit:active { background: #1a63c9; }

/* Settings page */
/* Settings section sub-nav (Account / Users / Collections). Mirrors
   `.search-tabs`: a full-width underline tab bar at the top of each
   /settings/* page, so the three pages read as one section. */
.settings-tabs {
  display: flex;
  gap: 24px;
  margin: 0 0 24px;
  padding: 0 4px;
  border-bottom: 1px solid var(--border);
}
.settings-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 2px;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
}
.settings-tabs a:hover { color: var(--fg); text-decoration: none; }
.settings-tabs a.active {
  color: var(--bg-sidebar);
  border-bottom-color: var(--bg-sidebar);
  font-weight: 600;
}
.settings-tabs .tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.settings-page {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Wide variant for data-table settings pages (e.g. Users): the narrow 560px
   form column crushes a multi-column table, so let it fill the content area. */
.settings-page--wide { max-width: none; }

.settings-section-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-muted);
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 13px;
}

.settings-row-label { color: var(--fg-muted); font-weight: 500; }
.settings-row-value { color: var(--fg); font-weight: 600; }

.settings-banner {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
}

.settings-banner--ok {
  background: rgba(34, 134, 58, 0.08);
  border: 1px solid rgba(34, 134, 58, 0.25);
  color: #1a7a34;
}

.settings-banner--err {
  background: rgba(181, 67, 67, 0.08);
  border: 1px solid rgba(181, 67, 67, 0.25);
  color: #b54343;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.settings-field:last-of-type { border-bottom: 0; }

.settings-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
}

.settings-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  max-width: 320px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.settings-input:focus {
  outline: none;
  border-color: var(--bg-sidebar);
  box-shadow: 0 0 0 3px rgba(12, 42, 74, 0.12);
  background: var(--surface);
}

.settings-hint {
  font-size: 11px;
  color: var(--fg-muted);
}

.settings-actions {
  padding: 16px 18px;
}

/* Appearance / Branding settings — colour picker + image upload rows. */
/* Hint sits directly in the card (not inside a padded field), so give it the
   same insets as the rows below instead of being glued to the card edge. */
.brand-hint {
  margin: 0;
  padding: 14px 18px 0;
}
.brand-color-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  flex-wrap: wrap;
}
.brand-color-swatch {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.brand-color-hex {
  width: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: lowercase;
}
.brand-field {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  flex-wrap: wrap;
}
.brand-field-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand-preview {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
/* Logos are light-on-transparent, so preview them on the actual sidebar colour. */
.brand-preview--logo {
  width: 200px;
  height: 60px;
  background: var(--bg-sidebar);
  padding: 8px 12px;
}
.brand-preview--logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-preview--icon {
  width: 60px;
  height: 60px;
  background: var(--bg-sidebar);
  padding: 8px;
}
.brand-preview--icon img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-preview--bg {
  width: 200px;
  height: 120px;
  background: var(--bg);
}
.brand-preview--bg img { width: 100%; height: 100%; object-fit: cover; }
.brand-file { font-size: 12px; color: var(--fg-muted); max-width: 320px; }
.brand-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-muted);
  cursor: pointer;
}

/* Users page — list + delete + admin/you badges. Reuses settings-card,
   settings-row, settings-banner from above; only the row-level controls
   are new. */
/* Each user is one bordered unit (name row + optional access editor), so the
   editor reads as part of its user rather than a detached strip. */
.users-item {
  border-bottom: 1px solid var(--border);
}
.users-item:last-child { border-bottom: 0; }

.users-row form { margin: 0; }

.users-badge {
  display: inline-block;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-sidebar);
  color: #ffffff;
}

.users-badge--muted {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

/* Role badges: system admin = solid accent, operational admin = outlined
   accent, plain user = muted/neutral. */
.users-badge--role { text-transform: none; letter-spacing: 0; }
.users-badge--system_admin { background: var(--accent); color: var(--accent-fg); }
.users-badge--operational_admin {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.users-badge--user {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

/* Users toolbar: section title on the left; search + role filter + Add-user
   on the right. Wraps on narrow widths. */
.users-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.users-toolbar .settings-section-title { margin: 0; }
.users-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.users-search { width: 200px; max-width: 100%; }

/* Users table: replaces the flat row list; header + rows live in the card. */
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.users-table thead th {
  text-align: left;
  padding: 10px 18px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.users-th-actions { text-align: right; }
.users-table tbody td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.users-table tbody tr:last-child td { border-bottom: 0; }
/* Keep the name cell a normal table-cell (NOT display:flex — that blockifies
   the <td> and knocks it out of the row's vertical alignment). Align its inline
   children instead. */
.users-td-name .settings-row-value,
.users-td-name .users-badge {
  vertical-align: middle;
}
.users-td-name .users-badge { margin-left: 8px; }
.users-td-actions { text-align: right; }

/* Email column: plain, slightly muted so the username stays primary. */
.users-td-email { color: var(--fg-muted); }
.users-email { color: var(--fg); }

/* Row action buttons — quiet "ghost" icon buttons (transparent until hover)
   rather than two loud solid squares. Neutral by default; Permissions reveals
   accent on hover, Delete reveals red. Composes on .btn-icon-only (sizing). */
.users-icon-btn {
  -webkit-appearance: none;
          appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.users-icon-btn:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}
.users-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.users-icon-btn--danger:hover {
  background: color-mix(in srgb, #b54343 12%, transparent);
  border-color: color-mix(in srgb, #b54343 26%, transparent);
  color: #b54343;
}
.users-icon-btn svg { width: 16px; height: 16px; }

/* Access column: grants grouped by company (hierarchy). Each company is one
   row (`.users-access-group`): an accent company chip followed by its granted
   collections as lighter sub-chips (or an "All collections" tag for a whole-
   company grant). System admins get a filled "Unrestricted" chip. */
.users-td-access { max-width: 420px; }
.users-access-groups {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.users-access-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.users-access-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
  font-size: 11px;
  line-height: 1.5;
  padding: 2px 7px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  white-space: nowrap;
}
.users-access-tag--company { font-weight: 600; }
/* Icon inside a chip: smaller than the grant-editor's 18px, inheriting the
   chip's text colour so company/collection glyphs read on the tint. */
.users-access-tag .users-access-ico,
.users-access-sub .users-access-ico {
  width: 14px;
  height: 14px;
  color: inherit;
}
.users-access-tag .users-access-ico svg,
.users-access-sub .users-access-ico svg { width: 12px; height: 12px; }
.users-access-tag-name {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.users-access-tag--all {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
/* Collection sub-chips: lighter/neutral so the company chip reads as parent. */
.users-access-sub {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
  font-size: 11px;
  line-height: 1.5;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.users-access-sub--all { font-style: italic; }
.users-access-sub--more { color: var(--fg-muted); }
.users-muted { color: var(--fg-muted); }
/* IP: plain monospace text, no badge/pill. */
.users-ip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--fg);
}
.users-empty-cell {
  text-align: center;
  color: var(--fg-muted);
  padding: 16px 18px;
}

/* Username + role badge group on the left of each user row. */
.users-row-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.users-role-line { justify-content: flex-start; gap: 12px; }
.users-role-select {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
}

/* ── Users page: per-user document-access (ABAC) grant editor ─────────────── */
/* Row actions: the right-hand cluster of badges + Permissions/Delete buttons. */
.users-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Square icon-only buttons (Permissions / Delete) in the user row. Compose on
   top of .btn-primary / .btn-danger--solid (solid fills); the SVG inherits the
   button's white text colour. A fixed box (not padding) guarantees both buttons
   are exactly the same size regardless of each base class's own padding. */
.btn-icon-only {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;   /* base buttons only set align — center the icon */
  width: 34px;
  height: 34px;
  padding: 0;
  gap: 0;
}
/* Base classes (.btn-primary / .btn-danger) declare their own padding *after*
   .btn-icon-only, so at equal specificity their padding wins and — with the fixed
   border-box — eats the inner area, shrinking the flex-item SVG to a sliver. Win
   the padding back with a 2-class selector, and pin the SVG so it never shrinks. */
.btn-primary.btn-icon-only,
.btn-danger.btn-icon-only { padding: 0; }
.btn-icon-only svg { width: 18px; height: 18px; display: block; flex: 0 0 auto; }

/* The grant editor lives in a per-user modal opened by the Permissions button. */
.users-perms-card {
  width: min(560px, 92vw);
  text-align: left;
}
.users-perms-body {
  max-height: 60vh;
  overflow-y: auto;
  margin: 14px 0;
  padding-right: 4px;   /* breathing room for the scrollbar */
}
/* Username/password fields inside the Add-user modal: full-width, no side
   padding (the shared .settings-field/.settings-input styles are tuned for the
   Settings page, so override only here). */
.users-perms-body .settings-field {
  padding: 0 0 12px;
  border-bottom: 0;
}
.users-perms-body .settings-input {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}

.users-access-company {
  border: 0;
  margin: 0 0 10px;
  padding: 0;
}
.users-access-company:last-of-type { margin-bottom: 0; }
.users-access-caps {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.users-access-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--fg);
}
.users-access-line--nested {
  padding-left: 24px;
  font-size: 12px;
  color: var(--fg-muted);
}
.users-access-line input {
  margin: 0;
  flex: none;
  accent-color: var(--bg-sidebar);
}
.users-access-ico {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  overflow: hidden;
  color: var(--fg-muted);
}
.users-access-ico img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.users-access-ico svg { width: 14px; height: 14px; }
.users-access-line--nested .users-access-ico { width: 16px; height: 16px; }
.users-access-line--nested .users-access-ico svg { width: 13px; height: 13px; }
.users-access-line .settings-hint { margin-left: auto; }

.btn-danger {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: transparent;
  color: #b54343;
  border: 1px solid rgba(181, 67, 67, 0.4);
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.btn-danger:hover {
  background: #b54343;
  border-color: #b54343;
  color: #ffffff;
}

.btn-danger:active {
  background: #913636;
  border-color: #913636;
}

/* Solid red variant for the confirm button inside the delete dialog —
   reads as the destructive primary action of the modal. */
.btn-danger--solid {
  background: #b54343;
  color: #ffffff;
  border-color: #b54343;
}
.btn-danger--solid:hover {
  background: #913636;
  border-color: #913636;
  color: #ffffff;
}
.btn-danger--solid:active {
  background: #7a2d2d;
  border-color: #7a2d2d;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--fg-muted);
}

.btn-secondary:active {
  background: rgba(0, 0, 0, 0.08);
}

.btn-secondary .btn-icon { width: 15px; height: 15px; }

/* Native <dialog> modal — used for the delete-user confirmation. The
   browser handles focus trapping, Esc-to-close, and overlay stacking;
   we just style the box and the backdrop. */
.modal {
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  max-width: 92vw;
}

.modal::backdrop {
  background: rgba(26, 26, 26, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px 18px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 16px 40px rgba(26, 26, 26, 0.22);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.modal-body {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-muted);
}

.modal-body strong {
  color: var(--fg);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Footer */
.footer {
  grid-area: footer;
  height: var(--footer-h);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  color: var(--fg-muted);
  font-size: 12px;
}

/* Placeholder / empty-state page (e.g. /files and / before they ship) */
.placeholder-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 96px 24px;
  color: var(--fg-muted);
}
.placeholder-icon {
  width: 64px;
  height: 64px;
  opacity: 0.35;
  margin-bottom: 20px;
  color: var(--fg);
}
.placeholder-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
  margin: 0 0 10px;
}
.placeholder-detail {
  max-width: 460px;
  line-height: 1.55;
  margin: 0 0 20px;
}
.placeholder-badge {
  display: inline-block;
  padding: 4px 10px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* ── Chat page ────────────────────────────────────────────────────────────── */

.main.chat-main {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.chat-root {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

/* ── Conversation sidebar ─────────────────────────────────────────────────── */
.chat-convos {
  width: 252px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
}

.chat-new-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.chat-new-btn:hover { background: var(--border); }

.chat-convo-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Date-bucket header between groups of conversations (Today / Yesterday / …). */
.chat-convo-group {
  padding: 12px 10px 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.chat-convo-group:first-child { padding-top: 4px; }

.chat-convo {
  display: flex;
  align-items: center;
  border-radius: 7px;
  position: relative;      /* anchors the absolutely-positioned action buttons */
}

.chat-convo:hover { background: var(--bg); }
.chat-convo.is-active { background: var(--bg); }

/* Running indicator: a pulsing dot on threads with a live turn. Takes no width
   until active, so idle rows align with the group headers. */
.chat-convo-dot {
  flex-shrink: 0;
  width: 0;
  height: 6px;
  margin-left: 0;
  border-radius: 50%;
  background: var(--accent, #2d7ff9);
  transition: width 0.15s ease, margin-left 0.15s ease;
}
.chat-convo.is-running .chat-convo-dot {
  width: 6px;
  margin-left: 8px;
  animation: chat-convo-pulse 1.4s ease-in-out infinite;
}
@keyframes chat-convo-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-convo.is-running .chat-convo-dot { animation: none; }
}

.chat-convo-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--fg);
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Relative age, pinned to the far right. Hidden on hover / for the active row
   so the action buttons take its place (opacity, not display, so the row width
   never jumps). */
.chat-convo-age {
  flex-shrink: 0;
  margin-left: auto;                 /* push to the right edge */
  padding: 0 12px 0 6px;             /* a bit of breathing room on the right */
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
  transition: opacity 0.12s ease;
}
.chat-convo:hover .chat-convo-age,
.chat-convo.is-active .chat-convo-age { opacity: 0; }

/* Rename + delete, overlaid on the right edge (absolute → no layout space) and
   revealed on hover / for the active thread. The gradient masks any title text
   that runs behind them. */
.chat-convo-actions {
  position: absolute;
  right: 4px;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding-left: 14px;
  background: linear-gradient(to right, transparent, var(--bg) 12px);
  opacity: 0;
  pointer-events: none;              /* not clickable until revealed */
  transition: opacity 0.12s ease;
}
.chat-convo:hover .chat-convo-actions,
.chat-convo.is-active .chat-convo-actions {
  opacity: 1;
  pointer-events: auto;
}

.chat-convo-rename,
.chat-convo-del {
  display: flex;
  align-items: center;
  padding: 6px 6px;
  color: var(--fg-muted);
  background: none;
  border: none;
  cursor: pointer;
}
.chat-convo-rename:hover { color: var(--fg); }
.chat-convo-del:hover { color: #c0392b; }

/* Inline rename input replaces the title button in place. */
.chat-convo-rename-input {
  flex: 1;
  min-width: 0;
  margin: 4px 6px;
  padding: 4px 6px;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--accent, #2d7ff9);
  border-radius: 5px;
  outline: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 10px;
  color: var(--fg-muted);
  text-align: center;
  padding: 48px 24px;
}

.chat-welcome-icon {
  width: 48px;
  height: 48px;
  opacity: 0.3;
  color: var(--fg);
}

.chat-welcome-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin: 0;
}

.chat-welcome-sub {
  font-size: 13px;
  margin: 0;
  max-width: 340px;
  line-height: 1.6;
}

.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-bubble--user {
  align-self: flex-end;
  background: #0C2A4A;
  color: #f1f3f2;
  border-bottom-right-radius: 4px;
}

.chat-bubble--assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--fg);
}

.chat-bubble--error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.chat-bubble-text {
  word-break: break-word;
  display: block;
}

/* Markdown content inside assistant bubbles */
.chat-bubble-text p          { margin: 0 0 8px; }
.chat-bubble-text p:last-child { margin-bottom: 0; }
.chat-bubble-text h1,
.chat-bubble-text h2,
.chat-bubble-text h3         { font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.chat-bubble-text h1:first-child,
.chat-bubble-text h2:first-child,
.chat-bubble-text h3:first-child { margin-top: 0; }
.chat-bubble-text ul,
.chat-bubble-text ol         { margin: 0 0 8px; padding-left: 20px; }
.chat-bubble-text li         { margin-bottom: 2px; }
.chat-bubble-text code       { font-family: ui-monospace, monospace; font-size: 12px;
                               background: rgba(0,0,0,0.06); border-radius: 3px;
                               padding: 1px 4px; }
.chat-bubble-text pre        { background: rgba(0,0,0,0.06); border-radius: 6px;
                               padding: 10px 12px; overflow-x: auto; margin: 0 0 8px; }
.chat-bubble-text pre code   { background: none; padding: 0; }
.chat-bubble-text blockquote { border-left: 3px solid var(--border); margin: 0 0 8px;
                               padding-left: 10px; color: var(--fg-muted); }
.chat-bubble-text a          { color: var(--accent); }
.chat-bubble-text strong     { font-weight: 600; }
.chat-bubble-text em         { font-style: italic; }
.chat-bubble-text hr         { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

/* ── Activity trace ────────────────────────────────────────────────────────
   An agentic turn runs for minutes across dozens of tool calls, so the bubble
   carries an append-only log of what it did (collapsed to a one-line summary
   once finished) instead of a single status line that overwrote itself. */
.chat-activity {
  /* A sibling of the answer bubble, not a child — see `appendAssistantTurn`.
     Matches the assistant bubble's alignment and width so the turn reads as one
     column, while staying visually its own object. */
  align-self: flex-start;
  max-width: 78%;
  margin-bottom: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--hover);
  font-size: 12px;
}
.chat-activity-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  color: var(--fg-muted);
}
/* Hide the native disclosure triangle in both engines. */
.chat-activity-summary::-webkit-details-marker { display: none; }
.chat-activity-summary::marker { content: ''; }
.chat-activity-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 8px;
}
.chat-activity-spinner {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}
/* Finished: freeze the spinner into a static ring rather than swapping nodes. */
.chat-activity.is-done .chat-activity-spinner {
  animation: none;
  border-top-color: var(--border);
  opacity: 0.5;
}
.chat-activity-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-activity-meta {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;  /* stop the clock jittering each tick */
  opacity: 0.75;
}
.chat-activity-steps {
  margin: 0;
  padding: 2px 10px 8px 26px;
  border-top: 1px solid var(--border);
  max-height: 190px;
  overflow-y: auto;
  color: var(--fg-muted);
}
.chat-activity-step {
  margin: 3px 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

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

/* ── Copy / download under a finished answer ───────────────────────────── */
.chat-answer-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.chat-answer-action {
  font: inherit;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.chat-answer-action:hover {
  background: var(--hover);
  color: var(--fg);
}
.chat-answer-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.chat-answer-action svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
/* Confirmation state after a successful copy. */
.chat-answer-action.is-done {
  color: var(--accent);
  border-color: var(--accent);
}

@keyframes chat-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

.chat-citations-wrap {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
/* Folded overflow cards. `display: none` rather than height clipping, so the
   hidden ones cost no layout and the hover previews of the visible ones are
   never trapped inside an overflow context. */
.chat-citation.is-hidden { display: none; }

.chat-cites-toggle {
  margin-top: 8px;
  font: inherit;
  font-size: 11px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.chat-cites-toggle:hover { background: var(--hover); color: var(--fg); }
.chat-cites-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chat-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-citation {
  display: flex;
  flex-direction: column;
  width: 110px;
  border: 1px solid var(--border);
  border-radius: 8px;
  /* NOT `overflow: hidden` — that would clip the hover preview, which is
     absolutely positioned outside the card. The thumbnail does its own
     clipping instead (`.chat-citation-thumb` is `overflow: hidden` and carries
     the matching top-corner radius), so the rounded look is unchanged. */
  position: relative;
  text-decoration: none;
  color: var(--fg);
  background: var(--bg);
  transition: box-shadow 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.chat-citation:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: #c0c4c2;
  text-decoration: none;
}

.chat-citation-thumb {
  width: 100%;
  height: 72px;
  /* 1px inside the card's 8px radius, to sit flush against the border. */
  border-radius: 7px 7px 0 0;
  background: var(--hover);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.chat-citation-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Source cards showing a file-type icon (email, Word, Excel, PowerPoint, PDF)
   rather than a rendered page preview: contain + pad so the glyph sits centred
   instead of being cover-cropped. Mirrors `.fb-card-thumb--icon` on the Files
   page, with less padding — these cards are ~72px tall, not full grid tiles.
   Qualified by the parent so it outweighs the `.chat-citation-thumb img`
   `cover` rule above, which is otherwise the more specific selector. */
.chat-citation-thumb img.chat-citation-thumb--icon {
  object-fit: contain;
  object-position: center;
  padding: 12px;
  background: var(--surface);
}

.chat-citation-thumb--fallback svg {
  width: 24px;
  height: 24px;
  opacity: 0.3;
  color: var(--fg);
}

.chat-citation-info {
  padding: 6px 7px;
}

/* ── Citation preview ──────────────────────────────────────────────────────
   The extract the file was cited from, on hover or keyboard focus, so a claim
   can be checked without navigating away. Positioned above the card and
   centred on it; `.chat-citation` is the positioning context. */
.chat-citation-preview {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  z-index: 20;
  width: max-content;
  max-width: min(340px, 78vw);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  /* Never intercept the pointer: the card underneath stays clickable, and the
     preview can't flicker by stealing hover from its own trigger. */
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
.chat-citation:hover .chat-citation-preview,
.chat-citation:focus-visible .chat-citation-preview {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
/* Cards near the top of the thread would clip a preview rendered above them;
   the messages column scrolls, so flip those to sit below instead. */
.chat-bubble:first-child .chat-citation-preview,
.chat-bubble:nth-child(2) .chat-citation-preview {
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-3px);
}
.chat-bubble:first-child .chat-citation:hover .chat-citation-preview,
.chat-bubble:first-child .chat-citation:focus-visible .chat-citation-preview,
.chat-bubble:nth-child(2) .chat-citation:hover .chat-citation-preview,
.chat-bubble:nth-child(2) .chat-citation:focus-visible .chat-citation-preview {
  transform: translateX(-50%) translateY(0);
}

.chat-citation-name {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg);
}

.chat-citation-loc {
  font-size: 10px;
  color: var(--fg-muted);
  margin-top: 1px;
}

.chat-input-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  outline: none;
  background: var(--bg);
  color: var(--fg);
}

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(12, 42, 74, 0.15);
}

.chat-input::placeholder { color: var(--fg-muted); }

.chat-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}

.chat-send:hover   { background: var(--sidebar-hover); }
.chat-send:active  { background: var(--sidebar-border); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* While the LLM is responding, the send button becomes a Stop button. */
.chat-send--stop          { background: #b23b3b; }
.chat-send--stop:hover    { background: #9a3030; }
.chat-send--stop:active   { background: #842828; }

/* A turn the user stopped before any text arrived. */
.chat-bubble--stopped .chat-bubble-text { color: var(--fg-muted); font-style: italic; }

/* Chat file-scope banner — shown when a chat is restricted to a Files-page
   selection (sits between the messages and the input bar). */
.chat-context-banner[hidden] { display: none; }   /* beat the inline-flex below */
.chat-context-banner {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 2px auto 10px 16px;
  padding: 5px 12px 5px 9px;
  border: 1px solid var(--sidebar-border);
  border-radius: 999px;                 /* pill */
  background: var(--bg-sidebar);        /* same color as the nav sidebar */
  color: var(--sidebar-fg);
  font-size: 12px;
  line-height: 1.2;
}
.chat-context-icon {
  width: 15px;
  height: 15px;
  color: var(--sidebar-fg);
  flex-shrink: 0;
}
.chat-context-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat input-bar pickers (category + AI model) — fully custom dropdowns
   (built in chat.html). The trigger is a pill with a leading icon reflecting
   the choice; the menu is a themed popover with per-item icons + an active
   checkmark, replacing the un-styleable native <select> popup. */
.chat-dd { position: relative; display: inline-flex; }

.chat-dd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px 5px 9px;
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.chat-dd-trigger:hover { background: var(--hover); border-color: var(--fg-muted); }
.chat-dd.is-open .chat-dd-trigger,
.chat-dd-trigger:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(12, 42, 74, 0.15);
  outline: none;
}

.chat-dd-trigger-icon { display: inline-flex; align-items: center; color: var(--accent); flex-shrink: 0; }
.chat-dd-trigger-icon svg { width: 15px; height: 15px; display: block; }
/* Brand-logo icons (provider picker) — match the SVG footprint. */
.chat-dd-img { width: 15px; height: 15px; object-fit: contain; display: block; border-radius: 3px; }
.chat-dd-item-icon .chat-dd-img { width: 16px; height: 16px; }
.chat-dd-trigger-label { white-space: nowrap; }
.chat-dd-caret { display: inline-flex; align-items: center; color: var(--fg-muted); margin-left: 1px; transition: transform 0.15s; }
.chat-dd-caret svg { width: 13px; height: 13px; display: block; }
.chat-dd.is-open .chat-dd-caret { transform: rotate(180deg); }

/* Menu — opens upward (input bar sits at the bottom of the page). */
.chat-dd-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 260px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  z-index: 50;
}
.chat-dd.is-open .chat-dd-menu { display: flex; }

.chat-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 12.5px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.chat-dd-item:hover { background: var(--hover); }
.chat-dd-item-icon { display: inline-flex; align-items: center; color: var(--fg-muted); flex-shrink: 0; }
.chat-dd-item-icon svg { width: 15px; height: 15px; display: block; }
.chat-dd-item-label { flex: 1; }
.chat-dd-item-check { display: inline-flex; align-items: center; color: var(--accent); opacity: 0; flex-shrink: 0; }
.chat-dd-item-check svg { width: 14px; height: 14px; display: block; }
.chat-dd-item.is-active { color: var(--accent); font-weight: 600; }
.chat-dd-item.is-active .chat-dd-item-icon { color: var(--accent); }
.chat-dd-item.is-active .chat-dd-item-check { opacity: 1; }
/* Collections sit under their company in the scope picker — indented so the
   hierarchy reads at a glance without a second level of markup. */
.chat-dd-item--sub { padding-left: 24px; }
/* The scope menu can list the whole taxonomy; keep it scrollable rather than
   letting it run off the top of the viewport. */
#chat-scope .chat-dd-menu { max-height: 320px; overflow-y: auto; }
#chat-scope .chat-dd-trigger-label { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* Locked picker (model is fixed once a thread starts) — dim and inert. */
.chat-dd.is-disabled { opacity: 0.55; }
.chat-dd.is-disabled .chat-dd-trigger {
  cursor: not-allowed;
  background: var(--surface);
  border-color: var(--border);
  box-shadow: none;
}
.chat-dd.is-disabled .chat-dd-trigger:hover { background: var(--surface); border-color: var(--border); }

/* ── Files page — folder browser (/files) ────────────────────────────
   Breadcrumb + a full-width responsive grid of folder/file cards,
   navigated by stable folder id (location.hash). Each card is a
   navigable `.fb-card-link` with a corner checkbox + corner actions
   (download / rename / delete). Reuses the shared design tokens — no
   new colors. See docs/webapp.md#files-page. */
.fb {
  width: 100%;
}

/* Workspace (company / collection) cards reuse the folder-card shell but
   carry the entity's uploaded icon — or the default folder glyph — so the
   taxonomy reads as part of the same browser. */
.fb-card-media--ws .fb-ws-card-ico {
  width: 112px;
  height: 112px;
  border-radius: 14px;
  object-fit: contain;   /* show the whole icon — never crop/cut it */
}
/* Default glyph on a workspace card — larger than a plain folder glyph. The
   two-class selector beats `.fb-card-media--folder svg` (52px) regardless of
   source order, and is scoped to workspace cards so real folders are untouched. */
.fb-card-media--folder.fb-card-media--ws svg {
  width: 92px;
  height: 92px;
}

.fb-crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
}

.fb-crumb { color: var(--accent); }
a.fb-crumb:hover { text-decoration: underline; }
.fb-crumb.is-current { color: var(--fg); font-weight: 600; }
.fb-crumb-sep { color: var(--fg-muted); }

/* Toolbar above the grid: live filter (left) + upload button (right). */
.fb-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
/* Class display:flex would otherwise beat the [hidden] UA rule. The toolbar
   is hidden at the company/collection grid levels (only shown in a collection). */
.fb-toolbar[hidden] { display: none; }

.fb-search {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  max-width: 420px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 150ms ease, border-color 150ms ease;
}
.fb-search:hover {
  box-shadow: 0 1px 6px rgba(32, 33, 36, 0.12);
}
.fb-search:focus-within {
  border-color: transparent;
  box-shadow: 0 1px 8px rgba(32, 33, 36, 0.18);
}
.fb-search .search-icon {
  width: 18px;
  height: 18px;
  color: var(--fg-muted);
  flex-shrink: 0;
}
.fb-search input[type="search"] {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  padding: 2px 0;
}
.fb-search input[type="search"]::placeholder { color: var(--fg-muted); }
.fb-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* Push the upload button to the right edge of the toolbar. */
.fb-upload-btn { margin-left: auto; }

/* Cards hidden by the live filter. */
.fb-card.fb-hidden { display: none; }

/* Matched substring in a name, highlighted by the live filter — matches
   the search-result snippet highlight. */
.fb-mark {
  background: var(--accent);      /* #0C2A4A */
  color: var(--accent-fg);        /* #ffffff */
  font-weight: 600;
  padding: 0 1px;
  border-radius: 2px;
}

/* ── Upload modal ──────────────────────────────────────────────────── */
.fb-up-card { width: 480px; }

.fb-up-dest {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}
.fb-up-dest-label { color: var(--fg-muted); }
.fb-up-dest-path { color: var(--fg); font-weight: 600; }

.fb-up-target {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
}
.fb-up-target-opt {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
}
.fb-up-target-opt input {
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.fb-up-subfolder { display: block; margin-bottom: 16px; }
.fb-up-subfolder[hidden] { display: none; }   /* class display: block beats UA [hidden] */
.fb-up-subfolder-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--fg-muted);
}
.fb-up-subfolder .modal-input { margin-bottom: 0; }

/* Custom dropdown (upload modal company/collection pickers). A fully custom
   widget — not a native <select> — so the option panel can be styled and each
   row can carry an icon. Markup is built by CustomSelect() in files.html. */
.fb-select-row { display: flex; flex-direction: column; gap: 8px; }

.cs { position: relative; }
.cs[hidden] { display: none; }

.cs-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.cs-trigger:hover { border-color: var(--fg-muted); }
.cs.is-open .cs-trigger,
.cs-trigger:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(12, 42, 74, 0.15);
  outline: none;
}
.cs-trigger:disabled { opacity: 0.6; cursor: default; }

.cs-value { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.cs-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-label--muted { color: var(--fg-muted); }

.cs-chev { display: grid; place-items: center; flex-shrink: 0; color: var(--fg-muted); transition: transform 150ms ease; }
.cs-chev svg { width: 16px; height: 16px; }
.cs.is-open .cs-chev { transform: rotate(180deg); }

/* Left-side icon — uploaded image or a centered default glyph. */
.cs-ico {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  overflow: hidden;
}
img.cs-ico { object-fit: cover; }
.cs-ico--default svg { width: 14px; height: 14px; }

.cs-panel {
  position: absolute;
  z-index: 50;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.cs-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
}
.cs-option.is-active { background: var(--bg); }
.cs-option.is-selected .cs-label { font-weight: 600; }

.fb-up-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border);
  border-radius: 9px;
  background: var(--bg-elevated);
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}
.fb-up-drop.is-drag {
  border-color: var(--accent);
  background: rgba(12, 42, 74, 0.06);
}
.fb-up-drop.is-busy { opacity: 0.6; pointer-events: none; }
.fb-up-drop svg { width: 26px; height: 26px; color: var(--fg-muted); }
.fb-up-drop-text { margin: 0; font-size: 13px; color: var(--fg-muted); }
.fb-up-drop-btns { display: flex; gap: 8px; }

.fb-up-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.fb-up-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.fb-up-item:last-child { border-bottom: 0; }
.fb-up-item.is-skipped { opacity: 0.6; }
.fb-up-item-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.fb-up-item-name {
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-up-item-meta { font-size: 11px; color: var(--fg-muted); }
.fb-up-item.is-skipped .fb-up-item-meta { color: #b54343; }
.fb-up-item-remove {
  flex-shrink: 0;
  padding: 4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.fb-up-item-remove:hover { background: var(--border); color: var(--fg); }

/* Per-file upload status (#1): a status badge + a thin per-file progress bar
   (bar shows only while that file is uploading). */
.fb-up-item-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
}
.fb-up-item.is-uploading .fb-up-item-badge { color: var(--accent); }
.fb-up-item.is-done .fb-up-item-badge { color: #5a8f3c; }
.fb-up-item.is-duplicate .fb-up-item-badge { color: #b7791f; }
.fb-up-item.is-failed .fb-up-item-badge,
.fb-up-item.is-canceled .fb-up-item-badge { color: #b54343; }
.fb-up-item-bar {
  display: none;
  height: 3px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.fb-up-item.is-uploading .fb-up-item-bar { display: block; }
.fb-up-item-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms ease;
}
/* While an upload is in flight, per-row remove is disabled (can't unstage a
   file mid-run). */
.fb-up-list.is-locked .fb-up-item-remove { display: none; }
/* Cancel button becomes a red "Stop" during upload. */
.btn-secondary.fb-up-stop { color: #b54343; }
.btn-secondary.fb-up-stop:hover { background: rgba(181, 67, 67, 0.12); }
/* Submit button while uploading: swap the upload-arrow icon for a spinner
   (reuses the page-loader keyframes). The spinner is only rendered — and only
   animating — while the button carries `.is-busy`, so it never spins on the
   idle Upload button. */
#fb-up-submit.is-busy .btn-icon { display: none; }
.btn-spinner { display: none; }
#fb-up-submit.is-busy .btn-spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: page-loader-spin 0.7s linear infinite;
}

.fb-up-summary {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--fg-muted);
}

/* Upload progress bar (shown while files are being sent). */
.fb-up-progress { margin-top: 14px; }
.fb-up-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.fb-up-progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 150ms ease;
}
.fb-up-progress-text {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--fg-muted);
}

/* Breathing room above the Cancel/Upload row so it doesn't touch the
   drop zone's dashed border (or the summary). */
.fb-up-card .modal-actions { margin-top: 18px; }

/* Completion panel — shown when the upload finishes. */
.fb-up-result { text-align: center; padding: 6px 4px 2px; }
.fb-up-result-icon {
  width: 48px;
  height: 48px;
  margin: 4px auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.fb-up-result-icon svg { width: 26px; height: 26px; }
.fb-up-result-icon.is-ok { background: rgba(12, 42, 74, 0.12); color: var(--accent); }
.fb-up-result-icon.is-warn { background: rgba(181, 67, 67, 0.12); color: #b54343; }
.fb-up-result-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}
.fb-up-result-sub {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted);
}
.fb-up-result .modal-actions { justify-content: center; }

/* Disabled primary button (e.g. Upload with nothing staged). */
.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

/* Responsive card grid — fills the full content width, wrapping like a
   gallery. Notices (empty / truncated) span the whole row. */
.fb-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 14px;
}

.fb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.fb-card:hover {
  border-color: rgba(12, 42, 74, 0.35);
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.18);
}
.fb-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* The navigable part of a card — folder drill-in or file → /document. */
.fb-card-link {
  display: flex;
  flex-direction: column;
  color: var(--fg);
  text-decoration: none;
}
.fb-card-link:hover { text-decoration: none; }

.fb-card-body {
  padding: 9px 12px 12px;
  min-width: 0;
}
.fb-card-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-card-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* ── Search results: table view ──────────────────────────────────────
   When searching, `.fb-list` gets `.fb-list--table` and renders a compact
   file listing (Name+location · Size · Modified) on a card-surface panel,
   instead of the card grid. Columns are a shared grid on the header + rows. */
.fb-list--table {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.fb-trow {
  display: flex;
  align-items: center;
  min-height: 62px;
  cursor: pointer;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  transition: background 120ms ease;
}
.fb-trow:last-child { border-bottom: 0; }
.fb-trow:hover { background: rgba(12, 42, 74, 0.05); }
.fb-trow.is-selected {
  background: rgba(12, 42, 74, 0.09);
  box-shadow: inset 2px 0 0 var(--accent);
}
.fb-tcell {
  min-width: 0;
  font-size: 13px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-tcell--name { flex: 1 1 auto; min-width: 0; }
.fb-tname {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--fg);
}
/* Text column: name (link) over its location path (link). */
.fb-tname-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.fb-tname-text {
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fb-tname-text:hover { text-decoration: underline; }
.fb-tname-sub {
  min-width: 0;
  font-size: 12px;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The location path is a link to that folder — align it left, own hover. */
.fb-tname-sub--link {
  color: var(--fg-muted);
  text-decoration: none;
  align-self: flex-start;
  max-width: 100%;
}
.fb-tname-sub--link:hover {
  color: var(--fg);
  text-decoration: underline;
}
.fb-tname-ico {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 54px;
  height: 40px;
  color: #0C2A4A;
}
.fb-tname-ico svg { width: 26px; height: 26px; }
/* File preview thumbnail chip on the left of a file row: a wide 54×40 tile
   showing the page-1 preview (docs) or waveform (audio), reusing fileThumb(). */
.fb-tname-thumb {
  flex-shrink: 0;
  width: 54px;
  height: 40px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}
.fb-tname-thumb .fb-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Static type-icon thumbnails (email / Word / PowerPoint) in the small 54×40
   search-row chip: contain the glyph with tight padding so it reads as a whole
   icon instead of being cover-cropped and squished. Needs the two-class
   `.fb-tname-thumb .fb-card-thumb--*` specificity to beat the `cover` rule
   above, and overrides the large 18px card-grid padding for this small tile. */
.fb-tname-thumb .fb-card-thumb--email,
.fb-tname-thumb .fb-card-thumb--icon {
  object-fit: contain;
  padding: 4px;
  background: var(--surface);
}

/* Corner actions overlay (download / rename / delete) — revealed on
   hover/focus only (the selection checkbox stays always visible), with a
   backing so the glyphs read over a thumbnail. */
.fb-card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 120ms ease;
}
.fb-card:hover .fb-card-actions,
.fb-card:focus-within .fb-card-actions {
  opacity: 1;
}
.fb-card-actions .fb-action {
  width: 26px;
  height: 26px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
}
.fb-card-actions .fb-action:hover { background: #fff; }

.fb-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.fb-action svg { width: 15px; height: 15px; }
.fb-action:hover { background: var(--border); color: var(--fg); }

/* Destructive action — the delete (trash) buttons read red. */
.fb-action--danger { color: #b54343; }
.fb-action--danger:hover { background: rgba(181, 67, 67, 0.12); color: #913636; }

/* Selection checkbox — corner overlay on a card. Just the checkbox, no
   backing box/border. */
.fb-card-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}
.fb-card-check input {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}
/* Floating selection action card — centred over the content column. */
.fb-selbar {
  position: fixed;
  bottom: 26px;
  left: calc(50% + var(--sidebar-w) / 2);
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 12px 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(26, 26, 26, 0.22);
}
.fb-selbar[hidden] { display: none; }

.fb-selbar-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.fb-selbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fb-selbar .btn-secondary,
.fb-selbar .btn-danger { gap: 7px; }
.fb-selbar svg { width: 15px; height: 15px; }
.fb-selbar .btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.fb-selbar .btn-secondary:disabled:hover {
  background: transparent;
  border-color: var(--border);
}

/* Text input inside a modal (folder rename). */
.modal-input {
  width: 100%;
  margin: 0 0 18px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}
.modal-input:focus { border-color: var(--accent); }

.fb-selbar-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: 2px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.fb-selbar-clear:hover { background: var(--hover); color: var(--fg); }

/* Card media — the large top area: a preview thumbnail for files, a
   centered folder glyph for folders. */
.fb-card-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  background: var(--bg);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

/* Company / collection membership badges. `.group-badges` is the inline row
   used in the search result body; `.fb-card-badges` overlays the bottom of the
   Files-page card preview. Both use the `.fb-badge` pills. */
.group-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.fb-card-badges {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
/* Slight shadow only over the preview image, for legibility. */
.fb-card-badges .fb-badge { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); }
.fb-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.6;
  border-radius: 999px;
}
.fb-badge-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-badge-ico {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  object-fit: contain;
}
.fb-badge--company { background: var(--accent); color: var(--accent-fg); }
.fb-badge--collection {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
}
.fb-badge--more { background: rgba(0, 0, 0, 0.6); color: #fff; }
.fb-card-thumb {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}
/* Files shown with a static type icon rather than a page preview (email icon,
   PowerPoint icon, …): contain + pad so the glyph sits centred rather than being
   cover-cropped like a real thumbnail. */
.fb-card-thumb--email,
.fb-card-thumb--icon {
  object-fit: contain;
  object-position: center;
  padding: 18px;
  background: var(--surface);
}
.fb-card-media--folder {
  color: var(--accent);
  background: var(--surface);
  border-bottom: 0;
}
.fb-card-media--folder svg { width: 52px; height: 52px; }

/* Notices (loading / empty / truncated) span the full grid width. */
.fb-empty,
.fb-truncated { grid-column: 1 / -1; }

.fb-empty {
  padding: 40px 14px;
  text-align: center;
  color: var(--fg-muted);
}

/* Rich zero-data view for the Files grid + folder levels (Workspaces, a
   company's collections, an empty collection/folder). Reuses the Collections
   page's .cc-empty-state look but must span the full card grid. */
.fb-empty-state { grid-column: 1 / -1; }

.fb-truncated {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--fg-muted);
}

/* ── Collections page ──────────────────────────────────────────────────────
   Files-page-flavoured: a toolbar with a right-aligned "Add company" button,
   then a stack of company cards each listing its collections. Reuses .fb-action
   for the small per-row buttons and the modal component for create/rename. */
.cc-add-btn { margin-left: auto; }

.cc-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));  /* col-4: three per row */
  gap: 14px;
  align-items: start;  /* natural card heights — don't stretch short cards */
}
@media (max-width: 1100px) { .cc-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px)  { .cc-list { grid-template-columns: minmax(0, 1fr); } }

.cc-company {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.cc-company-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.cc-collections { border-top: 1px solid var(--border); }
.cc-collection {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 24px;
  border-top: 1px solid var(--border);
}
.cc-collection:first-child { border-top: 0; }

.cc-name { font-weight: 600; color: var(--fg); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cc-collection .cc-name { font-weight: 500; }
.cc-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-count { font-size: 12px; font-weight: 400; color: var(--fg-muted); margin-top: 1px; }
.cc-actions { display: flex; gap: 6px; flex-shrink: 0; }

.cc-add-collection {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 12px 24px;
  border-top: 1px dashed var(--border);
}
.cc-add-collection input {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
}

/* Empty state — a centered icon + heading + CTA, like a proper zero-data view. */
.cc-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 64px 24px;
  gap: 6px;
}
/* `display: flex` above would override the `hidden` attribute (author rule beats
   the UA `[hidden]{display:none}`), so make hidden explicit. */
.cc-empty-state[hidden] { display: none; }
.cc-empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.cc-empty-icon svg { width: 32px; height: 32px; }
.cc-empty-title { font-size: 16px; font-weight: 600; color: var(--fg); margin: 0; }
.cc-empty-text { font-size: 13px; color: var(--fg-muted); margin: 0; max-width: 360px; }

/* Icon: an uploaded image (object-fit cover) or a centered default glyph.
   Clickable — clicking opens the file picker to set/replace it. */
.cc-icon {
  position: relative;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg-muted);
  cursor: pointer;
  overflow: hidden;
}
.cc-icon--company { width: 40px; height: 40px; }
.cc-icon--collection { width: 30px; height: 30px; border-radius: 8px; }
.cc-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cc-icon svg { width: 58%; height: 58%; }
.cc-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity 120ms ease;
}
.cc-icon:hover::after { opacity: 1; }
.cc-icon .cc-icon-edit {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  opacity: 0;
  z-index: 1;
  transition: opacity 120ms ease;
}
.cc-icon:hover .cc-icon-edit { opacity: 1; }
.cc-icon .cc-icon-edit svg { width: 44%; height: 44%; }

/* Icon preview + "Choose icon" button inside the create modal — centered as a
   row; the hint sits below so it doesn't throw off vertical alignment. */
.cc-modal-icon {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 6px;
}
.cc-icon-hint { margin: 0 0 8px; }

/* ── Email search results ─────────────────────────────────────────── */
/* Participant panel in the left column of an email result — From/To
   addresses, each with its domain favicon. Takes the slot the PDF/audio
   thumbnail occupies, but wider so addresses fit. */
.result-emails {
  flex-shrink: 0;
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  overflow: hidden;
}
.result-eml-group { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.result-eml-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--fg-muted);
}
.result-eml-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.result-eml-ico {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--hover);
}
.result-eml-ico--none { display: inline-block; }
.result-eml-addr {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}
.result-eml-more { font-size: 11px; color: var(--fg-muted); padding-left: 27px; }

/* Linked email attachments — a wrapped row of chips under the snippet. Each
   chip carries a PDF preview thumbnail (or a paperclip glyph) + the filename;
   PDF/audio chips link to the attachment's own file view. */
.result-attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.result-attach-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}
.result-attach {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 3px 9px 3px 4px;
  border: 1px solid var(--border, var(--hover));
  border-radius: 6px;
  background: var(--hover);
  color: var(--fg);
  font-size: 12px;
  text-decoration: none;
  overflow: hidden;
}
a.result-attach:hover { border-color: var(--accent, var(--fg-muted)); }
.result-attach--static { cursor: default; }
.result-attach-thumb {
  flex-shrink: 0;
  width: 22px;
  height: 28px;
  border-radius: 3px;
  object-fit: cover;
  object-position: top center;
  background: var(--bg, #fff);
}
.result-attach-thumb--img {
  width: 26px;
  height: 26px;
  object-position: center;
}
/* Word / PowerPoint attachment chips: a static type icon, contained + padded
   so the glyph reads whole in the small chip rather than being cover-cropped. */
.result-attach-thumb--icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  object-position: center;
  padding: 2px;
}
.result-attach-ico {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--fg-muted);
}
.result-attach-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Email-viewer attachment badges (document.html email view) — a wrapped row of
   clickable chips between the headers and the body. Mirrors the search chips. */
.doc-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}
.doc-attach {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 260px;
  padding: 4px 11px 4px 5px;
  border: 1px solid var(--border, var(--hover));
  border-radius: 7px;
  background: var(--hover);
  color: var(--fg);
  font-size: 13px;
  text-decoration: none;
}
a.doc-attach:hover { border-color: var(--accent, var(--fg-muted)); }
.doc-attach--static { cursor: default; }
.doc-attach-thumb {
  flex-shrink: 0;
  width: 24px;
  height: 30px;
  border-radius: 3px;
  object-fit: cover;
  object-position: top center;
  background: var(--bg, #fff);
}
.doc-attach-thumb--img { width: 28px; height: 28px; object-position: center; }
/* Office-format attachments show their type icon, contained + centred (not
   cover-cropped like a page preview) — mirrors .result-attach-thumb--icon. */
.doc-attach-thumb--icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  object-position: center;
  padding: 2px;
}
.doc-attach-ico {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--fg-muted);
}
.doc-attach-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Email provenance panel (document.html / image.html / pdf.html) — the emails
   a file is attached to, as a list of linked email cards. */
/* The panel already sits in `.doc-body`'s 8fr column, so the cap here only
   needs to stop cards from stretching on an ultrawide — at 760px it was
   leaving big empty gutters inside a column that's already bounded. */
.doc-prov-wrap { max-width: 1100px; margin: 0 auto; padding: 24px; }
.doc-prov-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
/* One email = a card laid out like a search result: participants column on
   the left, message on the right. The card is not itself a link (attachment
   chips inside it are), so the hover cue is on the card and the subject
   carries the href. */
.doc-prov-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border, var(--hover));
  border-radius: 8px;
  background: var(--hover);
  color: var(--fg);
}
.doc-prov-item:hover { border-color: var(--accent, var(--fg-muted)); }
/* Same width as the search page's participants column, now that the card has
   the room — long addresses truncate less. */
.doc-prov-people { width: 210px; }
.doc-prov-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.doc-prov-head { display: flex; align-items: baseline; gap: 10px; }
.doc-prov-subject {
  min-width: 0;
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-prov-subject:hover { text-decoration: underline; }
.doc-prov-date {
  flex-shrink: 0;
  color: var(--fg-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
/* Attachment-level facts: the name it was sent under, the source inbox. */
.doc-prov-detail { margin: 0; color: var(--fg-muted); font-size: 12px; }
.doc-prov-detail [title] { cursor: help; }
.doc-prov-sentas { color: var(--fg); font-weight: 600; }
/* The other attachments that travelled with this file, as chips. */
.doc-prov-atts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }
.doc-prov-atts-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}
/* Stack the columns when the viewport can't hold both. */
@media (max-width: 640px) {
  .doc-prov-item { flex-direction: column; gap: 10px; }
  .doc-prov-people { width: 100%; }
}

/* Image viewer (image.html) — centred, bounded, on a checkerboard-free surface. */
.doc-image-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background: var(--hover);
  border-radius: 8px;
}
.doc-image {
  max-width: 100%;
  max-height: 80vh;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}

/* Non-clickable facet row (Top inboxes — display-only for now). */
.facet-list-item--static { cursor: default; }
.facet-list-item--static:hover { background: transparent; }

/* ApexCharts bar chart on the search dashboard ("Files by document date").
   Reserve height so the chart-card doesn't reflow when the chart mounts. */
.chart-bars { min-height: 220px; }

/* ── Email detail view (/document/<sha> for category=email) ─────────── */
/* Sits in the primary doc panel where the PDF <embed> would be. */
.doc-email {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  padding: 20px 24px;
}
.doc-email-headers {
  margin: 0 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.doc-email-row { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.doc-email-row dt {
  flex-shrink: 0;
  width: 64px;
  text-align: right;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--fg-muted);
}
.doc-email-row dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; min-width: 0; }
.doc-email-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.doc-email-chip-ico {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  object-fit: contain;
  background: var(--hover);
}
/* Plain-text fallback (emails indexed before the formatter). */
.doc-email-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 80ch;
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg);
}

/* Structured render: quote blocks, signature, attachment chips. */
.doc-email-render { max-width: 80ch; font-size: 14px; line-height: 1.4; color: var(--fg); }
/* Every text block keeps its own newline layout (headers on their own lines,
   hard wraps preserved) via pre-wrap — display only; the search `text` is
   normalized separately. Links wrap rather than overflow. */
.doc-email-render .doc-email-note,
.doc-email-render .doc-email-block {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0 0 8px;
}
/* HTML emails are converted to laid-out text by inscriptis (tables → columns
   aligned with spaces). Render monospace so the columns line up, keep pre-wrap
   so prose still wraps, but don't break inside words/columns; wide tables get a
   horizontal scroll instead of being mangled, and we lift the 80ch prose cap. */
.doc-email-render .doc-email-html {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  overflow-wrap: normal;
  overflow-x: auto;
  max-width: none;
}
/* Nested quote levels: a left rule + indent, muted, like a mail client. */
.doc-email-render blockquote {
  margin: 6px 0;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border);
  color: var(--fg-muted);
}
/* Foldable quoted history. */
.doc-email-quote { margin: 10px 0; }
.doc-email-quote > summary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--fg-muted);
  list-style: none;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  user-select: none;
}
.doc-email-quote > summary::-webkit-details-marker { display: none; }
.doc-email-quote > summary::before { content: "···"; font-weight: 700; letter-spacing: 1px; }
.doc-email-quote[open] > summary::before { content: "×"; }
/* Signature — muted, set off from the message. */
.doc-email-sig {
  white-space: pre-wrap;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--fg-muted);
}
/* Inline attachment chip (placeholder in the text — not the file itself). */
.doc-email-attach {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  margin: 0 1px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
}
.doc-email-attach svg { width: 12px; height: 12px; }

/* ── Security page (/security) ──────────────────────────────────────────
   The login audit. Deliberately thin: the table itself reuses `.users-table`
   and the shell reuses `.settings-card` / `.settings-tabs`, so only the
   audit-specific cells and the pager are styled here. */
.sec-table-wrap { overflow-x: auto; }   /* narrow viewports scroll the table, not the page */
.sec-table { min-width: 860px; }
.sec-when { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--fg-muted); }
.sec-muted { color: var(--fg-muted); }

/* Outcome badges — only the failures are badged. A successful sign-in is the
   norm and shows a muted dash instead; a column of identical green pills would
   be noise you'd have to look past to find the row that matters. */
.sec-badge--fail { background: var(--danger, #b42318); color: #fff; }
.sec-badge--warn {
  background: transparent;
  border: 1px solid var(--danger, #b42318);
  color: var(--danger, #b42318);
}

/* Location cell: flag + country name, place after it. The name carries the
   meaning on its own, so nothing breaks on Windows, where regional-indicator
   pairs render as bare letters instead of a flag. */
.sec-loc { display: inline-flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.sec-flag { font-size: 15px; line-height: 1; }
.sec-country { font-weight: 600; }
.sec-city { color: var(--fg-muted); }

/* Network cell: AS org on top, the machine-readable detail muted beneath. */
.sec-as { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sec-asorg { color: var(--fg); }
.sec-asmeta { font-size: 11px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }

/* Network type (PeeringDB `info_types`) — a classification, so it reads as a
   quiet tag rather than plain text. */
.sec-nettype {
  display: inline-block;
  white-space: nowrap;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

/* Pager */
.sec-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.sec-pager-nums { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sec-pager-num,
.sec-pager-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--fg-muted);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.sec-pager-num:hover,
.sec-pager-step:hover { background: var(--hover); color: var(--fg); }
.sec-pager-num.is-current {
  background: var(--accent);
  color: var(--accent-fg, #fff);
  font-weight: 600;
}
.sec-pager-step.is-disabled { opacity: 0.4; pointer-events: none; }
.sec-pager-gap { color: var(--fg-muted); padding: 0 2px; }

/* Empty state */
.sec-empty { padding: 40px 24px; text-align: center; }
.sec-empty-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--fg); }
.sec-empty-sub { margin: 6px 0 0; font-size: 13px; color: var(--fg-muted); }
