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

:root {
  --blue:    #2563EB;
  --blue-dk: #1D4ED8;
  --green:   #16A34A;
  --red:     #DC2626;
  --amber:   #D97706;
  --bg:      #F1F5F9;
  --card:    #FFFFFF;
  --border:  #E2E8F0;
  --text:    #1E293B;
  --muted:   #64748B;
  --radius:  10px;
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}

/* ── Start / Login page ──────────────────────────────────────────────────── */
.start-card {
  width: 100%;
  max-width: 480px;
  padding: 48px 40px;
}

.brand { text-align: center; margin-bottom: 32px; }
.brand-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--blue), #3B82F6);
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.brand-icon svg { width: 32px; height: 32px; fill: #fff; }
.brand h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.brand p  { font-size: 14px; color: var(--muted); margin-top: 4px; }

.info-box {
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 28px;
}
.info-box h3 { font-size: 13px; font-weight: 600; color: var(--blue); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .05em; }
.info-box ul { list-style: none; }
.info-box li { font-size: 13px; color: var(--text); padding: 3px 0; padding-left: 18px; position: relative; }
.info-box li::before { content: '✓'; position: absolute; left: 0; color: var(--green); font-weight: 700; }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px; color: var(--text);
  transition: border-color .15s;
  background: #fff;
}
.form-group input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 24px;
  border-radius: 8px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; border: none;
  transition: background .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn-primary  { background: var(--blue);  color: #fff; width: 100%; }
.btn-primary:hover  { background: var(--blue-dk); }
.btn-danger   { background: var(--red);   color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.error-msg { color: var(--red); font-size: 13px; margin-top: 10px; text-align: center; display: none; }

/* ── Assessment layout ───────────────────────────────────────────────────── */
.assess-layout {
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.assess-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.assess-header .logo-sm { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.assess-header .logo-sm .dot {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--blue), #3B82F6);
  border-radius: 8px;
}

.timer-box {
  display: flex; align-items: center; gap: 8px;
  font-size: 20px; font-weight: 700; font-family: monospace;
  color: var(--text);
}
.timer-box.warn { color: var(--amber); }
.timer-box.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.candidate-pill {
  font-size: 13px; font-weight: 500; color: var(--muted);
  background: var(--bg); border-radius: 20px; padding: 5px 12px;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px; gap: 4px;
}
.tab-btn {
  padding: 14px 20px;
  font-size: 14px; font-weight: 500; color: var(--muted);
  background: none; border: none; cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
  transition: color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-color: var(--blue); font-weight: 600; }
.tab-btn .badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; font-size: 11px; font-weight: 700;
  margin-left: 6px; background: var(--bg); color: var(--muted);
}
.tab-btn.pass .badge { background: #DCFCE7; color: var(--green); }
.tab-btn.fail .badge { background: #FEE2E2; color: var(--red); }

/* ── Challenge panel ─────────────────────────────────────────────────────── */
.challenge-panel { display: none; padding: 24px; gap: 24px; }
.challenge-panel.active { display: flex; }

.challenge-info {
  flex: 0 0 380px;
  display: flex; flex-direction: column; gap: 16px;
}

.ch-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.ch-card h2 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.ch-card .fn-sig {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  background: #1E293B; color: #93C5FD;
  padding: 10px 14px; border-radius: 6px;
  margin-bottom: 12px;
}
.ch-card p { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 10px; }
.ch-card .rules { font-size: 13px; color: var(--text); }
.ch-card .rules li { padding: 3px 0; padding-left: 16px; position: relative; }
.ch-card .rules li::before { content: '→'; position: absolute; left: 0; color: var(--blue); }

.test-table-wrap { overflow-x: auto; }
.test-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.test-table th {
  background: var(--bg); text-align: left;
  padding: 7px 10px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border);
}
.test-table td {
  padding: 7px 10px; border: 1px solid var(--border);
  font-family: monospace; vertical-align: top; word-break: break-all;
  max-width: 200px;
}
.test-table tr:nth-child(even) td { background: #F8FAFC; }
.hidden-tests {
  font-size: 12px; color: var(--muted); text-align: center;
  padding: 6px; background: var(--bg); border-radius: 0 0 6px 6px;
  border: 1px solid var(--border); border-top: none;
  font-style: italic;
}

/* ── Code editor area ────────────────────────────────────────────────────── */
.editor-wrap {
  flex: 1; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  min-width: 0;
}
.editor-header {
  background: #1E293B; color: #94A3B8;
  padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 500;
}
.editor-lang { color: #38BDF8; font-weight: 600; }
.CodeMirror {
  height: 100% !important;
  font-size: 14px !important;
  font-family: 'Fira Code', 'Courier New', monospace !important;
}
.CodeMirror-scroll { min-height: 420px; }

/* ── Submit bar ──────────────────────────────────────────────────────────── */
.submit-bar {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; bottom: 0;
}
.submit-progress { font-size: 14px; color: var(--muted); }
.submit-progress strong { color: var(--text); }
.btn-submit { background: var(--green); color: #fff; padding: 11px 32px; font-size: 15px; }
.btn-submit:hover { background: #15803D; }

/* ── Results page ────────────────────────────────────────────────────────── */
.result-card {
  width: 100%; max-width: 520px;
  padding: 48px 40px; text-align: center;
}
.result-icon { font-size: 56px; margin-bottom: 12px; }
.result-card h1 { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.result-card .sub { font-size: 15px; color: var(--muted); margin-bottom: 32px; }
.score-row { display: flex; justify-content: center; gap: 12px; margin-bottom: 32px; }
.score-chip {
  padding: 8px 18px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
}
.score-chip.pass { background: #DCFCE7; color: var(--green); }
.score-chip.fail { background: #FEE2E2; color: var(--red); }
.ch-result-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  text-align: left; font-size: 14px;
}
.ch-result-row:last-child { border-bottom: none; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; margin-right: 8px;
}
.status-dot.pass { background: var(--green); }
.status-dot.fail { background: var(--red); }

/* ── Admin pages ─────────────────────────────────────────────────────────── */
.admin-layout { display: flex; flex-direction: column; min-height: 100vh; }

.admin-nav {
  background: #1E293B; color: #F1F5F9;
  padding: 0 24px; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.admin-nav .logo-text { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.admin-nav .nav-right { display: flex; align-items: center; gap: 16px; }
.admin-nav .nav-right span { font-size: 13px; color: #94A3B8; }
.btn-logout {
  background: rgba(255,255,255,.1); color: #F1F5F9;
  padding: 6px 14px; font-size: 13px; border-radius: 6px;
  border: none; cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,.2); }

.admin-body { padding: 28px 32px; flex: 1; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.page-sub   { font-size: 14px; color: var(--muted); margin-bottom: 28px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-card .value { font-size: 32px; font-weight: 800; color: var(--text); }
.stat-card.green .value { color: var(--green); }
.stat-card.red   .value { color: var(--red);   }
.stat-card.amber .value { color: var(--amber);  }

.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.table-card-header h3 { font-size: 16px; font-weight: 700; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  background: var(--bg); text-align: left;
  padding: 11px 16px; font-weight: 600; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #F8FAFC; }

.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 600;
}
.badge-pass  { background: #DCFCE7; color: var(--green); }
.badge-fail  { background: #FEE2E2; color: var(--red);   }
.badge-low   { background: #DCFCE7; color: var(--green); }
.badge-medium{ background: #FEF3C7; color: var(--amber); }
.badge-high  { background: #FEE2E2; color: var(--red);   }

.btn-view { background: var(--blue); color: #fff; padding: 5px 12px; font-size: 12px; font-weight: 600; border: none; border-radius: 6px; cursor: pointer; }
.btn-view:hover { background: var(--blue-dk); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto; z-index: 200;
}
.modal-backdrop.hidden { display: none; }
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%; max-width: 760px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head {
  background: #1E293B; color: #F1F5F9;
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; color: #94A3B8; font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: #fff; }
.modal-body { padding: 24px; }

.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.detail-item .di-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.detail-item .di-val   { font-size: 15px; font-weight: 600; color: var(--text); }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 20px 0 10px; }

.ai-flags { list-style: none; }
.ai-flags li {
  font-size: 13px; color: var(--text);
  padding: 5px 0 5px 20px; position: relative;
  border-bottom: 1px solid var(--border);
}
.ai-flags li:last-child { border-bottom: none; }
.ai-flags li::before { content: '⚑'; position: absolute; left: 0; color: var(--red); }

.ch-detail {
  border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 12px; overflow: hidden;
}
.ch-detail-head {
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); font-size: 14px; font-weight: 600;
}
.ch-detail-body { padding: 12px 14px; }
.test-result-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-family: monospace;
  padding: 4px 0; border-bottom: 1px solid var(--border);
}
.test-result-row:last-child { border-bottom: none; }
.tick { color: var(--green); font-weight: 700; }
.cross{ color: var(--red);   font-weight: 700; }

/* ── Reference Solutions ────────────────────────────────────────────────── */
.solution-block { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; overflow: hidden; }
.solution-head {
  padding: 10px 14px; background: var(--bg);
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: space-between;
}
.solution-head .fn-label { font-family: monospace; color: var(--blue); }
.solution-body {
  margin: 0; padding: 14px 16px;
  background: #1E293B; color: #E2E8F0;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13px; line-height: 1.55;
  white-space: pre; overflow-x: auto;
}

.code-preview {
  background: #1E293B; color: #E2E8F0;
  padding: 12px 14px; border-radius: 6px;
  font-family: monospace; font-size: 12px;
  overflow-x: auto; white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow-y: auto;
  margin-top: 8px;
}

/* ── Loader overlay ──────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
}
.overlay.hidden { display: none; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .challenge-panel { flex-direction: column; }
  .challenge-info { flex: none; }
}
@media (max-width: 600px) {
  .start-card { padding: 32px 24px; }
  .admin-body { padding: 16px; }
  .detail-grid { grid-template-columns: 1fr; }
}
