/* ═══════════════════════════════════════
   VESPER — Design System
   Dual theme, 12-col grid, transitions
   ═══════════════════════════════════════ */

:root {
  /* Dark theme (default) */
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-card: #18181b;
  --bg-input: #1e1e22;
  --bg-hover: #27272a;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #27272a;
  --border-hover: #3f3f46;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-muted: rgba(59, 130, 246, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-muted: rgba(245, 158, 11, 0.15);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.5);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f4f4f5;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f0f2;
  --bg-hover: #e4e4e7;
  --text-primary: #0a0a0b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --border: #d4d4d8;
  --border-hover: #a1a1aa;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-muted: rgba(59, 130, 246, 0.1);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-muted: rgba(245, 158, 11, 0.1);
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

/* ── 12-Column Grid ── */
.grid {
  display: grid;
  gap: 1rem;
}
.grid-1  { grid-template-columns: repeat(1, 1fr); }
.grid-2  { grid-template-columns: repeat(2, 1fr); }
.grid-3  { grid-template-columns: repeat(3, 1fr); }
.grid-4  { grid-template-columns: repeat(4, 1fr); }
.grid-6  { grid-template-columns: repeat(6, 1fr); }
.grid-12 { grid-template-columns: repeat(12, 1fr); }

.col-span-1  { grid-column: span 1; }
.col-span-2  { grid-column: span 2; }
.col-span-3  { grid-column: span 3; }
.col-span-4  { grid-column: span 4; }
.col-span-6  { grid-column: span 6; }
.col-span-8  { grid-column: span 8; }
.col-span-12 { grid-column: span 12; }

@media (max-width: 1024px) {
  .grid-4, .grid-6, .grid-12 { grid-template-columns: repeat(2, 1fr); }
  .col-span-3, .col-span-4, .col-span-6, .col-span-8 { grid-column: span 1; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4, .grid-6, .grid-12 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3, .col-span-4, .col-span-6, .col-span-8, .col-span-12 { grid-column: span 1; }
}

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

.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  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), background var(--transition);
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand svg {
  width: 28px;
  height: 28px;
  fill: var(--accent);
}

.sidebar-brand span {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

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

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
}

.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.sidebar-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

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

.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-content {
  padding: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── Stat Cards ── */
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-icon.blue { background: var(--accent-muted); color: var(--accent); }
.stat-icon.blue svg { fill: var(--accent); }
.stat-icon.green { background: var(--success-muted); color: var(--success); }
.stat-icon.green svg { fill: var(--success); }
.stat-icon.yellow { background: var(--warning-muted); color: var(--warning); }
.stat-icon.yellow svg { fill: var(--warning); }
.stat-icon.red { background: rgba(239,68,68,0.15); color: var(--danger); }
.stat-icon.red svg { fill: var(--danger); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  line-height: 1.4;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
  transform: translateY(-1px);
}

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

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-icon svg { width: 18px; height: 18px; }

/* ── Forms ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 0.4rem;
  text-decoration: none;
  background: none;
  -webkit-text-decoration: none;
}

.form-input,
.form-select,
.form-textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: all var(--transition);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ── Tables ── */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

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

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

td {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr:last-child td { border-bottom: none; }

tr:hover td {
  background: var(--bg-hover);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-online {
  background: var(--success-muted);
  color: var(--success);
}

.badge-offline {
  background: rgba(113,113,122,0.15);
  color: var(--text-muted);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.badge-online .badge-dot { background: var(--success); }
.badge-offline .badge-dot { background: var(--text-muted); }

/* ── Search ── */
.search-box {
  position: relative;
  max-width: 320px;
}

.search-box svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.tab {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 520px;
  transform: scale(0.95);
  transition: transform var(--transition);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body { margin-bottom: 1.25rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ── Progress Bar ── */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-hover);
  border-radius: 100px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 300ms ease;
  width: 0%;
}

/* ── Skeleton Loaders ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-card) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

.skeleton-text {
  height: 14px;
  margin-bottom: 0.5rem;
}

.skeleton-text:last-child { width: 60%; }

.skeleton-card {
  height: 120px;
}

.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Toggle Switch ── */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border-radius: 100px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  top: 3px;
  left: 3px;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ── Log / Terminal ── */
.log-container {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  color: #22c55e;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.8;
}

.log-entry { white-space: pre-wrap; }
.log-time { color: #71717a; margin-right: 0.5rem; }
.log-info { color: #3b82f6; }
.log-warn { color: #f59e0b; }
.log-error { color: #ef4444; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Code Editor ── */
.code-editor {
  width: 100%;
  min-height: 300px;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  tab-size: 2;
}

.code-editor:focus {
  border-color: var(--accent);
}

/* ── Preview Frame ── */
.preview-frame {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 400px;
  overflow: hidden;
}

.preview-frame iframe {
  width: 100%;
  height: 400px;
  border: none;
}

/* ── Misc ── */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: 0.8rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ── Responsive sidebar ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

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

@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

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

.page-content { animation: fadeIn 400ms ease; }

.card { animation: slideUp 400ms ease backwards; }
.grid > .card:nth-child(1) { animation-delay: 0ms; }
.grid > .card:nth-child(2) { animation-delay: 60ms; }
.grid > .card:nth-child(3) { animation-delay: 120ms; }
.grid > .card:nth-child(4) { animation-delay: 180ms; }
.grid > .card:nth-child(5) { animation-delay: 240ms; }
.grid > .card:nth-child(6) { animation-delay: 300ms; }

.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.card-value { animation: countUp 500ms ease backwards; animation-delay: 200ms; }

tbody tr { animation: fadeIn 300ms ease backwards; }
tbody tr:nth-child(1) { animation-delay: 50ms; }
tbody tr:nth-child(2) { animation-delay: 100ms; }
tbody tr:nth-child(3) { animation-delay: 150ms; }
tbody tr:nth-child(4) { animation-delay: 200ms; }
tbody tr:nth-child(5) { animation-delay: 250ms; }
tbody tr:nth-child(6) { animation-delay: 300ms; }
tbody tr:nth-child(7) { animation-delay: 350ms; }
tbody tr:nth-child(8) { animation-delay: 400ms; }
tbody tr:nth-child(n+9) { animation-delay: 450ms; }

.badge-online .badge-dot { animation: livePulse 2s ease-in-out infinite; }

.btn:active { transform: scale(0.96); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }

.sidebar-link:hover { transform: translateX(4px); }
.sidebar-link.active { animation: slideInLeft 300ms ease; }

.modal-overlay.active .modal { animation: scaleIn 250ms cubic-bezier(0.4, 0, 0.2, 1); }

.progress-bar-fill {
  background: linear-gradient(90deg, var(--accent) 0%, #60a5fa 50%, var(--accent) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.search-box input:focus { transform: scaleX(1.02); }
.tab:hover { transform: translateY(-1px); }
.btn-icon:hover { transform: rotate(15deg) scale(1.1); }
.btn-icon:active { transform: rotate(0deg) scale(0.95); }

.form-input:focus, .form-select:focus, .form-textarea:focus { transform: translateY(-1px); }
.topbar { animation: slideDown 300ms ease; }
.sidebar { animation: slideInLeft 300ms ease; }

.log-entry { animation: fadeIn 200ms ease; }

.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-muted); animation: fadeIn 500ms ease;
}
.empty-state svg {
  width: 48px; height: 48px; margin-bottom: 1rem;
  opacity: 0.3; animation: pulse 3s ease-in-out infinite;
}
.empty-state p { font-size: 0.9rem; margin-top: 0.5rem; }

.download-link { animation: slideUp 400ms ease; }
.download-link:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2); }

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 100px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
