/* ═══════════════════════════════════════════════════════════════
   AetherStore Key System — Design System
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─── */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #0f0f2a;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-hover: rgba(255, 255, 255, 0.15);

  --text-primary: #f1f1f9;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.35);

  --accent-1: #6366f1;
  --accent-2: #8b5cf6;
  --accent-3: #a78bfa;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);

  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.25);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.25);
  --yellow: #f59e0b;
  --yellow-glow: rgba(245, 158, 11, 0.25);
  --blue: #3b82f6;
  --blue-glow: rgba(59, 130, 246, 0.25);

  --font-primary: 'Outfit', 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

  --sidebar-width: 240px;
  --header-height: 64px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

/* ─── Glass Utility ─── */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}
.glass:hover {
  border-color: var(--border-glass-hover);
  box-shadow: var(--shadow-glow);
}

/* ─── Screens ─── */
.screen { display: none; }
.screen.active { display: flex; }

/* ═══════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════════════════════════ */

#login-screen {
  position: fixed; inset: 0;
  align-items: center; justify-content: center;
  background: var(--bg-primary);
  z-index: 100;
}

.login-container {
  position: relative;
  width: 100%; max-width: 420px;
  padding: 20px;
}

.login-bg {
  position: absolute; inset: -50%;
  background:
    radial-gradient(circle at 30% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(168, 85, 247, 0.05) 0%, transparent 50%);
  animation: bgPulse 8s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes bgPulse {
  0% { opacity: 0.5; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.1); }
}

.login-card {
  position: relative;
  padding: 40px 32px;
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon { margin-bottom: 16px; }

.login-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

.login-form { display: flex; flex-direction: column; gap: 20px; }

.input-group {
  position: relative;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-primary);
  transition: all var(--transition);
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

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

.input-icon {
  position: absolute;
  bottom: 13px; left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.login-error {
  color: var(--red);
  font-size: 0.85rem;
  text-align: center;
  min-height: 20px;
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD LAYOUT
   ═══════════════════════════════════════════════════════════════ */

#dashboard-screen {
  min-height: 100vh;
}

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: rgba(15, 15, 42, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  z-index: 50;
  animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-glass);
}

.logo-mini {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.nav-item::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--accent-gradient);
  opacity: 0;
  border-radius: var(--radius-md);
  transition: opacity var(--transition);
}

.nav-item:hover { color: var(--text-primary); background: rgba(255,255,255,0.03); }
.nav-item.active {
  color: white;
  background: var(--accent-gradient);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.nav-item svg { flex-shrink: 0; position: relative; z-index: 1; }
.nav-item span { position: relative; z-index: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-logout:hover { color: var(--red); background: rgba(239,68,68,0.1); }

/* ─── Main Content ─── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.header-left h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search-box {
  position: relative;
}

.search-box svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  padding: 8px 12px 8px 36px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-primary);
  width: 200px;
  outline: none;
  transition: all var(--transition);
}

.search-box input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
  width: 260px;
}

.connection-status {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(34, 197, 94, 0.1);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.2);
}
.connection-status.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.2);
}

/* ─── Tabs ─── */
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

/* ═══════════════════════════════════════════════════════════════
   STATS CARDS
   ═══════════════════════════════════════════════════════════════ */

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

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon.total { background: rgba(99, 102, 241, 0.15); color: var(--accent-1); }
.stat-icon.active { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.stat-icon.revoked { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.stat-icon.activations { background: rgba(245, 158, 11, 0.15); color: var(--yellow); }

.stat-info { display: flex; flex-direction: column; }
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.5px;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   CARDS & TABLES
   ═══════════════════════════════════════════════════════════════ */

.card {
  margin-bottom: 24px;
  overflow: hidden;
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 0; }

.select-filter {
  padding: 6px 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: var(--font-primary);
  outline: none;
  cursor: pointer;
}

.table-container {
  overflow-x: auto;
}

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

.table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-glass);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  vertical-align: middle;
}

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

.table .loading-cell {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

/* ─── Status Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.active {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.2);
}
.badge.revoked, .badge.banned {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.badge.expired {
  background: rgba(245, 158, 11, 0.12);
  color: var(--yellow);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.key-display {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-3);
  letter-spacing: 0.5px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary.danger { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 4px 15px rgba(239,68,68,0.3); }
.btn-primary.danger:hover { box-shadow: 0 6px 20px rgba(239,68,68,0.4); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
}
.btn-outline:hover {
  border-color: var(--accent-2);
  color: var(--accent-3);
  background: rgba(99, 102, 241, 0.05);
}

.btn-sm { padding: 4px 10px; font-size: 0.78rem; border-radius: var(--radius-sm); }

.btn-full { width: 100%; justify-content: center; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ─── Generate Form ─── */
.generate-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-primary);
  outline: none;
  transition: all var(--transition);
}

.form-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.generated-keys {
  padding: 0 20px 20px;
}
.generated-keys h4 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.keys-output {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.keys-output .placeholder { color: var(--text-muted); font-family: var(--font-primary); }
.keys-output .key-line {
  padding: 4px 0;
  color: var(--accent-3);
  animation: keyAppear 0.3s ease;
}

@keyframes keyAppear {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Pagination ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
}

.page-btn {
  padding: 4px 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--accent-1); color: var(--accent-3); }
.page-btn.active { background: var(--accent-gradient); color: white; border-color: transparent; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── Modal ─── */
.modal {
  position: fixed; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 90%; max-width: 440px;
  padding: 24px;
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 20px; line-height: 1.5; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Toast ─── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }

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

.toast-out {
  animation: toastOut 0.3s ease forwards;
}

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

/* ─── Settings ─── */
.settings-body { padding: 20px; }

.setting-group {
  margin-bottom: 24px;
}
.setting-group h4 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-glass);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.9rem;
  gap: 12px;
}

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

.setting-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-key-display, .endpoint {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-3);
  background: rgba(0,0,0,0.2);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

/* ─── Spinner ─── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.hidden { display: none !important; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .logo-text,
  .sidebar .nav-item span,
  .sidebar .user-details { display: none; }
  .sidebar .nav-item { justify-content: center; padding: 10px; }
  .sidebar .user-info { justify-content: center; }
  .sidebar .user-avatar { width: 28px; height: 28px; font-size: 0.7rem; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .header-right .search-box input { width: 140px; }
  .header-right .search-box input:focus { width: 180px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .header-left h2 { font-size: 1.2rem; }
  .content-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .header-right { width: 100%; justify-content: space-between; }
}
