/* Copyright 2024-2026 course-assistant contributors. SPDX-License-Identifier: MIT */

/* Unified design tokens for the course-assistant UI.
 * Replaces the per-page :root blocks that previously drifted.
 */
:root {
  /* Canonical tokens — these are the source of truth. Legacy alias names
   * below keep older page stylesheets working without per-page overrides. */
  --bg: #f8fafc;
  --bg-grad: linear-gradient(160deg, #eef2ff 0%, #f5f3ff 50%, #fff7ed 100%);
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(255, 255, 255, 0.55);
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-dim: #6366f1;
  --primary-hover: #4338ca;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --border: #e5e7eb;
  --shadow: 0 10px 30px rgba(79, 70, 229, 0.08);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  /* Soft tinted backgrounds used by legacy badges/messages. */
  --success-bg: rgba(236, 253, 245, 0.8);
  --danger-bg:  rgba(254, 242, 242, 0.8);
  --warning-bg: rgba(255, 251, 235, 0.8);

  /* Legacy alias used by teacher.html / student.html before consolidation. */
  --text-secondary: var(--text-muted);

  --sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --max-width: 860px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px 96px;
}

/* ── Card ─────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 20px; }
.card h3 { margin-top: 0; font-size: 16px; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn,
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 16px rgba(79, 70, 229, 0.2); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: #e2e8f0;
  color: #1e293b;
}
.btn-secondary:hover { background: #cbd5e1; box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(79,70,229,0.08); }

.btn-danger {
  background: linear-gradient(135deg, #f87171 0%, var(--danger) 100%);
}

/* ── Form controls ─────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* ── Tables ────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: rgba(79, 70, 229, 0.06);
  font-weight: 600;
  color: var(--text-muted);
}
.table tbody tr:hover { background: rgba(79, 70, 229, 0.04); }

/* ── Tab bar ───────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  flex: 1;
  padding: 10px 18px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  text-align: center;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

/* ── Toast ─────────────────────────────────────────────────────── */
#toast-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0,0,0,0.16);
  font-size: 14px;
  animation: toastin 0.18s ease-out;
  max-width: 90vw;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-warn    { background: var(--warning); color: #1e293b; }
@keyframes toastin {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  animation: fadein 0.15s ease-out;
}
.modal-backdrop > .modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
  max-width: 420px;
  width: calc(100vw - 32px);
  padding: 24px;
  animation: popin 0.18s ease-out;
}
.modal-backdrop > .modal h3 { margin-top: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes popin { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── Empty / message ───────────────────────────────────────────── */
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.message {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
}
.message.info  { background: rgba(79, 70, 229, 0.08); color: var(--primary); }
.message.error { background: rgba(239, 68, 68, 0.08); color: var(--danger); }
.message.warn  { background: rgba(245, 158, 11, 0.1); color: #b45309; }

/* ── Spinner ───────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ───────────────────────────────────────────────────── */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-right { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.grow  { flex: 1; }
.hidden { display: none !important; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ── Login / logout layout helpers ─────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.logout-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .app-shell { padding: 16px 12px 96px; }
  .card { padding: 16px; border-radius: 12px; }
}
