/* === 통계 화면 === */

/* 페이지 제목 */
.stats-page-title {
  color: var(--gold);
  margin-bottom: 1.2rem;
}

/* 탭 */
.stats-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.stats-tab {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(11, 16, 38, 0.85);
  color: var(--sand-dark);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-main);
}

.stats-tab:hover {
  border-color: var(--gold);
  color: var(--sand);
}

.stats-tab.active {
  background: rgba(244, 197, 66, 0.12);
  border-color: var(--gold);
  color: var(--gold);
}

.stats-tab:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(244, 197, 66, 0.25);
}

.stats-tab:focus:not(:focus-visible) {
  outline: none;
}

.stats-sub-text {
  font-size: 0.72rem;
  color: var(--sand-muted);
  margin-left: 0.15rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stats-summary-card {
  padding: 1rem 0.75rem;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stats-number {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}

.stats-label {
  font-size: 0.72rem;
  color: var(--sand);
  margin-top: 0.2rem;
}

/* 테이블 */
.stats-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats-table th {
  text-align: center;
  padding: 0.5rem 0.4rem;
  color: var(--sand-dark);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.stats-table th:first-child {
  text-align: left;
}

.stats-table td {
  padding: 0.5rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid rgba(37, 48, 82, 0.4);
  color: var(--sand);
  max-width: 200px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.stats-table td:first-child {
  text-align: left;
  color: var(--sand-dark);
}

.stats-table tbody tr:hover {
  background: rgba(244, 197, 66, 0.03);
}

/* === AI 분석 리포트 === */
.report-card {
  background: rgba(11, 16, 38, 0.88);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
}

.report-section-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--sand);
}

.report-stats-row {
  display: flex;
  justify-content: space-around;
  text-align: center;
  gap: 0.5rem;
}

.report-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.report-stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
}

.report-stat-label {
  font-size: 0.7rem;
  color: var(--sand-dark);
}

.report-list {
  list-style: none;
  padding: 0;
}

.report-list li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--sand);
}

.report-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--gold);
}

.report-motivational {
  background: linear-gradient(135deg, rgba(244, 197, 66, 0.08), rgba(123, 198, 126, 0.08));
  border: 1px solid rgba(244, 197, 66, 0.15);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}

.report-motivational p {
  font-size: 0.92rem;
  color: var(--gold-light);
  line-height: 1.6;
  font-style: italic;
}

/* AI 생성 미리보기 */
.ai-gen-preview {
  font-size: 0.85rem;
  color: var(--sand);
  line-height: 1.6;
  max-height: 120px;
  overflow: hidden;
  padding: 0.6rem;
  background: rgba(11, 16, 38, 0.88);
  border-radius: var(--radius-xs);
}

.ai-gen-form .form-group {
  margin-bottom: 0.75rem;
}

/* === 인라인 대체 유틸 클래스 === */

/* 빈 상태 카드 */
.stats-empty-card {
  padding: 2rem;
}

/* 빈 상태 일러스트 (메인) */
.stats-empty-illust {
  border-radius: 50%;
  margin-bottom: 1.25rem;
  opacity: 0.85;
}

/* 빈 상태 아이콘 (탭별) */
.stats-empty-icon {
  border-radius: 14px;
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

/* 빈 상태 제목 */
.stats-empty-title {
  color: var(--gold);
  margin-bottom: 0.75rem;
}

/* 빈 상태 설명 */
.stats-empty-desc {
  margin-bottom: 1.5rem;
}

/* 데이터 초기화 버튼 */
.stats-clear-btn {
  opacity: 0.6;
}

/* AI 리포트 섹션 */
.stats-report-desc {
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
}

.stats-report-period-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.stats-report-generate {
  width: 100%;
}

.stats-report-result {
  margin-top: 1rem;
}

/* 캔버스 반응형 */
.stats-canvas {
  width: 100%;
  height: auto;
}

/* 리포트 카드 간격 */
.report-card + .report-card {
  margin-top: 0.75rem;
}

.report-motivational.mt {
  margin-top: 0.75rem;
}

/* 리포트 섹션 색상 변형 */
.report-section-title--sage {
  color: var(--sage);
}

.report-section-title--gold {
  color: var(--gold);
}

/* 리포트 텍스트 */
.report-text {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--sand);
}

.report-text--sm {
  font-size: 0.88rem;
}

/* 이탈 방향 텍스트 */
.report-deviation {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--sand-dark);
}

/* PDF 빈 탭 시작 버튼 */
.stats-empty-action {
  margin-top: 0.75rem;
}

/* ══ 졸음감지 요약 카드 색상 ══ */
.drowsy-stat-warn .stats-number { color: var(--amber); }
.drowsy-stat-danger .stats-number { color: var(--rose); }

/* ══ 졸음감지 세션 리스트 ══ */
.drowsy-session-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.drowsy-session-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
}
.drowsy-session-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: rgba(255,255,255,0.03);
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--sand);
  transition: background 0.15s;
}
.drowsy-session-header:hover {
  background: rgba(244, 197, 66, 0.05);
}
.drowsy-session-header[aria-expanded="true"] {
  border-bottom: 1px solid var(--border);
}
.drowsy-session-header[aria-expanded="true"] .ds-arrow {
  transform: rotate(90deg);
}
.ds-header-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.ds-date {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--sand-dark);
  min-width: 80px;
}
.ds-dur {
  font-size: 0.8rem;
  color: var(--sand-muted);
}
.ds-end {
  font-size: 0.75rem;
  color: var(--sand-muted);
  opacity: 0.7;
}
.ds-header-badges {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex: 1;
  justify-content: flex-end;
}
.ds-arrow {
  font-size: 0.8rem;
  color: var(--sand-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

/* 뱃지 */
.ds-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.ds-badge-warn { background: rgba(240,160,48,0.15); color: var(--amber); }
.ds-badge-danger { background: rgba(232,93,117,0.15); color: var(--rose); }
.ds-badge-tab { background: rgba(91,155,213,0.15); color: #5b9bd5; }
.ds-badge-ok { background: rgba(123,198,126,0.15); color: var(--sage); }

/* 세션 바디 (펼침) */
.drowsy-session-body {
  padding: 0.75rem;
  animation: fadeIn 0.2s ease;
}

/* 상세 그리드 */
.ds-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.ds-detail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem;
  background: rgba(21, 32, 66, 0.85);
  border-radius: 4px;
}
.ds-detail-label {
  font-size: 0.7rem;
  color: var(--sand-muted);
}
.ds-detail-val {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--sand);
}
.ds-val-warn { color: var(--amber); }
.ds-val-danger { color: var(--rose); }

/* 이벤트 타임라인 */
.ds-evt-timeline {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}
.ds-evt-item {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.25rem 0;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.ds-evt-item:last-child { border-bottom: none; }
.ds-evt-time {
  font-family: monospace;
  font-size: 0.72rem;
  color: var(--sand-muted);
  flex-shrink: 0;
  min-width: 34px;
}
.ds-evt-icon {
  flex-shrink: 0;
  font-size: 0.75rem;
}
.ds-evt-label {
  font-weight: 700;
  font-size: 0.72rem;
  flex-shrink: 0;
  min-width: 30px;
}
.ds-evt-detail {
  color: var(--sand-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ds-evt-warn { color: var(--amber); }
.ds-evt-danger { color: var(--rose); }
.ds-evt-ok { color: var(--sage); }
.ds-evt-tab { color: #5b9bd5; }
.ds-evt-muted { color: var(--sand-muted); }
.ds-evt-empty {
  text-align: center;
  font-size: 0.78rem;
  color: var(--sand-muted);
  padding: 0.5rem 0;
}

/* 반응형 */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stats-number {
    font-size: 1.3rem;
  }

  .ds-header-top {
    flex-wrap: wrap;
  }
  .ds-detail-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* === 오답노트 + 복습 카드 (기록 탭 상단) === */
.stats-wrongnote-card {
  margin-bottom: 0.75rem;
}

.stats-wrongnote-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.stats-wrongnote-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stats-wrongnote-count {
  font-size: 0.78rem;
  color: var(--sand-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 0.15rem 0.45rem;
  border-radius: 8px;
}

.stats-wrongnote-actions {
  display: flex;
  gap: 0.4rem;
}

.sr-section {
  margin-top: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sr-section-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sage);
  margin-bottom: 0.4rem;
}

/* === 간격복습 현황 (기록 탭) === */
.sr-summary {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--sand-muted);
}

.sr-summary-item strong {
  color: var(--sage);
}

.sr-exam-item {
  margin-bottom: 0.3rem;
}

.sr-exam-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--sand-light);
  cursor: pointer;
  font-size: 0.84rem;
  transition: background 0.15s;
}

.sr-exam-header:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sr-exam-header.sr-no-toggle {
  cursor: default;
}

.sr-exam-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
}

.sr-exam-dday {
  font-size: 0.75rem;
  color: var(--sand-muted);
}

.sr-exam-dday.sr-near {
  color: var(--amber);
  font-weight: 600;
}

.sr-exam-dday.sr-urgent {
  color: var(--rose, #e74c6f);
  font-weight: 600;
}

.sr-arrow {
  font-size: 0.7rem;
  color: var(--sand-muted);
}

.sr-exam-detail {
  padding: 0.5rem 0.65rem 0.65rem;
  margin-top: -0.15rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.sr-progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.sr-progress-fill {
  height: 100%;
  background: var(--sage);
  border-radius: 3px;
  transition: width 0.3s;
}

.sr-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
  text-align: center;
}

.sr-stat-num {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--sand-light);
}

.sr-stat-num.sr-graduated {
  color: var(--sage);
}

.sr-stat-num.sr-pending {
  color: var(--amber);
}

.sr-stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--sand-muted);
}

/* === 단과학습 탭 === */
.stats-subject-summary {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-subject-summary-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
}

.stats-subject-name {
  font-weight: 600;
  color: var(--sand);
  min-width: 3rem;
}

.stats-subject-count {
  font-size: 0.82rem;
  color: var(--sand-dark);
}

.stats-subject-avg {
  font-size: 0.82rem;
  color: var(--gold);
  font-weight: 600;
  margin-left: auto;
}

.stats-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--sand);
  margin-bottom: 0.6rem;
}

.stats-session-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-session-card {
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.stats-session-card:last-child {
  border-bottom: none;
}

.stats-session-date {
  font-size: 0.72rem;
  color: var(--sand-muted);
  margin-bottom: 0.15rem;
}

.stats-session-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stats-session-mode {
  font-size: 0.85rem;
  color: var(--sand);
  font-weight: 600;
}

.stats-session-score {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
}

.stats-session-detail {
  font-size: 0.75rem;
  color: var(--sand-dark);
  margin-top: 0.1rem;
}

/* ══ 주간 학습량 차트 + 히트맵 ══ */
.stats-charts {
  margin-bottom: 0.75rem;
}

.stats-chart-card {
  padding: var(--card-padding);
  background: var(--night-card-70);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.stats-chart-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 0.75rem;
}

.stats-chart-wrap {
  position: relative;
  height: 200px;
}

/* 히트맵 */
.stats-heatmap {
  padding: 1rem;
  background: var(--night-card-70);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.heatmap-day-header {
  text-align: center;
  font-size: 0.65rem;
  color: var(--sand-muted);
  padding-bottom: 2px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
  min-width: 0;
}

.heatmap-cell.heatmap-empty {
  background: transparent;
}

.heatmap-cell.level-1 { background: rgba(244, 197, 66, 0.25); }
.heatmap-cell.level-2 { background: rgba(244, 197, 66, 0.5); }
.heatmap-cell.level-3 { background: var(--gold); }
.heatmap-cell.today {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--sand-muted);
}

.heatmap-level {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

/* Chart.js 로드 실패 시 대체 메시지 */
.stats-chart-fallback {
  text-align: center;
  padding: 1rem;
  color: var(--sand-muted);
  font-size: 0.82rem;
}
