:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --control-h: 2.125rem;
  --form-label-line: calc(0.8125rem * 1.3 + 0.35rem);
  --header-h: 3.25rem;
  --header-tab-radius: 8px;
  --content-max: 1100px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

/* ——— Top header (tabbed nav: active tab blends into page --bg) ——— */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.header-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0.5rem 1rem 0;
  min-height: var(--header-h);
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.site-header:not(.site-header--app) .header-inner {
  align-items: center;
  padding: 0 1rem;
}

.site-header:not(.site-header--app) .brand {
  padding-bottom: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
  padding-bottom: 0.55rem;
  line-height: 1.2;
}

.brand__mark {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand__icon {
  width: 1.65rem;
  height: 1.65rem;
  color: var(--accent);
}

.brand:hover .brand__icon {
  color: var(--accent-hover);
}

.brand:hover {
  color: var(--accent);
}

.brand__name {
  white-space: nowrap;
}

.nav-main {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.nav-main a {
  position: relative;
  z-index: 0;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem 0.55rem;
  border-radius: var(--header-tab-radius) var(--header-tab-radius) 0 0;
  white-space: nowrap;
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -1px;
}

.nav-main a:hover {
  color: var(--accent);
  background: rgba(239, 246, 255, 0.65);
  border-color: rgba(226, 232, 240, 0.9);
}

.nav-main a.is-active {
  z-index: 2;
  color: var(--text);
  font-weight: 600;
  background: var(--bg);
  border-color: var(--border);
  border-bottom: 1px solid var(--bg);
  box-shadow: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
  padding-bottom: 0.45rem;
}

.tenant-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--muted);
  text-decoration: none;
  max-width: 200px;
  padding: 0.35rem 0.65rem;
  background: var(--bg);
  border-radius: 999px;
  border: 1px solid var(--border);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.tenant-pill:hover {
  color: var(--accent);
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--accent-soft);
}

.tenant-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tenant-pill.is-active {
  color: var(--text);
  font-weight: 600;
  border-color: var(--border-strong);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

.tenant-pill__icon {
  flex-shrink: 0;
  display: block;
  opacity: 0.9;
}

.tenant-pill__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Mobile menu toggle (hidden on wide screens; see media query below) */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-toggle__icon {
  width: 1.35rem;
  height: 1.35rem;
}

.nav-toggle__icon--close {
  display: none;
}

.site-header.nav-is-open .nav-toggle__icon--open {
  display: none;
}

.site-header.nav-is-open .nav-toggle__icon--close {
  display: block;
}

.nav-overlay {
  display: none;
}

@media (max-width: 900px) {
  .site-header {
    min-height: 0;
  }

  .site-header--app .header-inner {
    flex-wrap: nowrap;
    align-items: center;
    padding: 0.5rem 1rem;
    position: relative;
  }

  .site-header--app .brand {
    padding-bottom: 0;
    flex: 1;
    min-width: 0;
  }

  .nav-toggle {
    display: inline-flex;
    margin-left: 0.35rem;
  }

  .header-actions {
    margin-left: 0;
    padding-bottom: 0;
    gap: 0.5rem;
  }

  .tenant-pill {
    max-width: min(7.5rem, 32vw);
  }

  /* Drawer: hide horizontal tab bar; open from menu button */
  .nav-main {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 110;
    flex: none;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    min-width: 0;
    width: 100%;
    margin: 0;
    padding: 0.25rem 0 0.5rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    overflow-x: visible;
    overflow-y: auto;
    max-height: min(70vh, calc(100dvh - 3.5rem));
    -webkit-overflow-scrolling: touch;
  }

  .site-header.nav-is-open .nav-main {
    display: flex;
  }

  .nav-main a {
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    padding: 0.8rem 1rem;
    white-space: normal;
    line-height: 1.35;
  }

  .nav-main a:last-child {
    border-bottom: none;
  }

  .nav-main a.is-active {
    background: var(--accent-soft);
    border-bottom-color: var(--border);
    box-shadow: none;
  }

  .nav-main a:hover {
    background: rgba(239, 246, 255, 0.95);
  }

  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s;
    pointer-events: none;
  }

  .nav-overlay.nav-overlay--visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.nav-menu-open {
    overflow: hidden;
    overscroll-behavior: contain;
  }
}

@media (min-width: 901px) {
  .nav-overlay {
    display: none !important;
  }
}

/* ——— Main content ——— */
.main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

h1 {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 0.35rem;
  color: var(--text);
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.card > h2:first-child {
  margin-top: 0;
}

.card__title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.card__title-row h2 {
  margin: 0;
}

.card__subhead {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 1.25rem 0 0.35rem;
  color: var(--text);
}

.card--success {
  border-color: rgba(22, 163, 74, 0.35);
  background: var(--ok-soft);
}

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

th,
td {
  text-align: left;
  padding: 0.4rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

td {
  font-size: 0.9em;
}

.td-status {
  vertical-align: middle;
  text-align: center;
  width: 5rem;
}

.user-status-form {
  display: inline-flex;
  justify-content: center;
  margin: 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 2.75rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
  margin: 0;
}

.switch__slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background 0.15s ease;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.1);
}

.switch__slider::before {
  position: absolute;
  content: "";
  height: 1.15rem;
  width: 1.15rem;
  left: 0.2rem;
  bottom: 0.175rem;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
}

.switch input:checked + .switch__slider {
  background: var(--ok);
}

.switch input:focus-visible + .switch__slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:checked + .switch__slider::before {
  transform: translateX(1.2rem);
}

.switch input:disabled + .switch__slider {
  opacity: 0.5;
  cursor: not-allowed;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Sentence-case headers aligned with form labels (e.g. Users page tables) */
.table--labels th {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text-secondary);
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: rgba(241, 245, 249, 0.6);
}

/* Tables: scroll horizontally on small screens instead of squishing columns */
.card:has(table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.card:has(table) table {
  width: max-content;
  min-width: 100%;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
}

.table-wrap > table {
  width: max-content;
  min-width: 100%;
}

label {
  display: block;
  margin: 0 0 0.2rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
}

/* Form controls - shared styles */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  width: 100%;
  max-width: 420px;
  height: var(--control-h);
  padding: 0 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.35;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):hover,
select:hover,
textarea:hover {
  border-color: #94a3b8;
  background: var(--surface);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

select {
  cursor: pointer;
  appearance: auto;
}

textarea {
  height: auto;
  min-height: 4.5rem;
  padding: 0.35rem 0.55rem;
  line-height: 1.4;
  resize: vertical;
}

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-h);
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1;
}

.btn:hover,
button:hover {
  background: var(--accent-hover);
}


.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  height: var(--control-h);
  padding: 0 0.65rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

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

.flash {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-size: 0.9375rem;
}

.flash.error {
  background: var(--danger-soft);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: #991b1b;
}

.flash.ok {
  background: var(--ok-soft);
  border: 1px solid rgba(22, 163, 74, 0.25);
  color: #166534;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

code {
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.84em;
  border: 1px solid var(--border);
  color: #334155;
}

.pre-block {
  white-space: pre-wrap;
  font-size: 0.8125rem;
  line-height: 1.45;
  overflow: auto;
  padding: 0.65rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0;
}

/* Login & auth shells */
.auth-wrap {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2rem;
}

.auth-card {
  width: 100%;
  max-width: min(36rem, 100%);
}

/* Wider card when showing TLS / EAP install steps (onboarding invite success) */
.auth-card--cert-guide {
  max-width: min(42rem, 100%);
}

.onboarding-install-help {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.onboarding-install-help__title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.onboarding-install-help__lead {
  font-size: 0.875rem;
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.onboarding-install-help__panel {
  margin-top: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
}

.onboarding-install-help__panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.onboarding-install-help__panel ol {
  margin: 0.65rem 0 0.15rem;
  padding-left: 1.2rem;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.onboarding-install-help__panel code {
  font-size: 0.84em;
}

/* —— Modern login (sign-in page only) —— */
.auth-page {
  align-items: center;
  padding: 2rem 1rem 3rem;
}

.auth-card--login {
  max-width: 26rem;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.8) inset,
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 24px 48px -12px rgba(15, 23, 42, 0.14);
}

.auth-card--login::before {
  content: "";
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #6366f1, #0ea5e9);
  opacity: 0.95;
}

.auth-card__head {
  padding: 1.75rem 1.75rem 0.25rem;
  text-align: center;
}

.auth-card__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  border-radius: 0.875rem;
  background: linear-gradient(145deg, var(--accent-soft), #eef2ff);
  color: var(--accent);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

.auth-card__mark svg {
  width: 1.5rem;
  height: 1.5rem;
}

.auth-card__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1.2;
}

.auth-card__lead {
  margin: 0.5rem 0 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.auth-card__lead strong {
  font-weight: 600;
  color: var(--text);
}

.auth-card--login .flash--auth {
  margin: 0.75rem 1.75rem 0;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  line-height: 1.45;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  padding: 1.5rem 1.75rem 1.75rem;
}

.auth-form .form-field {
  flex: none;
  max-width: none;
}

.auth-card--login .form-field label {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
}

.auth-card--login input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
  max-width: none;
  height: 2.75rem;
  padding: 0 0.85rem;
  border-radius: 0.625rem;
  border: 1px solid var(--border-strong);
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-card--login input::placeholder {
  color: #94a3b8;
}

.btn--auth-primary {
  width: 100%;
  margin-top: 0.25rem;
  min-height: 2.875rem;
  border-radius: 0.625rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn--auth-primary:hover {
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.28);
}

/* ---- Horizontal form row ---- */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 220px;
  max-width: 280px;
}

.form-field label {
  margin-bottom: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-field input:not([type="hidden"]),
.form-field select {
  margin-bottom: 0;
  height: var(--control-h);
}

.form-field textarea {
  margin-bottom: 0;
  height: auto;
  min-height: 5rem;
  max-width: 100%;
  resize: vertical;
}

.form-field--action {
  flex: 0 0 auto;
  padding-top: 1.2rem;
}

.form-field--action button,
.form-field--action .btn {
  white-space: nowrap;
  height: var(--control-h);
}

/* Vertical field stack (e.g. password change) */
.form-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
}

.form-col .form-field {
  max-width: none;
}

.form-col input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.form-col select,
.form-col textarea {
  max-width: 100%;
}

.form-col .form-field--action {
  padding-top: 0.25rem;
  align-self: flex-start;
}

/* ---- Add user: grouped label+control, responsive grid (no split label/field rows on narrow viewports) ---- */
.form-add-user {
  display: grid;
  gap: 0.65rem 0.75rem;
  align-items: end;
  width: 100%;
  grid-template-columns: 1fr;
}

.form-add-user__group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.form-add-user__group > label {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.3;
}

.form-add-user input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
.form-add-user select {
  width: 100%;
  max-width: none;
}

.form-add-user .input-with-toggle {
  width: 100%;
}

.form-add-user .input-with-toggle input[type="password"],
.form-add-user .input-with-toggle input[type="text"] {
  height: var(--control-h);
}

.form-add-user__group--sessions .input-sessions {
  align-self: flex-start;
}

.form-add-user__submit {
  display: flex;
  align-items: flex-end;
}

.form-add-user__submit button {
  width: 100%;
  height: var(--control-h);
}

@media (min-width: 601px) {
  .form-add-user {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-add-user__submit {
    grid-column: 1 / -1;
  }

  .form-add-user__submit button {
    width: auto;
    min-width: 7.5rem;
  }
}

@media (min-width: 901px) {
  .form-add-user {
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  }

  .form-add-user__submit {
    grid-column: auto;
  }
}

/* New user modal: readable grid inside dialog (overrides wide-viewport add-user columns) */
#new-user-modal .form-add-user {
  grid-template-columns: 1fr;
}

@media (min-width: 520px) {
  #new-user-modal .form-add-user {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

#new-user-modal .form-add-user .form-add-user__submit {
  grid-column: 1 / -1;
}

#new-user-modal .form-add-user .form-add-user__group[style*="grid-column"] {
  grid-column: 1 / -1;
}

.new-user-modal__actions {
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.new-user-modal__actions .btn {
  width: auto;
  min-width: 5rem;
  height: var(--control-h);
}

/* ---- Users page: aligned label row + control row (no padding hacks) ---- */
.form-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.form-toolbar__labels,
.form-toolbar__fields {
  display: grid;
  gap: 0 1rem;
  align-items: end;
}

.form-toolbar--cols-5 .form-toolbar__labels,
.form-toolbar--cols-5 .form-toolbar__fields {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
}

.form-toolbar--cols-6 .form-toolbar__labels,
.form-toolbar--cols-6 .form-toolbar__fields {
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
}

.form-toolbar--cols-2 .form-toolbar__labels,
.form-toolbar--cols-2 .form-toolbar__fields {
  grid-template-columns: minmax(0, 1fr) auto;
}

.form-toolbar--cols-3 .form-toolbar__labels,
.form-toolbar--cols-3 .form-toolbar__fields {
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
}

.form-toolbar__labels label {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.3;
  letter-spacing: normal;
  text-transform: none;
}

@media (min-width: 901px) {
  .form-toolbar__labels label {
    white-space: nowrap;
  }
}

.form-toolbar__label-slot {
  min-height: var(--form-label-line);
  visibility: hidden;
  font-size: 0.8125rem;
  line-height: 1.3;
  pointer-events: none;
  user-select: none;
}

.form-toolbar__fields input:not([type="hidden"]),
.form-toolbar__fields select {
  width: 100%;
  max-width: none;
  margin-bottom: 0;
  height: var(--control-h);
}

.form-toolbar__submit {
  display: flex;
  align-items: flex-end;
}

.form-toolbar__submit button,
.form-toolbar__submit .btn {
  height: var(--control-h);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .form-toolbar--cols-5 .form-toolbar__labels,
  .form-toolbar--cols-5 .form-toolbar__fields {
    grid-template-columns: 1fr;
  }
  .form-toolbar--cols-6 .form-toolbar__labels,
  .form-toolbar--cols-6 .form-toolbar__fields {
    grid-template-columns: 1fr;
  }
  .form-toolbar--cols-2 .form-toolbar__labels,
  .form-toolbar--cols-2 .form-toolbar__fields {
    grid-template-columns: 1fr;
  }
  .form-toolbar--cols-3 .form-toolbar__labels,
  .form-toolbar--cols-3 .form-toolbar__fields {
    grid-template-columns: 1fr;
  }
  .form-toolbar__label-slot {
    display: none;
  }
}

/* ---- Inline form (used in table cells) ---- */
.form-inline {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: nowrap;
}

.form-inline input:not([type="hidden"]) {
  margin-bottom: 0;
  max-width: 100%;
}

/* ---- Small buttons ---- */
.btn-sm {
  height: 1.625rem;
  font-size: 0.75rem;
  padding: 0 0.55rem;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
}

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

.btn-danger:hover {
  background: #b91c1c;
}

/* ---- Input sizes ---- */
.input-sm {
  height: 1.625rem;
  font-size: 0.8125rem;
  padding: 0 0.4rem;
  max-width: 9rem;
}

.input-inline {
  max-width: 6rem;
  margin-bottom: 0;
}

/* Max concurrent sessions / small integers (Simultaneous-Use) */
.input-sessions {
  width: auto;
  max-width: 3.75rem;
  min-width: 2.5rem;
  flex: 0 0 auto;
}

.form-toolbar__fields input.input-sessions[type="number"] {
  width: auto;
  max-width: 3.75rem;
}

td .form-inline input.input-sessions {
  width: auto;
  max-width: 3.75rem;
}

/* Password field + eye toggle inside input */
.input-with-toggle {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}

.input-with-toggle input[type="password"],
.input-with-toggle input[type="text"] {
  width: 100%;
  margin-bottom: 0;
  padding-right: 2.35rem;
  box-sizing: border-box;
}

.form-toolbar__fields .input-with-toggle input[type="password"],
.form-toolbar__fields .input-with-toggle input[type="text"] {
  height: var(--control-h);
}

.input-with-toggle__btn {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 2rem;
  min-width: 2rem;
  height: calc(var(--control-h) - 4px);
  max-height: 2rem;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 400;
}

.input-with-toggle__btn:hover {
  color: var(--text);
  background: rgba(15, 23, 42, 0.06);
}

.input-with-toggle__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.input-with-toggle__icon--show,
.input-with-toggle__icon--hide {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.input-with-toggle__icon--hide {
  display: none;
}

.input-with-toggle.input-with-toggle--plain .input-with-toggle__icon--show {
  display: none;
}

.input-with-toggle.input-with-toggle--plain .input-with-toggle__icon--hide {
  display: flex;
}

.input-with-toggle__btn svg {
  display: block;
  flex-shrink: 0;
}

.modal-dialog__form .input-with-toggle {
  width: 100%;
}

.modal-dialog__form .input-with-toggle input[type="password"],
.modal-dialog__form .input-with-toggle input[type="text"] {
  height: var(--control-h);
}

/* ---- Status badges ---- */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge--on {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.badge--off {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

/* ---- Modal (native dialog) ---- */
.modal-dialog {
  border: none;
  padding: 0;
  max-width: min(22rem, calc(100vw - 2rem));
  border-radius: 0.5rem;
  background: transparent;
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog__panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.15rem 1.25rem 1.25rem;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
}

.modal-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.modal-dialog__header .modal-dialog__title {
  margin: 0;
  line-height: 1.3;
}

.modal-dialog__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin: -0.25rem -0.35rem 0 0;
  padding: 0;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  transition: background 0.12s ease, color 0.12s ease;
}

.modal-dialog__close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-dialog__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-dialog__close svg {
  display: block;
}

.modal-dialog__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.modal-dialog__context {
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.modal-dialog__form label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.modal-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.modal-dialog--wide {
  max-width: min(36rem, calc(100vw - 2rem));
}

.user-edit-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.user-edit-dl dt {
  margin: 0;
  color: var(--text-secondary);
  font-weight: 500;
}

.user-edit-dl dd {
  margin: 0;
  min-width: 0;
}

.modal-dialog__form--stacked {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-dialog__form--stacked > div label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

.modal-dialog--wide .modal-dialog__form input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
.modal-dialog--wide .modal-dialog__form select,
.modal-dialog--wide .modal-dialog__form textarea {
  max-width: 100%;
}

/* ---- Button group (inline toggle/delete) ---- */
.btn-group {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  margin-top: 0.25rem;
}

.btn-group form {
  display: inline;
}

/* ---- Table action cells ---- */
.td-actions {
  white-space: nowrap;
  text-align: right;
}

.td-actions > .btn-group {
  margin-top: 0;
  justify-content: flex-end;
}

table:has(td.td-actions) thead th:last-child {
  text-align: right;
}

.td-mono {
  font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.8125rem;
  letter-spacing: -0.02em;
}

/* ---- Inline fields in tables ---- */
td input:not([type="hidden"]),
td select,
td textarea {
  margin-bottom: 0;
  max-width: 100%;
}

.main h1 + .muted {
  margin-bottom: 0.65rem;
}

/* Visually hidden, available to screen readers */
.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;
}

/* Monospace textarea (config snippets, RADIUS lines) */
.textarea-code {
  font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
  min-height: 5.5rem;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.65rem;
  background: #f8fafc;
  border-color: var(--border-strong);
}

.textarea-code::placeholder {
  color: #94a3b8;
}

.field-hint {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
}

.field-hint code {
  font-size: 0.88em;
}

/* Groups page */
.radius-reply-details {
  margin-top: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.radius-reply-details summary {
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  list-style: none;
  user-select: none;
}

.radius-reply-details summary::-webkit-details-marker {
  display: none;
}

.radius-reply-details summary::before {
  content: "";
  display: inline-block;
  width: 0.35rem;
  height: 0.35rem;
  margin-right: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  vertical-align: 0.15rem;
  transition: transform 0.15s ease;
}

.radius-reply-details[open] summary::before {
  transform: rotate(45deg);
  vertical-align: 0.05rem;
}

.radius-reply-details__body {
  padding: 0 0.85rem 0.85rem;
  border-top: 1px solid var(--border);
}

.radius-reply-details__label {
  display: block;
  margin: 0.65rem 0 0.3rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Sites page — "Add site" form layout.
   Bypasses the 280px cap on .form-field so the textareas can breathe
   while keeping the short name/notes inputs in a two-column top row. */
.site-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.site-form__row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.site-form__row--inputs {
  max-width: 48rem;
}

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

.site-form__field label {
  margin-bottom: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.site-form__field input:not([type="hidden"]),
.site-form__field select {
  height: var(--control-h);
  width: 100%;
  box-sizing: border-box;
  max-width: 100%;
}

.site-form__field textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 7.5rem;
  resize: vertical;
  max-width: 100%;
}

.site-form__field .field-hint {
  margin: 0.4rem 0 0;
}

.site-form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

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

  .site-form__actions {
    justify-content: stretch;
  }

  .site-form__actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Usage / statistics (Chart.js) */
.stats-toolbar {
  margin-bottom: 0.85rem;
}

.stats-toolbar__form {
  align-items: center;
}

.chart-card .chart-wrap {
  position: relative;
  height: min(22rem, 55vh);
  margin-top: 0.5rem;
}

.chart-wrap--bar {
  height: min(24rem, 60vh);
}

/* ---- Dashboard stat cards ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  padding: 1.25rem 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.stat-value--fraction {
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.35rem, 4vw, 2rem);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.35rem;
  font-weight: 500;
}

/* ---- Status table (settings) ---- */
.status-table {
  max-width: 24rem;
}

.status-table td:first-child {
  font-weight: 500;
  padding-right: 1rem;
}

/* Stack horizontal form rows on small viewports (inputs are capped at 420px globally otherwise) */
@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .form-field {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .form-field--action {
    flex: none;
    width: 100%;
    max-width: none;
    padding-top: 0.2rem;
    align-self: stretch;
  }

  .form-row input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  .form-row select,
  .form-row textarea {
    max-width: 100%;
  }

  .form-field--action button,
  .form-field--action .btn {
    width: 100%;
    justify-content: center;
  }

  th,
  td {
    padding: 0.35rem 0.45rem;
  }

  table {
    font-size: 0.875rem;
  }

  td {
    overflow-wrap: break-word;
  }
}
