/* ==========================================================================
   DIÁRIO DE CLASSE DIGITAL - SPREADSHEET TABLE CSS
   Tabela interativa inspirada no diário escolar oficial com cabeçalhos azul e verde,
   colunas congeladas, edição inline e visualização profissional
   ========================================================================== */

/* Card de Cabeçalho do Diário */
.diary-header-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  padding: 18px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px -4px rgba(15, 23, 42, 0.04);
  transition: all var(--transition-normal);
}

.diary-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.diary-title-container {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.diary-icon-badge {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.diary-main-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.diary-main-title h2 {
  font-size: 1.45rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
  margin: 0;
}

.diary-subject-tag {
  background: #eff6ff;
  color: var(--primary-700);
  border: 1px solid var(--primary-200);
  padding: 3px 12px;
  border-radius: var(--border-radius-full);
  font-size: 0.78rem;
  font-weight: 800;
}

.diary-meta-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.8rem;
  color: #475569;
}

.meta-chip.chip-highlight {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
  font-weight: 700;
}

.diary-container {
  background: #ffffff;
  border-radius: 18px;
  border: 1px solid rgba(226, 232, 240, 0.85);
  box-shadow: 0 4px 20px -4px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toolbar da Tabela */
.diary-toolbar {
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.diary-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.diary-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-group-actions,
.btn-group-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-strong);
  margin: 0 4px;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--slate-200);
  color: var(--slate-800);
  padding: 1px 6px;
  border-radius: var(--border-radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 2px;
}

.toolbar-filter-box {
  padding: 4px 10px;
}

/* Busca Rápida de Aluno */
.search-box {
  position: relative;
  min-width: 220px;
}

.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-400);
  font-size: 0.85rem;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-strong);
  font-size: 0.85rem;
  background: var(--slate-50);
  transition: all var(--transition-fast);
}

.search-box input:focus {
  background: #ffffff;
  border-color: var(--primary-500);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Legenda da Planilha */
.diary-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--border-light);
  font-size: 0.75rem;
  color: var(--slate-600);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.legend-badge {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
}

.legend-present { background: var(--emerald-100); color: var(--emerald-700); border: 1px solid var(--emerald-300); }
.legend-absent { background: var(--danger-100); color: var(--danger-700); border: 1px solid var(--danger-300); }
.legend-justified { background: var(--warning-100); color: var(--warning-800); border: 1px solid var(--warning-300); }

/* Wrapper com Scroll Horizontal */
.table-scroll-wrapper {
  position: relative;
  overflow-x: auto;
  max-width: 100%;
  background: #ffffff;
  scrollbar-width: thin;
  scrollbar-color: var(--slate-400) var(--slate-100);
}

.table-scroll-wrapper::-webkit-scrollbar {
  height: 9px;
}

.table-scroll-wrapper::-webkit-scrollbar-track {
  background: var(--slate-100);
}

.table-scroll-wrapper::-webkit-scrollbar-thumb {
  background-color: var(--slate-400);
  border-radius: 4px;
}

/* Estrutura Principal da Tabela */
.diary-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  text-align: center;
  font-family: inherit;
}

/* Estilos de Cabeçalhos Principais */
.diary-table thead tr:first-child th {
  padding: 10px 8px;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom: 2px solid rgba(0, 0, 0, 0.15);
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

/* Bloco AZUL - Identificação do Aluno */
.th-group-student {
  background: linear-gradient(180deg, #1e3a8a, #1d4ed8) !important;
  color: #ffffff !important;
}

/* Bloco AZUL - Controle de Atividades (Mesma cor da Identificação do Aluno) */
.th-group-attendance {
  background: linear-gradient(180deg, #1e3a8a, #1d4ed8) !important;
  color: #ffffff !important;
  border-left: 1px solid rgba(255, 255, 255, 0.25) !important;
}

/* Bloco AZUL REAL - Avaliações */
.th-group-evaluation {
  background: linear-gradient(180deg, #1e40af, #2563eb) !important;
  color: #ffffff !important;
  border-left: 1px solid rgba(255, 255, 255, 0.25) !important;
}

/* Bloco ÂMBAR - Recuperação */
.th-group-recovery {
  background: linear-gradient(180deg, #d97706, #b45309) !important;
  color: #ffffff !important;
  border-left: 1px solid rgba(255, 255, 255, 0.25) !important;
}

/* Bloco AZUL ESCURO / SLATE - Média Final */
.th-group-average {
  background: linear-gradient(180deg, #0f172a, #1e293b) !important;
  color: #ffffff !important;
  border-left: 1px solid rgba(255, 255, 255, 0.25) !important;
}

/* Sub-cabeçalhos (Segunda Linha de th) */
.diary-table thead tr:nth-child(2) th {
  padding: 8px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--slate-100);
  color: var(--slate-700);
  border-bottom: 2px solid var(--slate-300);
  border-right: 1px solid var(--border-light);
  white-space: nowrap;
  vertical-align: middle;
}

/* Colunas de Dias de Aula (Header) */
.th-day-column {
  min-width: 44px;
  max-width: 52px;
  background: #f0f7ff !important;
  color: #1e3a8a !important;
  border-right: 1px solid #dbeafe !important;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.th-day-column:hover {
  background: #e0f2fe !important;
}

.th-day-column.th-day-inactive,
.th-day-column.th-day-feriado {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border-right: 1px solid #fecaca !important;
}

.th-day-column.th-day-emenda {
  background: #f5f3ff !important;
  color: #5b21b6 !important;
  border-right: 1px solid #ddd6fe !important;
}

.th-day-column.th-day-inactive:hover,
.th-day-column.th-day-feriado:hover {
  background: #fee2e2 !important;
}

.th-day-column.th-day-emenda:hover {
  background: #ede9fe !important;
}

.badge-aula-1 {
  background: #2563eb !important;
  color: #ffffff !important;
  font-size: 0.58rem !important;
  font-weight: 700 !important;
  padding: 1px 4px !important;
  border-radius: 3px;
  display: inline-block;
  line-height: 1.1;
  margin-top: 2px;
}

.badge-aula-2 {
  background: #064e3b !important;
  color: #ffffff !important;
  font-size: 0.58rem !important;
  font-weight: 800 !important;
  padding: 1px 4px !important;
  border-radius: 3px;
  display: inline-block;
  line-height: 1.1;
  margin-top: 2px;
}

.badge-feriado {
  background: #ef4444 !important;
  color: #ffffff !important;
  font-size: 0.58rem !important;
  padding: 1px 4px !important;
  border-radius: 3px;
  display: inline-block;
  line-height: 1.1;
  margin-top: 2px;
}

.badge-emenda {
  background: #8b5cf6 !important;
  color: #ffffff !important;
  font-size: 0.58rem !important;
  padding: 1px 4px !important;
  border-radius: 3px;
  display: inline-block;
  line-height: 1.1;
  margin-top: 2px;
}

.cell-attendance-inactive {
  background-color: #f8fafc !important;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(0,0,0,0.03) 6px, rgba(0,0,0,0.03) 12px);
  color: #94a3b8 !important;
  text-align: center;
  user-select: none;
  font-weight: 700;
}

.th-day-date {
  font-weight: 700;
  display: block;
}

.th-day-weekday {
  font-size: 0.65rem;
  color: var(--emerald-700);
  display: block;
  text-transform: uppercase;
}

/* Colunas de Avaliações (Header) */
.th-activity-column {
  min-width: 100px;
  max-width: 140px;
  background: #f0fdfa !important;
  color: #134e4a !important;
  border-right: 1px solid #ccfbf1 !important;
  position: relative;
  padding: 6px 8px !important;
}

.th-activity-title {
  font-weight: 700;
  display: block;
  white-space: normal;
  line-height: 1.1;
  font-size: 0.75rem;
}

.th-activity-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 0.65rem;
  color: #0f766e;
}

.th-activity-actions {
  display: inline-flex;
  gap: 2px;
  margin-top: 3px;
}

.th-activity-action-btn {
  background: transparent;
  border: none;
  color: var(--slate-400);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px;
  border-radius: 2px;
}

.th-activity-action-btn:hover {
  color: var(--danger-600);
  background: rgba(0, 0, 0, 0.05);
}

/* --- COLUNAS CONGELADAS (STICKY) --- */
.sticky-col-num {
  position: sticky;
  left: 0;
  z-index: 20;
  width: 44px;
  min-width: 44px;
  background: inherit;
}

.sticky-col-name {
  position: sticky;
  left: 44px;
  z-index: 20;
  min-width: 240px;
  max-width: 280px;
  text-align: left !important;
  background: inherit;
  border-right: 2px solid var(--primary-300) !important;
}

.sticky-col-status {
  position: sticky;
  left: 284px;
  z-index: 20;
  width: 80px;
  min-width: 80px;
  background: inherit;
  border-right: 2px solid var(--slate-300) !important;
}

/* Z-Index maior para os headers fixos */
.diary-table thead .sticky-col-num,
.diary-table thead .sticky-col-name,
.diary-table thead .sticky-col-status {
  z-index: 30;
}

/* Linhas e Células do Corpo da Tabela */
.diary-table tbody tr {
  background: #ffffff;
  transition: background-color var(--transition-fast);
}

.diary-table tbody tr:nth-child(even) {
  background: #fbfcfe;
}

.diary-table tbody tr:hover {
  background: #f1f7ff !important;
}

.diary-table tbody tr.student-inactive {
  background: #f8fafc;
  opacity: 0.65;
}

.diary-table tbody td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  vertical-align: middle;
  height: 42px;
}

/* Células de Frequência */
.cell-attendance {
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  width: 44px;
  padding: 0 !important;
  position: relative;
}

.cell-attendance:hover {
  filter: brightness(0.95);
  transform: scale(1.08);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  z-index: 5;
}

.cell-attendance.status-p {
  background-color: #ecfdf5;
  color: #059669;
}

.cell-attendance.status-f {
  background-color: #fef2f2;
  color: #dc2626;
}

.cell-attendance.status-j {
  background-color: #fffbeb;
  color: #d97706;
}

.cell-attendance.status-empty {
  background-color: #ffffff;
  color: #cbd5e1;
  font-weight: 500;
}

.cell-attendance.status-empty:hover {
  background-color: #f8fafc;
  color: #94a3b8;
}

/* Mini Caixa Popover de Seleção de Frequência */
.attendance-popover {
  position: fixed;
  z-index: 9999;
  background: #ffffff;
  border-radius: var(--border-radius-md);
  box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-strong);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 185px;
  animation: popoverFadeIn 0.15s ease-out;
}

@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.attendance-popover-header {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px 4px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-option-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--border-radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-700);
  transition: all var(--transition-fast);
  text-align: left;
  width: 100%;
}

.popover-option-btn:hover {
  background: var(--slate-100);
}

.popover-option-btn.opt-presente:hover {
  background: #ecfdf5;
  color: #059669;
}

.popover-option-btn.opt-falta:hover {
  background: #fef2f2;
  color: #dc2626;
}

.popover-option-btn.opt-justificada:hover {
  background: #fffbeb;
  color: #d97706;
}

.popover-option-btn.opt-limpar:hover {
  background: var(--slate-100);
  color: var(--slate-600);
}

.popover-badge {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.popover-badge-p { background: var(--emerald-100); color: var(--emerald-700); border: 1px solid var(--emerald-300); }
.popover-badge-f { background: var(--danger-100); color: var(--danger-700); border: 1px solid var(--danger-300); }
.popover-badge-j { background: var(--warning-100); color: var(--warning-800); border: 1px solid var(--warning-300); }
.popover-badge-clear { background: var(--slate-100); color: var(--slate-500); border: 1px dashed var(--slate-400); }

/* Células de Notas Editáveis */
.cell-grade {
  padding: 2px !important;
  width: 90px;
}

.grade-input {
  width: 100%;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 4px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--slate-800);
  background: transparent;
  transition: all var(--transition-fast);
  font-family: 'Fira Code', 'Courier New', monospace;
}

.grade-input:hover {
  border-color: var(--slate-300);
  background: #ffffff;
}

.grade-input:focus {
  outline: none;
  border-color: var(--primary-500);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.grade-input.grade-high {
  color: var(--primary-700);
}

.grade-input.grade-low {
  color: var(--danger-600);
}

/* Célula de Média Final */
.cell-final-average {
  font-size: 0.95rem;
  font-weight: 800;
  font-family: 'Fira Code', 'Courier New', monospace;
  width: 80px;
  background: inherit;
  text-align: center;
}

.final-average-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  background: transparent !important;
  border: none !important;
  border-radius: 6px;
  min-width: 44px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.average-satisfactory {
  background: transparent !important;
  color: var(--text-primary) !important;
  border: none !important;
}

.average-unsatisfactory {
  background: transparent !important;
  color: var(--text-primary) !important;
  border: none !important;
}

.average-empty {
  color: var(--text-muted) !important;
}

/* Linha de Rodapé / Estatísticas da Tabela */
.diary-table tfoot tr {
  background: var(--slate-100);
  font-weight: 700;
  border-top: 2px solid var(--slate-300);
}

.diary-table tfoot td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border-light);
  font-size: 0.8rem;
}

.tfoot-label {
  text-align: right !important;
  padding-right: 12px !important;
  color: var(--slate-700);
}

/* Nome do Aluno e Ações Inline */
.student-name-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 8px;
}

.student-name-text {
  font-weight: 600;
  color: var(--slate-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-actions-menu {
  opacity: 0;
  transition: opacity var(--transition-fast);
  display: flex;
  gap: 4px;
}

.diary-table tbody tr:hover .student-actions-menu {
  opacity: 1;
}

/* Responsividade da Tabela */
@media (max-width: 768px) {
  .sticky-col-name {
    min-width: 180px;
    max-width: 180px;
  }
}
