/* ============================================================
   style.css — CAPE Admin UI
   Dark mode, premium feel, glassmorphism accents
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design tokens ────────────────────────────────────────── */
:root {
  --bg:           #0d0f14;
  --bg-card:      rgba(255,255,255,0.04);
  --bg-card-hov:  rgba(255,255,255,0.07);
  --border:       rgba(255,255,255,0.08);
  --border-hov:   rgba(255,255,255,0.16);
  --text:         #e8eaf0;
  --text-muted:   #8890a4;
  --text-dim:     #4a5168;
  --accent:       #6c6aff;
  --accent-hov:   #8583ff;
  --accent-dim:   rgba(108,106,255,0.15);
  --green:        #34d399;
  --green-dim:    rgba(52,211,153,0.15);
  --red:          #f87171;
  --red-dim:      rgba(248,113,113,0.15);
  --yellow:       #fbbf24;
  --yellow-dim:   rgba(251,191,36,0.15);
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 4px 32px rgba(0,0,0,0.5);
  --transition:   0.18s ease;
  --font:         'Inter', system-ui, sans-serif;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hov); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── Layout ───────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,15,20,0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.topbar-logo span { color: var(--accent); }
.topbar-spacer { flex: 1; }
.topbar-settings-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 0.82rem;
  transition: var(--transition);
}
.topbar-settings-btn:hover {
  border-color: var(--border-hov);
  color: var(--text);
}

.sidebar {
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 12px;
  margin: 16px 0 6px;
}
.sidebar-label:first-child { margin-top: 0; }
.nav-btn {
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 9px 12px;
  text-align: left;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
  width: 100%;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--accent-dim);
  color: var(--text);
}
.nav-btn.active { color: var(--accent); font-weight: 500; }
.nav-icon { width: 18px; text-align: center; font-size: 1rem; }

.main {
  padding: 32px;
  overflow-y: auto;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: var(--transition);
}
.card:hover { border-color: var(--border-hov); }

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.page-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.page-actions { margin-left: auto; display: flex; gap: 10px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hov); transform: translateY(-1px); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--border-hov); color: var(--text); }
.btn-danger {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-red    { background: var(--red-dim);    color: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-muted  { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead {
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-card-hov); }

/* ── Progress bar ─────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  border-radius: 100px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
  min-width: 80px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 100px;
  transition: width 0.4s ease;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
label { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); }
.input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.88rem;
  transition: var(--transition);
  width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input::placeholder { color: var(--text-dim); }

/* ── Drop zone ────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.dropzone-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.6; }
.dropzone-text { color: var(--text-muted); font-size: 0.92rem; }
.dropzone-text strong { color: var(--text); }
.dropzone-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 6px; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #161922;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}
.modal-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; }
.modal-body { color: var(--text-muted); font-size: 0.9rem; line-height: 1.7; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

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

/* ── Settings panel ───────────────────────────────────────── */
.settings-panel {
  position: fixed; top: 60px; right: 0; bottom: 0;
  width: 360px;
  background: #161922;
  border-left: 1px solid var(--border);
  padding: 28px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 150;
}
.settings-panel.open { transform: none; }
.settings-title { font-size: 1rem; font-weight: 600; margin-bottom: 24px; }

/* ── Notifications ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column-reverse; gap: 10px;
  z-index: 300;
}
.toast {
  background: #1e2230;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.875rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
  max-width: 340px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ── Validation row colours ───────────────────────────────── */
.row-error  td { background: var(--red-dim);    }
.row-warn   td { background: var(--yellow-dim); }

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex    { display: flex; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 12px; }
.mt-4    { margin-top: 16px; }
.mt-6    { margin-top: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.82rem; }
.mono       { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 0.82rem; }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state-text { font-size: 0.95rem; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 20px; }
}

/* ── KaTeX preview container ──────────────────────────────── */
.latex-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: rgba(0,0,0,0.2);
  min-height: 42px;
  font-size: 0.9rem;
  color: var(--text);
}
