/* ═══════════════════════════════════════════
   API Key Manager — Premium Dark Theme
   ═══════════════════════════════════════════ */

:root {
  /* Colors */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(31, 41, 55, 0.8);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.03);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #6366f1;
  --accent-primary-hover: #818cf8;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --accent-glow: rgba(99, 102, 241, 0.3);

  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --info: #3b82f6;

  --sidebar-width: 260px;
  --topbar-height: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s cubic-bezier(.4,0,.2,1);
}

/* ═══ Reset ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

a { color: var(--accent-primary); text-decoration: none; }

/* ═══ Glass Card ═══ */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ═══ Scrollbar ═══ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ═══════════════════════
   LOGIN PAGE
   ═══════════════════════ */
.page { display: none; }
.page.active { display: flex; }

#login-page {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  position: relative;
}

.login-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99,102,241,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139,92,246,0.1) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(6,182,212,0.08) 0%, transparent 50%),
    var(--bg-primary);
  z-index: 0;
}

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  padding: 20px;
}

.login-card {
  padding: 48px 40px;
  animation: fadeInUp 0.6s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  width: 64px;
  height: 64px;
  background: var(--accent-gradient);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px var(--accent-glow);
  animation: float 3s ease-in-out infinite;
}
.logo-icon svg { width: 32px; height: 32px; color: white; }
.logo-icon.small { width: 40px; height: 40px; border-radius: 10px; }
.logo-icon.small svg { width: 20px; height: 20px; }

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, #f1f5f9, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ═══ Form Inputs ═══ */
.form-group {
  margin-bottom: 20px;
  flex: 1;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.form-group label small {
  font-weight: 400;
  color: var(--text-muted);
}

.input-wrapper {
  position: relative;
}
.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color 0.3s;
}

input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: var(--transition);
  outline: none;
}

.input-wrapper input {
  padding-left: 44px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input:focus ~ .input-icon,
input:focus + .input-icon { color: var(--accent-primary); }

input::placeholder, textarea::placeholder { color: var(--text-muted); }

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: 16px;
}

/* ═══ Buttons ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.1);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}
.btn-outline:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}
.btn-sm svg { width: 14px; height: 14px; }

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.btn-icon svg { width: 16px; height: 16px; }

.btn-login {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  margin-top: 4px;
  position: relative;
}

.btn-login.loading .btn-text { visibility: hidden; }
.btn-login.loading .btn-loader { display: block; }

.btn-loader {
  display: none;
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.error-message {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* ═══════════════════════
   DASHBOARD LAYOUT
   ═══════════════════════ */
#dashboard-page {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 10% 10%, rgba(99,102,241,0.06) 0%, transparent 40%),
    radial-gradient(ellipse at 90% 90%, rgba(139,92,246,0.04) 0%, transparent 40%),
    var(--bg-primary);
}

/* ═══ Sidebar ═══ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--glass-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
}

.logout-btn:hover {
  background: rgba(239,68,68,0.1) !important;
  color: var(--danger) !important;
}

/* ═══ Main Content ═══ */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(10, 14, 26, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 50;
}

.topbar h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
  margin-right: 12px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: var(--transition);
}

.admin-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.admin-badge svg { width: 16px; height: 16px; }

.content-section {
  display: none;
  padding: 28px 32px;
  animation: fadeIn 0.3s ease;
}
.content-section.active { display: block; }

/* ═══ Stats Grid ═══ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}
.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; color: white; }

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ═══ Action Bar ═══ */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.action-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.action-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  width: 280px;
}
.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}
.search-box input {
  padding-left: 38px;
  background: rgba(255,255,255,0.04);
}

.select-filter {
  min-width: 140px;
}

/* ═══ Table ═══ */
.table-container {
  padding: 0;
  overflow: hidden;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 14px 16px;
  text-align: left;
  white-space: nowrap;
  font-size: 0.875rem;
}

th {
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
}

.th-check { width: 40px; }
.th-check input { cursor: pointer; }

tr {
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.2s;
}
tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody tr:last-child { border-bottom: none; }

.key-cell {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  color: var(--accent-primary-hover);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.key-cell:hover { color: white; }
.key-cell .copy-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
}
.key-cell:hover .copy-hint { opacity: 1; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.status-active {
  background: rgba(34,197,94,0.1);
  color: var(--success);
}
.status-active::before { background: var(--success); }

.status-inactive {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
}
.status-inactive::before { background: var(--danger); }

.status-expired {
  background: rgba(245,158,11,0.1);
  color: var(--warning);
}
.status-expired::before { background: var(--warning); }

.action-btns {
  display: flex;
  gap: 4px;
}

/* ═══ Empty State ═══ */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 8px; }

/* ═══ Pagination ═══ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px;
  border-top: 1px solid var(--glass-border);
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}
.page-btn:hover { background: rgba(255,255,255,0.05); }
.page-btn.active {
  background: var(--accent-gradient);
  color: white;
  border-color: transparent;
}
.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ═══ Modal ═══ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
  width: 100%;
  max-width: 520px;
  padding: 32px;
  animation: modalIn 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ═══ Docs ═══ */
.docs-container {
  padding: 32px;
  max-width: 800px;
}
.docs-container h3 { margin-bottom: 12px; font-size: 1.2rem; }
.docs-container h4 { margin-top: 24px; margin-bottom: 8px; color: var(--text-secondary); }
.docs-container p { color: var(--text-secondary); margin-bottom: 16px; }

.code-block {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.code-block pre {
  padding: 16px;
  overflow-x: auto;
  margin: 0;
}
.code-block code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.8;
}

.method-badge {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.method-badge.get { background: rgba(34,197,94,0.15); color: var(--success); }
.method-badge.post { background: rgba(59,130,246,0.15); color: var(--info); }

.btn-copy {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.btn-copy:hover { color: white; background: rgba(255,255,255,0.06); }

.docs-table {
  width: 100%;
  margin-bottom: 16px;
}
.docs-table th { font-size: 0.8rem; }
.docs-table code {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(99,102,241,0.1);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent-primary-hover);
}

/* ═══ Settings ═══ */
.settings-container {
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-card {
  padding: 28px;
}
.settings-card h3 { margin-bottom: 20px; }

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.9rem;
}
.info-row:last-child { border-bottom: none; }
.info-row span:first-child { color: var(--text-muted); }

/* ═══ Generated Keys Result ═══ */
.gen-keys-list {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  line-height: 2;
  color: var(--accent-primary-hover);
}

/* ═══ Toast ═══ */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
}
.toast.success { background: rgba(34,197,94,0.9); }
.toast.error { background: rgba(239,68,68,0.9); }
.toast.info { background: rgba(59,130,246,0.9); }
.toast.removing { animation: toastOut 0.3s ease forwards; }

/* ═══ Animations ═══ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(100px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ═══ Responsive ═══ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .main-content {
    margin-left: 0;
  }
  .hamburger {
    display: flex;
  }
  .content-section {
    padding: 16px;
  }
  .topbar {
    padding: 0 16px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-box {
    width: 100%;
  }
  .action-right {
    justify-content: flex-end;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .login-card {
    padding: 32px 24px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  display: none;
}
.sidebar-overlay.active {
  display: block;
}

/* Row-selected highlight */
tbody tr.selected {
  background: rgba(99,102,241,0.08);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

/* HWID cell truncation */
.hwid-cell {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.8rem;
  color: var(--text-muted);
}
