/*
 * Global CSS Stylesheet — Professional Indigo & Slate Design System
 * Unified color palette, consistent typography, and premium layout
 */

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

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --accent: #4f46e5;
  --accent-light: rgba(79, 70, 229, 0.08);
  --accent-hover: #4338ca;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --sidebar-w: 240px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.04);
  --radius: 10px;
  --radius-sm: 6px;
}

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

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

/* ─── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.3rem; }
h5 { font-size: 1rem; }
.text-muted { color: var(--text-muted) !important; }
.text-subtle { color: var(--text-subtle) !important; }

/* ─── Card Component ─────────────────────────────────────────────────────── */
.card-glass {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}
.card-glass:hover {
  box-shadow: var(--shadow-md);
}
/* Remove the over-aggressive bottom border on card headings */
.card-glass h4, .card-glass h5 {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

/* ─── Accent Utilities ───────────────────────────────────────────────────── */
.text-accent { color: var(--accent) !important; }
.bg-accent-soft { background: var(--accent-light) !important; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn-accent {
  background-color: var(--accent);
  color: #fff !important;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1.1rem;
  transition: all 0.18s ease;
  letter-spacing: 0.01em;
}
.btn-accent:hover {
  background-color: var(--accent-hover);
  color: #fff !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

/* Override Bootstrap btn-primary to use our accent */
.btn-primary {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
}
.btn-primary:hover {
  background-color: var(--accent-hover) !important;
  border-color: var(--accent-hover) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

/* Outline buttons — uniform, no wild colors */
.btn-outline-secondary {
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
}
.btn-outline-secondary:hover {
  background-color: #f1f5f9 !important;
  color: var(--text) !important;
  border-color: var(--border-hover) !important;
}

/* sm buttons in tables */
.btn-sm {
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  border-radius: 5px;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text);
  background-color: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  outline: none;
}
.form-control::placeholder { color: var(--text-subtle); }
.form-label {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.form-control-glass {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
}
.form-control-glass:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-control-glass::placeholder { color: var(--text-subtle); }
.form-control-glass option { background-color: #fff; color: var(--text); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  border-radius: 4px;
  padding: 0.28em 0.6em;
}
/* Override bright-green "Published" badge to a professional style */
.badge.bg-success {
  background-color: #dcfce7 !important;
  color: #166534 !important;
}
.badge.bg-secondary {
  background-color: #f1f5f9 !important;
  color: #475569 !important;
}
.badge.bg-danger {
  background-color: #fee2e2 !important;
  color: #991b1b !important;
}
.badge.bg-warning {
  background-color: #fef9c3 !important;
  color: #854d0e !important;
}
.badge.bg-primary {
  background-color: var(--accent-light) !important;
  color: var(--accent) !important;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table {
  font-size: 0.875rem;
  color: var(--text);
}
.table thead th {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background-color: #f8fafc;
  padding: 0.75rem 1rem;
  white-space: nowrap;
}
.table tbody td {
  padding: 0.75rem 1rem;
  color: var(--text);
  border-color: #f1f5f9;
  vertical-align: middle;
}
.table-hover tbody tr:hover {
  background-color: #f8fafc;
}
/* Kill the random colored hyperlinks in student name cells */
.table td a, .table td { color: var(--text) !important; text-decoration: none; }
.table-active, .table-active > td { background-color: #f8fafc !important; color: var(--text) !important; }
.table-light { background-color: #f8fafc !important; }
.table-dark {
  --bs-table-bg: #fff;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
}

/* Scrollable table container */
.scrollable-table-container {
  max-height: 550px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.scrollable-table-container::-webkit-scrollbar { width: 5px; height: 5px; }
.scrollable-table-container::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 10px;
}
.scrollable-table-container th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #f8fafc;
}
.table-responsive { border: none !important; }

/* ─── Sidebar & Layout ───────────────────────────────────────────────────── */
.app-sidebar-layout {
  display: flex;
  min-height: 100vh;
}
.app-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
/* Sidebar header brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.sidebar-brand-icon {
  width: 34px;
  height: 34px;
  background: var(--accent-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-brand-text {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-brand-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}
/* Sidebar nav sections */
.sidebar-nav { flex: 1; padding: 0 12px; }
.sidebar-section-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  font-weight: 700;
  padding: 16px 8px 6px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: var(--text-muted);
  border-radius: 7px;
  margin-bottom: 2px;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.15s ease;
}
.sidebar-link i {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-link:hover {
  background: #f8fafc;
  color: var(--text);
}
.sidebar-link.sidebar-active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}
.sidebar-link.sidebar-active i { color: var(--accent); }
/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}
.sidebar-logout-btn:hover {
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
}

/* Main content area */
.app-content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
  background: var(--bg);
  overflow-y: auto;
}

/* ─── Stat Cards (Uniform) ───────────────────────────────────────────────── */
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.1rem;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}

/* ─── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.page-header h2, .page-header h3 {
  margin: 0 0 4px;
}
.page-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.alert-warning {
  background-color: #fffbeb;
  border-color: #fde68a;
  color: #78350f;
}
.alert-danger {
  background-color: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}
.alert-info {
  background-color: #f0f9ff;
  border-color: #bae6fd;
  color: #0c4a6e;
}
.alert-success {
  background-color: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

/* ─── Global visibility overrides ──────────────────────────────────────── */
/* Prevent Bootstrap's dark overrides in card text from breaking layout */
.card h1, .card h2, .card h3, .card h4, .card h5, .card h6 { color: var(--text); }
.card p, .card small { color: var(--text-muted); }
.card span { color: inherit; }
.bg-dark { background-color: #f1f5f9 !important; border: 1px solid var(--border) !important; }
.text-white, .text-light { color: var(--text) !important; }

/* Navbar (legacy pages) */
.navbar-light .navbar-nav .nav-link { color: var(--text) !important; font-weight: 500; }
.navbar-light .navbar-nav .nav-link:hover { color: var(--accent) !important; }

/* ─── Code Blocks (Prism.js) ─────────────────────────────────────────────── */
pre[class*="language-"],
code[class*="language-"] {
  color: #1e293b !important;
  background: #f1f5f9 !important;
  font-family: 'Consolas', 'Courier New', monospace !important;
  font-size: 0.875rem !important;
  line-height: 1.6 !important;
}
pre[class*="language-"] {
  padding: 1rem 1.25rem !important;
  border-radius: 8px !important;
  border: 1px solid #e2e8f0 !important;
  overflow-x: auto !important;
  white-space: pre !important;
  margin-top: 0.5rem !important;
  margin-bottom: 0.5rem !important;
}
:not(pre) > code {
  background: #f1f5f9 !important;
  color: #7c3aed !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
  font-size: 0.85em !important;
  font-family: 'Consolas', 'Courier New', monospace !important;
}

/* ─── Exam Builder Workspace ──────────────────────────────────────────────── */
.sticky-preview-container {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 8px;
}
.sticky-preview-container::-webkit-scrollbar { width: 5px; }
.sticky-preview-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
.mcq-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  background: #f8fafc;
  transition: all 0.2s ease;
  cursor: pointer;
}
.upload-dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.segmented-control {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.segmented-control-item { flex: 1; text-align: center; }
.segmented-control-input { display: none; }
.segmented-control-label {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}
.segmented-control-input:checked + .segmented-control-label {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
/* Question preview cards */
.preview-q-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  transition: all 0.2s ease;
}
.preview-q-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
.preview-q-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.preview-q-body { font-size: 0.9rem; line-height: 1.6; }
.preview-q-option {
  display: flex;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 7px;
  margin-top: 8px;
  font-size: 0.875rem;
  font-weight: 500;
}
.preview-q-option-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}
.preview-q-option.correct-option {
  border-color: #a7f3d0;
  background: #f0fdf4;
}
.preview-q-option.correct-option .preview-q-option-marker {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}
.preview-text-answer {
  background: #f0fdf4;
  border-left: 3px solid #10b981;
  padding: 12px 16px;
  border-radius: 0 7px 7px 0;
  font-size: 0.875rem;
  margin-top: 12px;
}
.preview-q-actions { display: flex; gap: 6px; }
.preview-q-action-btn {
  background: #f1f5f9;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s ease;
}
.preview-q-action-btn:hover { background: var(--border); color: var(--text); }
.preview-q-action-btn.delete-btn:hover { background: #fee2e2; color: #dc2626; }

/* Card glow variants */
.ai-glow-card {
  border: 1px solid rgba(79, 70, 229, 0.2);
  box-shadow: 0 0 15px rgba(79, 70, 229, 0.04);
}
.ai-glow-card:hover {
  border-color: rgba(79, 70, 229, 0.4);
  box-shadow: 0 0 20px rgba(79, 70, 229, 0.08);
}
.csv-glow-card {
  border: 1px solid rgba(79, 70, 229, 0.15);
}
.csv-glow-card:hover {
  border-color: rgba(79, 70, 229, 0.3);
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.transition-all { transition: all 0.2s ease; }

/* Ensure images don't overflow */
img { max-width: 100%; height: auto; }
pre { max-width: 100%; }

/* ─── Global Loading Overlay ─────────────────────────────────────────────── */
.global-loader-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(248, 250, 252, 0.75);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loader-content {
  background: #fff;
  padding: 36px 44px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  border: 1px solid var(--border);
  animation: fadeInScale 0.25s ease;
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ─── Mobile Responsiveness ──────────────────────────────────────────────── */
@media (max-width: 992px) {
  .app-sidebar-layout { flex-direction: column; }
  .app-sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: visible;
  }
  .sidebar-brand { padding: 8px 12px 8px 4px; border-bottom: none; margin-bottom: 0; flex-shrink: 0; }
  .sidebar-brand-sub { display: none; }
  .sidebar-nav { display: flex; flex-direction: row; padding: 0 8px; flex: 1; overflow-x: auto; }
  .sidebar-section-title { display: none; }
  .sidebar-link { margin-bottom: 0; margin-right: 4px; white-space: nowrap; }
  .sidebar-footer {
    padding: 0 0 0 8px;
    border-top: none;
    margin-top: 0;
    border-left: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }
  .sidebar-logout-btn { width: auto; }
  .app-content { padding: 16px; }
  .mcq-options-grid { grid-template-columns: 1fr; }
  .sticky-preview-container { position: static; max-height: none; overflow-y: visible; padding-right: 0; }
}

@media (max-width: 768px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.15rem; }
  .container { padding-left: 12px !important; padding-right: 12px !important; }
  .card-glass { margin-bottom: 1rem; }
  /* Exam attempt fixed header/footer */
  .position-fixed.top-0 { padding: 0.75rem !important; }
  #examTitleHeader {
    font-size: 0.9rem !important;
    max-width: 55%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #timerBadge { font-size: 0.9rem !important; padding: 5px 10px !important; }
  .position-fixed.bottom-0 { padding: 0.5rem !important; }
  #tabWarningBanner { font-size: 0.75rem !important; }
  .row[style*="margin-top: 100px"] {
    margin-top: 70px !important;
    margin-bottom: 60px !important;
  }
}
