/* =========================================================
   Performance History page — history.html
   ========================================================= */

/* Config panel */
.hist-config {
  display: grid;
  gap: 18px;
}

.hist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

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

.hist-field label {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.hist-exams-note {
  margin: 0;
  padding-top: 4px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-secondary);
}
.hist-exams-note strong {
  color: var(--text-primary);
}

.hist-field-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.hist-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hist-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
  min-height: 1.4em;
}

/* Progress panel */
.progress-panel {
  margin-top: 20px;
}

.progress-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  margin-bottom: 12px;
}

.progress-head .ph-circle-notch {
  color: var(--accent);
  animation: spin 1s linear infinite;
}

.hist-progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.hist-progress-list::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.hist-progress-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  font-size: 0.9rem;
}

.hp-status {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
}

.hp-status.fetching {
  color: var(--accent);
  animation: spin 1s linear infinite;
}

.hp-status.done {
  color: var(--success);
}

.hp-status.error {
  color: var(--error);
}

.hp-label {
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hp-msg {
  color: var(--text-secondary);
  font-size: 0.85em;
  margin-left: auto;
  flex-shrink: 0;
}

/* Results */
.hist-student {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}

.hist-student .summary-avatar {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.hist-student-name {
  font-size: 1.3rem;
  font-weight: 800;
}

.hist-student-meta {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 16px;
}

.results-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* Allow chart cards & canvases to shrink inside the grid (fixes mobile overflow). */
.chart-card,
.chart-wrap {
  min-width: 0;
}

.chart-wrap canvas {
  max-width: 100%;
}

.chart-card {
  /* Frosted glass — translucent surface + backdrop blur + glossy sheen (light). */
  --glass-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0.18) 40%, rgba(255, 255, 255, 0.04) 100%), rgba(248, 250, 252, 0.5);
  --glass-border: rgba(148, 163, 184, 0.32);
  --glass-shadow: 0 12px 32px -18px rgba(15, 23, 42, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  padding: 20px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  box-shadow: var(--glass-shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

[data-theme="dark"] .chart-card {
  --glass-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 45%, transparent 100%), rgba(22, 27, 36, 0.48);
  --glass-border: rgba(148, 163, 184, 0.18);
  --glass-shadow: 0 12px 32px -18px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.chart-card:hover {
  border-color: rgba(148, 163, 184, 0.55);
  box-shadow: 0 18px 44px -20px rgba(15, 23, 42, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .chart-card:hover {
  border-color: rgba(148, 163, 184, 0.35);
  box-shadow: 0 18px 44px -20px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* No backdrop-filter support → fall back to a readable, near-opaque surface. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .chart-card {
    background: var(--surface-2);
  }
}

.chart-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-card h3 i {
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
}

.chart-card .chart-sub {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

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

.chart-wrap.tall {
  height: 380px;
}

/* History table */
.hist-table-wrap {
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin-top: 8px;
}

.hist-table-wrap::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.hist-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.hist-table th {
  text-align: left;
  padding: 10px 14px;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.hist-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

.hist-table tbody tr:hover {
  background: var(--surface-2);
}

.hist-table td.num {
  font-variant-numeric: tabular-nums;
}

.hist-table td.exam {
  font-weight: 700;
}

/* "View report card" link-button in the exam history table */
.hist-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
}

.hist-view-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.hist-view-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hist-view-btn i {
  font-size: 0.95em;
  line-height: 1;
}

/* Subject breakdown */
.breakdown-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0 12px;
}

.breakdown-row h3 {
  margin: 0;
  font-size: 1rem;
}

.breakdown-row select {
  margin-left: auto;
}

.subject-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.subject-table th {
  text-align: left;
  padding: 10px 14px;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.subject-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.subject-table td.sub-name {
  min-width: 200px;
  white-space: normal;
  font-weight: 700;
}

.subject-table td.num {
  font-variant-numeric: tabular-nums;
}

/* Empty / error states */
.hist-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.hist-empty i {
  font-size: 2.4rem;
  color: var(--accent);
}

.hist-empty ul {
  text-align: left;
  margin: 4px 0 0;
}

@media (max-width: 900px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .chart-card {
    padding: 16px;
  }

  /* Stat card labels wrap instead of ellipsizing on narrow screens. */
  .compare-stat {
    padding: 12px;
  }

  .compare-stat-top {
    gap: 6px;
  }

  .compare-stat-icon {
    width: 26px;
    height: 26px;
    font-size: 0.95rem;
  }

  .compare-stat-label {
    white-space: normal;
    letter-spacing: 0.01em;
    font-size: 0.66rem;
    line-height: 1.3;
  }

  /* A bit more room for the per-subject horizontal bars on mobile. */
  .chart-wrap.tall {
    height: 440px;
  }

  /* Breakdown rows stack and their selects go full-width on mobile. */
  .breakdown-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .breakdown-row select {
    margin-left: 0;
    width: 100%;
  }

  .hist-student .summary-avatar {
    width: 48px;
    height: 48px;
  }

  .hist-student-name {
    font-size: 1.1rem;
  }
}
