/* ===== CUBOPAG — DESIGN SYSTEM ===== */
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --purple-deep:   #1E1B4B;
  --purple-mid:    #312E81;
  --purple-brand:  #4F46E5;
  --purple-light:  #6D64F7;
  --teal:          #2DD4BF;
  --teal-light:    #5EEAD4;
  --bg-dark:       #0D0B1E;
  --bg-card:       #13112A;
  --bg-card2:      #1A1740;
  --border:        rgba(111,99,247,.18);
  --text-primary:  #F0EEFF;
  --text-secondary:#A8A4CC;
  --text-muted:    #6B67A8;
  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;
  --info:          #3B82F6;
  --font-head:     'Syne', sans-serif;
  --font-body:     'DM Sans', sans-serif;
  --radius:        14px;
  --radius-sm:     8px;
  --shadow:        0 4px 32px rgba(0,0,0,.45);
  --shadow-glow:   0 0 32px rgba(79,70,229,.22);
  --transition:    .22s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--purple-mid); border-radius: 99px; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo img { height: 36px; width: auto; }

.sidebar-nav { flex: 1; padding: 16px 0; overflow-y: auto; }

.nav-group { margin-bottom: 8px; }
.nav-group-label {
  font-family: var(--font-head);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 20px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: all var(--transition);
  cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  position: relative;
}
.nav-item:hover { color: var(--text-primary); background: rgba(79,70,229,.1); }
.nav-item.active {
  color: var(--teal);
  background: rgba(45,212,191,.07);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--teal), var(--purple-brand));
  border-radius: 0 3px 3px 0;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-size: .65rem;
  font-weight: 700;
  background: var(--teal);
  color: var(--bg-dark);
  border-radius: 99px;
  padding: 2px 7px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .env-selector {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--text-secondary);
}
.env-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); flex-shrink: 0; }
.env-dot.prod { background: var(--success); }

/* ===== MAIN CONTENT ===== */
.main {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== TOPBAR ===== */
.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-body);
  font-size: .85rem; font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  cursor: pointer; border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--purple-brand), var(--purple-light));
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,70,229,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(79,70,229,.5); }
.btn-teal {
  background: linear-gradient(135deg, var(--teal), var(--teal-light));
  color: var(--bg-dark);
  font-weight: 700;
}
.btn-teal:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(45,212,191,.35); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--purple-brand); background: rgba(79,70,229,.08); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger-ghost:hover { background: rgba(239,68,68,.1); }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-icon { padding: 9px; border-radius: var(--radius-sm); }

/* ===== PAGE CONTENT ===== */
.page { display: none; flex: 1; flex-direction: column; }
.page.active { display: flex; }
.page-body { padding: 32px; flex: 1; max-width: 1400px; width: 100%; }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}
.stat-card:hover { border-color: rgba(79,70,229,.4); transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.stat-card::before {
  content: '';
  position: absolute; top: 0; right: 0;
  width: 80px; height: 80px;
  background: radial-gradient(circle, rgba(79,70,229,.2), transparent 70%);
  border-radius: 50%;
}
.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; margin-bottom: 8px; }
.stat-value { font-family: var(--font-head); font-size: 1.8rem; font-weight: 800; color: var(--text-primary); margin-bottom: 6px; }
.stat-value.teal { color: var(--teal); }
.stat-value.purple { color: var(--purple-light); }
.stat-delta { font-size: .78rem; color: var(--success); display: flex; align-items: center; gap: 4px; }
.stat-delta.neg { color: var(--danger); }
.stat-icon { position: absolute; top: 20px; right: 20px; width: 40px; height: 40px; background: rgba(79,70,229,.15); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.stat-icon svg { width: 20px; height: 20px; color: var(--purple-light); }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}
.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-title { font-family: var(--font-head); font-size: 1rem; font-weight: 700; flex: 1; }
.card-body { padding: 24px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 14px 16px; border-bottom: 1px solid rgba(111,99,247,.07); vertical-align: middle; }
tbody tr:hover { background: rgba(79,70,229,.04); }
tbody tr:last-child td { border-bottom: none; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .72rem; font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
}
.badge-success { background: rgba(16,185,129,.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-info    { background: rgba(59,130,246,.15); color: var(--info); }
.badge-purple  { background: rgba(79,70,229,.2); color: var(--purple-light); }
.badge-teal    { background: rgba(45,212,191,.15); color: var(--teal); }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1/-1; }
label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); }
input, select, textarea {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: .875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple-brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select option { background: var(--bg-card2); }
textarea { resize: vertical; min-height: 90px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn .25s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 32px 80px rgba(0,0,0,.6), var(--shadow-glow);
}
.modal.modal-lg { max-width: 760px; }
@keyframes modalIn { from { opacity:0; transform:scale(.93) translateY(16px); } }
.modal-header {
  padding: 24px 24px 0;
  display: flex; align-items: center; gap: 12px;
}
.modal-header h2 { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; flex:1; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 0 24px 24px;
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== ALERTS ===== */
.alert {
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: .875rem;
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.25); color: #6ee7b7; }
.alert-danger   { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.25); color: #fca5a5; }
.alert-info     { background: rgba(59,130,246,.1); border: 1px solid rgba(59,130,246,.25); color: #93c5fd; }
.alert-warning  { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.25); color: #fde68a; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed; bottom: 28px; right: 28px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: .85rem;
  display: flex; align-items: center; gap: 10px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: toastIn .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes toastIn { from { opacity:0; transform:translateX(40px); } }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--purple-brand); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 32px;
  color: var(--text-muted);
}
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 16px; opacity: .4; }
.empty-state h3 { font-family: var(--font-head); font-size: 1rem; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: .85rem; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 10px 20px;
  font-size: .85rem; font-weight: 600;
  color: var(--text-muted);
  background: none; border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--teal); border-bottom-color: var(--teal); }
.tab-btn:hover { color: var(--text-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== API KEY DISPLAY ===== */
.api-key-box {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: monospace;
  font-size: .85rem;
  color: var(--teal);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  word-break: break-all;
}

/* ===== LOADER ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.1);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== HAMBURGER (mobile) ===== */
.hamburger {
  display: none;
  background: none; border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
}

/* ===== GLOW DECORATIONS ===== */
.glow-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  opacity: .12;
  z-index: 0;
}
.glow-blob-1 { width: 500px; height: 500px; background: var(--purple-brand); top: -120px; left: 80px; }
.glow-blob-2 { width: 400px; height: 400px; background: var(--teal); bottom: -100px; right: 0; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,.5); }
  .main { margin-left: 0; }
  .hamburger { display: flex; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-body { padding: 20px; }
  .topbar { padding: 0 20px; }
}
@media (max-width: 500px) {
  .stats-grid { grid-template-columns: 1fr; }
}
