:root {
  --bg: #09090B;
  --surface: #111113;
  --surface-2: #18181B;
  --border: #27272A;
  --text: #FAFAFA;
  --text-secondary: #A1A1AA;
  --text-muted: #71717A;
  --primary: #0EA5E9;
  --primary-hover: #38BDF8;
  --primary-subtle: rgba(14, 165, 233, 0.1);
  --primary-ring: rgba(14, 165, 233, 0.4);
  --success: #22C55E;
  --success-bg: rgba(34, 197, 94, 0.12);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --font: "Fira Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "Fira Code", monospace;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F5F5F5;
  --surface-2: #EAEAEA;
  --border: #D4D4D4;
  --text: #171717;
  --text-secondary: #525252;
  --text-muted: #A3A3A3;
  --primary: #0284C7;
  --primary-hover: #0369A1;
  --primary-subtle: rgba(2, 132, 199, 0.08);
  --primary-ring: rgba(2, 132, 199, 0.3);
  --success: #16A34A;
  --success-bg: rgba(22, 163, 74, 0.1);
  --error: #DC2626;
  --error-bg: rgba(220, 38, 38, 0.1);
  --warning: #D97706;
  --warning-bg: rgba(217, 119, 6, 0.1);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --font: "Fira Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "Fira Code", monospace;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #FFFFFF;
    --surface: #F5F5F5;
    --surface-2: #EAEAEA;
    --border: #D4D4D4;
    --text: #171717;
    --text-secondary: #525252;
    --text-muted: #A3A3A3;
    --primary: #0284C7;
    --primary-hover: #0369A1;
    --primary-subtle: rgba(2, 132, 199, 0.08);
    --primary-ring: rgba(2, 132, 199, 0.3);
    --success: #16A34A;
    --success-bg: rgba(22, 163, 74, 0.1);
    --error: #DC2626;
    --error-bg: rgba(220, 38, 38, 0.1);
    --warning: #D97706;
    --warning-bg: rgba(217, 119, 6, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre, .user-id, #api-key-new-value {
  font-family: var(--font-mono);
}

/* ── Login page ──────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: radial-gradient(ellipse at top, rgba(14, 165, 233, 0.06), transparent 60%),
              radial-gradient(ellipse at bottom, rgba(34, 197, 94, 0.03), transparent 60%),
              var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  transition: border-color 0.2s ease-out, box-shadow 0.2s ease-out;
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.login-form input::placeholder {
  color: var(--text-muted);
}

.login-form button {
  width: 100%;
  padding: 0.7rem 1rem;
  margin-top: 0.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s ease-out, transform 0.1s ease-out;
}

.login-form button:hover {
  background: var(--primary-hover);
}

.login-form button:active {
  transform: scale(0.98);
}

.login-form button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Alerts ─────────────────────────────────────────── */

.alert {
  padding: 0.65rem 0.85rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  line-height: 1.5;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

/* ── Notifications ──────────────────────────────────── */

.notification-container {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  max-width: 480px;
  width: 100%;
  pointer-events: none;
}

.notification {
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  animation: notification-slide-in 0.3s ease-out;
  font-size: 0.875rem;
  line-height: 1.5;
  padding-bottom: calc(0.75rem + 5px);
}

@keyframes notification-slide-in {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.notification-info {
  background: var(--primary-subtle);
  color: var(--primary);
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.notification-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.notification-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.notification-dismiss {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.6;
  padding: 0.1rem;
  flex-shrink: 0;
  color: currentColor;
  font-family: var(--font);
  transition: opacity 0.15s ease-out;
}

.notification-dismiss:hover {
  opacity: 1;
}

.notification-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: currentColor;
  opacity: 0.3;
}

.text-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s ease-out;
}

.text-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* ── Dashboard shell ────────────────────────────────── */

.dashboard-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.dashboard-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.float-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.back-link {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease-out, background 0.2s ease-out;
}

.back-link:hover {
  color: var(--primary);
  background: var(--primary-subtle);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  justify-content: center;
}

.header-nav-link {
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease-out, background 0.2s ease-out;
  white-space: nowrap;
}

.header-nav-link:hover {
  color: var(--primary);
  background: var(--primary-subtle);
}

/* ── Buttons ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  text-decoration: none;
  cursor: pointer;
  border: none;
  line-height: 1.4;
  transition: background 0.2s ease-out, color 0.2s ease-out,
              border-color 0.2s ease-out, box-shadow 0.2s ease-out,
              transform 0.1s ease-out;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

.btn-accent {
  background: var(--primary);
  color: white;
}

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

.btn-danger {
  background: var(--error);
  color: white;
}

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

.card-danger {
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.card-danger .card-header {
  border-bottom-color: rgba(239, 68, 68, 0.15);
}

/* ── SVG Icon helper ────────────────────────────────── */

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

.icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary-subtle);
  color: var(--primary);
}

/* ── Dashboard main & card grid ─────────────────────── */

.dashboard-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

@media (max-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Summary cards (dashboard) ──────────────────────── */

.summary-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease-out, background 0.2s ease-out,
              box-shadow 0.2s ease-out, transform 0.15s ease-out;
}

.summary-card:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.summary-card-static {
  cursor: default;
}

.summary-card-static:hover {
  border-color: var(--border);
  background: var(--surface);
  box-shadow: none;
  transform: none;
}

.summary-count {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
  font-family: var(--font-mono);
  text-align: right;
}

.stat-value {
  font-variant-numeric: tabular-nums;
}

.summary-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* ── Cards ──────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  align-self: stretch;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  gap: 0.75rem;
}

.card-header h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.card-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--surface);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.card-toolbar {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card-body {
  padding: 0.85rem 1.25rem;
}

.card-body > div:first-child,
.card-body > form:first-child {
  padding-top: 0;
}

.card-body > .form-row,
.card-body > .domain-roles-list,
.card-body > .role-manage-group,
.card-body > .danger-zone-item,
.card-body > .add-role-form,
.card-body > hr {
  margin-left: -1.25rem;
  margin-right: -1.25rem;
}

.card-body > hr {
  border-color: var(--border);
}

.card-body > .empty-state {
  margin: 0;
  border: none;
  border-radius: 0;
}

/* ── Search ─────────────────────────────────────────── */

.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  transition: border-color 0.2s ease-out, box-shadow 0.2s ease-out;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* ── Tabs ───────────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  overflow-x: auto;
  margin-bottom: 0;
}

.tab-btn {
  padding: 0.65rem 1rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  margin-top: 0.75rem;
}

.tab-content.active {
  display: block;
}

/* ── Data tables ────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.data-table th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

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

.data-table tbody tr {
  transition: background 0.15s ease-out;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

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

.text-right {
  text-align: right;
}

/* ── Empty state ────────────────────────────────────── */

.empty-state {
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* ── Role badges & overview ─────────────────────────── */

.role-overview-group {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.role-overview-group:last-child {
  border-bottom: none;
}

.role-overview-group:first-child {
  padding-top: 1rem;
}

.role-overview-domain {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}

.role-overview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  margin: 3px;
  background: var(--primary-subtle);
  color: var(--primary);
  border-radius: 4px;
  font-weight: 500;
  border: 1px solid rgba(14, 165, 233, 0.15);
}

.role-domain-inline {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.15rem;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.role-overview-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.role-overview-entry:last-child {
  margin-bottom: 0;
}

.role-user-list {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.role-user-link {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease-out;
}

.role-user-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.role-badge-removable {
  padding-right: 0.2rem;
}

.role-remove-form {
  display: inline;
  margin: 0;
  padding: 0;
}

.role-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  opacity: 0.5;
  transition: color 0.2s ease-out, opacity 0.2s ease-out;
}

.role-remove-btn:hover {
  color: var(--error);
  opacity: 1;
}

/* ── User-roles page ────────────────────────────────── */

.user-roles-container {
  max-width: 680px;
  margin: 0 auto;
}

.user-roles-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.user-header-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-roles-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.avatar-cell {
  width: 40px;
  padding-right: 0 !important;
  text-align: center;
}

.user-list-avatar {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
}

.user-list-avatar-empty {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 28px;
  text-align: center;
}

.user-id {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  word-break: break-all;
}

.user-roles-container .card {
  margin-bottom: 1rem;
}

.user-roles-container .card:last-child {
  margin-bottom: 0;
}

.role-manage-group {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.role-manage-group:last-child {
  border-bottom: none;
}

.role-manage-group:first-child {
  padding-top: 1rem;
}

/* ── Permissions editor ─────────────────────────────── */

.perm-category {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.perm-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.85rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.perm-category.collapsed .perm-category-header {
  border-bottom-color: transparent;
}

.perm-category-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.perm-items {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.85rem;
}

.perm-category.collapsed .perm-items {
  display: none;
}

.accordion-arrow {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.15s ease-out;
  flex-shrink: 0;
}

.perm-category.collapsed .accordion-arrow {
  transform: rotate(-90deg);
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease-out;
  font-size: 0.8rem;
}

.perm-item:hover {
  background: var(--bg-secondary);
}

.perm-item code {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 16rem;
  flex-shrink: 0;
}

.perm-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.perm-item input[type="checkbox"]:checked + code {
  color: var(--text);
  font-weight: 500;
}

.perm-item:has(input[type="checkbox"]:checked) {
  background: rgba(59, 130, 246, 0.06);
  border-color: var(--primary);
}

.perm-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace);
  padding: 0.08rem 0.45rem;
  border-radius: 3px;
  line-height: 1.4;
  flex-shrink: 0;
}

.perm-badge-green {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.perm-badge-yellow {
  background: rgba(234, 179, 8, 0.15);
  color: #a16207;
}

.perm-badge-blue {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
}

.perm-badge-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.smart-perm-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.smart-perm-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease-out;
  white-space: nowrap;
}

.smart-perm-btn:hover {
  border-color: var(--primary);
  color: var(--text);
  background: var(--primary-subtle);
}

.smart-perm-btn.smart-perm-active {
  background: rgba(34, 197, 94, 0.12);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Add-role form ──────────────────────────────────── */

.add-role-form {
  padding: 0;
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
}

.form-row:first-child {
  padding-top: 1rem;
}

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

.form-field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-input {
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  transition: border-color 0.2s ease-out, box-shadow 0.2s ease-out;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.form-field-action {
  flex: 0 0 auto;
}

/* ── Select inputs (dropdowns) ──────────────────────── */

select.form-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a1a1aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2rem;
  cursor: pointer;
}

select.form-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Checkbox label ─────────────────────────────────── */

.form-field-checkbox {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  padding: 0.15rem 0;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Invite status badges ───────────────────────────── */

.invite-status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: capitalize;
  font-family: var(--font-mono);
}

.status-pending {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.15);
}

.status-completed {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.15);
}

.status-expired {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

/* ── Banned badge ───────────────────────────────────── */

.badge-banned {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.35rem;
  border: 1px solid rgba(239, 68, 68, 0.15);
}

/* ── User status badges ─────────────────────────────── */

.user-status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: capitalize;
  font-family: var(--font-mono);
}

.status-active {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.15);
}

.status-banned {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

.status-deleted {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.15);
}

/* ── Danger zone items ──────────────────────────────── */

.danger-zone-item {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.danger-zone-item:last-child {
  border-bottom: none;
}

/* ── Domain roles list (detail page) ────────────────── */

.domain-roles-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1.25rem;
}

/* ── API Key display cards ──────────────────────────── */

.api-key-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease-out;
}

.api-key-card:hover {
  border-color: var(--text-muted);
}

/* ── 2FA specific ───────────────────────────────────── */

.twofa-container {
  padding: 0.25rem 0;
}

.twofa-success-box,
.recovery-box {
  margin: 0 1.25rem 1rem;
  padding: 0.85rem;
  background: rgba(26, 58, 26, 0.5);
  border: 1px solid rgba(46, 125, 50, 0.4);
  border-radius: var(--radius-sm);
}

.twofa-success-box p:first-child,
.recovery-box p:first-child {
  color: var(--success);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.recovery-box {
  background: rgba(26, 58, 26, 0.3);
}

.secret-display {
  display: block;
  padding: 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  word-break: break-all;
  font-size: 0.9rem;
  color: var(--text);
  margin-top: 0.25rem;
}

/* ── QR code container ────────────────────────────── */

.qr-code-box {
  margin: 0.75rem 0;
  background: white;
  display: inline-block;
  padding: 8px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.qr-code-box img {
  display: block;
  margin: 0 auto;
}

/* ── Utility ────────────────────────────────────────── */

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0;
}

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

/* ── User dropdown ──────────────────────────────────── */

.user-dropdown {
  position: relative;
}

.user-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid transparent;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.2s ease-out, border-color 0.2s ease-out, background 0.2s ease-out;
}

.user-dropdown-trigger:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}

.user-dropdown-trigger:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.dropdown-chevron {
  transition: transform 0.2s ease-out;
}

.user-dropdown[aria-expanded="true"] .dropdown-chevron {
  transform: rotate(180deg);
}

.user-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  overflow: hidden;
}

.user-dropdown[aria-expanded="true"] .user-dropdown-menu {
  display: block;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s ease-out, color 0.15s ease-out;
}

.user-dropdown-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.user-dropdown-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ── Summary card icon variant ───────────────────────── */

.summary-card-icon {
  color: var(--primary);
}

/* ── Loading state ──────────────────────────────────── */

.loading-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Theme selector (settings page) ──────────────────── */

.hidden {
  display: none !important;
}

.theme-selector {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  min-width: 120px;
  padding: 1.25rem 0.75rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.2s ease-out, background 0.2s ease-out;
  text-align: center;
  user-select: none;
}

.theme-option:hover {
  border-color: var(--text-muted);
}

.theme-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-option-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.theme-option-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.theme-option-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 768px) {
  .dashboard-header {
    padding: 0 1rem;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .dashboard-main {
    padding: 1rem;
  }

  .user-email {
    display: none;
  }

  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .summary-card {
    padding: 1.5rem 1rem;
  }

  .summary-count {
    font-size: 1.75rem;
  }

  .form-row {
    flex-wrap: wrap;
  }

  .form-field-action {
    width: 100%;
  }

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

  .card-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 0.75rem;
  }

  .dashboard-header .float-left,
  .dashboard-header .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .dashboard-header .header-actions {
    padding: 0.25rem 0;
    gap: 0.4rem;
  }

  .header-actions .btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .header-actions .btn .icon {
    width: 16px;
    height: 16px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 1.5rem;
  }

  .card-header {
    flex-wrap: wrap;
  }

  .data-table th,
  .data-table td {
    padding: 0.5rem 0.65rem;
    font-size: 0.8rem;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-field,
  .form-field-action {
    width: 100%;
  }

  .perm-item {
    flex-wrap: wrap;
  }

  .perm-item code {
    min-width: 0;
  }

  .perm-desc {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}
