:root {
  --bg: #0f1222;
  --bg-2: #161a30;
  --panel: #1b2040;
  --panel-2: #222949;
  --line: #2c335c;
  --text: #e8eaf6;
  --muted: #9aa3c7;
  --accent: #6c8cff;
  --accent-2: #8a6cff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(108, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(138, 108, 255, 0.14), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
small { font-size: 0.8em; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  background: rgba(15, 18, 34, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 26px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: 0.2px; font-weight: 650; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s;
}
.btn:hover { background: #2a325a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--panel); }
.btn-primary { background: linear-gradient(180deg, var(--accent), #5570f0); border-color: #4b66e6; }
.btn-primary:hover { background: linear-gradient(180deg, #7d99ff, #5e79f5); }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(248, 113, 113, 0.4); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.12); }

.btn-add {
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 26px; line-height: 1;
  font-weight: 400;
  display: grid; place-items: center;
  padding: 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: #5a5ce0;
  box-shadow: 0 8px 22px rgba(108, 140, 255, 0.4);
}
.btn-add:hover { filter: brightness(1.08); }

.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

/* ---------- Table ---------- */
.container { max-width: 980px; margin: 0 auto; padding: 26px 18px 80px; }
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table.exams { width: 100%; border-collapse: collapse; }
.exams thead th {
  text-align: left;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
  padding: 14px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.exams tbody td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.exams tbody tr { cursor: pointer; transition: background 0.12s ease; }
.exams tbody tr:hover { background: var(--panel-2); }
.exams tbody tr:last-child td { border-bottom: none; }
.col-grade, .col-status { white-space: nowrap; }
.code-cell { font-weight: 600; }
.code-empty { color: var(--muted); font-weight: 400; font-style: italic; }
.grade-cell { font-variant-numeric: tabular-nums; font-weight: 600; }
.grade-pct { color: var(--muted); font-weight: 400; margin-left: 6px; }
.date-cell { color: var(--muted); font-size: 13px; }

.empty { padding: 56px 20px; text-align: center; }
.empty p { margin: 6px 0; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.queued  { color: var(--blue);  background: rgba(96, 165, 250, 0.12); border-color: rgba(96,165,250,.3); }
.badge.grading { color: var(--amber); background: rgba(251, 191, 36, 0.12); border-color: rgba(251,191,36,.3); }
.badge.graded  { color: var(--green); background: rgba(52, 211, 153, 0.12); border-color: rgba(52,211,153,.3); }
.badge.error   { color: var(--red);   background: rgba(248, 113, 113, 0.12); border-color: rgba(248,113,113,.3); }
.badge.grading::before { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 8, 18, 0.62);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
}
.modal-lg { max-width: 820px; }
@keyframes pop { from { transform: translateY(8px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--line);
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span { font-size: 13px; color: var(--muted); }
.field-inline { max-width: 240px; }
textarea, input[type="text"], input[type="number"] {
  font: inherit; color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
  resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,140,255,.18); }

/* ---------- Dropzone / previews ---------- */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: 12px;
  padding: 26px 16px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg-2);
}
.dropzone p { margin: 4px 0; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(108,140,255,.08); }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 14px; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 3/4; background: var(--bg-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .num { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.thumb .rm { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: none; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1; }
.thumb .rm:hover { background: var(--red); }
.thumb .move { position: absolute; bottom: 4px; display: flex; gap: 4px; left: 4px; }
.thumb .move button { background: rgba(0,0,0,.6); color: #fff; border: none; width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 13px; line-height: 1; }
.thumb .move button:hover { background: var(--accent); }
.add-status { min-height: 20px; margin: 12px 0 0; font-size: 14px; }
.add-status.ok { color: var(--green); }
.add-status.err { color: var(--red); }

/* ---------- Detail view ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.detail-top { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.detail-field { display: flex; flex-direction: column; gap: 5px; }
.detail-field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.code-edit { display: flex; gap: 8px; align-items: center; }
.code-edit input { width: 180px; }
.score-big { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-big .pct { font-size: 16px; color: var(--muted); font-weight: 500; margin-left: 8px; }

.q-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.q-table th, .q-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
.q-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.q-table td.score { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 8px; }
.feedback-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; line-height: 1.5; white-space: pre-wrap; }
.error-box { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.35); color: #fecaca; border-radius: 10px; padding: 12px 14px; }

details.raw { border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); }
details.raw summary { cursor: pointer; padding: 10px 14px; color: var(--muted); font-size: 13px; }
details.raw pre { margin: 0; padding: 0 14px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.45; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery a { display: block; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; aspect-ratio: 3/4; background: var(--bg-2); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px;
  opacity: 0; transform: translateY(10px); transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(52, 211, 153, .4); color: #a7f3d0; }
.toast.err { border-color: rgba(248, 113, 113, .45); color: #fecaca; }

@media (max-width: 560px) {
  .col-date { display: none; }
  .container { padding: 16px 10px 80px; }
  .exams thead th, .exams tbody td { padding: 12px 12px; }
}
