/* ==========================================================================
   TPRC Client Portal — admin layer

   Layer 3, sitting on top of tprc-tokens.css (values) and tprc-ui.css
   (client-portal primitives). Admin screens are denser and more table-heavy
   than the client portal, so they need their own primitives: stat tiles,
   audit tables, filter bars and a branded auth shell.

   Rules this file follows, inherited from the design handoff:
     - Never a literal colour or pixel value. Everything resolves to a --t-*
       token, so a brand change propagates here for free.
     - Orange is the single accent. It marks the primary action and active
       state, never decoration.
     - Status is never colour alone: every badge carries a text label.
     - Minimum 44px tap target on anything interactive.

   Namespaced `adm-` so it cannot collide with the client `t-` primitives or
   the legacy Bootstrap/design-system rules still loaded on these pages.

   Load order: AFTER tprc-ui.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page scaffold
   The sidebar shell (rendered by sidebar.js) owns the chrome; .adm-page is
   the content column inside it.
   -------------------------------------------------------------------------- */

.adm-page {
    max-width: var(--t-container);
    margin: 0 auto;
    padding: var(--t-space-7) var(--t-page-pad) var(--t-space-9);
}

.adm-page-wide { max-width: 1440px; }

/* The shell appends its own Refresh button as the last child of whatever
   carries [data-refresh-anchor], so this row can hold THREE items: the text
   block, the page's own actions, and that injected button. `space-between`
   would spread all three and strand the page's action in the middle, so the
   text block claims the free space instead and everything else groups right. */
.adm-head {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    gap: var(--t-space-4);
    flex-wrap: wrap;
    margin-bottom: var(--t-space-7);
}

.adm-head-text { min-width: 0; margin-right: auto; }

/* .page-refresh-btn carries margin-left:auto for plain block banners; inside
   this flex row that would push it away from the actions it belongs beside. */
.adm-head > .page-refresh-btn { margin-left: 0; float: none; }

.adm-title {
    font-size: var(--t-page-title-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-page-title-track);
    color: var(--t-ink);
    margin: 0 0 var(--t-space-2);
    line-height: 1.2;
}

.adm-sub {
    font-size: var(--t-body-size);
    color: var(--t-muted);
    line-height: 1.55;
    margin: 0;
    max-width: 62ch;
}

.adm-head-actions {
    display: flex;
    align-items: center;
    gap: var(--t-space-2);
    flex-shrink: 0;
}

/* Eyebrow above the page title: "Admin", a role, a company name. */
.adm-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--t-space-2);
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-micro-track);
    text-transform: uppercase;
    color: var(--t-faint);
    margin: 0 0 var(--t-space-3);
}

.adm-section { margin-top: var(--t-section-gap); }
.adm-section:first-child { margin-top: 0; }

.adm-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--t-space-4);
    margin-bottom: var(--t-space-4);
}

.adm-section-title {
    font-size: var(--t-section-size);
    font-weight: var(--t-weight-bold);
    color: var(--t-ink);
    letter-spacing: -0.015em;
    margin: 0;
}

/* --------------------------------------------------------------------------
   2. Stat tiles
   A row of numbers that gives an admin a read on the day at a glance. The
   number is the loudest thing in the tile; the label sits above it, quiet.
   -------------------------------------------------------------------------- */

.adm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--t-space-4);
}

.adm-stat {
    position: relative;
    background: var(--t-surface);
    border: var(--t-border);
    border-radius: var(--t-radius);
    padding: var(--t-space-5) var(--t-space-5) var(--t-space-4);
    box-shadow: var(--t-shadow);
    display: flex;
    flex-direction: column;
    gap: var(--t-space-1);
    min-width: 0;
    text-decoration: none;
    color: inherit;
    transition: box-shadow var(--t-duration) var(--t-ease),
                transform var(--t-duration) var(--t-ease),
                border-color var(--t-duration) var(--t-ease);
}

/* Only tiles that link somewhere get the lift, so hover still means "this
   goes somewhere" rather than "this is decorative". */
a.adm-stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--t-shadow-raised);
    border-color: var(--t-brand-border);
    color: inherit;
    text-decoration: none;
}

a.adm-stat:focus-visible {
    outline: 2px solid var(--t-brand);
    outline-offset: 2px;
}

.adm-stat-label {
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-micro-track);
    text-transform: uppercase;
    color: var(--t-faint);
    display: flex;
    align-items: center;
    gap: var(--t-space-2);
}

.adm-stat-value {
    font-size: 34px;
    font-weight: var(--t-weight-bold);
    color: var(--t-ink);
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.adm-stat-meta {
    font-size: var(--t-body-sm-size);
    color: var(--t-muted);
    margin: 0;
    line-height: 1.4;
}

/* A tile that needs attention earns the accent, and says so in words. */
.adm-stat-attention .adm-stat-value { color: var(--t-brand); }
.adm-stat-attention { border-color: var(--t-brand-border); }

.adm-stat-icon {
    position: absolute;
    top: var(--t-space-4);
    right: var(--t-space-4);
    width: 32px;
    height: 32px;
    border-radius: var(--t-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--t-surface-sunken);
    color: var(--t-faint);
    font-size: 13px;
}

.adm-stat-attention .adm-stat-icon {
    background: var(--t-brand-subtle);
    color: var(--t-brand);
}

/* --------------------------------------------------------------------------
   3. Tool cards
   The launcher grid on Admin Home. Each card is one destination.
   -------------------------------------------------------------------------- */

.adm-tools {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
    gap: var(--t-space-4);
}

.adm-tool {
    position: relative;
    background: var(--t-surface);
    border: var(--t-border);
    border-radius: var(--t-radius);
    padding: var(--t-space-5);
    box-shadow: var(--t-shadow);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: var(--t-space-3);
    overflow: hidden;
    transition: transform var(--t-duration) var(--t-ease),
                box-shadow var(--t-duration) var(--t-ease),
                border-color var(--t-duration) var(--t-ease);
}

.adm-tool:hover {
    transform: translateY(-3px);
    box-shadow: var(--t-shadow-raised);
    border-color: var(--t-brand-border);
    color: inherit;
    text-decoration: none;
}

.adm-tool:focus-visible {
    outline: 2px solid var(--t-brand);
    outline-offset: 2px;
}

.adm-tool-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--t-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--t-brand-subtle);
    color: var(--t-brand);
    font-size: 17px;
    flex-shrink: 0;
}

.adm-tool-title {
    font-size: 16px;
    font-weight: var(--t-weight-row);
    color: var(--t-ink);
    margin: 0;
    letter-spacing: -0.01em;
}

.adm-tool-desc {
    font-size: var(--t-body-sm-size);
    color: var(--t-muted);
    line-height: 1.5;
    margin: 0;
    flex: 1;
}

.adm-tool-cta {
    display: inline-flex;
    align-items: center;
    gap: var(--t-space-2);
    font-size: var(--t-body-sm-size);
    font-weight: var(--t-weight-row);
    color: var(--t-action);
}

.adm-tool-cta i {
    font-size: 10px;
    transition: transform var(--t-duration) var(--t-ease);
}

.adm-tool:hover .adm-tool-cta i { transform: translateX(3px); }

/* Role pill, top-right of a restricted tool. */
.adm-tool-pill {
    position: absolute;
    top: var(--t-space-4);
    right: var(--t-space-4);
    background: var(--t-inactive-bg);
    color: var(--t-inactive-fg);
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: var(--t-radius-pill);
}

/* Unread counter, same slot as the pill. */
.adm-tool-count {
    position: absolute;
    top: var(--t-space-4);
    right: var(--t-space-4);
    background: var(--t-brand);
    color: var(--t-on-charcoal);
    font-size: 12px;
    font-weight: var(--t-weight-bold);
    line-height: 1;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: var(--t-radius-pill);
}

.adm-tool-count.is-shown { display: inline-flex; }

/* --------------------------------------------------------------------------
   4. Cards
   -------------------------------------------------------------------------- */

.adm-card {
    background: var(--t-surface);
    border: var(--t-border);
    border-radius: var(--t-radius);
    box-shadow: var(--t-shadow);
    padding: var(--t-card-pad);
}

.adm-card-lg { padding: var(--t-card-pad-lg); }

/* For cards whose whole body is a table or a list of rows. */
.adm-card-flush { padding: 0; overflow: hidden; }

.adm-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--t-space-4);
    flex-wrap: wrap;
    padding: var(--t-space-5) var(--t-card-pad);
    border-bottom: var(--t-border);
}

.adm-card-flush > .adm-card-head { border-bottom: var(--t-border); }
.adm-card > .adm-card-head:first-child {
    padding-top: 0;
    padding-left: 0;
    padding-right: 0;
    margin-bottom: var(--t-space-5);
}

.adm-card-title {
    font-size: 16px;
    font-weight: var(--t-weight-row);
    color: var(--t-ink);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--t-space-2);
}

.adm-card-title i { color: var(--t-brand); font-size: 14px; }

.adm-card-body { padding: var(--t-card-pad); }

/* Charcoal panel, for a hero or a "needs your attention" block. */
.adm-panel {
    background: var(--t-charcoal);
    border-radius: var(--t-radius-lg);
    padding: var(--t-card-pad-lg);
    color: var(--t-on-charcoal);
}

.adm-panel .adm-title,
.adm-panel .adm-section-title,
.adm-panel .adm-card-title { color: var(--t-on-charcoal); }

.adm-panel .adm-sub,
.adm-panel .adm-stat-meta { color: var(--t-on-charcoal-mute); }

/* --------------------------------------------------------------------------
   5. Forms and filters
   One filter bar pattern, reused on every list page.
   -------------------------------------------------------------------------- */

.adm-filters {
    display: flex;
    align-items: center;
    gap: var(--t-space-3);
    flex-wrap: wrap;
    margin-bottom: var(--t-space-4);
}

.adm-filters-grow { flex: 1; min-width: 220px; }

.adm-field { display: block; min-width: 0; }

.adm-label {
    display: block;
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-micro-track);
    text-transform: uppercase;
    color: var(--t-faint);
    margin-bottom: var(--t-space-2);
}

.adm-input,
.adm-select,
.adm-textarea {
    width: 100%;
    min-height: var(--t-tap);
    padding: 0 var(--t-space-3);
    border: 1px solid var(--t-border-strong);
    border-radius: var(--t-radius-sm);
    background: var(--t-surface);
    color: var(--t-ink);
    font-family: var(--t-font);
    font-size: var(--t-body-size);
    transition: border-color var(--t-duration) var(--t-ease),
                box-shadow var(--t-duration) var(--t-ease);
}

.adm-textarea { padding: var(--t-space-3); min-height: 96px; resize: vertical; }

.adm-input::placeholder,
.adm-textarea::placeholder { color: var(--t-faint); }

.adm-input:focus,
.adm-select:focus,
.adm-textarea:focus {
    outline: none;
    border-color: var(--t-brand);
    box-shadow: 0 0 0 3px var(--t-brand-subtle);
}

.adm-input:disabled,
.adm-select:disabled { background: var(--t-surface-sunken); opacity: 0.7; cursor: not-allowed; }

/* Native select needs its own chevron once the default look is overridden. */
.adm-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: var(--t-space-7);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--t-space-3) center;
    cursor: pointer;
}

/* Search box with a leading icon. */
.adm-search { position: relative; flex: 1; min-width: 220px; }

.adm-search > i {
    position: absolute;
    left: var(--t-space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--t-faint);
    font-size: 13px;
    pointer-events: none;
}

.adm-search .adm-input { padding-left: var(--t-space-8); }

/* Inline form grid, e.g. "add a new admin user". */
.adm-form-grid {
    display: grid;
    gap: var(--t-space-4);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    align-items: end;
}

.adm-form-grid .adm-btn { min-width: 0; }

/* --------------------------------------------------------------------------
   6. Buttons and links
   One filled button per context. Everything else outlined, ghost or text.
   -------------------------------------------------------------------------- */

.adm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--t-space-2);
    min-height: var(--t-tap);
    padding: 0 var(--t-space-4);
    border-radius: var(--t-radius-sm);
    border: 1px solid transparent;
    font-family: var(--t-font);
    font-size: var(--t-body-sm-size);
    font-weight: var(--t-weight-row);
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--t-duration) var(--t-ease),
                border-color var(--t-duration) var(--t-ease),
                color var(--t-duration) var(--t-ease);
}

.adm-btn:focus-visible { outline: 2px solid var(--t-brand); outline-offset: 2px; }
.adm-btn:disabled,
.adm-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.adm-btn-primary { background: var(--t-brand); color: var(--t-on-charcoal); }
.adm-btn-primary:hover:not(:disabled) { background: var(--t-brand-hover); color: var(--t-on-charcoal); }

.adm-btn-secondary {
    background: var(--t-surface);
    border-color: var(--t-border-strong);
    color: var(--t-ink);
}
.adm-btn-secondary:hover:not(:disabled) { background: var(--t-surface-sunken); color: var(--t-ink); }

.adm-btn-ghost { background: transparent; color: var(--t-muted); }
.adm-btn-ghost:hover:not(:disabled) { background: var(--t-surface-sunken); color: var(--t-ink); }

.adm-btn-danger {
    background: transparent;
    border-color: var(--t-overdue-bg);
    color: var(--t-overdue-fg);
}
.adm-btn-danger:hover:not(:disabled) { background: var(--t-overdue-bg); color: var(--t-overdue-fg); }

/* Compact variant for use inside a table row. */
.adm-btn-sm {
    min-height: 34px;
    padding: 0 var(--t-space-3);
    font-size: 13px;
}

/* Square icon-only button. Always needs an aria-label. */
.adm-btn-icon {
    min-height: var(--t-tap);
    width: var(--t-tap);
    padding: 0;
}

.adm-link {
    color: var(--t-action);
    font-weight: var(--t-weight-row);
    text-decoration: none;
    font-size: var(--t-body-sm-size);
}
.adm-link:hover { color: var(--t-brand); text-decoration: underline; }

/* --------------------------------------------------------------------------
   7. Tables
   Sticky header, tabular numerals, and a card-stacking layout on small
   screens so no column is ever dropped.
   -------------------------------------------------------------------------- */

.adm-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

.adm-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--t-body-sm-size);
}

.adm-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--t-surface-sunken);
    color: var(--t-faint);
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-micro-track);
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
    padding: var(--t-space-3) var(--t-space-4);
    border-bottom: 1px solid var(--t-border-color);
}

.adm-table td {
    padding: var(--t-space-4);
    border-bottom: 1px solid var(--t-border-color);
    color: var(--t-ink);
    vertical-align: middle;
}

.adm-table tbody tr:last-child td { border-bottom: 0; }

.adm-table tbody tr {
    transition: background var(--t-duration) var(--t-ease);
}

.adm-table tbody tr:hover { background: var(--t-surface-sunken); }

/* Rows that are focusable (clickable rows) must show it. */
.adm-table tbody tr:focus-visible {
    outline: 2px solid var(--t-brand);
    outline-offset: -2px;
    background: var(--t-surface-sunken);
}

.adm-td-strong { font-weight: var(--t-weight-row); color: var(--t-ink); }
.adm-td-meta { font-size: 13px; color: var(--t-faint); margin-top: 2px; }
.adm-td-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.adm-td-actions { text-align: right; white-space: nowrap; }

.adm-td-actions > * + * { margin-left: var(--t-space-2); }

/* --------------------------------------------------------------------------
   8. Badges
   Always paired with a text label. Never colour alone.
   -------------------------------------------------------------------------- */

.adm-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--t-space-1);
    padding: 3px 10px;
    border-radius: var(--t-radius-pill);
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.adm-badge-approved { background: var(--t-approved-bg); color: var(--t-approved-fg); }
.adm-badge-pending  { background: var(--t-pending-bg);  color: var(--t-pending-fg); }
.adm-badge-awaiting { background: var(--t-awaiting-bg); color: var(--t-awaiting-fg); }
.adm-badge-review   { background: var(--t-review-bg);   color: var(--t-review-fg); }
.adm-badge-overdue  { background: var(--t-overdue-bg);  color: var(--t-overdue-fg); }
.adm-badge-inactive { background: var(--t-inactive-bg); color: var(--t-inactive-fg); }

/* Softer, squared variant for an action type in an audit row. */
.adm-tag {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: var(--t-weight-row);
    background: var(--t-inactive-bg);
    color: var(--t-inactive-fg);
    white-space: nowrap;
}

.adm-tag-approved { background: var(--t-approved-bg); color: var(--t-approved-fg); }
.adm-tag-overdue  { background: var(--t-overdue-bg);  color: var(--t-overdue-fg); }
.adm-tag-review   { background: var(--t-review-bg);   color: var(--t-review-fg); }
.adm-tag-pending  { background: var(--t-pending-bg);  color: var(--t-pending-fg); }

/* --------------------------------------------------------------------------
   9. Loading, empty and alert states
   A skeleton stands in for the table it is replacing, so the layout does not
   jump when the rows land.
   -------------------------------------------------------------------------- */

.adm-skel {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(
        90deg,
        var(--t-surface-sunken) 0%,
        rgba(27, 34, 40, 0.07) 50%,
        var(--t-surface-sunken) 100%);
    background-size: 200% 100%;
    animation: adm-shimmer 1.4s var(--t-ease) infinite;
}

.adm-skel-sm { width: 45%; }
.adm-skel-md { width: 70%; }
.adm-skel-lg { width: 90%; }

@keyframes adm-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .adm-skel { animation: none; }
}

.adm-empty {
    text-align: center;
    padding: var(--t-space-9) var(--t-space-5);
    color: var(--t-muted);
}

.adm-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--t-space-4);
    border-radius: var(--t-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--t-surface-sunken);
    color: var(--t-faint);
    font-size: 18px;
}

.adm-empty-title {
    font-size: 16px;
    font-weight: var(--t-weight-row);
    color: var(--t-ink);
    margin: 0 0 var(--t-space-2);
}

.adm-empty-body {
    font-size: var(--t-body-sm-size);
    color: var(--t-muted);
    margin: 0 auto;
    max-width: 44ch;
    line-height: 1.55;
}

.adm-alert {
    display: none;
    align-items: flex-start;
    gap: var(--t-space-2);
    padding: var(--t-space-3) var(--t-space-4);
    border-radius: var(--t-radius-sm);
    border: 1px solid transparent;
    font-size: var(--t-body-sm-size);
    line-height: 1.5;
    margin-bottom: var(--t-space-4);
}

.adm-alert.is-shown { display: flex; }

.adm-alert-error {
    background: var(--t-overdue-bg);
    border-color: var(--t-overdue-bg);
    color: var(--t-overdue-fg);
}

.adm-alert-success {
    background: var(--t-approved-bg);
    border-color: var(--t-approved-bg);
    color: var(--t-approved-fg);
}

.adm-alert-info {
    background: var(--t-review-bg);
    border-color: var(--t-review-bg);
    color: var(--t-review-fg);
}

/* --------------------------------------------------------------------------
   10. Activity feed
   -------------------------------------------------------------------------- */

.adm-feed { display: flex; flex-direction: column; }

.adm-feed-item {
    display: flex;
    align-items: flex-start;
    gap: var(--t-space-3);
    padding: var(--t-space-4) var(--t-card-pad);
    border-bottom: 1px solid var(--t-border-color);
}

.adm-feed-item:last-child { border-bottom: 0; }

.adm-feed-dot {
    width: 32px;
    height: 32px;
    border-radius: var(--t-radius-pill);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--t-surface-sunken);
    color: var(--t-faint);
    font-size: 12px;
    margin-top: 1px;
}

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

.adm-feed-title {
    font-size: var(--t-body-sm-size);
    font-weight: var(--t-weight-row);
    color: var(--t-ink);
    margin: 0;
    line-height: 1.45;
}

.adm-feed-meta {
    font-size: 13px;
    color: var(--t-faint);
    margin: 2px 0 0;
    line-height: 1.45;
}

.adm-feed-time {
    font-size: 13px;
    color: var(--t-faint);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   11. Pagination
   -------------------------------------------------------------------------- */

.adm-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--t-space-4);
    flex-wrap: wrap;
    padding: var(--t-space-4) var(--t-card-pad);
    border-top: 1px solid var(--t-border-color);
}

.adm-pager-info {
    font-size: 13px;
    color: var(--t-muted);
    font-variant-numeric: tabular-nums;
}

.adm-pager-btns { display: flex; align-items: center; gap: var(--t-space-2); }

/* --------------------------------------------------------------------------
   12. Modal
   -------------------------------------------------------------------------- */

.adm-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1080;
    background: rgba(27, 34, 40, 0.55);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--t-space-5);
}

.adm-modal-overlay.is-open { display: flex; }

.adm-modal {
    background: var(--t-surface);
    border-radius: var(--t-radius-lg);
    box-shadow: var(--t-shadow-raised);
    width: 100%;
    max-width: 640px;
    max-height: calc(100vh - var(--t-space-9));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.adm-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--t-space-4);
    padding: var(--t-space-5) var(--t-card-pad);
    border-bottom: var(--t-border);
}

.adm-modal-head h3 {
    font-size: 17px;
    font-weight: var(--t-weight-row);
    color: var(--t-ink);
    margin: 0;
}

.adm-modal-body { padding: var(--t-card-pad); overflow-y: auto; }

.adm-modal-close {
    border: none;
    background: transparent;
    color: var(--t-faint);
    width: 36px;
    height: 36px;
    border-radius: var(--t-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.adm-modal-close:hover { background: var(--t-surface-sunken); color: var(--t-ink); }

/* --------------------------------------------------------------------------
   13. Auth shell
   Login, email verification and password reset. A charcoal brand panel on
   the left carries the identity; the form sits on a clean surface at right,
   so the orange primary button is the only accent on the screen.
   -------------------------------------------------------------------------- */

.adm-auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    background: var(--t-surface);
    font-family: var(--t-font);
}

.adm-auth-brand {
    position: relative;
    background: var(--t-charcoal);
    color: var(--t-on-charcoal);
    padding: var(--t-space-9) var(--t-space-8);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

/* One soft orange bloom, the only decoration on the panel. */
.adm-auth-brand::after {
    content: "";
    position: absolute;
    width: 460px;
    height: 460px;
    right: -180px;
    bottom: -220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 76, 0, 0.22) 0%, rgba(255, 76, 0, 0) 68%);
    pointer-events: none;
}

.adm-auth-brand > * { position: relative; z-index: 1; }

/* The lockup is the orange/grey one, which sits on charcoal as well as on
   white: the mark and "tprc" are orange, and the grey descender line stays
   legible against the panel. */
.adm-auth-logo img { height: 52px; width: auto; }

.adm-auth-brand h1 {
    font-size: 30px;
    font-weight: var(--t-weight-bold);
    letter-spacing: -0.028em;
    line-height: 1.2;
    margin: 0 0 var(--t-space-3);
    color: var(--t-on-charcoal);
}

.adm-auth-brand p {
    font-size: var(--t-body-size);
    line-height: 1.6;
    color: var(--t-on-charcoal-mute);
    margin: 0;
    max-width: 34ch;
}

.adm-auth-foot {
    font-size: 13px;
    color: var(--t-on-charcoal-mute);
    margin: 0;
}

.adm-auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--t-space-8) var(--t-page-pad);
    background: linear-gradient(180deg, var(--t-page-from), var(--t-page-to));
}

.adm-auth-card {
    width: 100%;
    max-width: 420px;
}

/* Logo shown above the form only when the brand panel is hidden. */
.adm-auth-logo-sm { display: none; text-align: center; margin-bottom: var(--t-space-6); }
.adm-auth-logo-sm img { height: 38px; width: auto; }

.adm-auth-card h2 {
    font-size: 24px;
    font-weight: var(--t-weight-bold);
    letter-spacing: -0.022em;
    color: var(--t-ink);
    margin: 0 0 var(--t-space-2);
}

.adm-auth-card .adm-auth-lede {
    font-size: var(--t-body-size);
    color: var(--t-muted);
    margin: 0 0 var(--t-space-6);
    line-height: 1.55;
}

.adm-auth-form { display: flex; flex-direction: column; gap: var(--t-space-4); }

.adm-auth-form .adm-btn { width: 100%; }

/* Password field with a reveal toggle. */
.adm-input-wrap { position: relative; }

.adm-input-toggle {
    position: absolute;
    right: var(--t-space-1);
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--t-faint);
    cursor: pointer;
    border-radius: var(--t-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.adm-input-toggle:hover { color: var(--t-ink); }
.adm-input-wrap .adm-input { padding-right: 46px; }

.adm-auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--t-space-3);
    flex-wrap: wrap;
}

.adm-check {
    display: inline-flex;
    align-items: center;
    gap: var(--t-space-2);
    font-size: var(--t-body-sm-size);
    color: var(--t-muted);
    cursor: pointer;
}

.adm-check input {
    width: 16px;
    height: 16px;
    accent-color: var(--t-brand);
    cursor: pointer;
}

/* "or" rule between the password form and the SSO button. */
.adm-auth-or {
    display: flex;
    align-items: center;
    gap: var(--t-space-3);
    color: var(--t-faint);
    font-size: 13px;
    margin: var(--t-space-2) 0;
}

.adm-auth-or::before,
.adm-auth-or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--t-border-color);
}

/* Centred status screens: verify and reset outcomes. */
.adm-status { text-align: center; }

.adm-status-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--t-space-5);
    border-radius: var(--t-radius-pill);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    background: var(--t-surface-sunken);
    color: var(--t-faint);
}

.adm-status-icon.is-success { background: var(--t-approved-bg); color: var(--t-approved-fg); }
.adm-status-icon.is-error   { background: var(--t-overdue-bg);  color: var(--t-overdue-fg); }
.adm-status-icon.is-working { background: var(--t-brand-subtle); color: var(--t-brand); }

.adm-status h2 { margin-bottom: var(--t-space-2); }

/* Password strength meter on the reset screen. */
.adm-meter {
    display: flex;
    gap: var(--t-space-1);
    margin-top: var(--t-space-2);
}

.adm-meter span {
    flex: 1;
    height: 4px;
    border-radius: var(--t-radius-pill);
    background: var(--t-border-color);
    transition: background var(--t-duration) var(--t-ease);
}

.adm-meter[data-score="1"] span:nth-child(-n+1),
.adm-meter[data-score="2"] span:nth-child(-n+2) { background: var(--t-overdue-fg); }
.adm-meter[data-score="3"] span:nth-child(-n+3) { background: var(--t-awaiting-fg); }
.adm-meter[data-score="4"] span { background: var(--t-approved-fg); }

.adm-hint { font-size: 13px; color: var(--t-faint); margin: var(--t-space-2) 0 0; }

/* --------------------------------------------------------------------------
   14. Utilities
   -------------------------------------------------------------------------- */

.adm-hidden { display: none !important; }
.adm-spacer { flex: 1; }

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

/* --------------------------------------------------------------------------
   15. Responsive
   The table stacking rule is the important one: below 768px every row
   becomes its own card and each cell shows the header it belongs to, taken
   from the cell's data-label. No column is ever hidden, so an admin on a
   phone sees the same audit trail as one at a desk.
   -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
    .adm-auth { grid-template-columns: 1fr; }
    .adm-auth-brand { display: none; }
    .adm-auth-logo-sm { display: block; }
}

@media (max-width: 768px) {
    .adm-page { padding: var(--t-space-5) var(--t-page-pad) var(--t-space-8); }
    .adm-title { font-size: 23px; }
    .adm-stat-value { font-size: 29px; }

    .adm-head { flex-direction: column; align-items: stretch; }
    .adm-head-actions { width: 100%; }
    .adm-head-actions .adm-btn { flex: 1; }

    .adm-table-wrap { overflow-x: visible; }

    .adm-table,
    .adm-table thead,
    .adm-table tbody,
    .adm-table tr,
    .adm-table th,
    .adm-table td { display: block; }

    /* Keep the header in the accessibility tree, take it out of the layout. */
    .adm-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .adm-table tbody tr {
        background: var(--t-surface);
        border: var(--t-border);
        border-radius: var(--t-radius-sm);
        padding: var(--t-space-2) var(--t-space-4);
        margin-bottom: var(--t-space-3);
        box-shadow: var(--t-shadow);
    }

    .adm-table tbody tr:last-child { margin-bottom: 0; }

    /* Label above value, both left-aligned, and the cell stays a BLOCK.
       A flex row here would promote every child of the cell to a flex item,
       so a cell holding a value plus a .adm-td-meta line would lay the two
       out side by side instead of stacked. */
    .adm-table td {
        display: block;
        padding: var(--t-space-3) 0;
        border-bottom: 1px solid var(--t-border-color);
        text-align: left;
        /* Emails and reference ids have no spaces to break on. */
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .adm-table td:last-child { border-bottom: 0; }

    /* The label each cell answers to, so a stacked row still reads. */
    .adm-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: var(--t-space-1);
        font-size: var(--t-micro-size);
        font-weight: var(--t-weight-bold);
        letter-spacing: var(--t-micro-track);
        text-transform: uppercase;
        color: var(--t-faint);
    }

    /* A cell with no data-label (an actions column) just shows its content. */
    .adm-table td:not([data-label])::before { content: none; }

    /* Actions go full-width on their own row so they stay easy to hit. */
    .adm-td-actions { text-align: left; }
    .adm-td-actions > * { margin-left: 0; }
    .adm-td-actions > .adm-btn { width: 100%; }

    .adm-filters { flex-direction: column; align-items: stretch; }
    .adm-search, .adm-filters-grow { min-width: 0; width: 100%; }

    .adm-pager { flex-direction: column; align-items: stretch; }
    .adm-pager-btns { justify-content: space-between; }
    .adm-pager-btns .adm-btn { flex: 1; }

    .adm-feed-item { padding: var(--t-space-4) var(--t-space-5); }
    .adm-card-head { padding: var(--t-space-4) var(--t-space-5); }
    .adm-card-body { padding: var(--t-space-5); }
    .adm-pager { padding: var(--t-space-4) var(--t-space-5); }
}

@media (max-width: 480px) {
    .adm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .adm-stat { padding: var(--t-space-4); }
    .adm-stat-icon { display: none; }
    .adm-tools { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   16. Admin sidebar
   The deck specifies a sticky top bar with no sidebar, but that is the client
   portal: six destinations and a single tenant. Admin has eleven destinations
   and role gating, which a horizontal bar cannot carry, so the sidebar stays
   and instead inherits the deck's restraint.

   What that means concretely:
     - The charcoal is the deck's panel charcoal, not the old blue-slate.
     - Labels are quiet by default and only the ACTIVE item gets ink and
       weight, so the eye lands on where you are rather than on the menu.
     - Active state is a 3px orange bar plus white text, the sidebar analogue
       of the deck's 2px orange tab underline. No filled orange block: the
       accent marks, it does not decorate.
     - Micro labels follow the type scale (11px / 700 / 0.08em / uppercase).

   Scoped to .sidebar-admin so the client sidebar is untouched. Dropping
   `.sidebar-admin` from these selectors would extend the same treatment to
   the whole portal.
   -------------------------------------------------------------------------- */

.sidebar.sidebar-admin {
    background: var(--t-charcoal-deep);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar.sidebar-admin .sidebar-nav {
    padding: var(--t-space-3) var(--t-space-3) var(--t-space-5);
}

/* Section label: the deck's micro label, dimmed for a dark surface. */
.sidebar.sidebar-admin .sidebar-section-label {
    padding: var(--t-space-5) var(--t-space-3) var(--t-space-2);
    font-size: var(--t-micro-size);
    font-weight: var(--t-weight-bold);
    letter-spacing: var(--t-micro-track);
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.34);
}

.sidebar.sidebar-admin .nav-item-sidebar { margin-bottom: 1px; }

.sidebar.sidebar-admin .nav-link-sidebar {
    position: relative;
    gap: var(--t-space-3);
    padding: 10px var(--t-space-3);
    border-radius: var(--t-radius-sm);
    font-size: var(--t-body-sm-size);
    font-weight: 500;
    letter-spacing: -0.005em;
    color: var(--t-on-charcoal-mute);
    transition: background var(--t-duration) var(--t-ease),
                color var(--t-duration) var(--t-ease);
}

/* Icons sit back until the row is hovered or current. */
.sidebar.sidebar-admin .nav-link-sidebar i {
    width: 18px;
    font-size: 14px;
    text-align: center;
    color: rgba(255, 255, 255, 0.42);
    transition: color var(--t-duration) var(--t-ease);
}

.sidebar.sidebar-admin .nav-link-sidebar:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--t-on-charcoal);
}

.sidebar.sidebar-admin .nav-link-sidebar:hover i {
    color: rgba(255, 255, 255, 0.72);
}

.sidebar.sidebar-admin .nav-link-sidebar:focus-visible {
    outline: 2px solid var(--t-brand);
    outline-offset: -2px;
}

/* Current page: white label, orange icon, orange bar. The bar is the
   sidebar's version of the deck's 2px active tab underline. */
.sidebar.sidebar-admin .nav-link-sidebar.active {
    background: rgba(255, 76, 0, 0.10);
    color: var(--t-on-charcoal);
    font-weight: var(--t-weight-row);
}

.sidebar.sidebar-admin .nav-link-sidebar.active i { color: var(--t-brand); }

.sidebar.sidebar-admin .nav-link-sidebar.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    border-radius: 0 var(--t-radius-pill) var(--t-radius-pill) 0;
    background: var(--t-brand);
}

/* Collapsed rail: the bar would crowd a centred icon, so it goes. */
.sidebar.sidebar-admin.collapsed .nav-link-sidebar.active::before { display: none; }
.sidebar.sidebar-admin.collapsed .nav-link-sidebar { border-radius: var(--t-radius-sm); }

/* Support card and footer: hairline separation, no gradient. */
.sidebar.sidebar-admin .sidebar-chatbot {
    margin: var(--t-space-3);
    padding: var(--t-space-4);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--t-radius);
}

.sidebar.sidebar-admin .sidebar-chatbot-icon { color: var(--t-brand); }

.sidebar.sidebar-admin .sidebar-chatbot-title {
    font-size: var(--t-body-sm-size);
    font-weight: var(--t-weight-row);
    color: var(--t-on-charcoal);
}

.sidebar.sidebar-admin .sidebar-chatbot-desc {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.5);
}

.sidebar.sidebar-admin .sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar.sidebar-admin .sidebar-toggle {
    color: rgba(255, 255, 255, 0.5);
    font-size: var(--t-body-sm-size);
}

.sidebar.sidebar-admin .sidebar-toggle:hover { color: var(--t-on-charcoal); }

/* --------------------------------------------------------------------------
   17. Page ground
   Admin screens were landing on three different greys: most inherited
   --bg-body (#F5F6FA), pages still carrying .dashboard-page got #F8FAFC, and
   the client shell used the deck's wash. They all share one ground now.

   background-attachment: fixed matches body.t-shell. The background
   propagates from <body> to the canvas (the root is deliberately transparent,
   see css/styles.css), and a propagated gradient would otherwise stretch over
   the whole document — several thousand pixels on a long page — leaving the
   visible area looking flat and shifting as you scroll. Fixed maps it to the
   viewport so the ground reads the same at any scroll position.
   -------------------------------------------------------------------------- */

body.admin-only-page {
    background: linear-gradient(180deg, var(--t-page-from) 0%, var(--t-page-to) 100%);
    background-attachment: fixed;
}
