/**
 * Admin Dashboard Styles
 * Dark theme with CSS custom properties
 */

:root {
  /* Color palette */
  --bg: #1e1e1e;
  --fg: #d4d4d4;
  --accent: #007acc;
  --danger: #f48771;
  --warn: #dcdcaa;
  --ok: #4ec9b0;
  --sidebar-bg: #252526;
  --border: #3e3e42;
  /* Accent as TEXT: --accent (#007acc) is only 3.4:1 on the dark panels. */
  --accent-text: #4daafc;
  
  /* Spacing */
  --sidebar-width: 240px;
  --topbar-height: 50px;
  
  /* Fonts */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  overflow: hidden;
}

/* Top Bar */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 1.5rem;
  z-index: 100;
}

#topbar .user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#topbar .user-details {
  text-align: right;
}

#topbar .user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

#topbar .user-roles {
  font-size: 0.8rem;
  color: var(--accent-text);
}

#topbar .btn-logoff {
  background: var(--danger);
  color: var(--text-inverse, #1e1e1e);
  font-weight: 600;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}

#topbar .btn-logoff:hover {
  opacity: 0.85;
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  overflow-y: auto;
  z-index: 101;
}

#sidebar .sidebar-header {
  padding: 0 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

#sidebar .sidebar-header h1 {
  font-size: 1.25rem;
  color: var(--accent-text);
}

#sidebar nav {
  list-style: none;
}

#sidebar nav a {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--fg);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}

#sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent-text);
}

#sidebar nav a.active {
  background: rgba(0, 122, 204, 0.2);
  color: var(--fg);
  font-weight: 600;
  border-left: 3px solid var(--accent);
  padding-left: calc(1.5rem - 3px);
}

/* Main Content
 *
 * `position: absolute`, NOT fixed, and no z-index, on purpose: a fixed box is
 * always a stacking context, which trapped every `position: fixed` overlay a
 * view puts inside it (the static `.modal` dialogs in views/*.html) BELOW the
 * sidebar (z 101) and top bar (z 100) no matter what z-index the overlay had.
 * As a plain positioned box #main adds no stacking context, so the shell's
 * layers - top bar 100, sidebar 101, drawers 800, modals 900/1000 - compete in
 * the one root context. body is overflow:hidden and the initial containing
 * block is the viewport, so the box covers the same area it did as fixed. */
#main {
  position: absolute;
  top: var(--topbar-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 2rem;
}

#content {
  max-width: 1200px;
}

#content h1 {
  margin-bottom: 1.5rem;
  color: var(--fg);
  font-size: 2rem;
}

#content h2 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: var(--fg);
  font-size: 1.5rem;
}

#content p {
  margin-bottom: 1rem;
  color: #b3b3b3;
}

#content pre {
  background: #2d2d30;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* Login Form */
#login-form {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

#login-form h2 {
  margin: 0 0 1rem 0;
  color: var(--accent-text);
}

#login-form p {
  margin-bottom: 1.5rem;
  color: #b3b3b3;
}

#login-form .login-form-note {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#login-form .btn-login {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  font-size: 1rem;
  transition: opacity 0.2s;
}

#login-form .btn-login:hover {
  opacity: 0.85;
}

#login-form .form-row {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#login-form .form-row label {
  color: #b3b3b3;
  font-size: 0.9rem;
}

#login-form .form-row input {
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}

#login-form .form-row input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Modal Root */
#modal-root {
  /* Placeholder for error modals (Task 22) */
}

/* Loading State */
.loading {
  text-align: center;
  padding: 3rem;
  color: #888;
  font-size: 1.1rem;
}

/* Error State */
.error {
  background: rgba(244, 135, 113, 0.1);
  border: 1px solid var(--danger);
  border-radius: 4px;
  padding: 1rem;
  margin: 1rem 0;
  color: var(--danger);
}

/* Utilities */
.hidden {
  display: none !important;
}

.text-accent {
  color: var(--accent-text);
}

.text-danger {
  color: var(--danger);
}

.text-warn {
  color: var(--warn);
}

.text-ok {
  color: var(--ok);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4e4e52;
}

/* Realms View Styles (round-61 rename of "sites" -> "realms").
 * Legacy .sites-view + .site-registry-view selectors are kept alongside
 * the new ones for one release so any consumer that still emits the old
 * markup keeps the same styling. Phase 2 will drop the legacy selectors.
 */
.realms-view,
.realm-registry-view,
.sites-view,
.site-registry-view,
.users-view,
.groups-view,
.policies-view,
.sessions-view,
.settings-view {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
}

.btn-primary, .btn-secondary, .btn-danger {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--border);
  color: var(--fg);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse, #1e1e1e);
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover {
  opacity: 0.85;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.data-table thead {
  background: #2d2d30;
}

.data-table th {
  padding: 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.05);
}

.clickable-row {
  cursor: pointer;
}

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-active {
  background: rgba(78, 201, 176, 0.2);
  color: var(--ok);
}

.status-disabled {
  background: rgba(220, 220, 170, 0.2);
  color: var(--warn);
}

.status-deleted {
  background: rgba(244, 135, 113, 0.2);
  color: var(--danger);
}

/* Realm Detail Pane (round-61 rename — .site-detail-pane kept alongside) */
.realm-detail-pane,
.site-detail-pane {
  position: fixed;
  right: 0;
  top: var(--topbar-height);
  bottom: 0;
  width: 500px;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 50;
}

/* Task 134 — fullscreen modal overlay for the realm detail content.
 * The overlay is appended to <body> so it stacks above the sidebar +
 * topbar regardless of where #realm-detail-pane sits in the layout.
 *
 * It is a PAGE layer, not a dialog layer: z-index 880 sits above the top bar
 * and sidebar (100/101), the drawers (800) and the mobile nav panel and its
 * backdrop (850/840, views.css), and BELOW every dialog layer - .modal-overlay
 * (900, web-ui-base/components.css, which wins over admin.css's 1000), the
 * static .modal (1000), the toasts (1000) and the error modal (10000). At
 * 1000 it out-ranked .modal-overlay, so every dialog opened from the
 * full-screen view (Edit, Rename, Delete, Add redirect, Create registry
 * definition, any openDialog() in #modal-root) painted underneath it and
 * could not be clicked, whatever its DOM order. */
.realm-detail-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  z-index: 880;
}

.realm-detail-modal {
  flex: 1 1 auto;
  margin: 2vh 4vw;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* The toggle button itself (Expand/Collapse glyph). */
.btn-toggle-detail-mode {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
}

.btn-toggle-detail-mode:hover {
  color: var(--accent-text);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
}

.btn-close:hover {
  color: var(--danger);
}

/* The realm detail has eight tabs (Info ... Providers ... Roles, Federation): in the
 * 500px drawer they did not fit (515px of tabs in a 452px bar, "Roles"
 * clipped). Tighter padding fits them in the drawer; wrapping keeps every
 * tab visible and reachable (no hidden sideways scroll) wherever the bar is
 * narrower, e.g. the full-width phone drawer. */
.detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--fg);
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s;
}

.tab-btn:hover {
  border-bottom-color: var(--accent);
}

.tab-btn.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

.detail-content {
  margin-top: 1rem;
}

/* Realm Info (round-61 rename — .site-info kept alongside) */
.realm-info .info-row,
.site-info .info-row {
  display: flex;
  margin-bottom: 0.75rem;
  gap: 1rem;
}

.realm-info .info-row label,
.site-info .info-row label {
  flex: 0 0 150px;
  font-weight: 600;
  color: #888;
}

.realm-info .info-row span,
.site-info .info-row span {
  flex: 1;
  word-break: break-all;
}

.realm-info .info-actions,
.site-info .info-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* Realm Redirects (round-61 rename — .site-redirects kept alongside) */
.realm-redirects .redirects-header,
.site-redirects .redirects-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.realm-redirects h3,
.site-redirects h3 {
  margin: 0;
  font-size: 1.1rem;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* Static template modals (policies.html, users.html, ...) are declared as
   `<div class="modal hidden">` and shown by dropping `hidden`. Nothing styled
   `.modal`, so an "open" one rendered as an in-flow card under the page
   instead of a dialog. Same look as .modal-overlay. */
.modal:not(.hidden) {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin: 0 0 1.5rem 0;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-family: var(--font-family);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Local-only elevated access indicator (whoami.localBrowser === true).
   Deliberately loud so privileged local sessions are unmistakable. */
.local-browser-banner {
  display: block;
  background: #8a4b00;
  color: #fff3e0;
  border-bottom: 2px solid #ffb74d;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-align: center;
}

/* Onboarding / "Getting Started" checklist (Overview view).
   State-driven from real backend reads; see app.js renderOverview(). */
.onboarding {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 1rem 0 1.5rem 0;
}

.onboarding-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.onboarding-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.onboarding-progress {
  color: var(--warn);
  font-size: 0.85rem;
  font-weight: 600;
}

.onboarding-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.75rem 0 1rem 0;
}

.onboarding-bar-fill {
  height: 100%;
  background: var(--ok);
  transition: width 0.3s ease;
}

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

.onboarding-step {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}

.onboarding-step:first-child {
  border-top: none;
}

.onboarding-check {
  font-size: 1.1rem;
  line-height: 1.4;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}

.onboarding-step.done .onboarding-check {
  color: var(--ok);
}

.onboarding-step.todo .onboarding-check {
  color: var(--warn);
}

.onboarding-step-label {
  font-weight: 600;
}

.onboarding-step.done .onboarding-step-label {
  color: var(--ok);
}

.onboarding-step-detail {
  font-size: 0.85rem;
  color: var(--fg);
  opacity: 0.85;
  margin-top: 0.15rem;
}

.onboarding-step-actions {
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.onboarding-link {
  color: var(--accent-text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.onboarding-link:hover {
  text-decoration: underline;
}

.onboarding-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-family: var(--font-family);
  cursor: pointer;
}

.onboarding-btn.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}

.onboarding-btn:hover {
  filter: brightness(1.1);
}

.onboarding-footer {
  margin-top: 1rem;
}

.onboarding-hint {
  font-size: 0.8rem;
  color: var(--fg);
  opacity: 0.7;
}

.onboarding-collapsed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.onboarding-collapsed-label {
  color: var(--ok);
  font-weight: 600;
}

/* Overview stats strip */
.overview-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
}

.overview-card {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  min-width: 120px;
  flex: 1;
  text-align: center;
}

.overview-num {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.overview-cap {
  font-size: 0.8rem;
  color: var(--fg);
  opacity: 0.75;
  margin-top: 0.25rem;
}

/* ------------------------------------------------------------------ */
/* Audit View (round-32)                                              */
/* ------------------------------------------------------------------ */

.audit-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.audit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
}

.audit-actions label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  gap: 0.25rem;
}

.audit-actions select,
.audit-actions input[type="text"],
.audit-actions input[type="datetime-local"] {
  background: var(--sidebar-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

.audit-actions select[multiple] {
  min-width: 9rem;
}

.audit-text-field input {
  min-width: 12rem;
}

.audit-new-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255, 200, 0, 0.12);
  border: 1px solid rgba(255, 200, 0, 0.45);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
}

.audit-pagination {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.85rem;
}

.audit-pagination-info {
  margin-right: auto;
  opacity: 0.85;
}

/* Severity chips — info=gray, warn=yellow, error=red, critical=red+bold */
.audit-severity {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.audit-severity-info {
  background: rgba(160, 160, 160, 0.18);
  color: #ccc;
  border: 1px solid rgba(160, 160, 160, 0.35);
}

.audit-severity-warn {
  background: rgba(240, 200, 50, 0.18);
  color: #ffd95a;
  border: 1px solid rgba(240, 200, 50, 0.45);
}

.audit-severity-error {
  background: rgba(220, 60, 60, 0.18);
  color: #ff7878;
  border: 1px solid rgba(220, 60, 60, 0.45);
}

.audit-severity-critical {
  background: rgba(220, 30, 30, 0.28);
  color: #ff5555;
  border: 1px solid rgba(220, 30, 30, 0.75);
  font-weight: 800;
}

.audit-detail-drawer {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin-top: 1rem;
  background: var(--sidebar-bg);
}

.audit-event-detail .info-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.25rem 0;
}

.audit-event-detail .info-row label {
  min-width: 9rem;
  font-weight: 600;
  opacity: 0.85;
}

.audit-event-detail .muted {
  opacity: 0.6;
}

.audit-json-heading {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.audit-event-json {
  background: #1c1c1f;
  color: #d8d8d8;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
  font-family: ui-monospace, "Consolas", "Menlo", monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  max-height: 24rem;
  overflow: auto;
  white-space: pre;
}

.help-body h4 {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.95rem;
}

/* Deprecation banner shown atop legacy standalone Users + Groups views.
 * The realm-scoped Users/Groups/Roles tabs in the Realm detail modal are
 * the supported surface going forward; this view stays for one release
 * for back-compat. */
.deprecation-banner {
  margin: 0 0 0.75rem 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid #8a6d3b;
  background: #2a2417;
  color: #f8e8b8;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.deprecation-banner a {
  color: #ffd966;
  text-decoration: underline;
}

/* ------------------------------------------------------------------ */
/* Admin directory pages: Users, Groups & Roles (views/directory-*.js) */
/* Minimal, token-based; everything else reuses existing classes.      */
/* ------------------------------------------------------------------ */
.dir-view .dir-help {
  margin: -0.75rem 0 1rem 0;
  font-size: 0.9rem;
}

.dir-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.dir-filters input,
.dir-filters select,
.dir-dialog select,
.dir-inline-form select,
.dir-inline-form input,
.dir-edit-form input {
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-family: var(--font-family);
}

.dir-filters input[type="search"] {
  flex: 1 1 16rem;
  min-width: 12rem;
}

.dir-dialog select {
  width: 100%;
}

.dir-count {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.dir-pager {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.dir-notice {
  margin: 0 0 1rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 4px;
  background: var(--sidebar-bg);
}
.dir-notice[data-kind="ok"]    { border-left-color: var(--ok); }
.dir-notice[data-kind="warn"]  { border-left-color: var(--warn); }
.dir-notice[data-kind="error"] { border-left-color: var(--danger); color: var(--danger); }

.dir-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.dir-tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fg);
  cursor: pointer;
  font-size: 0.95rem;
}
.dir-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* Detail drawer (.drawer + .open come from web-ui-base/components.css).
   Its `top` (under the top bar) is set in views.css, which loads last: a
   `top` here lost to components.css's `.drawer { top: 0 }`. */
.dir-drawer {
  width: 520px;
  overflow-y: auto;
}
.dir-drawer-body {
  padding: 1rem 1.25rem 2rem;
}
.dir-drawer .drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.dir-section {
  margin: 0 0 1.25rem 0;
}
.dir-section h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg);
  opacity: 0.8;
}
.dir-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin-bottom: 0.75rem;
}
.dir-dl dt { opacity: 0.7; }
.dir-dl dd { word-break: break-word; }
.dir-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.dir-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.dir-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.dir-chip {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}
.dir-chip-x {
  margin-left: 0.15rem;
  padding: 0 0.2rem;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.dir-inline-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.dir-inline-form select,
.dir-inline-form input { flex: 1 1 auto; min-width: 0; }
.dir-edit-form .form-group { margin-bottom: 0.5rem; }
.dir-edit-form input { width: 100%; max-width: 32rem; }
.realm-ugr-panel { margin-top: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 4px; }
.dir-mini-table { font-size: 0.85rem; }
.dir-list { margin-left: 1.25rem; }
.dir-inherited { font-size: 0.85rem; }

.dir-status-active   { background: rgba(78, 201, 176, 0.2); color: var(--ok); }
.dir-status-disabled { background: rgba(220, 220, 170, 0.2); color: var(--warn); }
.dir-status-locked   { background: rgba(220, 220, 170, 0.2); color: var(--warn); }
.dir-status-deleted  { background: rgba(244, 135, 113, 0.2); color: var(--danger); }

.dir-dialog { max-width: 520px; }
.dir-dialog .required { color: var(--danger); }
.dir-dialog small { display: block; margin-top: 0.25rem; }
.dir-warning { margin-bottom: 0.75rem; color: var(--warn); }
.dir-secret {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px dashed var(--warn);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  word-break: break-all;
  user-select: all;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ActionModal (components/ActionModal.js): the full-screen, URL-addressable
   modal every admin action (New / Edit / Test / Onboard / Manage ...) opens
   instead of an inline card. Same .modal-overlay layer (900) as the other
   dialogs so small confirm dialogs opened from inside it still stack above. */
.modal-overlay.action-modal-overlay,
.modal-overlay.modal-fullscreen,
.modal.modal-fullscreen:not(.hidden) {
  align-items: stretch;
  justify-content: stretch;
  background: var(--bg);
}
.action-modal-open { overflow: hidden; }
.modal-content.action-modal,
.modal-fullscreen > .modal-content,
.modal-fullscreen > .modal-dialog {
  background: var(--sidebar-bg);
  width: 100%;
  max-width: none;
  min-width: 0;
  max-height: none;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-sizing: border-box;
  padding: 1rem clamp(1rem, 4vw, 3rem) 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.action-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: -1rem;
  z-index: 1;
  background: var(--sidebar-bg);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.action-modal-head h2 { margin: 0; font-size: 1.25rem; }
.action-modal-close { font-size: 1.25rem; line-height: 1; min-width: 2.5rem; min-height: 2.5rem; }
.action-modal-body { flex: 1 1 auto; width: 100%; max-width: 60rem; margin: 0 auto; }
.action-modal-body .pi-form,
.action-modal-body .card { border: 0; box-shadow: none; padding: 0; background: transparent; }
.action-modal-body .pv-wizard-nav { position: sticky; bottom: 0; background: var(--sidebar-bg); padding: 0.75rem 0; flex-wrap: wrap; }
@media (max-width: 600px) {
  .modal-content.action-modal { padding: 0.5rem 0.75rem 1.5rem; }
  .action-modal-body .pv-wizard-nav .btn { flex: 1 1 auto; min-height: 2.5rem; }
}

/* Full-screen realm / policy form modals: keep the form column readable. */
.modal-fullscreen > .modal-content > form,
.modal-fullscreen > .modal-content > .modal-body { max-width: 60rem; margin-left: auto; margin-right: auto; width: 100%; }
.modal-fullscreen > .modal-content > h2 { max-width: 60rem; margin-left: auto; margin-right: auto; width: 100%; }

/* ------------------------------------------------------------------ */
/* Toolbar placement: action buttons sit ABOVE their table.            */
/* One .table-toolbar per table, directly above it (DOM order = tab    */
/* order). Primary action left, filters to its right, wraps on mobile. */
/* ------------------------------------------------------------------ */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 0.75rem 0;
}
.table-toolbar > .tt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  max-width: 100%;
}
.table-toolbar > :not(.tt-actions):not(.tt-label):not(.tt-note) {
  flex: 1 1 16rem;
  margin-top: 0;
  margin-bottom: 0;
  min-width: 0;
}
.table-toolbar > .tt-actions.tt-fill { flex: 1 1 100%; width: 100%; box-sizing: border-box; }
.table-toolbar > .tt-actions.tt-fill > .dir-inline-form { flex: 1 1 100%; width: 100%; min-width: 0; box-sizing: border-box; margin-top: 0; }
.table-toolbar > .tt-actions.tt-fill > .dir-inline-form > :is(input, select, .combo) { flex: 1 1 auto; min-width: 0; box-sizing: border-box; }
.table-toolbar > .tt-actions.tt-fill > .dir-inline-form > .combo > input { width: 100%; box-sizing: border-box; }
.table-toolbar > .tt-actions.tt-fill > .dir-inline-form > button { flex: 0 0 auto; }
.table-toolbar > .tt-label { font-weight: 600; }
.table-toolbar > .tt-note { flex: 1 1 100%; margin: 0; }
@media (max-width: 640px) {
  .table-toolbar > .tt-actions { flex: 1 1 100%; }
  .table-toolbar > :not(.tt-actions):not(.tt-label):not(.tt-note) { flex: 1 1 100%; }
}

/* Realm drop-down on the Users / Groups pages (components/RealmSelector.js, docs/admin-realm-dropdown.md) */
.realm-selector {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 1rem;
}
.realm-selector-label { font-weight: 600; }
.realm-selector-select { min-width: 16rem; max-width: 100%; }
.realm-selector-select:disabled { opacity: 0.8; }
.realm-selector-hint { flex: 1 1 18rem; font-size: 0.85rem; }
.realm-level-badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--sidebar-bg);
}
.realm-level-badge.level-read { border-color: var(--warn); }
.realm-level-badge.level-admin,
.realm-level-badge.level-global { border-color: var(--ok); }
.realm-selector-empty { padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 4px; }
.realm-scope-host { margin-top: 0.5rem; }
