/* ============================================
   Homework Page — Styles
   Luxury Minimal UI for Homework & AI Grading
   ============================================ */

/* Giao diện Quill phù hợp với hệ thống */
.hw-quill-wrapper {
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.hw-quill-wrapper .ql-toolbar {
  background: var(--bg-card);
  border-color: var(--card-border);
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
  padding: 4px 8px;
}
.hw-quill-wrapper .ql-container {
  border-color: var(--card-border);
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
}
.hw-quill-wrapper .ql-editor {
  min-height: 44px;
  padding: 8px 12px;
}
/* Tuỳ biến icon của Quill theo theme */
.hw-quill-wrapper .ql-snow .ql-stroke {
  stroke: var(--text-secondary);
}
.hw-quill-wrapper .ql-snow .ql-fill, 
.hw-quill-wrapper .ql-snow .ql-stroke.ql-fill {
  fill: var(--text-secondary);
}

/* Giao diện bài tập về nhà - Luxury Minimal */
.hw-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-alt);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid var(--card-border);
  transition: var(--t-fast);
}

.hw-card-row:hover {
  box-shadow: var(--card-shadow);
  transform: translateY(-1px);
  background: var(--bg-card);
}

.hw-card-row[hidden] {
  display: none !important;
}

.hw-deadline-editor {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--card-border);
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hw-deadline-editor label,
.hw-filter-label span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.hw-deadline-editor input,
.hw-list-toolbar input,
.hw-list-toolbar select {
  min-height: 38px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
}

.hw-deadline-editor input {
  padding: 7px 10px;
}

.hw-list-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.hw-search-box {
  display: flex;
  align-items: center;
  flex: 1 1 220px;
  min-width: 180px;
  position: relative;
}

.hw-search-box .material-symbols-rounded {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary);
  font-size: 19px;
  pointer-events: none;
}

.hw-search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
}

.hw-filter-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hw-filter-label select {
  padding: 7px 32px 7px 10px;
}

.hw-list-summary {
  margin-left: auto;
  padding-bottom: 8px;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
}

.stk-lesson:focus-visible,
.m-lesson-card:focus-visible,
.cal-event:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.stk-homework-active {
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
}

.stk-tag.pending {
  background: #fef3c7;
  color: #92400e;
}

/* Submission Badges - Semantic Colors */
.stk-tag.sub-good,
.m-lesson-status.sub-good {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
  font-weight: 600;
}

.stk-tag.sub-mid,
.m-lesson-status.sub-mid {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  font-weight: 600;
}

.stk-tag.sub-low,
.m-lesson-status.sub-low {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  font-weight: 600;
}

.hw-indicator-chip.link-active {
  cursor: pointer;
  transition: all var(--t-fast, 0.15s ease);
}

.hw-indicator-chip.link-active:hover {
  filter: brightness(0.92);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.m-lesson-card.homework-active,
.cal-event.homework-active {
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
}

.m-lesson-card.completed,
.cal-event.completed {
  opacity: 0.78;
}

.hw-attendance-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.hw-attendance-present {
  color: #166534;
  background: #dcfce7;
}

.hw-attendance-late {
  color: #92400e;
  background: #fef3c7;
}

.hw-attendance-absent {
  color: #991b1b;
  background: #fee2e2;
}

.hw-upload-zone {
  border: 2px dashed var(--accent-light);
  background: var(--accent-bg);
  border-radius: var(--radius-sm);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--t-fast);
}

.hw-upload-zone:hover {
  background: rgba(66, 133, 244, 0.1);
  border-color: var(--accent);
}

.hw-upload-icon {
  font-size: 32px;
  color: var(--accent);
  margin-bottom: 8px;
}

.hw-badge-score {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.hw-badge-score.high {
  background: var(--success-bg);
  color: var(--success-light);
}

.hw-badge-score.low {
  background: var(--danger-bg);
  color: var(--danger);
}

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

.rotating {
  animation: spin 1.2s linear infinite;
  display: inline-block;
}

@media (max-width: 768px) {
  .hw-card-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }

  .hw-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px !important;
  }

  .hw-time-input {
    flex: 1;
    min-width: 130px;
  }

  .hw-actions label {
    min-width: 80px;
  }

  .att-section-title {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }

  .att-section-title>div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .att-section-title>div:last-child button {
    flex: 1;
    justify-content: center;
    min-width: calc(50% - 8px);
  }

  .hw-deadline-editor {
    align-items: stretch;
  }

  .hw-deadline-editor input,
  .hw-deadline-editor button,
  .hw-filter-label,
  .hw-filter-label select {
    width: 100%;
  }

  .hw-list-summary {
    width: 100%;
    margin-left: 0;
    padding-bottom: 0;
  }
}

.hw-result-row {
  padding: 16px;
  margin-bottom: 0;
}

.hw-result-name {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.hw-result-actions {
  flex: 2;
  display: flex;
  gap: 8px;
  align-items: center;
}

.hw-result-score-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--card-border);
}

.hw-result-input {
  flex: 1;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  color: var(--text-secondary);
  font-size: 14px;
  min-width: 150px;
}

@media (max-width: 768px) {
  .hw-result-row {
    flex-direction: column;
    align-items: flex-start !important;
  }

  .hw-result-name,
  .hw-result-actions {
    flex: none;
    width: 100%;
  }

  .hw-result-actions {
    margin-top: 10px;
    flex-wrap: wrap;
  }

  .hw-mobile-header {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }

  .hw-image-modal-body {
    flex-direction: column !important;
  }

  #hw-image-edit-panel {
    width: 100% !important;
    border-left: none !important;
    border-top: 1px solid var(--card-border) !important;
    padding: 16px !important;
    flex-shrink: 0 !important;
    max-height: 50vh !important;
  }

  #hw-image-wrong-input {
    min-height: 100px !important;
  }
}

.hw-mobile-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: flex-start;
}

/* ===== CALENDAR MONTH VIEW ===== */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-card);
  min-width: 700px;
}

.cal-header-cell {
  padding: 10px 4px;
  text-align: center;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cal-header-cell:nth-child(7) {
  border-right: none;
}

.cal-cell {
  min-height: 100px;
  padding: 6px;
  border-right: 1px solid var(--card-border);
  border-bottom: 1px solid var(--card-border);
  background: var(--bg-card);
  transition: background var(--t-fast);
  display: flex;
  flex-direction: column;
}

.cal-cell:nth-child(7n) {
  border-right: none;
}

.cal-cell:hover {
  background: var(--bg-primary);
}

.cal-cell.out-of-month {
  background: var(--bg-void);
  opacity: 0.5;
}

.cal-cell.is-today {
  background: var(--accent-bg);
}

.cal-date {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  padding: 2px 4px;
}

.cal-cell.is-today .cal-date {
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  display: inline-block;
  padding: 2px 8px;
  width: fit-content;
}

.cal-cell.out-of-month .cal-date {
  color: var(--text-muted);
}

.cal-events {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.cal-event {
  padding: 4px 6px;
  border-radius: 5px;
  border-left: 3px solid #9ca3af;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.cal-event.cancelled {
  opacity: 0.5;
  text-decoration: line-through;
}

.cal-event-time {
  font-weight: 700;
  margin-right: 2px;
}

/* ===== MONTH VIEW — RESPONSIVE ===== */
@media (max-width: 768px) {
  .cal-grid {
    grid-template-columns: repeat(7, 1fr);
    font-size: 0.6rem;
  }

  .cal-cell {
    min-height: 60px;
    padding: 3px;
  }

  .cal-event {
    font-size: 0.55rem;
    padding: 2px 3px;
  }

  .cal-header-cell {
    font-size: 0.6rem;
    padding: 6px 2px;
  }
}

/* RESPONSIVE BẢNG ĐÁP ÁN (MOBILE ONLY, NO HORIZONTAL SCROLL) */
@media (max-width: 768px) {
  #hw-answer-key-table {
    min-width: 100% !important;
  }

  #hw-answer-key-table thead {
    display: none !important;
  }

  #hw-answer-key-table,
  #hw-answer-key-table tbody {
    display: block;
    width: 100%;
  }

  /* === HÀNG CHÍNH (tr.hw-row-main — 5 cột) === */
  #hw-answer-key-table tr.hw-row-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    margin-bottom: 0;
    border: 1px solid var(--card-border) !important;
    border-bottom: none !important;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: 12px;
    padding-right: 48px !important;
    background: var(--bg-card);
    box-shadow: none;
    position: relative;
    box-sizing: border-box;
  }

  #hw-answer-key-table tr.hw-row-main td {
    display: block;
    width: 100% !important;
    box-sizing: border-box;
  }

  /* Ẩn cột STT trên mobile */
  #hw-answer-key-table tr.hw-row-main td:nth-child(1) {
    display: none !important;
  }

  /* Câu (Dòng 1) */
  #hw-answer-key-table tr.hw-row-main td:nth-child(2) {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 !important;
    order: 1;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(2)::before {
    content: attr(data-stt) ". Câu:";
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    min-width: 65px;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(2) input {
    flex: 1;
    width: auto !important;
    padding: 8px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px;
    background: var(--bg-primary) !important;
  }

  /* Đáp án (Dòng 2) */
  #hw-answer-key-table tr.hw-row-main td:nth-child(4) {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 !important;
    order: 2;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(4)::before {
    content: "Đáp án:";
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    min-width: 65px;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(4) input {
    flex: 1;
    width: auto !important;
    padding: 8px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px;
    background: var(--bg-primary) !important;
  }

  /* Nút xóa */
  #hw-answer-key-table tr.hw-row-main td:nth-child(5) {
    width: 40px !important;
    padding: 0 !important;
    position: absolute;
    top: 16px;
    right: 4px;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(5) button {
    background: transparent !important;
    padding: 8px !important;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(5) button span {
    font-size: 24px !important;
  }

  /* Nội dung (Dòng 3) — full text, mở rộng qua vùng padding-right của nút xóa */
  #hw-answer-key-table tr.hw-row-main td:nth-child(3) {
    order: 3;
    padding: 0 !important;
    margin-top: 4px;
    margin-right: -36px;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(3)::before {
    content: "Nội dung:";
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    display: block;
    margin-bottom: 8px;
  }

  #hw-answer-key-table tr.hw-row-main td:nth-child(3) textarea {
    width: 100% !important;
    min-width: unset !important;
    min-height: unset !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px;
    background: var(--bg-primary) !important;
    padding: 12px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    resize: none !important;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* === HÀNG TÓM TẮT LỜI GIẢI (tr.hw-row-solution — 1 td colspan) === */
  #hw-answer-key-table tr.hw-row-solution {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    border: 1px solid var(--card-border) !important;
    border-top: none !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 0 12px 8px 12px !important;
    background: var(--bg-card);
    box-shadow: var(--card-shadow);
    box-sizing: border-box;
  }

  #hw-answer-key-table tr.hw-row-solution td {
    display: block;
    width: 100% !important;
    padding: 0 !important;
    box-sizing: border-box;
  }

  #hw-answer-key-table tr.hw-row-solution td > div {
    width: 100% !important;
    margin: 0 !important;
    padding: 4px 0 !important;
    box-sizing: border-box;
  }

  #hw-answer-key-table tr.hw-row-solution textarea {
    width: 100% !important;
    min-width: unset !important;
    box-sizing: border-box !important;
    word-break: break-word;
    overflow-wrap: break-word;
  }
}

/* ===== AI GRADING STATUS BADGES ===== */
.hw-ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
  line-height: 1.4;
}

.hw-ai-pending {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.hw-ai-processing {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
  animation: hwAiPulse 1.5s ease-in-out infinite;
}

.hw-ai-completed {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.hw-ai-failed {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.hw-ai-stale {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #f59e0b;
}

@keyframes hwAiPulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* ===== AI GRADING PROGRESS BAR & MODAL STYLING ===== */
.hw-progress-modal-content {
  width: 480px;
  max-width: 90vw;
  padding: 32px 24px;
  text-align: center;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
}

.hw-progress-bar-container {
  width: 100%;
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: hidden;
  margin: 16px 0 12px 0;
  border: 1px solid var(--card-border);
}

.hw-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 5px;
  transition: width 0.3s ease;
}

.hw-progress-percent {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

/* Modal Z-Index hierarchy */
#hw-modal-overlay { z-index: 10000; }
#hw-grading-progress-modal { z-index: 10001; }
#hw-image-modal-overlay { z-index: 10002; }
#hw-answer-key-modal { z-index: 10003; }
#hw-results-modal { z-index: 10004; }

/* ===== MATH FORMULA / KATEX LIVE PREVIEW & ANSWER KEY STYLING ===== */
.hw-math-preview {
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--accent-bg);
  border: 1px solid rgba(66, 133, 244, 0.2);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-primary);
  line-height: 1.75;
  word-break: break-word;
}

.hw-preview-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 10px;
  background: rgba(66, 133, 244, 0.1);
  color: var(--accent);
  font-weight: 600;
  border-radius: 6px;
}

.hw-solution-card {
  background: var(--bg-primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
}

.hw-solution-preview {
  margin-top: 8px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  line-height: 1.75;
}

.hw-key-dap-an {
  color: var(--accent) !important;
  font-weight: 700 !important;
}

/* ===== QUESTION CARD ARCHITECTURE (DESKTOP & MOBILE) ===== */
.hw-cards-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.hw-q-card {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: all 0.2s ease;
}

.hw-q-card:hover {
  border-color: var(--accent-light);
}

.hw-q-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--card-border);
}

.hw-q-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hw-q-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 4px 10px;
  border-radius: 6px;
}

.hw-q-cau-input {
  width: 100px !important;
  text-align: center;
  font-weight: 700;
  color: var(--text-primary);
  border: 1px solid var(--card-border);
  background: var(--bg-card);
  border-radius: 6px;
  padding: 6px 10px;
  outline: none;
}

.hw-q-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hw-q-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hw-q-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.hw-q-textarea,
.hw-result-wrong-textarea,
#hw-image-wrong-input {
  width: 100% !important;
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
  resize: none !important;
  overflow: hidden !important;
  min-height: 44px;
  line-height: 1.5 !important;
  box-sizing: border-box !important;
  word-break: break-word !important;
  white-space: pre-wrap !important;
  display: block !important;
}

.hw-q-textarea:focus,
.hw-result-wrong-textarea:focus,
#hw-image-wrong-input:focus {
  border-color: var(--accent);
  background: var(--bg-card);
}

.hw-q-dap-an-input {
  width: 180px !important;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  border-radius: 6px;
  padding: 8px 12px;
  outline: none;
}

/* ===== TWO-COLUMN HOMEWORK ANSWER EDITOR ===== */
.hw-answer-editor-modal {
  width: calc(100vw - 24px) !important;
  height: calc(100vh - 24px);
  max-width: none !important;
  max-height: none;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hw-answer-editor-header {
  flex: 0 0 auto;
  min-height: 64px;
  padding: 10px 16px !important;
}

.hw-answer-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.hw-answer-header-actions > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.hw-answer-header-actions .material-symbols-rounded {
  font-size: 18px;
}

.hw-answer-header-actions .modal-close {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.hw-answer-editor-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg-void);
  padding: 14px 16px !important;
}

.hw-answer-upload-panel {
  margin-bottom: 18px;
}

.hw-answer-editor-status {
  position: sticky;
  top: -14px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin: 0 0 10px;
  background: var(--bg-card);
  background: color-mix(in srgb, var(--bg-card) 94%, transparent);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
}

.hw-answer-editor-status > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

#hw-answer-question-count {
  color: var(--accent);
  background: var(--accent-bg);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

#hw-answer-validation-summary {
  font-size: 12px;
  color: var(--text-secondary);
}

.hw-answer-diagnostics {
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px solid #f59e0b;
  border-radius: var(--radius-sm);
  background: #fffbeb;
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
}

.hw-answer-diagnostics ul {
  margin: 5px 0 0;
  padding-left: 18px;
}

.hw-math-quick-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hw-math-toolbar-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.hw-math-toolbar-groups {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hw-math-btn-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-primary);
  padding: 3px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
}

.hw-math-tool-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 13px;
  font-family: 'KaTeX_Main', 'Cambria Math', 'Times New Roman', serif;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
  transition: all 0.15s ease;
  user-select: none;
}

.hw-math-tool-btn:hover {
  background: var(--accent-bg, #eff6ff);
  color: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
  transform: translateY(-1px);
}

.hw-math-tool-btn:active {
  transform: translateY(0);
}

.hw-math-tool-btn.hw-math-btn-featured {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent, #2563eb);
  font-weight: 700;
  border-color: rgba(37, 99, 235, 0.25);
}

.hw-math-tool-btn.hw-math-btn-featured:hover {
  background: var(--accent, #2563eb);
  color: #ffffff;
}

.hw-math-tool-btn.hw-math-btn-formula {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  font-weight: 700;
  border-color: rgba(16, 185, 129, 0.3);
}

.hw-math-tool-btn.hw-math-btn-formula:hover {
  background: #059669;
  color: #ffffff;
}

/* Syntax error helper badge inside code card */
.hw-syntax-warning-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 10px;
  background: #fffbeb;
  border-bottom: 1px solid #fef3c7;
  color: #b45309;
  font-size: 12px;
  font-weight: 600;
}

.hw-syntax-fix-btn {
  background: #f59e0b;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: background 0.15s ease;
}

.hw-syntax-fix-btn:hover {
  background: #d97706;
}

.hw-answer-column-headings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 0 8px 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hw-answer-pairs-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hw-answer-question-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  scroll-margin-top: 64px;
}

.hw-answer-code-card,
.hw-answer-preview-card {
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.hw-answer-question-pair.is-active .hw-answer-code-card,
.hw-answer-question-pair.is-active .hw-answer-preview-card {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg), var(--card-shadow);
}

.hw-answer-pair-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--card-border);
}

.hw-answer-pair-label {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  color: var(--accent);
  font-weight: 800;
}

.hw-answer-pair-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hw-answer-pair-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.hw-answer-pair-actions button {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
}

.hw-answer-pair-actions button:hover {
  background: var(--bg-secondary);
  color: var(--accent);
}

.hw-answer-pair-actions button[data-action="delete"]:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.hw-answer-code-editor {
  display: block;
  width: 100%;
  min-height: 270px;
  height: 100%;
  padding: 14px 16px;
  box-sizing: border-box;
  resize: none;
  overflow: hidden;
  border: 0;
  outline: 0;
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.hw-answer-code-editor:focus {
  background: var(--bg-primary);
}

.hw-answer-figure-refs {
  padding: 8px 16px 0;
  color: var(--accent);
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.hw-answer-preview-content {
  min-height: 270px;
  padding: 16px;
  color: var(--text-primary);
}

.hw-answer-preview-question {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 14px;
  white-space: pre-wrap;
}

.hw-answer-preview-section {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--card-border);
}

.hw-answer-preview-section > strong {
  display: block;
  margin-bottom: 5px;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
}

.hw-answer-preview-solution {
  border-left: 3px solid var(--accent);
}

.hw-answer-figures {
  border-left: 3px solid #8b5cf6;
}

.hw-answer-figure-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 6px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.hw-answer-source-figure {
  margin: 10px 0 0;
  padding: 8px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--bg-card);
}

.hw-answer-source-figure img {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: contain;
  border-radius: 5px;
  background: #fff;
}

.hw-answer-source-figure figcaption {
  margin-top: 6px;
  color: var(--text-tertiary);
  font-size: 11px;
  text-align: center;
}

.hw-answer-source-figure.is-error {
  min-height: 80px;
  border-color: var(--danger);
}

.hw-answer-question-pair.is-retrying {
  position: relative;
}

.hw-answer-retry-status {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}

.hw-answer-retry-spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid #bfdbfe;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: hw-answer-retry-spin 0.8s linear infinite;
}

@keyframes hw-answer-retry-spin {
  to { transform: rotate(360deg); }
}

.hw-answer-terminal-error {
  padding: 10px 12px;
  border-left: 4px solid #dc2626;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
}

.hw-answer-terminal-error ul {
  margin: 7px 0 0;
  padding-left: 20px;
}

@media (prefers-reduced-motion: reduce) {
  .hw-answer-retry-spinner { animation-duration: 1.8s; }
}

.hw-answer-outline-card {
  --outline-accent: #4f8df7;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--outline-accent) 30%, var(--card-border));
  border-left: 5px solid var(--outline-accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--outline-accent) 4%, var(--bg-card));
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.hw-answer-shared-stem-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--outline-accent) 6%, var(--bg-card));
  border: 1px dashed color-mix(in srgb, var(--outline-accent) 40%, var(--card-border));
}

.hw-answer-stem-header {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--outline-accent);
  font-size: 13px;
  font-weight: 700;
}

.hw-answer-stem-header .material-symbols-rounded {
  font-size: 18px;
}

.hw-answer-stem-preview-box {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
}

.hw-answer-outline-card.kind-chapter { --outline-accent: #7c3aed; }
.hw-answer-outline-card.kind-part { --outline-accent: #2563eb; }
.hw-answer-outline-card.kind-section,
.hw-answer-outline-card.kind-topic { --outline-accent: #0891b2; }
.hw-answer-outline-card.kind-question_group { --outline-accent: #059669; }
.hw-answer-outline-card.kind-subquestion_group { --outline-accent: #d97706; }

.hw-answer-outline-header {
  display: grid;
  grid-template-columns: 34px auto minmax(90px, 0.35fr) minmax(140px, 1fr);
  align-items: center;
  gap: 8px;
}

.hw-answer-outline-toggle {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--outline-accent) 12%, transparent);
  color: var(--outline-accent);
  cursor: pointer;
}

.hw-answer-outline-toggle .material-symbols-rounded { transition: transform 0.18s ease; }
.hw-answer-outline-card.is-collapsed > .hw-answer-outline-header .material-symbols-rounded {
  transform: rotate(-90deg);
}
.hw-answer-outline-card.is-collapsed > .hw-answer-outline-body,
.hw-answer-outline-card.is-collapsed > .hw-answer-outline-stem { display: none; }

.hw-answer-outline-kind {
  color: var(--outline-accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hw-answer-outline-label,
.hw-answer-outline-title,
.hw-answer-outline-stem {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
}

.hw-answer-outline-label,
.hw-answer-outline-title { padding: 7px 9px; font-weight: 750; }
.hw-answer-outline-title { font-weight: 600; }
.hw-answer-outline-stem {
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  resize: vertical;
  background: color-mix(in srgb, var(--outline-accent) 5%, var(--bg-card));
}
.hw-answer-outline-label:focus,
.hw-answer-outline-title:focus,
.hw-answer-outline-stem:focus {
  outline: none;
  border-color: var(--outline-accent);
  background: var(--bg-card);
}

.hw-answer-outline-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hw-answer-key-status {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #f59e0b;
}

.hw-answer-key-status[hidden] {
  display: none;
}

.hw-answer-key-status[data-status="approved"] {
  color: #065f46;
  background: #d1fae5;
  border-color: #10b981;
}

.hw-answer-table-wrap {
  max-width: 100%;
  margin-top: 10px;
  overflow-x: auto;
}

.hw-answer-ai-table {
  width: max-content;
  min-width: min(100%, 360px);
  border-collapse: collapse;
  background: #fff;
  color: #1f2937;
}

.hw-answer-ai-table th,
.hw-answer-ai-table td {
  min-width: 70px;
  padding: 7px 10px;
  border: 1px solid #64748b;
  vertical-align: middle;
}

.hw-answer-ai-table th {
  background: #f1f5f9;
  font-weight: 700;
}

.hw-answer-latex-table {
  max-width: 100%;
  margin-top: 10px;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
}

.hw-answer-conflict {
  margin-top: 10px;
  padding: 9px 11px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-size: 12px;
}

.hw-answer-conflict label {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 7px;
}

.hw-answer-empty-field {
  color: var(--text-tertiary);
  font-style: italic;
}

.hw-editable-formula {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 1px 2px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  vertical-align: middle;
  cursor: pointer;
}

.hw-editable-formula:hover,
.hw-editable-formula:focus-visible {
  border-color: var(--accent);
  background: var(--accent-bg);
  outline: none;
}

.hw-math-editor-overlay {
  display: none;
  z-index: 999999;
  padding: 40px 20px 330px;
  align-items: flex-start;
  justify-content: center;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
}

.hw-math-editor-dialog {
  width: min(1320px, calc(100vw - 32px));
  max-width: 1320px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 35px rgba(15, 23, 42, 0.28);
}

#math-editor-dialog {
  width: min(1320px, calc(100vw - 32px)) !important;
  max-width: 1320px !important;
}

.hw-math-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #e2e8f0;
}

.hw-math-editor-header > div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.hw-math-editor-header h3 {
  margin: 0;
  color: #0f172a;
  font-size: 17px;
}

.hw-math-editor-header .material-symbols-rounded {
  color: #2563eb;
}

.hw-math-editor-main {
  padding: 18px;
}

.hw-math-editor-row {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.hw-math-editor-field {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 2px solid #111827;
  border-radius: 9px;
  background: #fff;
  overflow: hidden;
}

#math-editor-field {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-height: 72px;
  padding: 4px 2px;
  border: 0;
  outline: 0;
  background: #fff;
  color: #0f172a;
  font-size: 32px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  --caret-color: #2563eb;
  --selection-background-color: #dbeafe;
}

#math-editor-field::part(menu-toggle),
#math-editor-field::part(virtual-keyboard-toggle) {
  display: none;
}

.math-editor-latex-fallback {
  display: none;
}

.math-editor-latex-fallback.is-visible {
  display: block;
  width: 100%;
  min-height: 58px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: 0;
  background: #f8fafc;
  color: #0f172a;
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 17px;
  font-weight: 600;
}

.hw-math-editor-insert {
  position: relative;
  z-index: 1;
  flex: 0 0 150px;
  min-width: 132px;
  min-height: 54px;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
}

.hw-math-keyboard-panel {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000000;
  padding: 12px 22px 18px;
  border-top: 1px solid #cbd5e1;
  background: #e2e8f0;
  box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.2);
}

#math-keyboard-panel.mathlive-replaced {
  display: none !important;
}

body.mathlive-formula-editor-open .ML__keyboard {
  z-index: 1000001 !important;
}

.hw-math-keyboard-toolbar,
.hw-math-keyboard-grids {
  width: min(1200px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.hw-math-keyboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hw-math-keyboard-tabs,
.hw-math-keyboard-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.hw-math-keyboard-tabs button,
.hw-math-keyboard-actions button,
.hw-math-keyboard-panel .math-key-btn {
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #334155;
  font-weight: 700;
  cursor: pointer;
}

.hw-math-keyboard-actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.hw-math-keyboard-actions .material-symbols-rounded {
  font-size: 17px;
}

.hw-math-keyboard-panel .math-key-grid {
  display: none;
  grid-template-columns: repeat(10, minmax(52px, 1fr));
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
}

.hw-math-keyboard-panel #math-grid-123 {
  display: grid;
}

.hw-math-keyboard-panel .math-key-btn {
  justify-content: center;
  min-height: 48px;
  padding: 5px;
  color: #0f172a;
  font-family: Georgia, serif;
  font-size: 17px;
}

.hw-math-keyboard-panel .math-key-btn:hover {
  border-color: #2563eb;
  background: #dbeafe;
}

.hw-grading-review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== GRADING ACCORDION & GROUPS ===== */
.hw-grading-accordion-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0;
}

.hw-grading-group {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--bg-card);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.hw-grading-group:hover {
  border-color: var(--accent-light, #93c5fd);
}

.hw-grading-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-secondary);
  border-bottom: 1px solid transparent;
  transition: background 0.15s ease;
}

.hw-grading-group-header:hover {
  background: var(--bg-hover, #f1f5f9);
}

.hw-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.hw-group-icon {
  font-size: 18px;
}

.hw-group-summary-labels {
  flex: 1;
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hw-group-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.2s ease, color 0.2s ease;
}

.hw-group-toggle-btn:hover {
  color: var(--accent);
  background: var(--bg-hover, #e2e8f0);
}

.hw-grading-group-body {
  padding: 10px 12px;
  border-top: 1px solid var(--card-border);
  background: var(--bg-primary);
}

/* Need Review Group */
.hw-grading-group-need-review {
  border-color: #fcd34d;
  background: #fffdf5;
}
.hw-grading-group-need-review .hw-grading-group-header {
  background: #fef3c7;
  color: #92400e;
  cursor: default;
}
.hw-grading-group-need-review .hw-group-icon {
  color: #d97706;
}

/* Correct Group */
.hw-grading-group-correct {
  border-color: #bbf7d0;
}
.hw-grading-group-correct .hw-grading-group-header {
  background: #f0fdf4;
  color: #166534;
}
.hw-grading-group-correct .hw-group-icon {
  color: #16a34a;
}

/* Incorrect Group */
.hw-grading-group-incorrect {
  border-color: #fecaca;
}
.hw-grading-group-incorrect .hw-grading-group-header {
  background: #fef2f2;
  color: #991b1b;
}
.hw-grading-group-incorrect .hw-group-icon {
  color: #dc2626;
}

/* Unreadable / Bad Handwriting Group */
.hw-grading-group-unreadable {
  border-color: #fed7aa;
}
.hw-grading-group-unreadable .hw-grading-group-header {
  background: #fff7ed;
  color: #9a3412;
}
.hw-grading-group-unreadable .hw-group-icon {
  color: #ea580c;
}

.hw-grading-summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #334155;
  font-size: 12px;
  line-height: 1.45;
}

.hw-grading-summary-row .is-warning {
  color: #92400e;
}

.hw-grading-summary-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
}

.hw-grading-review-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--text-tertiary);
  border-radius: 8px;
  background: var(--bg-primary);
}

.hw-grading-review-item.status-correct {
  border-left-color: var(--success);
}

.hw-grading-review-item.status-incorrect,
.hw-grading-review-item.status-blank {
  border-left-color: var(--danger);
}

.hw-grading-review-item.status-unreadable,
.hw-grading-review-item.status-ambiguous {
  border-left-color: #f59e0b;
}

.hw-grading-review-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 14px;
  min-width: 0;
  font-size: 13px;
}

.hw-grading-review-main strong {
  color: var(--accent);
}

.hw-grading-question,
.hw-grading-feedback {
  flex-basis: 100%;
  line-height: 1.5;
}

.hw-grading-feedback {
  color: var(--text-secondary);
  font-style: italic;
}

.hw-grading-review-item > label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.hw-grading-review-item select {
  padding: 6px 8px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ===== MOBILE RESPONSIVE FIX FOR ANSWER KEY MODAL ===== */
@media (max-width: 768px) {
  #hw-answer-key-modal {
    padding: 6px;
  }
  #hw-answer-key-modal .modal {
    width: calc(100vw - 12px) !important;
    height: calc(100vh - 12px) !important;
    max-height: none !important;
  }
  #hw-answer-key-modal .modal-body {
    padding: 14px !important;
    max-height: none !important;
  }
  .hw-answer-column-headings {
    display: none;
  }
  .hw-answer-editor-status {
    top: -14px;
    align-items: flex-start;
    flex-direction: column;
  }
  .hw-answer-editor-header {
    position: relative;
    min-height: 104px;
    align-items: stretch !important;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px !important;
  }
  .hw-answer-editor-header .modal-title {
    padding-right: 46px;
  }
  .hw-answer-header-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    padding-right: 0;
  }
  .hw-answer-header-actions > button:not(.modal-close) {
    width: 100%;
    min-width: 0;
    padding: 7px 5px;
    font-size: 12px;
  }
  .hw-answer-header-actions .modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
  }
  .hw-answer-question-pair {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .hw-answer-preview-card {
    order: 1;
  }
  .hw-answer-code-card {
    order: 2;
  }
  .hw-answer-preview-content,
  .hw-answer-code-editor {
    min-height: 220px;
  }
  .hw-answer-code-editor {
    font-size: 13px;
  }
  .hw-grading-review-item {
    grid-template-columns: 1fr;
  }
  .hw-grading-review-item > label {
    justify-content: space-between;
  }
  .hw-math-editor-overlay {
    padding: 12px 8px 360px;
  }
  .hw-math-editor-dialog {
    width: 100%;
    max-width: 100%;
  }
  .hw-math-editor-main {
    padding: 12px;
  }
  .hw-math-editor-row {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }
  .hw-math-editor-insert {
    flex-basis: auto;
    width: 100%;
    min-height: 44px;
  }
  #math-editor-field {
    min-height: 62px;
    font-size: 26px;
  }
  .hw-math-keyboard-panel {
    padding: 9px 8px 12px;
  }
  .hw-math-keyboard-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .hw-math-keyboard-tabs,
  .hw-math-keyboard-actions {
    width: 100%;
    overflow-x: auto;
  }
  .hw-math-keyboard-tabs button {
    flex: 1;
    min-width: 56px;
  }
  .hw-math-keyboard-actions button {
    flex: 1;
    justify-content: center;
  }
  .hw-math-keyboard-panel .math-key-grid {
    grid-template-columns: repeat(5, minmax(54px, 1fr));
    max-height: 190px;
  }
  .hw-math-keyboard-panel .math-key-btn {
    min-height: 44px;
  }
  #hw-answer-key-table {
    min-width: 100% !important;
  }
  #hw-answer-key-table thead {
    display: none !important;
  }
  #hw-answer-key-table tbody tr.hw-row-main {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    background: var(--bg-card) !important;
    padding: 12px !important;
    border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
    border: 1px solid var(--card-border) !important;
    border-bottom: none !important;
    margin-top: 14px !important;
    position: relative !important;
  }
  #hw-answer-key-table tbody tr.hw-row-main > td {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
  }
  #hw-answer-key-table tbody tr.hw-row-main > td:first-child {
    display: none !important;
  }
  #hw-answer-key-table tbody tr.hw-row-main > td[data-stt] {
    width: calc(100% - 46px) !important;
    margin-bottom: 4px !important;
  }
  #hw-answer-key-table tbody tr.hw-row-main > td:last-child {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    width: 36px !important;
    height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 10 !important;
  }
  #hw-answer-key-table tbody tr.hw-row-solution {
    display: block !important;
    background: var(--bg-card) !important;
    padding: 0 12px 12px 12px !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md) !important;
    border: 1px solid var(--card-border) !important;
    border-top: none !important;
    margin-bottom: 14px !important;
  }
  #hw-answer-key-table tbody tr.hw-row-solution > td {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
  }
}

/* ===== STUDENT RESULT CARD DESIGN (DESKTOP & MOBILE) ===== */
.hw-result-student-card {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 14px;
  transition: border-color 0.2s ease;
}

.hw-result-student-card:hover {
  border-color: var(--accent-light);
}

.hw-review-inbox {
  margin: 0 0 14px;
  padding: 13px 15px;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  background: #fffbeb;
  color: #78350f;
}

.hw-review-inbox-heading {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.hw-review-inbox-heading > .material-symbols-rounded { color: #d97706; }
.hw-review-inbox-heading strong { display: block; font-size: 14px; }
.hw-review-inbox-heading span:not(.material-symbols-rounded) { display: block; margin-top: 2px; font-size: 12px; color: #92400e; }
.hw-review-inbox-groups { display: grid; gap: 8px; margin-top: 10px; }
.hw-review-inbox-group { padding: 9px 10px; border-radius: 7px; background: rgba(255,255,255,.62); }
.hw-review-inbox-group strong { font-size: 12px; }
.hw-review-inbox-group strong span { display: inline-flex; min-width: 20px; justify-content: center; margin-left: 4px; padding: 1px 5px; border-radius: 99px; background: #fde68a; }
.hw-review-inbox-group p { margin: 4px 0 0; font-size: 12px; line-height: 1.45; color: #92400e; }

.hw-review-request {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #fffbeb;
  color: #78350f;
}

.hw-review-request > .material-symbols-rounded { color: #d97706; font-size: 20px; }
.hw-review-request strong { font-size: 13px; }
.hw-review-request p { margin: 2px 0 0; font-size: 12px; line-height: 1.45; color: #92400e; }

.hw-results-excluded {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #f59e0b;
  border-radius: var(--radius-md);
  background: #fffbeb;
  color: #78350f;
}

.hw-results-excluded[hidden] {
  display: none;
}

.hw-results-excluded-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hw-results-excluded-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
}

.hw-results-excluded-list {
  display: grid;
  gap: 7px;
}

.hw-results-excluded-item {
  display: grid;
  grid-template-columns: minmax(150px, 0.35fr) minmax(0, 1fr);
  gap: 12px;
  padding-top: 7px;
  border-top: 1px solid rgba(217, 119, 6, 0.22);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .hw-results-excluded-header,
  .hw-results-excluded-item {
    grid-template-columns: 1fr;
  }
  .hw-answer-outline-card {
    padding: 9px;
    gap: 9px;
    border-radius: 11px;
  }
  .hw-answer-outline-header {
    grid-template-columns: 30px auto minmax(0, 1fr);
  }
  .hw-answer-outline-title {
    grid-column: 3;
  }
  .hw-answer-outline-kind {
    font-size: 10px;
  }

  .hw-results-excluded-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

.hw-result-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--card-border);
  flex-wrap: wrap;
  gap: 10px;
}

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

.hw-result-stt {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hw-result-student-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.hw-score-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.hw-score-pill.score-excellent {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.hw-score-pill.score-good {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.hw-score-pill.score-average {
  background: rgba(245, 158, 11, 0.15);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.hw-score-pill.score-poor {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

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

.hw-card-review-btn {
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--accent);
  color: #ffffff;
  border: none;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  transition: all 0.15s ease;
}

.hw-card-review-btn:hover {
  background: var(--accent-hover, #1d4ed8);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.hw-result-score-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.hw-result-score-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.hw-result-score-input {
  width: 45px !important;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  border-radius: 4px;
  padding: 4px;
  outline: none;
}

.hw-result-score-total {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-tertiary);
}

/* Two-color progress bar */
.hw-student-progress-container {
  width: 100%;
  margin-top: 2px;
}

.hw-student-progress-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-primary);
  overflow: hidden;
  border: 1px solid var(--card-border);
}

.hw-progress-fill-correct {
  background: #10b981;
  height: 100%;
  transition: width 0.3s ease;
}

.hw-progress-fill-incorrect {
  background: #ef4444;
  height: 100%;
  transition: width 0.3s ease;
}

.hw-progress-fill-blank {
  background: #94a3b8;
  height: 100%;
  transition: width 0.3s ease;
}

.hw-result-card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hw-result-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hw-result-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.hw-result-card-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 4px;
}

@media (max-width: 768px) {
  .hw-result-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .hw-result-score-badge {
    width: 100%;
    justify-content: space-between;
  }
  .hw-result-card-footer {
    justify-content: stretch;
  }
  .hw-result-img-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================
   Homework Modal Tabs & Leaderboard
   ============================================ */
.hw-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 8px;
}

.hw-modal-tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: var(--t-fast);
}

.hw-modal-tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.hw-modal-tab-btn.active {
  border-color: var(--card-border);
  background: var(--bg-card);
  color: var(--accent);
}

.hw-leaderboard-summary-banner {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  box-shadow: var(--card-shadow);
}

.hw-summary-item {
  text-align: center;
}

.hw-summary-item-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.hw-summary-item-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.hw-summary-item-value.accent {
  color: var(--accent);
}

.hw-summary-item-value.danger {
  color: var(--danger);
}

.hw-summary-item-value.success {
  color: var(--success);
}

.hw-podium-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.hw-podium-card {
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--card-border);
}

.hw-podium-card.rank-1 {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.12), rgba(234, 179, 8, 0.03));
  border-color: #eab308;
}

.hw-podium-card.rank-2 {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.12), rgba(148, 163, 184, 0.03));
  border-color: #94a3b8;
}

.hw-podium-card.rank-3 {
  background: linear-gradient(135deg, rgba(217, 119, 6, 0.12), rgba(217, 119, 6, 0.03));
  border-color: #d97706;
}

.hw-podium-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.hw-podium-medal {
  font-size: 26px;
}

.hw-podium-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.06);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
}

.hw-podium-card.rank-1 .hw-podium-label { color: #eab308; }
.hw-podium-card.rank-2 .hw-podium-label { color: #94a3b8; }
.hw-podium-card.rank-3 .hw-podium-label { color: #d97706; }

.hw-podium-student-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.hw-podium-time {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.hw-podium-time .material-symbols-rounded {
  font-size: 14px;
  color: var(--accent);
}

.hw-podium-lead {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.hw-podium-score {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--success);
  background: rgba(5, 150, 105, 0.1);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  align-self: flex-start;
}

.hw-leaderboard-table-card {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.hw-leaderboard-table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hw-leaderboard-table-header h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hw-leaderboard-table-header h4 .material-symbols-rounded {
  color: var(--accent);
  font-size: 18px;
}

.hw-leaderboard-table-header span {
  font-size: 12px;
  color: var(--text-tertiary);
}

.hw-leaderboard-table-wrapper {
  overflow-x: auto;
}

.hw-leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.hw-leaderboard-table th {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--card-border);
  color: var(--text-secondary);
  font-weight: 600;
}

.hw-leaderboard-table th.col-center,
.hw-leaderboard-table td.col-center {
  text-align: center;
}

.hw-leaderboard-table th.col-rank {
  width: 90px;
  text-align: center;
}

.hw-leaderboard-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--card-border);
  transition: background var(--t-fast);
}

.hw-leaderboard-table tr:hover td {
  background: var(--bg-hover);
}

.hw-student-name-cell {
  font-weight: 600;
  color: var(--text-primary);
}

.hw-submit-time-cell {
  color: var(--text-secondary);
}

.hw-lead-time-cell {
  color: var(--text-tertiary);
  font-size: 12px;
}

.hw-score-tag {
  font-weight: 700;
  color: var(--success);
}

.hw-rank-tag {
  font-weight: 600;
}

.hw-rank-tag.rank-1 { color: #eab308; font-weight: 700; }
.hw-rank-tag.rank-2 { color: #94a3b8; font-weight: 700; }
.hw-rank-tag.rank-3 { color: #d97706; font-weight: 700; }
.hw-rank-tag.rank-other { color: var(--text-secondary); }

.hw-status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.hw-status-badge.submitted {
  background: rgba(5, 150, 105, 0.12);
  color: var(--success);
}

.hw-status-badge.unsubmitted {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.hw-answer-pair-actions button[data-action="resolve-single"]:hover {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.hw-answer-pair-actions button.is-loading .material-symbols-rounded {
  animation: hw-resolve-spin 0.8s linear infinite;
  color: #10b981;
}

@keyframes hw-resolve-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============================================================
   INTERACTIVE CROPPER STYLES
   ============================================================ */
.hw-crop-reselect-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(15, 23, 42, 0.85);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.hw-crop-reselect-btn:hover {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.4);
}

.hw-crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ffffff;
  border: 2px solid #0284c7;
  border-radius: 2px;
  box-sizing: border-box;
}

.hw-handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.hw-handle-n  { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.hw-handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.hw-handle-e  { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }
.hw-handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.hw-handle-s  { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.hw-handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.hw-handle-w  { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }

/* ===== HOMEWORK CALENDAR LESSON INDICATORS ===== */
.stk-lesson-indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 3px 0;
}

.hw-indicator-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 4px;
  line-height: 1.3;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.hw-indicator-chip .material-symbols-rounded {
  font-size: 12px;
}

.hw-indicator-chip.link-active {
  background: rgba(16, 185, 129, 0.16);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.hw-indicator-chip.has-key {
  background: rgba(59, 130, 246, 0.16);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.hw-month-indicators {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

.hw-month-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hw-month-icon .material-symbols-rounded {
  font-size: 13px;
}

.hw-month-icon.link-active {
  color: #059669;
}

.hw-month-icon.has-key {
  color: #2563eb;
}

/* ==========================================================================
   ERGONOMIC DUAL-PANE WORKSPACE FOR HOMEWORK REVIEW & IMAGE INSPECTION
   ========================================================================== */

/* Modal Workspace Shell */
.hw-workspace-modal {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-border);
}

/* Fixed Toolbar Header (Cố định ở trên đầu, 100% không che bài làm) */
.hw-image-fixed-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--card-border);
  z-index: 10;
  overflow-x: auto;
  scrollbar-width: thin;
}

:root:not([data-theme="dark"]) .hw-image-fixed-toolbar {
  background-color: #ffffff;
}

.hw-tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.hw-tb-sep {
  width: 1px;
  height: 18px;
  background: var(--card-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.hw-tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.hw-tb-btn .material-symbols-rounded {
  font-size: 16px;
}

.hw-tb-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.hw-tb-btn.active {
  background: var(--accent) !important;
  color: #ffffff !important;
  border-color: var(--accent) !important;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.hw-tb-btn.active-enhance {
  background: #f59e0b !important;
  color: #ffffff !important;
  border-color: #f59e0b !important;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

.hw-tb-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.hw-tb-btn-icon .material-symbols-rounded {
  font-size: 18px;
}

.hw-tb-btn-icon:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.hw-tb-zoom-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  user-select: none;
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
}

.hw-tb-zoom-text:hover {
  background: var(--bg-card);
  color: var(--accent);
}

.hw-tb-page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  max-width: 360px;
  scrollbar-width: thin;
  padding: 2px;
  flex-shrink: 1;
}

.hw-page-nav-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.hw-page-nav-badge:hover,
.hw-page-nav-badge.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* Splitter & Resize Controls */
.hw-workspace-splitter {
  width: 7px;
  background: var(--card-border);
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  user-select: none;
  z-index: 20;
}

.hw-workspace-splitter:hover,
.hw-workspace-splitter.is-dragging {
  background: var(--accent) !important;
}

.hw-splitter-handle {
  width: 3px;
  height: 36px;
  background: rgba(255, 255, 255, 0.45);
  border-radius: 2px;
  pointer-events: none;
}

:root:not([data-theme="dark"]) .hw-splitter-handle {
  background: rgba(0, 0, 0, 0.25);
}

body.is-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

.hw-ratio-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.hw-ratio-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.hw-ratio-btn.active {
  background: var(--accent) !important;
  color: #ffffff !important;
}

/* Canvas Container & Layouts */
.hw-images-canvas-container {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Continuous Vertical Layout: Auto-fit width to maximize readability */
.hw-images-canvas-container.hw-layout-continuous {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.hw-images-canvas-container.hw-layout-continuous .hw-img-page-wrapper {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hw-images-canvas-container.hw-layout-continuous .hw-img-element {
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--card-border);
}

/* Side-by-Side Dual Page Layout (Strict 2 Columns) */
.hw-images-canvas-container.hw-layout-sidebyside {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 16px !important;
  align-items: start !important;
  width: 100% !important;
}

.hw-images-canvas-container.hw-layout-sidebyside .hw-page-divider {
  display: none !important; /* Ẩn ranh giới phân cách khi đã xếp song song 2 cột */
}

.hw-images-canvas-container.hw-layout-sidebyside .hw-img-page-wrapper {
  width: 100% !important;
  max-width: 100% !important;
}

.hw-images-canvas-container.hw-layout-sidebyside .hw-img-element {
  width: 100% !important;
  max-width: 100% !important;
  max-height: 78vh !important;
  object-fit: contain !important;
}

.hw-img-page-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  transition: transform 0.2s ease;
}

.hw-img-element {
  max-width: 100%;
  max-height: 85vh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--card-border);
  transition: filter 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  background: var(--bg-card);
}

.hw-img-element.hw-img-enhanced {
  filter: contrast(135%) brightness(112%) drop-shadow(0 2px 8px rgba(0, 0, 0, 0.25));
}

/* Page Divider & Badge */
.hw-page-divider {
  width: 100%;
  max-width: 800px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
  position: relative;
}

.hw-page-divider::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--card-border), var(--accent), var(--card-border), transparent);
  opacity: 0.7;
}

.hw-page-divider-badge {
  position: relative;
  background: var(--bg-card);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--card-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.hw-page-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(6px);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 5px;
}

.hw-page-badge-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #ffffff;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
}

.hw-page-badge-btn:hover {
  background: var(--accent);
  transform: scale(1.1);
}

/* Question Filter Tabs */
.hw-review-filter-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-primary);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.hw-filter-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  white-space: nowrap;
}

.hw-filter-tab:hover {
  color: var(--text-primary);
}

.hw-filter-tab.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Fast Grading Review Item & Segmented Button Group */
.hw-grading-review-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--text-tertiary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s, transform 0.15s;
  cursor: pointer;
}

.hw-grading-review-item:hover {
  background: var(--bg-card);
  border-color: rgba(37, 99, 235, 0.3);
}

.hw-grading-review-item.is-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
  background: var(--bg-card);
}

.hw-grading-review-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.hw-page-tag-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  position: relative;
}

.hw-page-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.25);
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hw-page-tag:hover {
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
}

.hw-page-tag.hw-page-tag-unassigned {
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px dashed var(--card-border);
}

.hw-page-tag.hw-page-tag-unassigned:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}

.hw-page-tag-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
}

.hw-page-tag-edit-btn:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.hw-page-tag .material-symbols-rounded,
.hw-page-tag-edit-btn .material-symbols-rounded {
  font-size: 13px;
}

/* Page Assignment Popover Menu */
.hw-page-assign-popover {
  position: fixed;
  z-index: 10000;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  padding: 10px;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
}

.hw-page-assign-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.hw-page-assign-item-btn {
  padding: 5px 2px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid var(--card-border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
}

.hw-page-assign-item-btn:hover,
.hw-page-assign-item-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.hw-page-assign-quick-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(37, 99, 235, 0.3);
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s ease;
}

.hw-page-assign-quick-btn:hover {
  background: var(--accent);
  color: #ffffff;
}

/* Segmented Buttons for 1-Click Grading */
.hw-grading-btn-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
  margin-top: 4px;
}

.hw-grade-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.hw-grade-btn:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.hw-grade-btn.active-correct {
  background: #16a34a !important;
  color: #ffffff !important;
  border-color: #15803d !important;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35);
}

.hw-grade-btn.active-incorrect {
  background: #dc2626 !important;
  color: #ffffff !important;
  border-color: #b91c1c !important;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35);
}

.hw-grade-btn.active-blank {
  background: #64748b !important;
  color: #ffffff !important;
  border-color: #475569 !important;
}

.hw-grade-btn.active-unreadable {
  background: #d97706 !important;
  color: #ffffff !important;
  border-color: #b45309 !important;
  box-shadow: 0 2px 6px rgba(217, 119, 6, 0.35);
}

.hw-grade-btn.active-ambiguous {
  background: #9333ea !important;
  color: #ffffff !important;
  border-color: #7e22ce !important;
}

/* Modal Fullscreen state */
.hw-workspace-modal.is-fullscreen {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}
