/*
 * Korx Remote — admin panel stylesheet.
 * CSP: style-src 'self' — no inline styles anywhere; JS only sets element.style for bar widths.
 * Contrast pairs were checked against WCAG 2.1 AA (see docs/agents/AGENT-07.5-admin-report.md).
 */

/* ---- tokens ------------------------------------------------------------------------- */

:root {
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", "Segoe UI Mono", Consolas, "Liberation Mono", Menlo, monospace;

  /* brand palette */
  --navy-950: #08131e;
  --navy-900: #0b1a28;
  --navy-800: #0f2233;
  --navy-700: #17334c;
  --navy-600: #24486a;
  --blue-500: #438abf;
  --blue-400: #2d7ff9;
  --blue-200: #b8dcff;
  --orange-500: #e58a31;
  --orange-400: #f09a45;
  --green-600: #16a34a;
  --red-500: #e5484d;
  --slate-500: #64748b;

  /* light theme */
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f9;
  --surface-3: #e3ebf5;
  --row-hover: #f6f9fc;
  --border: #d5dfea;
  --border-strong: #7b8ba1;
  --text: #0f2233;
  --text-muted: #475569;
  --link: #1b5dbf;
  --focus: #2d7ff9;
  --accent: #2d7ff9;
  --primary: #e58a31;
  --primary-hover: #f09a45;
  --primary-text: #0f2233;
  --danger: #c62f35;
  --danger-hover: #a8262c;
  --danger-text: #b42318;
  --danger-bg: #fdecec;
  --success: #16a34a;
  --success-text: #146c34;
  --success-bg: #e3f6ea;
  --warning-text: #8a4a0b;
  --warning-bg: #fdf0e3;
  --info-text: #1b5dbf;
  --info-bg: #e7f0fc;
  --neutral-text: #475569;
  --neutral-bg: #eef3f9;
  --dot-online: #16a34a;
  --dot-offline: #7b8ba1;
  --dot-revoked: #e5484d;
  --nav-bg: #ffffff;
  --nav-active-bg: #e7f0fc;
  --nav-active-text: #0f2233;
  --bar-direct: #2d7ff9;
  --bar-relay: #e58a31;
  --topbar-bg: linear-gradient(90deg, #0f2233 0%, #17334c 62%, #1b3e5e 100%);
  --topbar-text: #e6eef7;
  --topbar-muted: #b6c8da;
  --shadow: 0 1px 2px rgba(15, 34, 51, 0.06), 0 4px 16px rgba(15, 34, 51, 0.06);
  --shadow-lg: 0 16px 48px rgba(15, 34, 51, 0.22);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1a28;
    --surface: #0f2233;
    --surface-2: #17334c;
    --surface-3: #1d3d5a;
    --row-hover: #132a3f;
    --border: #24486a;
    --border-strong: #5e7c9c;
    --text: #e6eef7;
    --text-muted: #9fb3c8;
    --link: #b8dcff;
    --focus: #5aa2e0;
    --accent: #5aa2e0;
    --primary-text: #0b1a28;
    --danger-text: #ff8a8d;
    --danger-bg: #3a1a22;
    --success-text: #4ade80;
    --success-bg: #11372a;
    --warning-text: #f5b26b;
    --warning-bg: #3a2a16;
    --info-text: #b8dcff;
    --info-bg: #15365a;
    --neutral-text: #b6c8da;
    --neutral-bg: #17334c;
    --dot-offline: #94a3b8;
    --nav-bg: #0f2233;
    --nav-active-bg: #17334c;
    --nav-active-text: #e6eef7;
    --topbar-bg: linear-gradient(90deg, #08131e 0%, #0f2233 62%, #132b42 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1a28;
  --surface: #0f2233;
  --surface-2: #17334c;
  --surface-3: #1d3d5a;
  --row-hover: #132a3f;
  --border: #24486a;
  --border-strong: #5e7c9c;
  --text: #e6eef7;
  --text-muted: #9fb3c8;
  --link: #b8dcff;
  --focus: #5aa2e0;
  --accent: #5aa2e0;
  --primary-text: #0b1a28;
  --danger-text: #ff8a8d;
  --danger-bg: #3a1a22;
  --success-text: #4ade80;
  --success-bg: #11372a;
  --warning-text: #f5b26b;
  --warning-bg: #3a2a16;
  --info-text: #b8dcff;
  --info-bg: #15365a;
  --neutral-text: #b6c8da;
  --neutral-bg: #17334c;
  --dot-offline: #94a3b8;
  --nav-bg: #0f2233;
  --nav-active-bg: #17334c;
  --nav-active-text: #e6eef7;
  --topbar-bg: linear-gradient(90deg, #08131e 0%, #0f2233 62%, #132b42 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
}

:root[data-theme="light"] {
  color-scheme: light;
}

/* ---- base ----------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

p {
  margin: 0 0 10px;
}

img {
  max-width: 100%;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  top: 10px;
}

.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

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

.small {
  font-size: 0.82rem;
}

.nowrap {
  white-space: nowrap;
}

.noscript {
  padding: 24px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

/* ---- boot / loading --------------------------------------------------------------------- */

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px;
  color: var(--text-muted);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---- application shell ---------------------------------------------------------------- */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 8px 20px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--orange-500) 18%, var(--blue-400) 62%, transparent 100%);
  opacity: 0.75;
  pointer-events: none;
}

.topbar :focus-visible {
  outline-color: var(--blue-200);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand img {
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(184, 220, 255, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--topbar-muted);
}

.topbar-org {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-width: 0;
}

.topbar-label {
  font-size: 0.78rem;
  color: var(--topbar-muted);
}

.topbar .input.org-select {
  max-width: 340px;
  min-width: 180px;
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--topbar-text);
  border-color: rgba(184, 220, 255, 0.4);
}

.org-select option {
  color: #0f2233;
  background: #ffffff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .icon-btn {
  color: var(--topbar-text);
}

.topbar .icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(184, 220, 255, 0.22);
  background: rgba(255, 255, 255, 0.05);
  max-width: 260px;
}

.user-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.user-name,
.user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.user-email {
  font-size: 0.72rem;
  color: var(--topbar-muted);
}

.topbar .btn--ghost {
  color: var(--topbar-text);
  border-color: rgba(184, 220, 255, 0.4);
}

.topbar .btn--ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidenav {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link[aria-current="page"] {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  font-weight: 650;
}

.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 7px;
  bottom: 7px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--orange-500);
}

.nav-link[aria-current="page"] .icon {
  color: var(--blue-400);
}

.sidenav-footer {
  margin: auto 0 0;
  padding: 16px 12px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.banner-slot {
  padding: 16px 28px 0;
}

.banner-slot:empty {
  display: none;
}

.banner-slot .alert {
  margin: 0;
}

.main {
  width: 100%;
  max-width: 1480px;
  padding: 24px 28px 56px;
  outline: none;
}

/* ---- page structure -------------------------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fade-in 0.15s ease-out;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.01em;
  outline: none;
}

.page-description {
  margin: 4px 0 0;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stack-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.toolbar--end {
  justify-content: flex-end;
}

.toolbar--between {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar-button {
  padding-bottom: 1px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.subheading {
  margin: 0 0 8px;
  font-size: 1rem;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

/* ---- cards / KPIs --------------------------------------------------------------------- */

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 0;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
}

.card-description {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-body {
  padding: 16px 20px 20px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.kpi {
  position: relative;
  overflow: hidden;
  padding: 18px 20px 20px;
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue-400), var(--blue-500) 45%, transparent 100%);
  opacity: 0.7;
}

.kpi-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.76rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi-title .icon {
  width: 18px;
  height: 18px;
  color: var(--blue-500);
}

.kpi-big {
  margin: 0 0 14px;
  font-size: 2.15rem;
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-unit {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-muted);
}

.kpi-empty {
  margin: 4px 0 0;
}

.kpi-foot {
  margin: 12px 0 0;
  font-size: 0.82rem;
}

.kpi-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
}

.kpi-alert .icon {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

@media (min-width: 1280px) {
  .kpi--wide {
    grid-column: span 2;
  }
}

.stat-grid {
  display: grid;
  gap: 10px;
  margin: 0;
}

.stat-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-value {
  margin: 2px 0 0;
  font-size: 1.3rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.stat-hint {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.stat--warning .stat-value {
  color: var(--warning-text);
}

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

.stat--danger {
  background: var(--danger-bg);
}

.split-bar {
  display: flex;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.split-direct {
  background: var(--bar-direct);
}

.split-relay {
  background: var(--bar-relay);
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 10px 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}

.swatch--direct {
  background: var(--bar-direct);
}

.swatch--relay {
  background: var(--bar-relay);
}

.bars {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(64px, max-content) 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue-500), var(--blue-400));
}

.bar-value {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.refresh-status {
  margin: 0;
  font-size: 0.82rem;
}

.refresh-status.is-error {
  color: var(--danger-text);
}

/* ---- key-value lists ----------------------------------------------------------------- */

.kv {
  display: grid;
  margin: 0;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(130px, 36%) minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv dt {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.kv--compact .kv-row {
  padding: 6px 0;
}

/* ---- buttons --------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

.btn .icon {
  width: 18px;
  height: 18px;
}

.btn--small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.btn--block {
  width: 100%;
  min-height: 44px;
}

.btn--primary {
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.btn--primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 0 4px rgba(229, 138, 49, 0.2);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--secondary:hover {
  background: var(--surface-2);
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--danger {
  background: var(--danger);
  color: #ffffff;
}

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

.btn--danger-ghost {
  background: transparent;
  color: var(--danger-text);
  border-color: currentColor;
}

.btn--danger-ghost:hover {
  background: var(--danger-bg);
}

.btn--link {
  min-height: 0;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 550;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn.is-busy::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- forms ------------------------------------------------------------------------------- */

.form {
  margin: 0;
}

.form--narrow {
  max-width: 440px;
}

.field {
  margin-bottom: 14px;
}

.field--inline {
  min-width: 170px;
  margin-bottom: 0;
}

.field--grow {
  flex: 1 1 260px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 650;
}

.label--strong {
  font-size: 0.95rem;
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
}

.input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.input[aria-invalid="true"] {
  border-color: var(--danger-text);
}

.input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.input--compact {
  width: auto;
  min-height: 34px;
  padding: 4px 8px;
}

textarea.input {
  resize: vertical;
}

.uri-box {
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.field--code .input {
  max-width: 240px;
  font-family: var(--mono);
  font-size: 1.4rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.help {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.field-error {
  margin: 6px 0 0;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--danger-text);
}

.form-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-weight: 550;
}

.checkbox,
.radio {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.check-label {
  font-weight: 550;
  cursor: pointer;
}

.check-row--desc .check-label {
  display: flex;
  flex-direction: column;
}

.check-desc {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
}

.check-row--day {
  align-items: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.check-row--day .checkbox {
  margin: 0;
}

.field--check {
  margin-bottom: 12px;
}

.fieldset {
  min-width: 0;
  margin: 0 0 14px;
  padding: 12px 14px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.fieldset > legend {
  padding: 0 6px;
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-bottom: 12px;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px 16px;
  margin-bottom: 12px;
}

.days {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.effective-line {
  margin: 0 0 8px;
}

.inline-form {
  margin: 0;
}

.inline-form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.inline-form-row .field {
  flex: 1 1 220px;
  margin-bottom: 0;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 46px;
  height: 26px;
  margin: 0;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.switch:checked {
  background: var(--success);
}

.switch:checked::after {
  transform: translateX(20px);
}

.switch:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.switch-label {
  font-weight: 650;
  cursor: pointer;
}

.switch-state {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.policy {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.secret-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.secret {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
}

.recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 28px;
  margin: 0 0 12px;
  padding: 14px 18px 14px 40px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 1rem;
}

.danger-zone {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--danger-text);
  border-radius: var(--radius);
  background: var(--danger-bg);
}

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

.status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
}

.stepup-account {
  margin: 0 0 14px;
}

/* ---- tables ----------------------------------------------------------------------------- */

.table-wrap {
  /* position: relative keeps absolutely positioned .sr-only labels inside the scroller */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

.table tbody tr:hover td {
  background: var(--row-hover);
}

.row--revoked td,
.row--muted td {
  color: var(--text-muted);
}

.cell-actions {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.cell-details {
  min-width: 220px;
}

.details {
  display: grid;
  gap: 2px;
  margin: 0;
  font-size: 0.8rem;
}

.details-row {
  display: flex;
  gap: 6px;
}

.details dt {
  color: var(--text-muted);
  white-space: nowrap;
}

.details dt::after {
  content: ":";
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.load-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.load-more p {
  margin: 0;
}

/* ---- status, badges, chips ------------------------------------------------------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 550;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
}

.dot--online,
.dot--ok {
  background: var(--dot-online);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2), 0 0 8px rgba(22, 163, 74, 0.55);
}

.dot--offline {
  background: var(--dot-offline);
}

.dot--revoked,
.dot--fail {
  background: var(--dot-revoked);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.18);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
}

.badge--success {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge--warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

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

.badge--info {
  background: var(--info-bg);
  color: var(--info-text);
}

.badge--neutral {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.chip {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--neutral-bg);
  color: var(--neutral-text);
  font-size: 0.75rem;
  white-space: nowrap;
}

.chip--info {
  border-color: transparent;
  background: var(--info-bg);
  color: var(--info-text);
}

/* ---- alerts, empty and restricted states ---------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
}

.alert p {
  margin: 0;
}

.alert-icon {
  margin-top: 1px;
}

.alert-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
}

.alert-title {
  font-weight: 700;
}

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.alert--info {
  background: var(--info-bg);
  color: var(--info-text);
}

.alert--warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.alert--error {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.alert--success {
  background: var(--success-bg);
  color: var(--success-text);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-muted);
  text-align: center;
}

.empty p {
  max-width: 560px;
  margin: 0;
}

.empty-icon {
  width: 32px;
  height: 32px;
  color: var(--blue-500);
}

.restricted {
  padding: 48px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.restricted h2 {
  margin: 8px 0;
  font-size: 1.2rem;
}

.restricted p {
  max-width: 560px;
  margin: 0 auto;
  color: var(--text-muted);
}

.restricted-icon {
  width: 36px;
  height: 36px;
  color: var(--text-muted);
}

/* ---- tabs -------------------------------------------------------------------------------- */

.tabs {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tablist {
  position: relative;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: inset 0 -1px 0 var(--border);
}

.tab {
  padding: 10px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--primary);
}

.tab-panel {
  outline: none;
}

.tab-panel:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ---- roles / devices details ------------------------------------------------------------- */

.roles-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.role-item {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
}

.role-item dd {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.device-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.device-id {
  font-size: 1.1rem;
  font-weight: 700;
}

.fingerprint {
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

/* ---- dialogs --------------------------------------------------------------------------- */

.dialog {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog[open] {
  animation: fade-in 0.12s ease-out;
}

.dialog--sm {
  width: min(500px, calc(100vw - 32px));
}

.dialog--md {
  width: min(620px, calc(100vw - 32px));
}

.dialog--lg {
  width: min(800px, calc(100vw - 32px));
}

.dialog--xl {
  width: min(1180px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(8, 19, 30, 0.66);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.dialog--danger .dialog-header {
  border-top: 4px solid var(--red-500);
}

.dialog-title {
  margin: 0;
  font-size: 1.12rem;
}

.dialog-description {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.dialog-close {
  margin: -4px -6px 0 0;
}

.dialog-body {
  padding: 16px 20px;
}

.dialog-message {
  margin: 0 0 10px;
}

.dialog-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.consequences {
  margin: 6px 0 12px;
  padding-left: 22px;
}

.consequences li {
  margin: 4px 0;
}

.dialog-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--danger-text);
}

/* ---- toasts ------------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.toast-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 10px 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: fade-in 0.18s ease-out;
}

.toast--success {
  border-left-color: var(--success);
}

.toast--error {
  border-left-color: var(--red-500);
}

.toast--warning {
  border-left-color: var(--orange-500);
}

.toast-icon {
  margin-top: 1px;
  color: var(--accent);
}

.toast--success .toast-icon {
  color: var(--success-text);
}

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

.toast--warning .toast-icon {
  color: var(--warning-text);
}

.toast-text {
  flex: 1;
  margin: 0;
  font-size: 0.9rem;
}

.toast-close {
  width: 28px;
  height: 28px;
  margin: -4px 0 0;
}

/* ---- login / register ------------------------------------------------------------------- */

.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(360px, 1fr);
}

.auth-brand {
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
  padding: 48px;
  color: #e6eef7;
  background:
    radial-gradient(900px 520px at 8% 12%, rgba(45, 127, 249, 0.3), transparent 62%),
    radial-gradient(700px 460px at 92% 92%, rgba(229, 138, 49, 0.24), transparent 62%),
    linear-gradient(160deg, #0b1a28 0%, #0f2233 46%, #17334c 100%);
}

.auth-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(184, 220, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(184, 220, 255, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at 30% 40%, #000 25%, transparent 75%);
  mask-image: radial-gradient(ellipse at 30% 40%, #000 25%, transparent 75%);
  pointer-events: none;
}

.auth-brand::after {
  content: "";
  position: absolute;
  left: 48px;
  right: 48px;
  bottom: 40px;
  height: 2px;
  background: linear-gradient(90deg, var(--orange-500), var(--blue-400) 55%, transparent);
  opacity: 0.8;
}

.auth-brand-inner {
  position: relative;
  max-width: 470px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.auth-logo img {
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(184, 220, 255, 0.28), 0 10px 32px rgba(45, 127, 249, 0.35);
}

.auth-product {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.auth-company {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b6c8da;
}

.auth-tagline {
  margin: 0 0 26px;
  font-size: 2.05rem;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.auth-highlights {
  list-style: none;
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  color: #cfe0f1;
}

.auth-highlights li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.auth-highlights .icon {
  color: var(--orange-500);
}

.auth-main {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 24px 40px;
  background: var(--bg);
  outline: none;
}

.auth-topbar {
  position: absolute;
  top: 16px;
  right: 16px;
}

.auth-topbar .icon-btn {
  border-color: var(--border);
  background: var(--surface);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card .alert {
  margin-bottom: 16px;
}

.auth-heading {
  margin-bottom: 20px;
}

.auth-title {
  margin: 0;
  font-size: 1.5rem;
  outline: none;
}

.auth-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
}

.auth-switch {
  margin: 18px 0 0;
  text-align: center;
  color: var(--text-muted);
}

.auth-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}

/* ---- responsive ------------------------------------------------------------------------- */

.brand-name {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand-sub,
  .topbar-label {
    display: none;
  }

  .topbar .input.org-select {
    min-width: 150px;
    max-width: 260px;
  }

  .user-chip {
    max-width: 210px;
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidenav {
    position: static;
    height: auto;
    padding: 6px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav-list {
    flex-direction: row;
    gap: 4px;
  }

  .nav-link {
    white-space: nowrap;
  }

  .nav-link[aria-current="page"]::before {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: -6px;
    width: auto;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  .sidenav-footer {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .main {
    padding: 20px 16px 48px;
  }

  .banner-slot {
    padding: 16px 16px 0;
  }
}

@media (max-width: 860px) {
  .auth-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-brand {
    padding: 28px 24px 36px;
  }

  .auth-brand::after {
    left: 24px;
    right: 24px;
    bottom: 18px;
  }

  .auth-logo {
    margin-bottom: 18px;
  }

  .auth-tagline {
    margin: 0;
    font-size: 1.35rem;
  }

  .auth-highlights {
    display: none;
  }

  .auth-main {
    justify-content: flex-start;
    padding-top: 64px;
  }
}

@media (max-width: 760px) {
  .user-text,
  .brand-sub,
  .topbar-label {
    display: none;
  }

  .topbar-org {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .topbar .input.org-select {
    flex: 1;
    max-width: none;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .grid-3,
  .stat-grid--3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .role-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .kv-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .recovery-codes {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (forced-colors: active) {
  .dot {
    forced-color-adjust: none;
    border: 1px solid CanvasText;
  }

  .btn,
  .input,
  .card,
  .badge,
  .chip {
    border: 1px solid CanvasText;
  }
}

.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: progress;
  box-shadow: none;
}
