/*
 * The dashboard's stylesheet. JQAI-64, following design/hifi/admin-users.html.
 *
 * ⚠️ THE TOKENS BELOW ARE A VENDORED SUBSET, NOT A NEW PALETTE
 * Every `--jq-*` value here is copied verbatim from
 * design/tokens/build/tokens.css, which is GENERATED from
 * design/tokens/tokens.json. Nothing in this block was chosen by this ticket.
 *
 * It is vendored rather than linked because that file does not exist on this
 * branch — it lives on feat/JQAI-s3-sadad-65 (JQAI-65) and has not merged, so
 * `@import "../../design/tokens/build/tokens.css"` would break the build in
 * CI. WHEN THAT BRANCH LANDS, delete this block and link the generated file;
 * a hand-maintained copy of a generated palette drifts, and a drifting palette
 * is how the dashboard stops matching the app.
 *
 * Only the tokens this screen actually uses are copied. Colour follows the
 * viewer's theme in the same three ways the generated file defines.
 *
 * NO CLIENT BRANDING IS INVENTED (clause 9-1). `.ad-brand` is a dashed
 * placeholder that says so, exactly as the hi-fi frame draws it.
 */

:root,
[data-theme='light'] {
  color-scheme: light;
  --jq-color-brand-primary: #3d3d3d;
  --jq-color-brand-on-primary: #ffffff;
  --jq-color-brand-primary-container: #e4e4e4;
  --jq-color-brand-on-primary-container: #1a1a1a;
  --jq-color-surface-base: #f7f7f7;
  --jq-color-surface-raised: #ffffff;
  --jq-color-surface-sunken: #ededed;
  --jq-color-surface-scrim: #000000;
  --jq-color-text-primary: #1b1b1b;
  --jq-color-text-secondary: #4f4f4f;
  --jq-color-text-disabled: #9e9e9e;
  --jq-color-border-subtle: #e0e0e0;
  --jq-color-border-default: #bdbdbd;
  --jq-color-border-strong: #757575;
  --jq-color-focus-ring: #3d3d3d;
  --jq-color-status-danger: #b3261e;
  --jq-color-status-on-danger: #ffffff;
  --jq-color-feedback-severe: #b00020;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --jq-color-brand-primary: #cfcfcf;
    --jq-color-brand-on-primary: #1a1a1a;
    --jq-color-brand-primary-container: #3a3a3a;
    --jq-color-brand-on-primary-container: #ededed;
    --jq-color-surface-base: #121212;
    --jq-color-surface-raised: #1d1d1d;
    --jq-color-surface-sunken: #0b0b0b;
    --jq-color-text-primary: #e6e6e6;
    --jq-color-text-secondary: #bdbdbd;
    --jq-color-text-disabled: #616161;
    --jq-color-border-subtle: #2c2c2c;
    --jq-color-border-default: #474747;
    --jq-color-border-strong: #8a8a8a;
    --jq-color-focus-ring: #cfcfcf;
    --jq-color-status-danger: #f2b8b5;
    --jq-color-status-on-danger: #601410;
    --jq-color-feedback-severe: #ff8a80;
  }
}

[data-theme='dark'] {
  color-scheme: dark;
  --jq-color-brand-primary: #cfcfcf;
  --jq-color-brand-on-primary: #1a1a1a;
  --jq-color-brand-primary-container: #3a3a3a;
  --jq-color-brand-on-primary-container: #ededed;
  --jq-color-surface-base: #121212;
  --jq-color-surface-raised: #1d1d1d;
  --jq-color-surface-sunken: #0b0b0b;
  --jq-color-text-primary: #e6e6e6;
  --jq-color-text-secondary: #bdbdbd;
  --jq-color-text-disabled: #616161;
  --jq-color-border-subtle: #2c2c2c;
  --jq-color-border-default: #474747;
  --jq-color-border-strong: #8a8a8a;
  --jq-color-focus-ring: #cfcfcf;
  --jq-color-status-danger: #f2b8b5;
  --jq-color-status-on-danger: #601410;
  --jq-color-feedback-severe: #ff8a80;
}

:root {
  --jq-font-family-ui: system-ui;
  --jq-font-size-title: 20px;
  --jq-line-height-title: 1.4;
  --jq-font-weight-title: 600;
  --jq-font-size-body-small: 14px;
  --jq-line-height-body-small: 1.6;
  --jq-font-size-label: 14px;
  --jq-font-weight-label: 500;
  --jq-font-size-caption: 12px;
  --jq-line-height-caption: 1.5;
  --jq-space-1: 4px;
  --jq-space-2: 8px;
  --jq-space-3: 12px;
  --jq-space-4: 16px;
  --jq-space-5: 20px;
  --jq-space-6: 24px;
  --jq-space-8: 32px;
  --jq-space-10: 40px;
  --jq-radius-md: 8px;
  --jq-radius-lg: 12px;
  --jq-radius-full: 999px;
  --jq-size-touch-target: 48px;
  --jq-size-admin-sidebar: 248px;
  --jq-stroke-hairline: 1px;
  --jq-stroke-strong: 2px;
  --jq-stroke-focus-ring: 3px;
  --jq-opacity-scrim: 0.48;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--jq-color-surface-base);
  color: var(--jq-color-text-primary);
  font-family: var(--jq-font-family-ui), sans-serif;
  font-size: var(--jq-font-size-body-small);
  line-height: var(--jq-line-height-body-small);
}

/* Focus is never removed. An admin tool is a keyboard tool. */
:focus-visible {
  outline: var(--jq-stroke-focus-ring) solid var(--jq-color-focus-ring);
  outline-offset: 2px;
}

.ad-frame {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.ad-app {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.ad-sidebar {
  flex: none;
  width: var(--jq-size-admin-sidebar);
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-1);
  padding: var(--jq-space-4);
  background: var(--jq-color-surface-raised);
  border-inline-end: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
}

/* The client has supplied no identity. Nothing is invented: the slot stays a
   dashed placeholder until one arrives (clause 9-1). */
.ad-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--jq-space-10);
  margin-block-end: var(--jq-space-4);
  font-size: var(--jq-font-size-caption);
  color: var(--jq-color-text-secondary);
  border: var(--jq-stroke-strong) dashed var(--jq-color-border-strong);
  border-radius: var(--jq-radius-md);
}

.ad-nav {
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-1);
}

.ad-nav > span {
  display: flex;
  align-items: center;
  min-height: var(--jq-size-touch-target);
  padding-inline: var(--jq-space-3);
  border-radius: var(--jq-radius-md);
  color: var(--jq-color-text-secondary);
}

.ad-nav > span[aria-current] {
  background: var(--jq-color-brand-primary-container);
  color: var(--jq-color-brand-on-primary-container);
  font-weight: var(--jq-font-weight-label);
}

/* JQAI-78 put a SECOND destination in the sidebar, so the entries became
   buttons. Styled to match the spans above exactly rather than replacing them:
   the users entry is still a span when it is the current page, and a nav whose
   two items look different is a nav that reads as broken. */
.ad-nav > button {
  display: flex;
  align-items: center;
  min-height: var(--jq-size-touch-target);
  padding-inline: var(--jq-space-3);
  border: none;
  border-radius: var(--jq-radius-md);
  background: none;
  font: inherit;
  text-align: start;
  cursor: pointer;
  color: var(--jq-color-text-secondary);
}

.ad-nav > button[aria-current] {
  background: var(--jq-color-brand-primary-container);
  color: var(--jq-color-brand-on-primary-container);
  font-weight: var(--jq-font-weight-label);
}

.ad-spacer {
  flex: 1;
}

.ad-who {
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-2);
  padding: var(--jq-space-3);
  background: var(--jq-color-surface-base);
  border: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
  border-radius: var(--jq-radius-md);
  font-size: var(--jq-font-size-caption);
}

/* The role is named because it is a real, separate role — not decoration. */
.ad-rolechip {
  align-self: flex-start;
  padding-block: 2px;
  padding-inline: var(--jq-space-2);
  background: var(--jq-color-brand-primary-container);
  color: var(--jq-color-brand-on-primary-container);
  border-radius: var(--jq-radius-full);
}

/* ─── Main ──────────────────────────────────────────────────────────────── */
.ad-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ad-topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--jq-space-4);
  padding-block: var(--jq-space-4);
  padding-inline: var(--jq-space-6);
  border-block-end: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
}

.ad-topbar h3 {
  margin: 0;
  font-size: var(--jq-font-size-title);
  line-height: var(--jq-line-height-title);
  font-weight: var(--jq-font-weight-title);
}

.ad-audit-hint {
  font-size: var(--jq-font-size-caption);
  color: var(--jq-color-text-secondary);
}

.ad-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-4);
  padding: var(--jq-space-6);
}

.ad-search {
  display: flex;
  gap: var(--jq-space-2);
  align-items: center;
}

.ad-input,
.ad-filled-input {
  flex: 1;
  min-height: var(--jq-size-touch-target);
  padding-inline: var(--jq-space-3);
  background: var(--jq-color-surface-raised);
  border: var(--jq-stroke-hairline) solid var(--jq-color-border-strong);
  border-radius: var(--jq-radius-md);
  color: var(--jq-color-text-primary);
  font: inherit;
}

.ad-error {
  margin: 0;
  padding: var(--jq-space-3);
  color: var(--jq-color-feedback-severe);
  border: var(--jq-stroke-hairline) solid currentColor;
  border-radius: var(--jq-radius-md);
}

.ad-empty {
  color: var(--jq-color-text-secondary);
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.ad-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--jq-space-2);
  min-height: var(--jq-size-touch-target);
  padding-inline: var(--jq-space-4);
  font: inherit;
  font-size: var(--jq-font-size-label);
  font-weight: var(--jq-font-weight-label);
  background: none;
  border: none;
  border-radius: var(--jq-radius-md);
  color: inherit;
  cursor: pointer;
}

.ad-btn[disabled] {
  cursor: not-allowed;
}

.ad-btn--filled {
  background: var(--jq-color-brand-primary);
  color: var(--jq-color-brand-on-primary);
}

.ad-btn--outlined {
  border: var(--jq-stroke-hairline) solid var(--jq-color-border-strong);
  color: var(--jq-color-text-primary);
}

.ad-btn--small {
  min-height: var(--jq-space-8);
  padding-inline: var(--jq-space-3);
  font-size: var(--jq-font-size-caption);
}

.ad-btn--danger {
  background: var(--jq-color-status-danger);
  color: var(--jq-color-status-on-danger);
}

/* A disabled destructive control reads without colour: dashed outline and
   disabled ink. The disabled button is a courtesy — the API refuses a
   reasonless suspension on its own. */
.ad-btn--danger-off {
  border: var(--jq-stroke-strong) dashed var(--jq-color-border-strong);
  color: var(--jq-color-text-disabled);
}

/* ─── Table ─────────────────────────────────────────────────────────────── */
.ad-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--jq-color-surface-raised);
  border-radius: var(--jq-radius-md);
  overflow: hidden;
}

.ad-table th,
.ad-table td {
  text-align: start;
  padding-block: var(--jq-space-2);
  padding-inline: var(--jq-space-3);
}

.ad-table th {
  height: var(--jq-space-10);
  background: var(--jq-color-surface-sunken);
  font-size: var(--jq-font-size-caption);
  font-weight: var(--jq-font-weight-label);
}

.ad-table td {
  height: 56px;
  border-block-start: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
}

.ad-mono {
  font-family: ui-monospace, monospace;
  font-size: var(--jq-font-size-caption);
  direction: ltr;
  unicode-bidi: isolate;
}

/* The open row is marked by a bar AND a background, not by colour alone. */
.ad-row-selected td {
  background: var(--jq-color-surface-sunken);
}

.ad-row-selected td:first-child {
  box-shadow: inset -3px 0 0 var(--jq-color-brand-primary);
}

/* Status: a WORD, a SHAPE and a GLYPH. Never colour alone. */
.ad-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--jq-space-1);
  padding-block: 2px;
  padding-inline: var(--jq-space-2);
  font-size: var(--jq-font-size-caption);
  border-radius: var(--jq-radius-full);
}

.ad-badge--active {
  background: var(--jq-color-brand-primary-container);
  color: var(--jq-color-brand-on-primary-container);
}

.ad-badge--suspended {
  border: var(--jq-stroke-strong) dashed var(--jq-color-border-strong);
  color: var(--jq-color-text-primary);
}

/* JQAI-78 AC4. A figure the server withheld because too few accounts stand
   behind it.

   It carries the WORD, and the dashed outline is decoration — the same rule as
   the status badge above: the state must survive a greyscale screen. It is
   emphatically NOT rendered as a faint zero, which is the tempting treatment
   and is a false statement the reader cannot detect. */
.ad-withheld {
  display: inline-flex;
  align-items: center;
  padding-block: 2px;
  padding-inline: var(--jq-space-2);
  font-size: var(--jq-font-size-caption);
  border: var(--jq-stroke-hairline) dashed var(--jq-color-border-strong);
  border-radius: var(--jq-radius-full);
  color: var(--jq-color-text-secondary);
}

/* Two tables stacked on the accuracy and errors screens need air between
   them, or they read as one table with a strange header in the middle. */
.ad-table + .ad-table {
  margin-block-start: var(--jq-space-4);
}

.ad-actions {
  display: flex;
  gap: var(--jq-space-1);
}

.ad-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--jq-font-size-caption);
  color: var(--jq-color-text-secondary);
}

.ad-pager > span:last-child {
  display: flex;
  gap: var(--jq-space-1);
}

/* ─── Detail panel ──────────────────────────────────────────────────────── */
.ad-panel {
  flex: none;
  width: 344px;
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-3);
  padding: var(--jq-space-5);
  background: var(--jq-color-surface-raised);
  border-inline-start: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
}

.ad-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--jq-space-2);
}

.ad-panel-head b {
  display: block;
  font-family: ui-monospace, monospace;
  font-size: var(--jq-font-size-title);
  direction: ltr;
  unicode-bidi: isolate;
}

.ad-sec {
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-1);
  padding-block-start: var(--jq-space-3);
  border-block-start: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
}

.ad-sec > .t {
  font-size: var(--jq-font-size-caption);
  font-weight: var(--jq-font-weight-label);
  color: var(--jq-color-text-secondary);
}

.ad-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--jq-space-2);
}

.ad-log {
  display: flex;
  flex-direction: column;
  font-size: var(--jq-font-size-caption);
  line-height: 1.5;
}

.ad-log > div {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: var(--jq-space-2);
  padding-block: var(--jq-space-1);
}

.ad-log > div + div {
  border-block-start: var(--jq-stroke-hairline) dotted var(--jq-color-border-default);
}

.ad-log .when {
  color: var(--jq-color-text-secondary);
  white-space: nowrap;
  direction: ltr;
  unicode-bidi: isolate;
}

.ad-readonly {
  font-size: var(--jq-font-size-caption);
  color: var(--jq-color-text-secondary);
}

/* The absence of a password field, said out loud so it does not read as a
   missing feature somebody asks for later. */
.ad-nopass {
  display: flex;
  align-items: center;
  gap: var(--jq-space-2);
  padding: var(--jq-space-3);
  background: var(--jq-color-surface-sunken);
  border-radius: var(--jq-radius-md);
  font-size: var(--jq-font-size-caption);
}

.ad-panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--jq-space-2);
}

/* ─── Dialog ────────────────────────────────────────────────────────────── */
.ad-scrim {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-scrim::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--jq-color-surface-scrim);
  opacity: var(--jq-opacity-scrim);
}

.ad-dialog {
  position: relative;
  width: min(520px, calc(100vw - var(--jq-space-8)));
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-3);
  padding: var(--jq-space-5);
  background: var(--jq-color-surface-raised);
  border-radius: var(--jq-radius-lg);
}

.ad-dialog h4 {
  margin: 0;
  font-size: var(--jq-font-size-title);
  line-height: var(--jq-line-height-title);
  font-weight: var(--jq-font-weight-title);
}

.ad-field {
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-1);
}

.ad-field > label {
  font-size: var(--jq-font-size-caption);
  font-weight: var(--jq-font-weight-label);
}

/* What the server will write, shown BEFORE the act. Who and when are marked
   as the server's, from the session and its own clock — never the browser's. */
.ad-record {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--jq-space-3);
  background: var(--jq-color-surface-sunken);
  border-radius: var(--jq-radius-md);
  font-size: var(--jq-font-size-caption);
}

.ad-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--jq-space-2);
}

/* ─── Sign-in ───────────────────────────────────────────────────────────── */
.ad-signin {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--jq-space-4);
}

.ad-signin-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--jq-space-4);
  padding: var(--jq-space-6);
  background: var(--jq-color-surface-raised);
  border: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
  border-radius: var(--jq-radius-lg);
}

.ad-signin-card h3 {
  margin: 0;
  font-size: var(--jq-font-size-title);
  line-height: var(--jq-line-height-title);
  font-weight: var(--jq-font-weight-title);
}

.ad-signin-card p {
  margin: 0;
  font-size: var(--jq-font-size-caption);
  color: var(--jq-color-text-secondary);
}

/* ─── Narrow screens ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ad-app {
    flex-direction: column;
  }

  .ad-sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-inline-end: none;
    border-block-end: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
  }

  .ad-brand {
    margin-block-end: 0;
    width: 120px;
    min-height: var(--jq-space-10);
    height: auto;
  }

  .ad-nav {
    order: 1;
    flex: 1 0 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .ad-topbar {
    flex-wrap: wrap;
  }

  .ad-panel {
    width: 100%;
    border-inline-start: none;
    border-block-start: var(--jq-stroke-hairline) solid var(--jq-color-border-subtle);
  }

  .ad-content {
    overflow-x: auto;
  }
}

/* Language switch: in the sidebar when signed in, in a corner on sign-in. */
.ad-lang {
  padding: 0 var(--ad-space-3, 12px);
}
.ad-lang-floating {
  position: fixed;
  inset-block-start: 12px;
  inset-inline-end: 12px;
}

.ad-pct {
  inline-size: 5.5rem;
}
.ad-details {
  margin-block: 12px;
}
