/**
 * Exam Result Tabs UI Styles
 * Modern tabbed interface for exam results
 */

/* ============================================
   CSS Variables (Fallback)
   ============================================ */
:root {
  --tabs-primary-color: #e74c3c;
  --tabs-secondary-color: #3498db;
  --tabs-success-color: #2ecc71;
  --tabs-danger-color: #e74c3c;
  --tabs-warning-color: #f1c40f;
  --tabs-bg-color: #ffffff;
  --tabs-card-bg: #ffffff;
  --tabs-text-color: #333333;
  --tabs-text-muted: #6c757d;
  --tabs-border-color: #e9ecef;
  --tabs-gray-100: #f8f9fa;
  --tabs-gray-200: #e9ecef;
  --tabs-gray-600: #6c757d;
  --tabs-gray-700: #495057;
  --tabs-gray-800: #343a40;
}

/* ============================================
   Override for result-wrapper when using tabs
   ============================================ */

#result-wrapper:has(.result-tabs-container) {
  display: block !important;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fallback for browsers not supporting :has() */
#result-wrapper.tabs-active {
  display: block !important;
  padding: 1rem;
  grid-template-columns: none !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Force override old exam_result.css styles */
body #result-wrapper.tabs-active {
  display: block !important;
}

/* Hide old UI elements when tabs are active */
#result-wrapper.tabs-active > .result-container,
#result-wrapper.tabs-active > .containp,
#result-wrapper.tabs-active > .result-left-column,
#result-wrapper.tabs-active > .result-right-column,
#result-wrapper.tabs-active > .charts-container,
#result-wrapper.tabs-active > .comparison-chart-container {
  display: none !important;
}

/* ============================================
   Tab Navigation
   ============================================ */

.result-tabs-container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.result-tabs-header {
  display: flex;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-bottom: 2px solid #e9ecef;
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.result-tabs-header::-webkit-scrollbar {
  display: none;
}

.result-tab-btn {
  flex: 1;
  min-width: 100px;
  padding: 0.875rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  color: #6c757d;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  white-space: nowrap;
}

.result-tab-btn i {
  font-size: 1.1rem;}


.result-tab-btn:hover {
  background: rgba(52, 152, 219, 0.08);
  color: #3498db;
}

.result-tab-btn.active {
  background: #ffffff;
  color: #e74c3c;
  border-bottom-color: #e74c3c;
}

.result-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 3px;
  background: #e74c3c;
  border-radius: 3px 3px 0 0;
}

.result-tabs-content {
  padding: 0;
}

.result-tab-content {
  display: none;
  padding: 1rem;
  animation: fadeIn 0.3s ease;
}

.result-tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Update header layout for reading info */
.detail-header-wrapper .detail-header {
  flex-wrap: wrap !important;
  gap: 0.75rem !important;
}

.reading-header-desc {
  flex: 1 1 100%;
  order: 5;
  font-size: 0.85rem;
  color: #7b1fa2;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  border-left: 3px solid #7b1fa2;
  margin-top: 0.25rem;
}

.reading-type-desc {
  display: none !important; /* Moved to header */
}

.reading-section h5 {
  display: none !important; /* Moved to header */
}

/* ============================================
   Tab 1: Overview
   ============================================ */

/* New container layout */
.overview-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.overview-header {
  text-align: center;
}

.overview-scores-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

.overview-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2rem;
  align-items: center;
}

/* Legacy grid support */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.overview-left, .overview-right {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Chinese-style Exam Title Banner */
.exam-title-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 30%, #a5d6a7 70%, #81c784 100%);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  position: relative;
  overflow: hidden;
  box-shadow: 
    0 4px 20px rgba(76, 175, 80, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border: 2px solid rgba(76, 175, 80, 0.2);
}

.exam-title-banner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(255,255,255,0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.2) 0%, transparent 40%);
  pointer-events: none;
}

.banner-content {
  flex: 1;
  text-align: center;
  z-index: 1;
}

.banner-bamboo {
  width: 120px;
  height: 100%;
  min-height: 80px;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 150'%3E%3C!-- Bamboo stalks --%3E%3Crect x='20' y='0' width='8' height='150' fill='%232e7d32' rx='2'/%3E%3Crect x='45' y='10' width='6' height='140' fill='%2343a047' rx='2'/%3E%3Crect x='65' y='5' width='7' height='145' fill='%234caf50' rx='2'/%3E%3C!-- Bamboo nodes --%3E%3Cellipse cx='24' cy='30' rx='5' ry='2' fill='%231b5e20'/%3E%3Cellipse cx='24' cy='70' rx='5' ry='2' fill='%231b5e20'/%3E%3Cellipse cx='24' cy='110' rx='5' ry='2' fill='%231b5e20'/%3E%3Cellipse cx='48' cy='45' rx='4' ry='2' fill='%232e7d32'/%3E%3Cellipse cx='48' cy='85' rx='4' ry='2' fill='%232e7d32'/%3E%3Cellipse cx='48' cy='125' rx='4' ry='2' fill='%232e7d32'/%3E%3Cellipse cx='68.5' cy='35' rx='4.5' ry='2' fill='%23388e3c'/%3E%3Cellipse cx='68.5' cy='75' rx='4.5' ry='2' fill='%23388e3c'/%3E%3Cellipse cx='68.5' cy='115' rx='4.5' ry='2' fill='%23388e3c'/%3E%3C!-- Bamboo leaves --%3E%3Cpath d='M28 25 Q40 20 35 10 Q30 18 28 25' fill='%2366bb6a'/%3E%3Cpath d='M28 65 Q42 58 38 48 Q32 56 28 65' fill='%2381c784'/%3E%3Cpath d='M52 40 Q65 32 60 22 Q54 30 52 40' fill='%2366bb6a'/%3E%3Cpath d='M52 80 Q68 72 62 60 Q55 70 52 80' fill='%2381c784'/%3E%3Cpath d='M72 30 Q88 22 82 10 Q75 20 72 30' fill='%234caf50'/%3E%3Cpath d='M72 70 Q90 60 84 48 Q76 58 72 70' fill='%2366bb6a'/%3E%3Cpath d='M16 50 Q2 42 8 30 Q14 40 16 50' fill='%2381c784'/%3E%3Cpath d='M16 90 Q0 82 6 70 Q13 80 16 90' fill='%2366bb6a'/%3E%3C/svg%3E") no-repeat center;
  background-size: contain;
  opacity: 0.7;
}

.exam-title-main {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.exam-title-main.chinese-style {
  color: #1b5e20;
  font-family: 'KaiTi', 'STKaiti', 'AR PL UKai CN', 'Noto Serif SC', serif;
  text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.9);
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  letter-spacing: 2px;
}

.exam-title-sub {
  font-size: 1rem;
  color: #2e7d32;
  font-weight: 600;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.9;
}

.candidate-info.info-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  padding: 1.5rem;
  border-radius: 8px;
  border-left: 4px solid #3498db;
}

.candidate-info h3 {
  margin-bottom: 1rem;
  color: #333333;
  font-size: 1.1rem;
}

.candidate-info p {
  margin: 0.5rem 0;
  color: #444444;
}

/* Score Table */
.score-table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.score-table caption {
  padding: 1rem;
  font-weight: bold;
  text-align: center;
  background: #f8f9fa;
}

.score-table th,
.score-table td {
  padding: 0.75rem 1rem;
  text-align: center;
  border: 1px solid #e9ecef;
}

.score-table th {
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
  font-weight: 600;
}

.score-table th small {
  display: block;
  font-weight: normal;
  opacity: 0.8;
}

.score-table td small {
  display: block;
  color: #666666;
  font-size: 0.85em;
}

.score-table tr.total-row {
  background: #f8f9fa;
  font-weight: bold;
}

/* Violation Card */
.violation-card {
  padding: 1.5rem;
  border-radius: 8px;
  margin-top: 1rem;
}

.violation-card.success-card {
  background: linear-gradient(135deg, #f0fff4 0%, #ffffff 100%);
  border-left: 4px solid #2ecc71;
}

.violation-card.danger-card {
  background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
  border-left: 4px solid #e74c3c;
}

.violation-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.violation-title.success { color: #2ecc71; }
.violation-title.danger { color: #e74c3c; }

.violation-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: bold;
}

.violation-badge.good {
  background: #2ecc71;
  color: white;
}

.violation-badge.bad {
  background: #e74c3c;
  color: white;
}

.violation-message {
  color: #444444;
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0;
}

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e9ecef;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}

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

/* Loading card state */
.violation-card.loading-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-left-color: #6c757d;
}

.violation-card.loading-card .violation-title {
  color: #6c757d;
  display: flex;
  align-items: center;
}

/* Violation list */
.violation-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.violation-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  font-size: 0.9rem;
  color: #333333;
}

.violation-list li:last-child {
  border-bottom: none;
}

.view-violations-btn {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.view-violations-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

/* Signature */
.signature-wrapper {
  text-align: right;
  padding: 1rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.signature-wrapper .sign {
  font-style: italic;
  color: #e74c3c;
}

.signature-logo {
  height: 48px; /* Shrink logo size */
  width: auto;
  max-width: 180px;
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

.signature-logo:hover {
  opacity: 1;
}

/* Score Dashboard */
.result-summary.score-dashboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  height: fit-content;
}

.result-box {
  background: white;
  padding: 1.25rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  text-align: center;
}

.result-label {
  display: block;
  font-size: 0.85rem;
  color: #666666;
  margin-bottom: 0.5rem;
}

.result-content {
  font-size: 1rem;
}

.result-status {
  font-size: 1.25rem;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 8px;
}

.result-status.pass {
  background: rgba(46, 204, 113, 0.1);
  color: #2ecc71;
}

.result-status.fail {
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
}

/* ============================================
   Tab 2: Analysis
   ============================================ */

.analysis-section {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.charts-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.chart-wrapper.chart-card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  height: 400px;
  
  position: relative;
}

.chart-wrapper.chart-card canvas {
  
  width: 100% !important;
  height: auto !important;
}

.chart-title {
  font-size: 1rem;
  color: #333333;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e9ecef;
}

.comparison-chart-container.chart-card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  height: 400px;
  
}

.chart-canvas-container {
  height: 300px;
  
  position: relative;
}

.chart-canvas-container canvas {
  
}

/* ============================================
   Tab 3: Details
   ============================================ */

.details-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.details-header {
  display: none; /* Hidden on all viewports */
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.details-stats {
  display: flex;
  gap: 1rem;
}

.stat-item {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  text-align: center;
  min-width: 80px;
}

.stat-item.total {
  background: #f8f9fa;
  color: #333333;
}

.stat-item.correct {
  background: rgba(46, 204, 113, 0.1);
  color: #2ecc71;
}

.stat-item.incorrect {
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
}

.stat-number {
  display: block;
  font-size: 1.5rem;
  font-weight: bold;
}

.stat-label {
  font-size: 0.8rem;
  opacity: 0.8;
}

.filter-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--gray-300, #dee2e6);
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: #3498db;
  color: #3498db;
}

.filter-btn.active {
  background: #3498db;
  color: white;
  border-color: #3498db;
}


/* Desktop Layout for Details Tab */
.details-content {
  display: grid;
  gap: 1.5rem;
  height: calc(100vh - 200px);
  min-height: 600px;
}

.question-detail-panel {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  height: 100%;
  overflow-y: auto;
  position: relative;
  border: 1px solid #e9ecef;
}

.questions-sidebar {
  height: 100%;
  border: 1px solid #e9ecef;
}

/* Ensure detail card takes full height */
.detail-card {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.detail-body {
  flex: 1;
  padding: 1.5rem;
}

/* Scrollbar styling for panels */
.question-detail-panel::-webkit-scrollbar,
.questions-list-wrapper::-webkit-scrollbar {
  width: 6px;
}

.question-detail-panel::-webkit-scrollbar-track,
.questions-list-wrapper::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.question-detail-panel::-webkit-scrollbar-thumb,
.questions-list-wrapper::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.question-detail-panel::-webkit-scrollbar-thumb:hover,
.questions-list-wrapper::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}


/* Questions List Sidebar */
.questions-sidebar {
  background: #f8f9fa;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  
  position: sticky;
  top: 1rem;
}

.sidebar-tabs {
  display: flex;
  background: #e9ecef;
  padding: 0.5rem;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.sidebar-tab {
  flex: 1;
  min-width: 60px;
  padding: 0.5rem 0.25rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.sidebar-tab:hover {
  background: rgba(255, 255, 255, 0.5);
}

.sidebar-tab.active {
  background: white;
  color: #3498db;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-tab .tab-icon {
  font-size: 1rem;
}

.sidebar-tab .tab-count {
  font-size: 0.65rem;
  opacity: 0.8;
}

.questions-list-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  min-height: 200px; /* Allow at least 4 rows of questions */
   /* Prevent too much height */
}

/* Questions Grid */
.questions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 0.3rem;
  align-content: start;
}

.question-item {
  padding: 0.4rem 0.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  aspect-ratio: 1;
}

.question-item.correct {
  background: #2ecc71;
}

.question-item.incorrect {
  background: #e74c3c;
}

.question-item:hover {
  transform: scale(1.06);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.question-item.selected {
  outline: 2px solid #3498db;
  outline-offset: 1px;
}

.q-number {
  font-size: 0.85rem;
  line-height: 1.2;
}

.q-answer {
  font-size: 0.6rem;
  opacity: 0.9;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Close button - now shown on all devices when panel is active */
.panel-close-btn {
  display: none; /* Hidden by default if panel is empty/placeholder */
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1101;
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
  border: none;
  border-radius: 24px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
  transition: all 0.25s ease;
}

.question-detail-panel.active .panel-close-btn {
  display: flex;
}


.panel-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  color: var(--gray-500, #adb5bd);
  text-align: center;
}

.panel-placeholder i {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Detail Card Redesign */
.detail-card {
  height: 100%;
  position: relative;
  z-index: 10010; /* Very high z-index to overlay everything */
}

.detail-card .detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 10px;
  margin-bottom: 1.25rem;
}

.detail-header .question-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-header h4 {
  margin: 0;
  font-size: 1.15rem;
  color: #2c3e50;
}

.detail-header .question-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #666;
  background: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.status-badge {
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: bold;
}

.status-badge.correct {
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  color: white;
}

.status-badge.incorrect {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
}

.detail-body {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* Answer Section */
.detail-body .answer-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.answer-box {
  padding: 1rem;
  border-radius: 10px;
  background: #f8f9fa;
}

.answer-box.user-answer {
  border-left: 4px solid #3498db;
}

.answer-box.user-answer.correct {
  border-left-color: #2ecc71;
  background: rgba(46, 204, 113, 0.08);
}

.answer-box.user-answer.incorrect {
  border-left-color: #e74c3c;
  background: rgba(231, 76, 60, 0.08);
}

.answer-box.correct-answer {
  border-left: 4px solid #2ecc71;
  background: rgba(46, 204, 113, 0.08);
}

.answer-box label {
  display: block;
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.answer-box .answer-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  word-break: break-word;
}

/* Pattern & Tip Section */
.pattern-box {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border: 1px solid #90caf9;
}

.tip-box {
  background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
  border: 1px solid #ffcc80;
}

.pattern-box label, .tip-box label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.pattern-box label {
  color: #1565c0;
}

.tip-box label {
  color: #e65100;
}

.pattern-box p, .tip-box p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #333;
}

/* Fill and Select Placeholders */
.fill-placeholder {
  display: inline-block;
  min-width: 50px;
  border-bottom: 2px solid #e65100;
  color: #e65100;
  font-weight: 600;
  margin: 0 0.25rem;
}

.select-placeholder {
  display: inline-block;
  padding: 0.1rem 0.3rem;
  background: #e3f2fd;
  color: #1565c0;
  border-radius: 4px;
  font-size: 0.8rem;
  margin: 0 0.25rem;
}

/* Word Chip for SGDR questions */
.word-chip {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border: 1px solid #90caf9;
  border-radius: 6px;
  font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  font-size: 1rem;
  color: #1565c0;
  margin: 0.15rem;
}

/* Legacy answer-row support */
.answer-row {
  margin-bottom: 1rem;
}

.answer-row label {
  display: block;
  font-size: 0.85rem;
  color: #666666;
  margin-bottom: 0.3rem;
}

.answer-value {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
}

.answer-value.correct {
  background: rgba(46, 204, 113, 0.1);
  color: #2ecc71;
}

.answer-value.incorrect {
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
}

.audio-section,
.explanation-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e9ecef;
}

.audio-section h5,
.explanation-section h5 {
  font-size: 0.95rem;
  color: #333333;
  margin-bottom: 0.75rem;
}

.audio-placeholder,
.explanation-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
  background: #f8f9fa;
  border-radius: 8px;
  color: var(--gray-500, #adb5bd);
  text-align: center;
}

.audio-placeholder i,
.explanation-placeholder i {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

/* ============================================
   Tab 4: AI Grading
   ============================================ */

.ai-grading-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  color: white;
}

.ai-model-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.model-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: white;
  padding: 8px;
}

.model-details h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.2rem;
}

.model-details p {
  margin: 0;
  opacity: 0.9;
  font-size: 0.9rem;
}

.ai-stats .stat {
  text-align: center;
}

.ai-stats .stat-value {
  display: block;
  font-size: 2rem;
  font-weight: bold;
}

.ai-stats .stat-label {
  font-size: 0.85rem;
  opacity: 0.9;
}

.ai-feedback-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ai-feedback-card {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border-left: 4px solid #667eea;
}

.feedback-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.question-num {
  font-weight: bold;
  color: #333333;
}

.star-rating {
  color: #f1c40f;
  font-size: 1.1rem;
}

.feedback-content p {
  margin: 0.5rem 0;
  color: #444444;
  line-height: 1.6;
}

.no-feedback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  background: #f8f9fa;
  border-radius: 8px;
  color: #666666;
  text-align: center;
}

.no-feedback i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.no-feedback small {
  opacity: 0.7;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 1024px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
  
  .overview-scores-row {
    grid-template-columns: 1fr;
  }
  
  .overview-footer {
    grid-template-columns: 1fr;
    text-align: center;
  }
  
  .signature-wrapper {
    justify-content: center;
  }
  
  .charts-container {
    grid-template-columns: 1fr;
  }
  
  .details-content {
    display: block;
    position: relative;
  }
  
  /* Hide details header on mobile/tablet */
  .details-header {
    display: none;
  }
  
  .questions-sidebar {
    
    position: relative;
    margin-bottom: 1rem;
  }
  
  .sidebar-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .sidebar-tab {
    min-width: 70px;
    flex: 0 0 auto;
  }
  
  /* Grid layout with min 4 rows before scroll - responsive */
  .questions-list-wrapper {
    min-height: 200px;
    
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }
  
  .questions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 0.3rem;
    align-content: start;
  }
  
  .question-item {
    flex: 0 0 auto;
    min-width: 42px;
    aspect-ratio: 1;
  }
  
  /* Popup overlay for question detail on tablet/mobile */
  .question-detail-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10005; /* Above 9999 as requested */
    background: white;
    padding: 1.5rem;
    /* Use safe-area-inset-top for devices with notch/status bar, fallback to 70px */
    padding-top: calc(70px + env(safe-area-inset-top, 0px));
    padding-top: max(70px, calc(60px + env(safe-area-inset-top, 0px)));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); /* Safe area for bottom */
    overflow-y: auto;
    overflow-x: visible; /* Changed from hidden to visible */
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
    
    border-radius: 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  }
  
  .question-detail-panel.active {
    transform: translateY(0);
    overflow-y: auto; /* Enable vertical scrolling when active */
  }
  
  /* Ensure content doesn't get cut off */
  .question-detail-panel .detail-card {
    padding-bottom: 2rem;
    overflow: visible; /* Prevent content clipping */
  }
  
  .question-detail-panel .detail-body {
    overflow: visible;
    padding: 0; /* Removed vertical padding */
  }
  
  /* Close button for popup on mobile - use fixed positioning for scrolling */
  .panel-close-btn {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
  }
  
  .panel-close-btn:hover {
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.5);
  }
  
  .panel-close-btn:active {
    transform: scale(0.95);
  }
  
  .panel-close-btn .close-icon {
    font-size: 1rem;
    line-height: 1;
  }
  
  .panel-close-btn .close-text {
    font-size: 0.8rem;
  }
  
  .detail-body .answer-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .result-tabs-container {
    border-radius: 0;
    box-shadow: none;
  }
  
  .result-tabs-header {
    justify-content: flex-start;
    padding: 0;
  }
  
  .result-tab-btn {
    min-width: 70px;
    padding: 0.6rem 0.5rem;
    font-size: 0.75rem;
    flex: 0 0 auto;
  }
  
  .result-tab-btn i {
    font-size: 1.1rem;
  }
  
  .result-tab-btn span {
    font-size: 0.65rem;
    display: block;
  }
  
  .result-tab-content {
    padding: 0.75rem;
  }
  
  .overview-container,
  .analysis-section,
  .details-section {
    gap: 1rem;
  }
  
  .exam-title-banner {
    padding: 1rem;
    border-radius: 8px;
  }
  
  .exam-title-main.chinese-style {
    font-size: 1.5rem;
  }
  
  .exam-title-sub {
    font-size: 0.8rem;
  }
  
  .banner-bamboo {
    width: 80px;
    right: 5px;
  }
  
  .candidate-info.info-card {
    padding: 1rem;
  }
  
  .candidate-info.info-card h3 {
    font-size: 0.9rem;
  }
  
  .candidate-info.info-card p {
    font-size: 0.8rem;
  }
  
  .overview-scores-row {
    gap: 1rem;
  }
  
  .score-table {
    font-size: 0.85rem;
  }
  
  .details-stats {
    justify-content: center;
  }
  
  .filter-buttons {
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .result-summary.score-dashboard {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .result-box {
    padding: 1rem;
  }
  
  .ai-header {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }
  
  .ai-model-info {
    flex-direction: column;
  }
  
  .overview-footer {
    gap: 1rem;
  }
  
  .signature-logo {
    
  }
}

@media (max-width: 480px) {
  .questions-grid {
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 0.25rem;
    padding: 0.5rem;
  }
  
  .question-item {
    min-height: 36px;
    padding: 0.25rem;
    border-radius: 4px;
    aspect-ratio: 1;
  }
  
  .q-number {
    font-size: 0.75rem;
  }
  
  .q-answer {
    display: none;
  }
}

/* Navigation Buttons in Detail Card */
.detail-nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn {
  background: white;
  border: 1px solid #dee2e6;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: #555;
  transition: all 0.2s;
  min-width: 90px;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  background: #e9ecef;
  color: #3498db;
  border-color: #3498db;
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #f1f3f5;
}

/* Update header layout to accommodate buttons */
.detail-header-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 1rem;
  border-radius: 10px;
  margin-bottom: 1.25rem;
}

.detail-header-wrapper .detail-header {
  background: transparent;
  padding: 0;
  margin: 0;
  box-shadow: none;
  border-radius: 0;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  width: 100% !important;
  gap: 1rem;
}

.nav-controls {
  display: flex !important;
  align-items: center !important;
  gap: 0.75rem !important;
  margin: 0 !important;
  padding: 0 !important;
  border-top: none !important;
}

.nav-btn {
  background: white;
  border: 1px solid #eee;
  padding: 0.5rem 1rem !important;
  border-radius: 50px !important; /* Pill shape */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.2rem !important; /* Larger arrows */
  color: #555;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  min-width: 50px !important; /* Circle-ish if text is small */
  height: 40px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
}

.nav-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); /* Premium purple/blue gradient matching AI header, or orange if preferred */
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
}

.nav-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f1f3f5;
  box-shadow: none;
  color: #adb5bd;
  border-color: #f1f3f5;
}

.detail-body {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

