@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Plus+Jakarta+Sans:wght@600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ═══════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════ */
:root {
  --sidebar-w: 220px;
  --topbar-h: 56px;

  --sidebar-bg: #0d0d0d;
  --sidebar-border: #1a1a1a;
  --sidebar-text: #9ca3af;
  --sidebar-text-hover: #f3f4f6;
  --sidebar-active-bg: rgba(37, 99, 235, 0.15);
  --sidebar-active-text: #60a5fa;
  --sidebar-active-dot: #2563eb;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --accent-text: #1e40af;

  --success: #059669;
  --success-bg: #ecfdf5;
  --success-text: #065f46;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;

  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;

  --info-bg: #eff6ff;
  --info-text: #1e40af;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);

  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);

  --font-body: 'Inter', system-ui, sans-serif;
  --font-heading: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ═══════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  background-image: radial-gradient(ellipse at 30% 20%, rgba(37,99,235,0.12) 0%, transparent 60%),
                    radial-gradient(ellipse at 70% 80%, rgba(37,99,235,0.06) 0%, transparent 50%);
}

.login-card {
  background: #111111;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 16px;
  color: white;
  letter-spacing: -0.02em;
}

.login-logo-text {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.1rem;
  color: #f3f4f6;
  letter-spacing: -0.02em;
}

.login-logo-text span {
  color: var(--accent);
}

.login-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.4rem;
  color: #f9fafb;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.login-subtitle {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 28px;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #9ca3af;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.login-form input {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #2d2d2d;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  color: #f3f4f6;
  font-family: var(--font-body);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.login-form input::placeholder { color: #4b5563; }

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.login-form .btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  font-size: 0.9rem;
  font-weight: 600;
}

.login-error {
  background: rgba(220,38,38,0.1);
  border: 1px solid rgba(220,38,38,0.3);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
  color: #fca5a5;
  font-size: 0.8rem;
  margin-top: 12px;
  display: none;
}

.login-error.visible { display: block; }

/* ═══════════════════════════════════════════
   APP SHELL (authed pages)
═══════════════════════════════════════════ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo-mark {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.875rem;
  color: #e5e7eb;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: 0.7rem;
  font-weight: 400;
  color: #4b5563;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #374151;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  color: var(--sidebar-text);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--sidebar-text-hover);
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.sidebar-user:hover { background: rgba(255,255,255,0.05); }

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.68rem;
  color: #4b5563;
}

.btn-logout {
  background: none;
  border: none;
  color: #4b5563;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  margin-left: auto;
  transition: color var(--transition);
  display: flex;
  align-items: center;
}
.btn-logout:hover { color: var(--danger); }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 2px;
}

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

.page-content {
  padding: 24px;
  flex: 1;
}

/* ═══════════════════════════════════════════
   COMPONENTS
═══════════════════════════════════════════ */

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.card-body {
  padding: 20px;
}

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.stat-value {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.8rem;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 4px;
}

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

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-icon.blue { background: var(--accent-light); color: var(--accent); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning); }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  border: none;
  outline: none;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(37,99,235,0.3); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

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

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

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-xs { padding: 3px 8px; font-size: 0.7rem; border-radius: 5px; }

.btn svg { width: 14px; height: 14px; }
.btn-sm svg { width: 13px; height: 13px; }

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

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

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

tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

tbody td {
  padding: 12px 16px;
  font-size: 0.825rem;
  color: var(--text-secondary);
  vertical-align: middle;
}

.td-main {
  font-weight: 600;
  color: var(--text);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-active { background: var(--success-bg); color: var(--success-text); }
.badge-revoked { background: var(--danger-bg); color: var(--danger-text); }
.badge-lambda { background: var(--accent-light); color: var(--accent-text); }
.badge-widget { background: #ede9fe; color: #5b21b6; }
.badge-none { background: var(--border-light); color: var(--text-muted); }

.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

/* Code / mono */
.code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

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

.page-header-text h1 {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.page-header-text p {
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  animation: modalIn 0.18s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.modal-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

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

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font-body);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid #fde68a;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #a7f3d0;
}

.alert-info {
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid #bfdbfe;
}

.alert strong { font-weight: 600; }

/* Key reveal box */
.key-box {
  background: #0d0d0d;
  border: 1px solid #2d2d2d;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #86efac;
  word-break: break-all;
  user-select: all;
  cursor: text;
  margin: 12px 0;
}

/* Expandable config rows */
.config-row {
  border-top: 1px solid var(--border-light);
  padding: 16px 20px;
  background: var(--surface-2);
  animation: slideDown 0.15s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.config-grid {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.config-grid:last-child { margin-bottom: 0; }

/* HTTP method badges */
.method {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.03em;
}

.method-get    { background: #dcfce7; color: #166534; }
.method-post   { background: #dbeafe; color: #1e40af; }
.method-put    { background: #fef9c3; color: #854d0e; }
.method-patch  { background: #ffedd5; color: #9a3412; }
.method-delete { background: #fee2e2; color: #991b1b; }

.auth-badge {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border-light);
  color: var(--text-muted);
}

.auth-badge.jwt     { background: #ede9fe; color: #5b21b6; }
.auth-badge.admin   { background: var(--accent-light); color: var(--accent-text); }
.auth-badge.internal { background: #fef9c3; color: #854d0e; }

/* APIs accordion */
.service-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.service-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.service-header:hover { background: var(--surface-2); }

.service-header h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.service-header .endpoint-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.service-body {
  display: none;
  border-top: 1px solid var(--border);
}

.service-body.open { display: block; }

.endpoint-row {
  display: grid;
  grid-template-columns: 70px 260px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

.endpoint-row:last-child { border-bottom: none; }
.endpoint-row:hover { background: var(--surface-2); }

.endpoint-path {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

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

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

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

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 8px;
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Toast notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
  max-width: 320px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast-success { background: var(--success); color: white; }
.toast-error   { background: var(--danger); color: white; }
.toast-info    { background: var(--accent); color: white; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--transition); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .endpoint-row { grid-template-columns: 60px 1fr; }
  .endpoint-row .endpoint-desc, .endpoint-row .auth-badge { display: none; }
}
