:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-dark: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 28px rgba(0,0,0,0.12);
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  padding-bottom: 40px;
}

.app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  font-size: 28px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0e7ff 0%, #ede9fe 100%);
  border-radius: var(--radius-sm);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Badges */
.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-warning { background: #fef3c7; color: #92400e; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-primary { background: #e0e7ff; color: #3730a3; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* Panels */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.panel-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Student Info Grid */
.student-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Nút Chụp & Tải ảnh Mobile To Bản */
.mobile-action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-mobile-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-camera-native {
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.btn-camera-native:active { transform: scale(0.98); }

.btn-gallery {
  background: #f8fafc;
  color: #1e293b;
  border-color: #cbd5e1;
}

.btn-gallery:active { background: #e2e8f0; }

.action-icon { font-size: 2rem; line-height: 1; }
.action-text strong { display: block; font-size: 1rem; font-weight: 700; line-height: 1.2; }
.btn-camera-native .action-text small { color: #e0e7ff; font-size: 0.75rem; }
.btn-gallery .action-text small { color: #64748b; font-size: 0.75rem; }

/* Live Webcam styling */
.webcam-accordion {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.camera-wrapper {
  position: relative;
  width: 100%;
  height: 260px;
  background: #090d16;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-video { width: 100%; height: 100%; object-fit: cover; }
.camera-placeholder { position: absolute; text-align: center; color: #94a3b8; padding: 10px; }
.camera-controls { display: flex; flex-wrap: wrap; gap: 10px; }

/* Multi-page Tray */
.multi-page-tray {
  background: #f8fafc;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed #94a3b8;
}

.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.pages-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.page-item {
  position: relative;
  flex: 0 0 100px;
  height: 130px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--primary);
  background: #000;
}

.page-item img { width: 100%; height: 100%; object-fit: cover; }
.page-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.page-remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* Barem & Inputs To Rộng Thân Thiện Mobile */
.label-large {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}

.form-control-large {
  font-size: 16px !important;
  padding: 12px 16px;
  border: 1.5px solid #94a3b8;
  border-radius: var(--radius-sm);
  width: 100%;
  font-family: inherit;
  color: #0f172a;
  background: #fff;
  transition: all 0.2s ease;
}

.form-control-large:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.form-textarea { min-height: 110px; line-height: 1.5; resize: vertical; }

/* Presets & Config Grid */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

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

.form-group.full-width { grid-column: 1 / -1; }

.preset-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 14px;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

.preset-icon { font-size: 1.3rem; margin-bottom: 4px; }
.preset-btn strong { font-size: 0.95rem; }
.preset-btn small { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Custom rules */
.custom-rules-container { border-top: 1px dashed var(--border); padding-top: 14px; }
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 12px;
  background: #f8fafc;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Action Button Chấm Bài */
.btn-success-large {
  width: 100%;
  padding: 18px;
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-success-large:hover:not(:disabled) {
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.45);
}

.btn-success-large:disabled { opacity: 0.5; cursor: not-allowed; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-secondary { background: #fff; color: #334155; border: 1.5px solid var(--border); }
.btn-primary-gradient { background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); color: #fff; }
.btn-text { background: none; border: none; color: var(--primary); font-weight: 700; font-size: 0.9rem; cursor: pointer; }
.btn-icon { background: none; border: none; font-size: 1.3rem; cursor: pointer; padding: 6px; }

/* Export Buttons & Actions Bar */
.export-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  width: 100%;
}

.btn-gsheet {
  background: #0f9d58;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(15, 157, 88, 0.3);
}

.btn-gsheet:hover { background: #0b8043; }

.btn-word {
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-word:hover { background: #1d4ed8; }

.btn-excel {
  background: #107c41;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(16, 124, 65, 0.3);
}

.btn-excel:hover { background: #0c5c30; }

/* Loading */
.loading-state {
  text-align: center;
  padding: 40px 20px;
  background: #fff;
  border-radius: var(--radius-md);
  margin: 20px 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e0e7ff;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

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

/* Results Section */
.results-header-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  color: #fff;
  padding: 22px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.score-display {
  display: flex;
  align-items: center;
  gap: 16px;
}

.score-circle {
  width: 86px;
  height: 86px;
  background: #fff;
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.big-score {
  font-size: 2.1rem;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
}

.max-score { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.score-meta h2 { font-size: 1.3rem; font-weight: 800; margin-bottom: 2px; }
.meta-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* Exercises breakdown */
.exercise-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 14px;
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.exercise-title { font-size: 1.05rem; font-weight: 700; }
.exercise-score {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
}

.errors-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.error-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--danger-light);
  border-left: 4px solid var(--danger);
  padding: 12px 14px;
  border-radius: 4px;
}

.error-penalty {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--danger);
  font-size: 1rem;
  white-space: nowrap;
}

.error-details strong { color: #991b1b; font-size: 0.9rem; }
.error-details p { font-size: 0.95rem; color: #450a0a; margin-top: 2px; }

.exercise-topics {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Pedagogical Skills Section */
.skills-content { display: flex; flex-direction: column; gap: 16px; }
.skill-box { padding: 18px; border-radius: var(--radius-sm); }
.strength-box { background: #f0fdf4; border: 1px solid #bbf7d0; }
.strength-box h3 { color: #166534; font-size: 1rem; margin-bottom: 8px; }

.weakness-box { background: #fffbeb; border: 1px solid #fde68a; }
.weakness-box h3 { color: #92400e; font-size: 1.05rem; margin-bottom: 12px; }

.skills-action-list { display: flex; flex-direction: column; gap: 14px; }
.skill-action-item {
  background: #fff;
  border: 1.5px solid #fed7aa;
  padding: 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.skill-action-item h4 { font-size: 1rem; font-weight: 800; color: #9a3412; margin-bottom: 6px; }

.lemma-badge {
  display: inline-block;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid #fca5a5;
}

.weak-point { font-size: 0.95rem; color: #334155; margin-bottom: 6px; }
.solution-guide {
  font-size: 0.95rem;
  color: #047857;
  font-weight: 500;
  background: #f0fdf4;
  padding: 10px 12px;
  border-radius: 6px;
  border-left: 3px solid #10b981;
  margin-top: 8px;
}

.practice-suggest {
  font-size: 0.95rem;
  color: #1e40af;
  background: #eff6ff;
  padding: 10px 12px;
  border-radius: 6px;
  border-left: 3px solid #3b82f6;
  margin-top: 8px;
}

.overview-box { background: #f8fafc; border: 1px solid #cbd5e1; }
.overview-box h3 { color: #334155; font-size: 1rem; margin-bottom: 6px; }
.comment-text { font-style: italic; color: #334155; font-size: 0.95rem; }
.bullet-list { padding-left: 20px; font-size: 0.95rem; color: #1e293b; }

/* Utilities */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.text-danger { color: var(--danger); }

/* Footer */
.app-footer { text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-top: 25px; }

/* Mobile responsive */
@media (max-width: 640px) {
  .app-container { padding: 8px; }
  .student-info-grid { grid-template-columns: 1fr; }
  .mobile-action-buttons { grid-template-columns: 1fr; }
  .score-display { flex-direction: column; text-align: center; }
  .meta-tags { justify-content: center; }
  .preset-buttons { grid-template-columns: 1fr; }
  .export-actions-bar { justify-content: stretch; }
  .export-actions-bar .btn { flex: 1 1 45%; }
}
