/* Header padding matches the page frame top/sides so the title sits at the same height as the scrolling-body pages (preferences/secrets). */
#toolbar {
  padding: var(--page-pad-y) var(--page-pad-x) var(--page-head-gap);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
#toolbar:empty {
  display: none;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}
.page-headings {
  display: flex;
  flex-direction: column;
}
.page-title {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
}
.page-sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: var(--fs-base);
}
.page-head .page-headings { margin-right: auto; }
.page-filters {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-filters:empty { display: none; }
.page-filters .filter-search {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.page-filters .filter-search input,
.page-filters .filter-search select { min-width: 150px; }
/* One height + text size so the filter row and action icons read as a single band. */
.page-filters input,
.page-filters select,
.page-filters .seg-toggle,
.page-actions .icon-btn,
.page-actions .pill-btn {
  height: var(--control-h);
  box-sizing: border-box;
  font-size: var(--control-fs);
}
/* the segmented toggle defaults to flex-end (catalog use); centre it in the header band */
.page-filters .seg-toggle { align-self: center; }
.page-filters .seg-btn { font-size: var(--control-fs); }
.page-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
/* Inside the scrolling body (preferences) the header needs its own bottom gap;
   the toolbar variant gets it from #toolbar padding instead. */
#table-body > .page-head { margin-bottom: var(--page-head-gap); }
button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid var(--accent-hover);
  padding: 7px 13px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  cursor: pointer;
}
button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-active);
}

table.data td.actions {
  text-align: right;
  white-space: nowrap;
}
/* :not(.icon-btn) so this higher-specificity rule doesn't re-box borderless icon buttons */
table.data td.actions button:not(.icon-btn) {
  margin-left: 4px;
  font-size: var(--fs-sm);
  padding: 4px 10px;
  border: 1px solid var(--border-input-plain);
  background: var(--surface-raised);
  border-radius: var(--r-sm);
}
table.data td.actions button.primary:not(.icon-btn) {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent-hover);
}
table.data td.actions button:not(.icon-btn):hover {
  border-color: var(--focus-ring);
}

#table-body {
  flex: 1;
  overflow: auto;
  padding: var(--page-pad-y) var(--page-pad-x);
}
/* When a toolbar header sits above (table pages), it already owns the top gap —
   drop the body's top padding so the header height matches the headerless pages. */
#toolbar:not(:empty) + #table-body { padding-top: 0; }
#table-host {
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0;
}

/* !important so [hidden] (0,1,0) beats element-id display rules like #login-overlay (1,0,0) */
[hidden] { display: none !important; }

.sidebar-spacer { flex: 1; }

.rail-toggle {
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--sidebar-fg-dim);
  padding: 4px;
  border-radius: var(--r-xs);
  display: inline-flex;
  cursor: pointer;
}
.rail-toggle .lucide { width: 18px; height: 18px; }
.rail-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }
.rail-toggle:focus-visible { outline: none; border-color: var(--sidebar-control-border); }

#sidebar-footer {
  position: relative;
  border-top: 1px solid var(--sidebar-divider);
  padding: 10px;
}

#user-trigger {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--sidebar-fg);
  padding: 6px 8px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font: inherit;
}
#user-trigger:hover {
  background: var(--sidebar-hover);
}
#user-trigger.is-open {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-control-border);
}
#user-trigger .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--focus-ring) 0%, var(--accent-grad-end) 100%);
  color: var(--text-inverse);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  flex-shrink: 0;
}
#user-trigger .meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  transition: opacity 0.12s ease;
}
#user-trigger .user-name {
  font-size: var(--fs-base);
  color: var(--sidebar-fg-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
#user-trigger .user-role {
  font-size: var(--fs-xs);
  color: var(--sidebar-fg-dim);
}
#user-trigger .caret {
  color: var(--sidebar-fg-dim);
  font-size: var(--fs-micro);
  transition: opacity 0.12s ease;
}

/* Collapsed: drop meta/caret from flow (not just opacity) so the avatar — and its hover plate — sit centred in the rail instead of left-aligned with empty slack. */
html.sidebar-collapsed #user-trigger {
  width: 40px;
  margin-inline: auto;
  padding: 6px;
  justify-content: center;
}
html.sidebar-collapsed #user-trigger .meta,
html.sidebar-collapsed #user-trigger .caret {
  display: none;
}
/* position:fixed (not absolute) so the popover escapes #sidebar's overflow:hidden,
   which would otherwise clip it the moment it pops out past the 64px rail. */
html.sidebar-collapsed #user-menu {
  position: fixed;
  left: calc(64px + 6px);  /* rail width (layout.css) + gap */
  right: auto;
  top: auto;               /* self-sufficient anchor, not reliant on the base bottom */
  bottom: 14px;
  min-width: 200px;
}

#user-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 10px;
  right: 10px;
  background: var(--menu-bg);
  border: 1px solid var(--sidebar-control-border);
  border-radius: var(--r-sm);
  box-shadow: 0 8px 24px var(--shadow-menu);
  padding: 6px;
  z-index: 100;
}
.menu-label {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sidebar-fg-dim);
  padding: 6px 10px 4px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--sidebar-fg);
  padding: 7px 10px;
  border-radius: var(--r-xs);
  font: inherit;
  font-size: var(--fs-base);
  cursor: pointer;
  text-decoration: none;
}
.menu-item .lucide {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.menu-item:hover {
  background: var(--menu-hover);
  color: var(--sidebar-fg-strong);
}
.menu-item.destructive {
  color: var(--danger-menu-fg);
}
.menu-item.destructive:hover {
  background: var(--danger-menu-hover-bg);
  color: var(--danger-menu-hover-fg);
}
.menu-divider {
  height: 1px;
  background: var(--sidebar-divider);
  margin: 6px 0;
}
/* Drop the divider when nothing sits above it (admin section + Preferences both hidden for viewers) so Sign out isn't left under a stray line. */
#admin-menu[hidden] + #menu-preferences[hidden] + .menu-divider { display: none; }

/* full reset so the Sign-out <button> renders identically to the <a> menu items */
button.menu-item {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  outline: none;
  white-space: nowrap;
  box-sizing: border-box;
  width: 100%;
  display: flex;  /* flex, not block, so the menu-item icon+label sit in a row */
  text-align: left;
  line-height: var(--lh-normal);
}

td.actions {
  white-space: nowrap;
  text-align: right;
  padding-right: 8px;
}
.pill-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--pill-border);
  background: var(--pill-bg);
  color: var(--pill-fg);
  font: inherit;
  font-size: var(--fs-sm);
  line-height: var(--lh-tight);
  padding: 4px 9px;
  margin: 0 3px;
  border-radius: var(--r-sm);
  vertical-align: middle;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.pill-btn:hover {
  background: var(--pill-hover-bg);
  color: var(--pill-hover-fg);
  border-color: var(--pill-hover-border);
}
.pill-btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent-hover);
}
.pill-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-active);
}
.pill-btn.danger {
  color: var(--danger);
  border-color: var(--danger-border);
}
.pill-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger-hover);
}

/* One keyboard focus ring for the whole unified text-button family (icon-btn keeps its own). */
button.primary:focus-visible,
.pill-btn:focus-visible,
.modal-actions button:focus-visible,
.cat-pane-header .primary:focus-visible,
.cat-pager button:focus-visible,
.prefs-actions .primary:focus-visible,
.prefs-actions #prefs-revert:focus-visible,
.home-actions .btn:focus-visible,
.logs-close:focus-visible,
.preview-modal-close:focus-visible,
#login-form button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

