/* ═══════════════════════════════════════════════════════════════
   RegionAI Admin Panel – Global Stylesheet
   Design System: Dark glassmorphism with purple/indigo accent
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  /* Colors */
  --c-bg:          #0a0b0f;
  --c-surface:     #111318;
  --c-surface-2:   #1a1d26;
  --c-border:      rgba(255,255,255,0.07);
  --c-border-2:    rgba(255,255,255,0.12);

  /* Accent */
  --c-accent:      #6366f1;
  --c-accent-h:    #818cf8;
  --c-accent-2:    #8b5cf6;
  --c-success:     #10b981;
  --c-warning:     #f59e0b;
  --c-danger:      #ef4444;
  --c-info:        #3b82f6;

  /* Text */
  --c-text:        #e2e8f0;
  --c-text-2:      #94a3b8;
  --c-text-3:      #64748b;

  /* Gradients */
  --g-accent:      linear-gradient(135deg, #6366f1, #8b5cf6);
  --g-surface:     linear-gradient(135deg, rgba(99,102,241,0.08), rgba(139,92,246,0.05));

  /* Glass */
  --glass-bg:      rgba(17, 19, 24, 0.8);
  --glass-blur:    20px;
  --glass-border:  rgba(255,255,255,0.08);

  /* Spacing */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;
  --sp-2xl: 48px;

  /* Radius */
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  24px;
  --r-full: 9999px;

  /* Shadow */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.5);
  --shadow-accent: 0 0 20px rgba(99,102,241,0.3);

  /* Sidebar */
  --sidebar-width: 260px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-med:  0.25s ease;
}

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth Page ──────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow: hidden; }

.auth-bg { position: fixed; inset: 0; z-index: 0; }
.auth-orbs { position: relative; width: 100%; height: 100%; }
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.15; animation: float 8s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: #6366f1; top: -100px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #8b5cf6; bottom: -100px; right: -100px; animation-delay: 3s; }
.orb-3 { width: 300px; height: 300px; background: #3b82f6; top: 50%; left: 50%; transform: translate(-50%,-50%); animation-delay: 6s; }

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-30px) scale(1.05); }
}

.auth-container { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: var(--sp-md); }

.auth-card {
  padding: var(--sp-2xl);
  border-radius: var(--r-xl);
  animation: slideUp 0.4s ease;
}

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

.auth-logo { display: flex; align-items: center; gap: var(--sp-md); margin-bottom: var(--sp-xl); }
.logo-icon svg { width: 48px; height: 48px; border-radius: var(--r-md); }
.logo-text h1 { font-size: 1.5rem; font-weight: 700; background: var(--g-accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-text p { font-size: 0.85rem; color: var(--c-text-2); }

.auth-footer { text-align: center; color: var(--c-text-3); font-size: 0.8rem; margin-top: var(--sp-xl); }

/* ── Glass Morphism ─────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
}

/* ── Forms ──────────────────────────────────────────────────────── */
.auth-form { display: flex; flex-direction: column; gap: var(--sp-md); }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--c-text-2); }

.input-wrapper {
  position: relative; display: flex; align-items: center;
}

.input-wrapper input {
  width: 100%; padding: 12px 14px 12px 42px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-md);
  color: var(--c-text);
  font-size: 0.9rem; font-family: inherit;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}

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

.input-icon {
  position: absolute; left: 12px;
  width: 18px; height: 18px;
  color: var(--c-text-3); pointer-events: none;
}

.toggle-password {
  position: absolute; right: 12px;
  background: none; border: none; cursor: pointer;
  color: var(--c-text-3); padding: 4px;
  display: flex; align-items: center;
}
.toggle-password:hover { color: var(--c-text); }
.toggle-password svg { width: 18px; height: 18px; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  background: var(--g-accent);
  color: white; font-weight: 600; font-size: 0.9rem;
  border: none; border-radius: var(--r-md); cursor: pointer;
  transition: opacity var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  box-shadow: var(--shadow-accent);
}

.btn-primary:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 0 30px rgba(99,102,241,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-full { width: 100%; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-md);
  color: var(--c-text); font-size: 0.85rem; font-weight: 500; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
  text-decoration: none;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }

.btn-danger {
  background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: #ef4444;
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-success {
  background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); color: #10b981;
}
.btn-success:hover { background: rgba(16,185,129,0.25); }

/* ── Error/Success Messages ─────────────────────────────────────── */
.error-message {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--r-md);
  color: #fca5a5;
  padding: 10px 14px;
  font-size: 0.85rem;
  animation: fadeIn var(--t-fast);
}

.success-message {
  background: rgba(16,185,129,0.12);
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: var(--r-md);
  color: #6ee7b7;
  padding: 10px 14px;
  font-size: 0.85rem;
}

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

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner { width: 18px; height: 18px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dashboard Layout ───────────────────────────────────────────── */
.app-layout {
  display: flex; min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; overflow-y: auto;
}

.sidebar-header {
  padding: var(--sp-lg);
  display: flex; align-items: center; gap: var(--sp-sm);
  border-bottom: 1px solid var(--c-border);
}

.sidebar-logo { width: 36px; height: 36px; }

.sidebar-brand {
  font-size: 1.1rem; font-weight: 700;
  background: var(--g-accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.sidebar-nav { flex: 1; padding: var(--sp-md) var(--sp-sm); display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  padding: var(--sp-sm) var(--sp-md);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--c-text-3);
  margin-top: var(--sp-md);
}

.nav-item {
  display: flex; align-items: center; gap: var(--sp-sm);
  padding: 10px var(--sp-md);
  border-radius: var(--r-md);
  color: var(--c-text-2); font-size: 0.875rem; font-weight: 500;
  text-decoration: none; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--c-text); }
.nav-item.active {
  background: rgba(99,102,241,0.15);
  color: var(--c-accent-h);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: var(--sp-md);
  border-top: 1px solid var(--c-border);
}

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

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-md) var(--sp-xl);
  background: rgba(10,11,15,0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--c-border);
}

.topbar-title { font-size: 1.1rem; font-weight: 600; }

.page-content { padding: var(--sp-xl); flex: 1; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-xl);
}

.card-sm { padding: var(--sp-lg); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-lg);
}

.card-title { font-size: 1rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: var(--c-text-2); margin-top: 2px; }

/* ── Stats Grid ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-md);
  margin-bottom: var(--sp-xl);
}

.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  display: flex; flex-direction: column; gap: var(--sp-sm);
  transition: border-color var(--t-fast);
}
.stat-card:hover { border-color: rgba(99,102,241,0.3); }

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
}

.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.indigo  { background: rgba(99,102,241,0.15);  color: #6366f1; }
.stat-icon.purple  { background: rgba(139,92,246,0.15);  color: #8b5cf6; }
.stat-icon.green   { background: rgba(16,185,129,0.15);  color: #10b981; }
.stat-icon.amber   { background: rgba(245,158,11,0.15);  color: #f59e0b; }

.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--c-text-2); }
.stat-change { font-size: 0.75rem; color: var(--c-success); }

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

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

thead th {
  padding: 10px var(--sp-md);
  text-align: left; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--c-text-3);
  border-bottom: 1px solid var(--c-border);
}

tbody tr {
  border-bottom: 1px solid var(--c-border);
  transition: background var(--t-fast);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.03); }

tbody td { padding: 12px var(--sp-md); font-size: 0.875rem; color: var(--c-text); }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 0.75rem; font-weight: 500;
}

.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }

.badge-active  { background: rgba(16,185,129,0.15); color: #10b981; }
.badge-active::before  { background: #10b981; }
.badge-inactive { background: rgba(100,116,139,0.15); color: #64748b; }
.badge-inactive::before { background: #64748b; }
.badge-error   { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge-error::before   { background: #ef4444; }
.badge-indexing { background: rgba(59,130,246,0.15); color: #3b82f6; animation: pulse 2s infinite; }
.badge-indexing::before { background: #3b82f6; }
.badge-pending  { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-pending::before  { background: #f59e0b; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-md);
  animation: fadeIn var(--t-fast);
}

.modal {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-xl);
  padding: var(--sp-xl);
  width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-xl); }
.modal-title { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: rgba(255,255,255,0.06); border: none; cursor: pointer;
  color: var(--c-text-2); display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: rgba(255,255,255,0.12); color: var(--c-text); }
.modal-close svg { width: 16px; height: 16px; }

.modal-footer { display: flex; gap: var(--sp-sm); justify-content: flex-end; margin-top: var(--sp-xl); }

/* ── Form Controls ───────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-md); }
.field-label { font-size: 0.8rem; font-weight: 500; color: var(--c-text-2); }

.field-input, .field-select, .field-textarea {
  width: 100%; padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-md);
  color: var(--c-text); font-size: 0.875rem; font-family: inherit;
  outline: none; transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

.field-select { appearance: none; cursor: pointer; }
.field-textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 0.75rem; color: var(--c-text-3); }

/* ── Toast Notifications ─────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: var(--sp-xl); right: var(--sp-xl);
  z-index: 9999; display: flex; flex-direction: column; gap: var(--sp-sm);
}

.toast {
  display: flex; align-items: center; gap: var(--sp-sm);
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--c-surface-2); border: 1px solid var(--c-border-2);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem; min-width: 280px;
  animation: slideInRight 0.3s ease;
}

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

.toast-success { border-color: rgba(16,185,129,0.4); color: #10b981; }
.toast-error   { border-color: rgba(239,68,68,0.4);  color: #ef4444; }
.toast-info    { border-color: rgba(99,102,241,0.4); color: var(--c-accent-h); }

/* ── Chat Test ───────────────────────────────────────────────────── */
.chat-test-window {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  height: 400px; overflow-y: auto;
  padding: var(--sp-md);
  display: flex; flex-direction: column; gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
}

.chat-bubble {
  max-width: 75%; padding: 10px 14px; border-radius: 14px;
  font-size: 0.875rem; line-height: 1.5;
}
.chat-bubble.user { align-self: flex-end; background: var(--g-accent); color: white; border-bottom-right-radius: 4px; }
.chat-bubble.assistant { align-self: flex-start; background: var(--c-surface-2); border: 1px solid var(--c-border); border-bottom-left-radius: 4px; }
.chat-bubble.typing { opacity: 0.7; }

.chat-input-row { display: flex; gap: var(--sp-sm); }
.chat-input { flex: 1; }

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

/* ── Utilities ───────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--sp-sm); }
.gap-md { gap: var(--sp-md); }
.text-2 { color: var(--c-text-2); }
.text-3 { color: var(--c-text-3); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.75rem; }
.font-600 { font-weight: 600; }
.w-full { width: 100%; }
.mb-md { margin-bottom: var(--sp-md); }
.mb-lg { margin-bottom: var(--sp-lg); }
.mt-md { margin-top: var(--sp-md); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-md); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-md); }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-content { padding: var(--sp-md); }
}
