:root {
  --bg-a: #0f1024;
  --bg-b: #1a1035;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-bg-strong: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-shadow: rgba(0, 0, 0, 0.35);
  --text-primary: #f3f2fb;
  --text-secondary: rgba(243, 242, 251, 0.65);
  --text-faint: rgba(243, 242, 251, 0.4);
  --accent: #8b7bff;
  --accent-strong: #a78bfa;
  --accent-contrast: #100c22;
  --danger: #ff6b81;
  --danger-strong: #ff4d68;
  --success: #4ade80;
  --warn: #fbbf24;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: radial-gradient(circle at 15% 10%, #241a4a 0%, transparent 45%),
    radial-gradient(circle at 85% 15%, #1c2b52 0%, transparent 40%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
  background-attachment: fixed;
  overflow-x: hidden;
}

.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
}

.orb-a { width: 420px; height: 420px; background: #6d5aff; top: -120px; left: -100px; }
.orb-b { width: 360px; height: 360px; background: #2fd3c8; bottom: -140px; right: -80px; }
.orb-c { width: 300px; height: 300px; background: #ff6b9d; top: 40%; right: 20%; opacity: 0.25; }

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 8px 32px var(--glass-shadow);
}

/* ---------- App shell ---------- */

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  margin: 16px 0 16px 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 24px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand-mark {
  font-size: 1.3rem;
  color: var(--accent-strong);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a:hover {
  background: var(--glass-bg-strong);
  color: var(--text-primary);
}

.nav a.active {
  background: linear-gradient(135deg, rgba(139, 123, 255, 0.35), rgba(139, 123, 255, 0.12));
  color: var(--text-primary);
  border: 1px solid rgba(139, 123, 255, 0.4);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border);
}

.account-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.account-link:hover, .account-link.active {
  color: var(--text-primary);
  background: var(--glass-bg-strong);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
}

.content {
  flex: 1;
  padding: 32px 40px;
  max-width: 1200px;
}

/* ---------- Typography / layout helpers ---------- */

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
p.subtitle { color: var(--text-secondary); margin: 0 0 28px; }

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

.card {
  padding: 24px;
  margin-bottom: 24px;
}

.grid {
  display: grid;
  gap: 20px;
}

.grid-stats {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 28px;
}

.stat-card {
  padding: 20px;
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
}

/* ---------- Forms ---------- */

label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"], input[type="password"], input[type="email"], select {
  width: 100%;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

input:focus, select:focus {
  border-color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.08);
}

/* Browsers force their own (usually yellow) background on autofilled fields and
   ignore background-color overrides directly; an inset box-shadow is the only
   reliable way to repaint it to match the glass theme. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.08) inset;
  box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.08) inset;
  transition: background-color 9999s ease-in-out 0s;
  caret-color: var(--text-primary);
}

.field {
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.form-row > * { flex: 1; min-width: 180px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, background 0.15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6b5bff);
  color: white;
  box-shadow: 0 4px 20px rgba(139, 123, 255, 0.35);
}
.btn-primary:hover { filter: brightness(1.08); }

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

.btn-danger {
  background: rgba(255, 107, 129, 0.15);
  border-color: rgba(255, 107, 129, 0.4);
  color: #ffb3c0;
}
.btn-danger:hover { background: rgba(255, 107, 129, 0.25); }

.btn-small { padding: 7px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tables ---------- */

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

thead th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 0 12px 10px;
  font-weight: 600;
}

tbody tr {
  background: rgba(255, 255, 255, 0.03);
}

tbody td {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
}

tbody tr:hover { background: rgba(255, 255, 255, 0.06); }

td:first-child, th:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); padding-left: 16px; }
td:last-child, th:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding-right: 16px; text-align: right; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-ok { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-danger { background: rgba(255, 107, 129, 0.15); color: var(--danger); }
.badge-muted { background: rgba(255,255,255,0.08); color: var(--text-secondary); }

.table-actions { display: flex; gap: 8px; justify-content: flex-end; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-faint);
}

/* ---------- Login page ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
  font-weight: 700;
  font-size: 1.15rem;
}

.login-brand .brand-mark { font-size: 1.6rem; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  margin-bottom: 16px;
}
.alert-error { background: rgba(255, 107, 129, 0.12); border: 1px solid rgba(255, 107, 129, 0.35); color: #ffc2cc; }
.alert-success { background: rgba(74, 222, 128, 0.12); border: 1px solid rgba(74, 222, 128, 0.35); color: #bdf5cf; }
.alert-info { background: rgba(139, 123, 255, 0.12); border: 1px solid rgba(139, 123, 255, 0.35); color: #d6d0ff; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 15, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 420px;
  padding: 26px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.generated-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  word-break: break-all;
  user-select: all;
}

/* ---------- Toasts ---------- */

.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  min-width: 220px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease;
}
.toast-error { border-color: rgba(255, 107, 129, 0.5); }
.toast-success { border-color: rgba(74, 222, 128, 0.5); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.text-secondary { color: var(--text-secondary); }
.text-faint { color: var(--text-faint); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Utilities ----------
   CSP sets style-src 'self' with no 'unsafe-inline', so browsers silently drop
   any inline style="" attribute — everything must be a class instead. */
.hidden { display: none !important; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.justify-center { justify-content: center; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-12 { margin-top: 12px; }
.fs-xs { font-size: 0.75rem; }
.fs-lg { font-size: 1.2rem; }
.max-w-320 { max-width: 320px; }
.max-w-420 { max-width: 420px; }
.error-code { font-size: 3rem; margin: 0; }
.inline-checkbox { width: auto; display: inline-block; margin-right: 6px; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: auto; margin: 12px; height: auto; position: relative; top: 0; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; align-items: center; margin-left: auto; border-top: none; padding-top: 0; }
  .content { padding: 20px; }
}
