/* Admin panel
 *
 * Density choices:
 *   - 3-up grid for the three allowlist editors so vertical scrolling
 *     is rarely needed even on a 13" laptop.
 *   - Per-section header is one row: h4 + a small inline hint, no
 *     dedicated <p> blocks.
 *   - Lists capped at 140px scroll, since real allowlists rarely have
 *     more than a handful of entries; if they do, the user scrolls.
 *   - The Users table is the dense piece — 32px rows, monospace email,
 *     small action buttons.
 */
/* Override .modal-wide's width (min(94vw,720px)) — the admin panel carries
   wide tables (OAuth providers has 7 columns) that need real room. ``width``
   not just ``max-width``, or the 720px cap from .modal-wide wins. */
.admin-modal { width: min(96vw, 1400px); max-width: none; }
/* FIXED height: the dialog keeps one footprint across every tab — short
   tabs (Storage) don't collapse it, long tables don't grow it. Scrolling
   happens INSIDE each tab (see .admin-scroll below), never on the dialog. */
.admin-modal { height: min(85vh, 940px); }  /* ≤ .modal's 85vh max-height */
.admin-body {
    padding: 16px 20px; gap: 14px;
    flex: 1; min-height: 0;
    overflow: hidden;   /* the body itself never scrolls — panes do */
}
.admin-tabs { flex-shrink: 0; }

/* Default pane behavior: fill the body and scroll as a whole (Sign-in
   gate, OAuth providers, Storage — mixed content with no single table). */
.admin-tab-pane { flex: 1; min-height: 0; overflow-y: auto; }

/* Panes that contain a dedicated scroll area (.admin-scroll wraps the
   data table / card list): the pane is a fixed frame — header, filter
   toolbar and count stay put; only the data area scrolls. */
.admin-tab-pane:has(.admin-scroll) { overflow: hidden; }
.admin-tab-pane:has(.admin-scroll) > section {
    flex: 1 1 auto; min-height: 0;
}
/* Inside the fixed frame only the scroll area gives way — header, filter
   toolbar and row count keep their natural height. */
.admin-tab-pane:has(.admin-scroll) > section > :not(.admin-scroll) {
    flex-shrink: 0;
}
.admin-scroll {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto;
}
/* Sticky column headers inside a scroll area. Opaque background (the th
   is transparent by default) and an inset shadow standing in for the
   border, which border-collapse drops on sticky cells. */
.admin-scroll .admin-table thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--color-bg-elevated);
    box-shadow: inset 0 -1px 0 var(--color-border);
}
/* Long list variant (Groups): same fill-and-scroll, drop the 140px cap
   meant for the small embedded lists on the Sign-in gate tab. */
.admin-list.admin-scroll { max-height: none; }
/* Editor views (user/group) live in the same fixed frame: the form body
   scrolls, the Back header and Save/Cancel footer stay pinned. */
.admin-tab-pane > .admin-editor-pane { flex: 1 1 auto; min-height: 0; }
.admin-editor-pane .admin-editor-body { overflow-y: auto; min-height: 0; }

/* Consistent control sizing across the whole admin panel — every text input
   and select shares one height + full-width-within-column so forms read as a
   tidy stack rather than a ragged set of differently-sized boxes. */
.admin-body input[type="text"],
.admin-body input[type="email"],
.admin-body input[type="search"],
.admin-body input[type="number"],
.admin-body select {
    height: 36px;
    box-sizing: border-box;
}
/* Uniform width only for the editor's primary actions — NOT for in-table row
   buttons (those must stay compact or they overflow the actions column). */
.admin-editor-footer .btn { min-width: 96px; justify-content: center; }

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
@media (max-width: 600px) {
    .admin-grid { grid-template-columns: 1fr; }
}

.admin-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}
.admin-section header {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.admin-section header h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-primary);
}
.admin-section header .hint { font-size: 11px; line-height: 1.3; }

.admin-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    max-height: 140px;
    overflow-y: auto;
    /* modal-body is display:flex/column with overflow-y:auto; without
       flex-shrink:0 the column flex layout collapses non-fixed-height
       items even though the modal can scroll. */
    flex-shrink: 0;
    background: var(--color-bg);
}
.admin-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px 4px 10px;
    border-bottom: 1px solid var(--color-border-light);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
}
.admin-list li:last-child { border-bottom: none; }
.admin-list li.empty { color: var(--color-text-tertiary); font-family: inherit; font-style: italic; padding: 6px 10px; }
.admin-list .btn-remove {
    background: none;
    border: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    padding: 0 4px;
    font-size: 14px;
    line-height: 1;
}
.admin-list .btn-remove:hover { color: #ef4444; }

.admin-add-row {
    display: flex;
    gap: 6px;
}
.admin-add-row input {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 12px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.admin-users { margin-top: 4px; }
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.admin-table th, .admin-table td {
    text-align: left;
    padding: 5px 10px;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}
.admin-table th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: transparent;
    border-bottom-color: var(--color-border);
}
.admin-table td:first-child {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.admin-table td:last-child {
    text-align: right;
    width: 80px;
}
.admin-add-user { margin-top: 8px; }

/* ---------- User management + Groups ---------- */

.admin-toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.admin-toolbar input { flex: 1; }
.admin-toolbar .btn-sm { flex: 0 0 auto; }
.admin-table-count {
    margin: 10px 2px 0; font-size: 12px; color: var(--color-text-tertiary);
}

/* Uniform headers across Users / OAuth / Caps so all tabs share one density. */
.admin-table th {
    text-transform: uppercase; letter-spacing: 0.04em;
    font-size: 10px; color: var(--color-text-tertiary); font-weight: 600;
}
.admin-table td, .admin-table th { padding: 9px 10px; vertical-align: middle; }
.admin-table tbody tr { height: 44px; }

/* The Users table uses a FIXED layout with explicit column widths so the
   variable-length Email/Name/Groups can't shove the action buttons out of
   their cell (the old auto layout let long emails + wide buttons overlap).
   Widths sum to 100%; overflow in text columns ellipsizes. */
.admin-users .admin-table { table-layout: fixed; width: 100%; }
.admin-users .admin-table th:nth-child(1),
.admin-users .admin-table td:nth-child(1) { width: 38%; }     /* Email   */
.admin-users .admin-table th:nth-child(2),
.admin-users .admin-table td:nth-child(2) { width: 24%; }     /* Name    */
.admin-users .admin-table th:nth-child(3),
.admin-users .admin-table td:nth-child(3) { width: 64px; text-align: center; }  /* Admin */
.admin-users .admin-table th:nth-child(4),
.admin-users .admin-table td:nth-child(4) { width: 16%; }     /* Groups  */
.admin-users .admin-table th:nth-child(5),
.admin-users .admin-table td:nth-child(5) { width: 200px; }   /* Actions */

/* The Clerk users table shares .admin-users styling but has its own column
   set (Email / Name / Companies / Last sign-in / Actions) — without these
   overrides it inherits the native table's widths and "Companies" lands in
   the 64px checkbox column. */
#admin-clerk-users-table th:nth-child(3),
#admin-clerk-users-table td:nth-child(3) { width: 24%; text-align: left; }  /* Companies    */
#admin-clerk-users-table th:nth-child(4),
#admin-clerk-users-table td:nth-child(4) { width: 120px; }                  /* Last sign-in */
#admin-clerk-users-table th:nth-child(5),
#admin-clerk-users-table td:nth-child(5) { width: 110px; }                  /* Actions      */
#admin-clerk-users-table td:nth-child(3) {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Ellipsize the text columns instead of wrapping into the buttons. */
.admin-users .admin-table td:nth-child(1),
.admin-users .admin-table td:nth-child(2),
.admin-users .admin-table td.admin-cell-groups {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Email cell: truncate the address, never the badges — a clipped badge
   reads as an empty colored chip. */
.admin-user-id { display: flex; align-items: center; min-width: 0; }
.admin-user-id .admin-user-email {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-user-id .src-badge { flex: 0 0 auto; }
.admin-actions-cell { overflow: visible; }
.admin-users .row-actions {
    display: flex; gap: 6px; justify-content: flex-end; align-items: center;
    flex-wrap: nowrap;
}
.admin-cell-groups { color: var(--color-text-secondary); font-size: 12px; }

/* Compact square icon button (delete in table rows). Ghost by default; the
   danger variant goes red on hover only — never a full red bar. */
.admin-icon-btn {
    flex: 0 0 auto;
    width: 28px; height: 28px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--color-border-light); border-radius: var(--radius-md, 6px);
    background: transparent; cursor: pointer; font-size: 13px; line-height: 1;
}
.admin-icon-btn:hover:not(:disabled) { background: var(--color-bg-hover); }
.admin-icon-danger:hover:not(:disabled) {
    background: rgba(220, 53, 69, 0.12);
    border-color: #dc3545;
}
.admin-icon-btn:disabled { opacity: 0.35; cursor: default; }

/* ----- Full-pane user editor (swaps with the list) ----- */
.admin-editor-pane {
    display: flex; flex-direction: column;
    min-height: 420px;
}
.admin-editor-head {
    display: flex; align-items: center; gap: 14px;
    padding-bottom: 12px; margin-bottom: 16px;
    border-bottom: 1px solid var(--color-border-light);
}
.admin-editor-head h4 { margin: 0; font-size: 15px; }
.admin-back-btn {
    border: none; background: none; cursor: pointer;
    color: var(--color-accent, #007aff); font-size: 13px; padding: 0;
}
.admin-back-btn:hover { text-decoration: underline; }
/* The form lives in a single centered column so fields don't stretch to an
   awkward full 1000px width on a wide modal. */
.admin-editor-body { flex: 1; display: flex; justify-content: center; }
.admin-form-col {
    width: 100%; max-width: 560px;
    display: flex; flex-direction: column; gap: 16px;
}
.admin-editor-footer {
    display: flex; align-items: center; gap: 8px;
    padding-top: 14px; margin-top: 16px;
    border-top: 1px solid var(--color-border-light);
}
.admin-footer-spacer { flex: 1; }            /* pushes Delete left, Cancel/Save right */
.admin-editor-error { color: var(--color-error); font-size: 12px; }
.admin-members-label { display: block; margin-top: 14px; }
/* Subtle danger: red text on a normal secondary button (not a filled red bar). */
.btn-danger-text { color: var(--color-error); }
.btn-danger-text:hover:not(:disabled) { border-color: var(--color-error); }

.admin-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.admin-field > span { color: var(--color-text-secondary); font-weight: 500; }
/* :not() guard — a bare `input { width: 100% }` also stretched checkboxes,
   shoving their label text to the far edge of the row. */
.admin-field input:not([type="checkbox"]) { width: 100%; }
.admin-field-hint { font-size: 11px; color: var(--color-text-tertiary); }
.admin-field .admin-inline-check { font-weight: 400; color: var(--color-text); }

/* Two-column form grid (user/group editors): labels in the left column,
   controls in the right, so every row lines up like a table. */
.admin-form-table {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 16px 20px;
    align-items: start;
    font-size: 13px;
}
.admin-form-label,
/* beat the uppercase .modal-body label treatment — these are form content */
.modal-body label.admin-form-label,
.modal-body label.admin-check-row {
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
}
.admin-form-label {
    color: var(--color-text-secondary);
    font-weight: 500;
    padding-top: 6px;   /* optically aligns with the first line of the control */
}
.admin-form-control {
    min-width: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.admin-form-control input:not([type="checkbox"]) { width: 100%; }
.admin-check-row,
.modal-body label.admin-check-row {
    display: flex; align-items: center; gap: 8px;
    font-weight: 400; color: var(--color-text-primary);
    cursor: pointer; user-select: none;
    padding-top: 6px;   /* matches .admin-form-label so Role aligns with its first checkbox */
}
.admin-check-row + .admin-check-row,
.modal-body label.admin-check-row + label.admin-check-row { padding-top: 0; }
.admin-check-row input[type="checkbox"] { margin: 0; flex: none; width: auto; }

/* ----- Groups tab: master-detail (list fixed, detail fills) ----- */
.admin-split { display: flex; gap: 20px; align-items: flex-start; }
.admin-split > .admin-section:first-child { flex: 0 0 280px; }
.admin-split > .admin-editor { flex: 1; min-width: 0; }
.admin-editor {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--lg);
    display: flex; flex-direction: column; gap: 14px;
}

.admin-groups-list { display: flex; flex-direction: column; gap: 2px; }
.admin-group-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 10px; border-radius: var(--radius-md, 6px); cursor: pointer;
}
.admin-group-row:hover { background: var(--color-bg); }
.admin-group-row.selected { background: rgba(0, 122, 255, 0.12); }
.admin-group-count { color: var(--color-text-tertiary); font-size: 11px; }
.admin-list-row {
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--color-border-light);
}
.admin-list-row:last-child { border-bottom: none; }

/* Chip multi-select (groups on the user editor, members on the group panel). */
.chip-select { position: relative; }
.chip-select-chips {
    display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
    border: 1px solid var(--color-border-light); border-radius: var(--radius-md, 6px);
    padding: 4px 6px; background: var(--color-bg);
}
.chip-select-input { flex: 1; min-width: 100px; border: none; outline: none; background: transparent; font-size: 12px; }
.chip {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(0, 122, 255, 0.12); color: var(--color-text);
    border-radius: 10px; padding: 1px 6px; font-size: 11px;
}
.chip-x { border: none; background: none; cursor: pointer; color: var(--color-text-tertiary); font-size: 10px; padding: 0; }
.chip-x:hover { color: var(--color-error); }
.chip-select-menu {
    position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin-top: 2px;
    background: var(--color-bg-elevated); border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md, 6px); max-height: 200px; overflow-y: auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.chip-select-item { padding: 6px 10px; font-size: 12px; cursor: pointer; }
.chip-select-item:hover { background: var(--color-bg); }
.chip-select-create { color: var(--color-accent, #007aff); font-style: italic; }

/* Admin tab strip: reuses .seg-tab from the GD modal but laid out
   full-width so all three buckets get equal real estate. The
   ``.admin-tabs`` selector adds the ``display:flex`` override (the
   default seg-tabs is inline-flex). */
.admin-tabs {
    display: flex;
    width: 100%;
    margin-bottom: 14px;
}
.admin-tabs .seg-tab { flex: 1; }

/* Storage tab — NFS root input + status pill. */
.admin-nfs-row {
    display: flex;
    align-items: center;
    gap: var(--sm);
}
.admin-nfs-row label {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--color-text-secondary);
}
.admin-nfs-row input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text-primary);
    font: 12px ui-monospace, "SF Mono", Menlo, monospace;
}
.admin-nfs-status {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.35;
    border-left: 3px solid var(--color-border);
    background: var(--color-bg);
}
.admin-nfs-status.ok   { border-left-color: var(--color-success); }
.admin-nfs-status.warn { border-left-color: var(--color-warning); }
.admin-nfs-status.err  { border-left-color: var(--color-error); }
.admin-tab-pane {
    display: flex;
    flex-direction: column;
    gap: var(--md);
    min-width: 0;
}

/* Auth-provider section: a wider table (the actions column carries a
   Check button + status pill + Delete). The Actions column overrides
   the global ``td:last-child {width:80px}`` rule because we need room
   for the inline check status. */
.admin-auth-providers { margin-top: 0; }

/* Each provider is a card (not a table row) — a header with the provider name,
   enabled toggle, and Check/Delete actions, over a labeled field grid. Cards
   align cleanly at any width where a 7-column table of inline inputs did not. */
.admin-provider-cards { display: flex; flex-direction: column; gap: 12px; }
.admin-provider-card {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    padding: 12px 14px;
}
.provider-card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
}
.provider-card-title {
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 600; text-transform: capitalize;
}
.provider-env-badge { background: #3b82f6; }
.provider-card-actions { display: flex; align-items: center; gap: 10px; }
.provider-enabled { font-size: 12px; text-transform: none; letter-spacing: 0; }
.provider-check-status { display: block; margin-top: 8px; font-size: 12px; }
/* Field inputs fill their grid column. */
.admin-provider-card .admin-form-grid { margin-bottom: 0; }
.admin-provider-card .admin-form-grid input[type="text"] { width: 100%; box-sizing: border-box; }

/* Add-provider card: a collapsible, labeled form. Rendered as a 2x2
   grid so each field has room to breathe and the credentials sit on
   their own lines (full-width). Never wider than the table above it. */
.admin-add-card {
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-bg);
}
.admin-add-card > summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
    user-select: none;
}
.admin-add-card > summary strong {
    color: var(--color-text-primary);
    font-weight: 600;
}
.admin-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    margin-bottom: 12px;
}
.admin-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 0;
}
.admin-form-grid label.span-2 { grid-column: span 2; }
.admin-form-grid input[type="text"],
.admin-form-grid select {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    background: var(--color-bg-elevated);
    color: var(--color-text);
    font-size: 13px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    text-transform: none;
    letter-spacing: 0;
}
.admin-inline-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    cursor: pointer;
    user-select: none;
    /* Match the input's vertical padding so all three controls in the
       row align on the same baseline. */
    padding: 0 6px;
}
.admin-inline-check input[type="checkbox"] { margin: 0; }

.admin-table .badge-super {
    font-size: 9px;
    background: var(--color-accent);
    color: #fff;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 6px;
    letter-spacing: 0.04em;
    font-family: var(--font);
}

/* Sign-in provenance badges (top bar + admin Users table).
   SUPERADMIN / VOITTA NATIVE / Clerk company chips. */
.src-badge {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 6px;
    letter-spacing: 0.04em;
    font-family: var(--font);
    white-space: nowrap;
    vertical-align: middle;
}
.src-badge-super  { background: #b45309; color: #fff; }   /* amber-700 */
/* Circular single-letter badge (super-admin "S") — fixed square + 50%
   radius; the flex centering keeps the glyph optically centered. */
.src-badge-round {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; padding: 0;
    border-radius: 50%;
    font-weight: 700; letter-spacing: 0;
}
.src-badge-native { background: var(--color-accent); color: #fff; }
.src-badge-clerk  { background: #6c47ff; color: #fff; }   /* Clerk purple */

/* Clerk companies tab — collapsed <details> card per organization.
   Summary row: name · admin email(s) · member count; table shows on expand. */
.admin-clerk-org-head {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    list-style: none; /* hide the default triangle; the chevron below replaces it */
}
.admin-clerk-org-head::-webkit-details-marker { display: none; }
.admin-clerk-org-head::before {
    content: "▸";
    font-size: 11px;
    opacity: 0.6;
    transition: transform 0.12s ease;
}
details[open] > .admin-clerk-org-head::before { transform: rotate(90deg); }
.admin-clerk-org-admin {
    margin-left: auto;   /* pushes admin email + count to the right edge */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45%;
}
.admin-clerk-org-count { white-space: nowrap; }
.admin-clerk-org > .admin-table { margin-top: 10px; }

