/* ── Reset & base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #6366f1;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Auth pages (login, consent, error) ───────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.account-page {
  min-height: 100vh;
  padding: 32px 16px;
}

.account-container {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

.auth-header { text-align: center; margin-bottom: 28px; }
.auth-logo { font-size: 48px; margin-bottom: 12px; }
.auth-header h1 { font-size: 24px; font-weight: 700; color: var(--text); }
.auth-header p { color: var(--text-muted); margin-top: 6px; }

.consent-user {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.consent-scopes { margin-bottom: 24px; }
.scopes-title { font-weight: 600; margin-bottom: 8px; }
.consent-scopes ul { list-style: none; }
.consent-scopes li { padding: 6px 0; color: var(--text); font-size: 13px; }

.consent-actions { display: flex; gap: 12px; }
.consent-actions .btn { flex: 1; }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; }
.form-group label small { font-weight: 400; color: var(--text-muted); }

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

textarea { resize: vertical; min-height: 90px; }

.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.form-check label { margin: 0; font-weight: 400; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }
.form-group-btn { flex: 0; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Admin layout ─────────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.logo-icon { font-size: 22px; }
.logo-text { font-size: 16px; font-weight: 700; color: #fff; }

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: rgba(99,102,241,.2); color: var(--sidebar-active); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.05);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-badge { font-size: 13px; font-weight: 600; color: #fff; }
.logout-btn { font-size: 12px; color: var(--sidebar-text); text-decoration: none; }
.logout-btn:hover { color: var(--danger); }

.main-content {
  margin-left: 240px;
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}

/* ── Page elements ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h2 { font-size: 22px; font-weight: 700; }

.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.section-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

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

.section-header h3 { margin-bottom: 0; }

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 20px;
  align-items: start;
}

/* ── Stats ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-icon { font-size: 32px; margin-bottom: 8px; }
.stat-value { font-size: 36px; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Table ────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }

/* ── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-ok { background: #dcfce7; color: #16a34a; }
.badge-off { background: #fee2e2; color: #dc2626; }
.badge-admin { background: #ede9fe; color: #7c3aed; }
.badge-app { background: #dbeafe; color: #2563eb; margin-right: 4px; }
.badge-role { background: #fef9c3; color: #854d0e; }

/* ── Alerts ───────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.alert-success { background: #dcfce7; color: #16a34a; }
.alert-error { background: #fee2e2; color: #dc2626; }
.alert-warning { background: #fef9c3; color: #92400e; }

/* ── Misc ─────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); font-size: 13px; }
code { font-family: 'Fira Code', monospace; font-size: 12px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }
.block-code { display: block; margin-bottom: 4px; word-break: break-all; }

.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  flex-wrap: wrap;
}

.copy-field code { background: none; padding: 0; word-break: break-all; flex: 1; }

.secret-blur { filter: blur(4px); transition: filter .2s; user-select: none; }

.apps-checklist { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.apps-checklist .form-check { margin-bottom: 0; }
.apps-checklist label { display: flex; flex-direction: column; gap: 2px; }
