/* ============================================================
   STUDENT INTERFACE — Chatbot Ôn Thi Tiếng Anh
   CĐ Kỹ thuật Cao Thắng
   ============================================================ */

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

:root {
  --primary: #1a237e;
  --primary-light: #e8eaf6;
  --accent: #f57c00;
  --accent-light: #fff3e0;
  --success: #2e7d32;
  --success-light: #e8f5e9;
  --error: #c62828;
  --error-light: #ffebee;
  --text: #1a1a2e;
  --text-secondary: #666;
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #e0e0e0;
  --radius: 12px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}

/* ============ HEADER ============ */
header {
  background: linear-gradient(135deg, var(--primary) 0%, #283593 100%);
  color: white;
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; }

.logo-img {
  height: 32px;
  width: 32px;
  object-fit: contain;
  background: white;
  border-radius: 6px;
  padding: 2px;
}
.login-logo { height: 80px; width: auto; }

#user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.btn-sm {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* ============ SCREENS ============ */
.screen { display: none; padding: 16px; max-width: 680px; margin: 0 auto; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ============ CARD ============ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 16px;
}

.card h2 { font-size: 20px; color: var(--primary); margin-bottom: 4px; }
.card .subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.text-center { text-align: center; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color .2s;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,35,126,.1); }

/* ============ LOGIN PAGE ============ */
.login-page {
  min-height: calc(100dvh - 52px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: #f5f7fb;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(26,35,126,.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(92,107,192,.08) 0%, transparent 50%);
}

.login-card {
  max-width: 420px;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  overflow: hidden;
}

/* --- Top section --- */
.login-top {
  text-align: center;
  padding: 36px 32px 24px;
  background: linear-gradient(170deg, #1a237e 0%, #283593 100%);
  color: white;
}

.login-logo {
  height: 72px;
  width: 72px;
  object-fit: contain;
  background: white;
  border-radius: 50%;
  padding: 8px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.3px;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  opacity: .75;
  font-weight: 400;
}

/* --- Features --- */
.login-features {
  padding: 24px 28px;
  border-bottom: 1px solid #f0f0f0;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  font-size: 13px;
  color: #444;
  line-height: 1.5;
}

.feature-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2ff;
  border-radius: 8px;
}

/* --- Bottom / login section --- */
.login-bottom {
  padding: 24px 32px 28px;
  text-align: center;
}

#google-btn-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
}

#google-btn-wrapper > div {
  margin: 0 auto;
}

.login-hint {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.login-footer {
  margin-top: 24px;
  font-size: 11px;
  color: #bbb;
  text-align: center;
}

/* Loading */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid #e0e0e0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 12px auto 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

#login-loading { text-align: center; }
#login-loading p { font-size: 13px; color: #999; }

/* Avatar */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: none;
  border: 2px solid rgba(255,255,255,.4);
}

.error-msg {
  background: var(--error-light);
  color: var(--error);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
  text-align: left;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}

.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: #283593; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover:not(:disabled) { background: #e65100; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--primary-light); }
.btn-full { width: 100%; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ============ GRID LIST (courses, exams) ============ */
.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

.grid-item {
  background: var(--primary-light);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 16px 12px;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}

.grid-item:hover { border-color: var(--primary); transform: translateY(-2px); }
.grid-item-title { font-weight: 600; font-size: 14px; color: var(--primary); }
.grid-item-sub { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

/* ============ QUIZ ============ */
.quiz-header { margin-bottom: 20px; }
.quiz-header h2 { font-size: 16px; margin-bottom: 8px; }

.quiz-progress { font-size: 13px; color: var(--text-secondary); }
.progress-bar { height: 6px; background: #e0e0e0; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .4s ease; }

.question-block { margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid #eee; }
.question-block:last-child { border-bottom: none; margin-bottom: 0; }

.passage {
  background: #f8f9fa;
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.7;
  color: #444;
  border-radius: 0 8px 8px 0;
  white-space: pre-line;
}

.question-text { font-size: 15px; font-weight: 500; margin-bottom: 10px; }
.q-num { color: var(--primary); font-weight: 700; }

.options { display: flex; flex-direction: column; gap: 6px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  font-size: 14px;
}

.option:hover { border-color: var(--primary); background: var(--primary-light); }
.option.selected { border-color: var(--primary); background: var(--primary-light); }
.option input { display: none; }

.option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e8eaf6;
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.option.selected .option-letter { background: var(--primary); color: white; }
.option-text { padding-top: 2px; }

.quiz-actions { display: flex; gap: 10px; margin-top: 20px; }
.quiz-actions .btn { flex: 1; }

/* ============ RESULTS ============ */
.batch-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid #eee;
}

.score-badge {
  background: var(--primary);
  color: white;
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 18px;
  font-weight: 700;
}

.score-total { font-size: 14px; color: var(--text-secondary); }

.result-item {
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.result-item.correct { background: var(--success-light); border-left: 4px solid var(--success); }
.result-item.wrong { background: var(--error-light); border-left: 4px solid var(--error); }

.result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-icon { font-size: 20px; font-weight: 700; }
.result-item.correct .result-icon { color: var(--success); }
.result-item.wrong .result-icon { color: var(--error); }

.result-label { font-weight: 600; font-size: 14px; }
.result-answer { font-size: 12px; color: var(--text-secondary); margin-left: auto; }

/* ============ EXPLANATION + FOLLOW-UP ============ */
.result-question {
  margin: 10px 0;
  padding: 12px;
  background: rgba(255,255,255,.7);
  border-radius: 8px;
}

.passage-mini {
  font-size: 12px;
  color: #666;
  font-style: italic;
  padding: 6px 10px;
  background: #f8f9fa;
  border-left: 2px solid #c5cae9;
  border-radius: 0 6px 6px 0;
  margin-bottom: 8px;
}

.rq-text {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: #333;
}

.result-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.result-option {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f5f5f5;
  color: #555;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ro-letter {
  font-weight: 700;
  font-size: 12px;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e0e0e0;
  color: #666;
  flex-shrink: 0;
}

.result-option.chosen-correct {
  background: #e8f5e9;
  color: #1b5e20;
  font-weight: 500;
}
.result-option.chosen-correct .ro-letter {
  background: #2e7d32;
  color: white;
}

.result-option.chosen-wrong {
  background: #ffebee;
  color: #b71c1c;
  font-weight: 500;
}
.result-option.chosen-wrong .ro-letter {
  background: #c62828;
  color: white;
}

.explanation-label {
  font-size: 12px;
  font-weight: 600;
  color: #e65100;
  margin-bottom: 4px;
}

.explanation {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(0,0,0,.08);
}

.explanation-text {
  font-size: 13px;
  line-height: 1.7;
  color: #333;
  background: rgba(255,255,255,.6);
  padding: 10px 12px;
  border-radius: 8px;
}

/* ============ GPT FORMATTED TEXT ============ */
.explanation-text strong, .msg-bot strong { font-weight: 700; color: #1a237e; }
.explanation-text em, .msg-bot em { font-style: italic; color: #555; }
.explanation-text code, .msg-bot code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: #c62828;
}

.gpt-list {
  margin: 6px 0;
  padding-left: 4px;
}

.gpt-list-item {
  padding: 3px 0;
  line-height: 1.6;
}

.gpt-num {
  font-weight: 700;
  color: #1a237e;
  margin-right: 2px;
}

.gpt-bullet {
  color: #f57c00;
  margin-right: 4px;
}

.gpt-break { height: 8px; }

.btn-followup {
  background: none;
  border: 1px dashed var(--primary);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: all .2s;
}

.btn-followup:hover { background: var(--primary-light); }

.followup-chat {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fafafa;
}

.chat-messages {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
}

.msg {
  padding: 8px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
  word-wrap: break-word;
}

.msg-user {
  background: var(--primary);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.msg-bot {
  background: white;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-bot.typing { color: #999; font-style: italic; }

.chat-input {
  display: flex;
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  padding: 10px 12px;
  border: none;
  font-size: 13px;
  outline: none;
  background: white;
}

.btn-send {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-send:hover { background: #283593; }

.followup-limit {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px;
  background: #f5f5f5;
}

/* ============ SUMMARY ============ */
.summary-icon { font-size: 60px; margin-bottom: 12px; }
.summary-score { font-size: 48px; font-weight: 800; color: var(--primary); }
.summary-percent { font-size: 20px; color: var(--text-secondary); margin-bottom: 8px; }

.summary-grade {
  display: inline-block;
  padding: 6px 24px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 24px;
}

.grade-excellent { background: #e8f5e9; color: #1b5e20; }
.grade-good { background: #e3f2fd; color: #1565c0; }
.grade-average { background: #fff3e0; color: #e65100; }
.grade-weak { background: #ffebee; color: #b71c1c; }

.summary-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 480px) {
  .card { padding: 16px; }
  .login-card { margin: 16px auto; }
  .grid-list { grid-template-columns: repeat(2, 1fr); }
  .quiz-actions { flex-direction: column; }
  .batch-summary { flex-direction: column; gap: 8px; text-align: center; }
  .result-header { font-size: 13px; }
  .result-answer { margin-left: 0; }
}
