:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #0ea5e9;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #374151; /* Darker gray (Gray 700) for better contrast on pastel backgrounds */
  --border-color: #e2e8f0;
  --hl-color: #f1f5f9;
--pd-color: #bae6fd;
  --el-color: #d1fae5;
  --mtf-color: #ffedd5;
  --edit-bg: #fffef2;
  --bg-header: rgba(248, 250, 252, 0.9);
  --bg-sticky-col: #f1f5f9;
  --header-height: 41px;
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --table-zoom: 1;
}

/* Controle de Zoom Flutuante */
.zoom-controls {
  position: fixed;
  top: 15px;
  right: 20px;
  z-index: 10005; /* Acima de outros elementos e modais */
  background: var(--bg-header);
  backdrop-filter: blur(12px) saturate(180%);
  padding: 6px 12px;
  border-radius: 50px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls .btn {
  padding: 2px 10px;
  height: 30px;
  justify-content: center;
  background: var(--bg-card);
  color: var(--text-main);
}

.dark-theme {
  --bg-main: #020617;
  --bg-card: #0f172a;
  --bg-header: rgba(30, 41, 59, 0.9);
  --bg-sticky-col: #1e293b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #475569;
  --hl-color: #334155;
  --pd-color: #1e40af;
  --el-color: #065f46;
  --mtf-color: #92400e;
  --edit-bg: #1e293b;
}

/* Wrapper para a área superior que ficará fixa */
.top-area-sticky-wrapper {
  position: sticky;
  top: 0;
  z-index: 1000; /* Garante que fique acima de outros conteúdos */
  background-color: var(--bg-main); /* Para cobrir o conteúdo que rola por baixo */
  padding-top: 20px; /* Padding superior original do body */
  padding-left: 20px; /* Padding lateral original do body */
  padding-right: 20px; /* Padding lateral original do body */
  padding-bottom: 16px; /* Espaçamento abaixo da toolbar */
  box-sizing: border-box;
  width: 100vw; /* Garante que não ultrapasse a largura da janela */
  max-width: 100%;
  border-bottom: 1px solid var(--border-color); /* Borda sutil para separar do conteúdo */
  overflow-x: hidden; /* Evita que o wrapper cause scroll horizontal na página */
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  /* O padding superior e lateral agora é tratado pelo .top-area-sticky-wrapper */
  /* O padding inferior é mantido para não cobrir a tabela com a barra de status */
  padding-top: 0;
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 60px;
  line-height: 1.6;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 5px 20px; /* Adiciona padding lateral para alinhar com o resto do conteúdo */
  border-bottom: none; /* A borda agora é no wrapper sticky */
  flex-wrap: wrap; /* Permite que título e logo quebrem linha se necessário em telas minúsculas */
  gap: 10px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.header-titles h1 {
  font-size: 1.25rem;
  color: var(--text-main);
  letter-spacing: -0.025em;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-titles p {
  color: var(--text-muted);
  margin: 2px 0 0 0;
  font-size: 0.85rem;
}

.legend-title {
  margin-right: 8px;
  color: var(--text-muted);
}

.legend {
  margin-bottom: 12px; /* Mantém o espaçamento interno */
  font-size: 0.9em;
  flex-wrap: wrap;
  display: flex; /* Adicionado para garantir o layout flex */
  gap: 12px; /* Adicionado para garantir o layout flex */
}

.table-container {
  width: 100%;
  overflow-x: auto;
  padding-top: 15px; /* Padding reduzido, pois não temos mais badge flutuante */
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  display: block; /* Garante comportamento de bloco */
  font-size: calc(1rem * var(--table-zoom));
  scroll-behavior: smooth;
}

/* --- Modo Compacto: Ajusta o padding do wrapper sticky --- */
body.compact-mode .top-area-sticky-wrapper {
  padding-top: 10px;
}

/* O padding inferior do body.compact-mode é herdado do body principal */


body.compact-mode th, 
body.compact-mode td {
  padding: 4px 2px;
  font-size: 0.85em;
}
body.compact-mode .table-container {
  margin-bottom: 16px;
} /* Mantém o margin-bottom do container da tabela */

#schedule-wrapper, 
div[id^="section-"] {
  width: 100%;
  display: block;
}

/* Garante que na impressão ou em telas grandes, as seções mantenham integridade */
div[id^="section-"] {
  margin-bottom: 40px;
  page-break-inside: avoid;
  break-inside: avoid;
  padding: 0 20px; /* Adiciona padding horizontal para alinhar com o cabeçalho fixo */
}

table {
  width: 100%;
  table-layout: fixed; /* Força as colunas a se expandirem para preencher 100% da tela */
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1250px; /* Mantém a rolagem horizontal em telas muito pequenas */
  border-radius: 16px;
  overflow: hidden; /* Esconder bordas que ultrapassam o radius */
}

th, td {
  padding: 10px 6px;
  text-align: center;
  vertical-align: top;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  min-width: 45px; /* Define um tamanho base igual para todas as colunas de dados */
  line-height: 1.4; /* Melhora a legibilidade e o respiro do texto */
}

/* Remover borda direita da última coluna */
th:last-of-type, td:last-of-type { border-right: none; }

/* Borda inferior da última linha */
tr:last-child th, tr:last-child td { border-bottom: none; }

/* Fixar a primeira coluna (Horário) */
th:first-child, tr:not(.recreio) td:first-child {
  position: sticky;
  left: 0;
  z-index: 20;
  background-color: var(--bg-sticky-col);
  border-right: 1px solid var(--border-color);
  font-weight: 700;
  color: var(--text-main);
  width: calc(145px * var(--table-zoom));
  min-width: calc(145px * var(--table-zoom));
  font-size: 0.95em;
  padding-left: 4px;
  padding-right: 4px;
  white-space: nowrap;
  box-shadow: 4px 0 8px -4px rgba(0,0,0,0.1); /* Sombra para indicar profundidade na rolagem */
}

/* New CSS for centering the table when a single day is selected */
.table-container.single-day-active table {
  width: auto; /* Allow table to shrink to content */
  table-layout: fixed; /* Keep fixed to respect defined widths */
  min-width: unset; /* Remove minimum width constraint */
  margin: 0 auto; /* Center the table itself within the container */
}

/* Estilo base para cabeçalhos */
thead th, 
th {
  background-color: var(--bg-header);
  backdrop-filter: blur(8px);
  font-weight: 700;
  font-size: 0.9em;
  text-transform: uppercase;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 25;
  border-bottom: 2px solid var(--border-color);
  transition: all 0.3s ease;
}

/* Ajuste para cabeçalho duplo sticky */
tr:nth-child(1) th { top: 0; z-index: 31; } 
tr:nth-child(2) th { top: var(--header-height); z-index: 30; }
tr:nth-child(1) th:first-child { z-index: 40; } /* Canto superior esquerdo */

/* Zebra Striping para facilitar o acompanhamento da linha */
tr:nth-child(even) td:not(:first-child) {
  background-color: rgba(0, 0, 0, 0.015);
}

.dark-theme tr:nth-child(even) td:not(:first-child) {
  background-color: rgba(255, 255, 255, 0.02);
}

tr:hover td {
  background-color: var(--hl-color);
}

/* Efeito de destaque na linha quando uma célula está focada */
tr.row-highlight {
  background-color: rgba(79, 70, 229, 0.04) !important;
  transition: background-color 0.2s ease;
}
/* Destaque na coluna do cabeçalho */
.col-highlight {
  background-color: var(--hl-color);
  filter: brightness(0.98);
}
td[contenteditable="true"], td[role="textbox"] {
  background-color: var(--edit-bg);
  transition: background 0.2s ease, outline 0.2s ease; /* Transição para foco e background */
}

/* Destaque para células com o mesmo conteúdo */
.match-highlight {
  outline: 3px solid var(--primary) !important;
  outline-offset: -3px;
  z-index: 5;
}

/* Destaque para seleção via legenda */
.category-select {
  box-shadow: inset 0 0 0 3px var(--primary) !important;
  transition: none; /* Remove a transição que pode causar oscilação visual ao filtrar */
}

/* Classe para ocultar colunas durante a filtragem */
.hidden-col {
  display: none !important;
}

.day-filter-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 2px solid var(--border-color);
  padding-left: 16px;
  padding-left: 8px;
}

.day-filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 0.9rem;
  background-color: var(--bg-card);
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.day-filter-select:hover {
  border-color: var(--primary);
}
.day-filter-select:focus {
  border-color: var(--primary);
}

/* A classe .hidden-col já está definida acima no seu CSS */

/* Exibe o nome do professor regente dentro da célula se houver mapeamento */
td[data-teacher]::after {
  content: attr(data-teacher);
  display: block;
  font-size: 0.85em;
  color: var(--text-muted);
  font-weight: 600; /* Negrito para destaque */
  margin-top: 4px;
  white-space: nowrap; /* Impede que o nome do professor quebre a linha e aumente a célula */
  overflow: hidden;
  text-overflow: ellipsis; /* Se o nome for longo demais para a coluna, ele encurta com "..." */
  pointer-events: none; /* Garante que não atrapalhe o clique/edição */
}

td[role="textbox"]:focus {
  background-color: #fff;
  outline: 2px solid var(--primary);
}

/* Divisória entre os Dias */
table tr th.day-divider,
table tr td.day-divider {
  border-right: 2px solid rgba(0, 0, 0, 0.15);
}

.dark-theme table tr th.day-divider,
.dark-theme table tr td.day-divider {
  border-right: 2px solid rgba(255, 255, 255, 0.2);
}

/* Identificação de Dias por Cores - Cabeçalhos */
.day-header-1 { background-color: #0369a1; color: white; } 
.day-header-2 { background-color: #15803d; color: white; } 
.day-header-3 { background-color: #581c87; color: white; } 
.day-header-4 { background-color: #c2410c; color: white; } 
.day-header-5 { background-color: #be185d; color: white; } 

/* Identificação de Dias por Cores - Colunas (Fundo Sutil) */
.day-cell-1 { background-color: rgba(3, 105, 161, 0.02); }
.day-cell-2 { background-color: rgba(21, 128, 61, 0.02); }
.day-cell-3 { background-color: rgba(88, 28, 135, 0.02); }
.day-cell-4 { background-color: rgba(194, 65, 12, 0.02); }
.day-cell-5 { background-color: rgba(190, 24, 93, 0.02); }

/* Ajuste para o Tema Escuro */
.dark-theme .day-cell-1 { background-color: rgba(3, 105, 161, 0.1) !important; }
.dark-theme .day-cell-2 { background-color: rgba(21, 128, 61, 0.1) !important; }
.dark-theme .day-cell-3 { background-color: rgba(88, 28, 135, 0.15) !important; }
.dark-theme .day-cell-4 { background-color: rgba(194, 65, 12, 0.1) !important; }
.dark-theme .day-cell-5 { background-color: rgba(190, 24, 93, 0.1) !important; }

/* Estilo para células em modo leitura */
body.readonly td[role="textbox"]:hover {
  background-color: var(--bg-main); /* Remove o hover em modo leitura */
}

/* Modo leitura - desativa o cursor de texto */
body.readonly td[role="textbox"] {
  cursor: default;
  background-color: var(--bg-card) !important;
}

/* Feedback visual para o botão de trava */
body.readonly #lock-btn {
  background-color: #64748b;
  color: white;
  opacity: 0.9;
}
body:not(.readonly) #lock-btn { background-color: #ef4444; color: white; }

/* Estilo para conflitos de horário */
.conflict-error {
  background-color: #fef2f2;
  box-shadow: inset 0 0 0 2px #f87171;
  color: #991b1b;
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
  cursor: help;
}

.conflict-error:hover {
  filter: brightness(1.05);
  background-color: #fee2e2;
  box-shadow: inset 0 0 0 3px #ef4444;
}

@keyframes shake { 10%, 90% { transform: translate3d(-1px, 0, 0); } 20%, 80% { transform: translate3d(2px, 0, 0); } }

/* Cores de Categoria com maior especificidade para evitar !important */
table tr td.hl, table tr th.hl { background-color: var(--hl-color); }
table tr td.pd, table tr th.pd { background-color: var(--pd-color); }
table tr td.el, table tr th.el { background-color: var(--el-color); }
table tr td.mtf, table tr th.mtf { background-color: var(--mtf-color); }

/* Ajuste de zebra stripe para não sobrepor cores de categoria */
tr:nth-child(even) td.pd, 
tr:nth-child(even) td.el, 
tr:nth-child(even) td.mtf,
tr:nth-child(even) td.hl {
  filter: brightness(0.97);
}

.recreio {
  background: linear-gradient(to bottom, var(--bg-header), var(--bg-main));
  color: var(--text-muted);
  font-weight: bold;
  text-align: center;
  font-size: 0.9em;
  letter-spacing: 0.05em;
}

.recreio td {
  border-right: none !important;
  width: 100%;
}

/* Destaque para células de dados e horários atuais */
table tr td.current-active:not(:first-child) {
  background-color: #fffbeb !important;
  box-shadow: inset 0 0 0 2px #f59e0b, 0 0 15px rgba(245, 158, 11, 0.2);
  position: relative;
  z-index: 2;
  font-weight: 700;
  color: #92400e; 
  animation: current-pulse 4s infinite ease-in-out;
}

.dark-theme table tr td.current-active:not(:first-child) {
  background-color: rgba(245, 158, 11, 0.15) !important;
  color: #fbbf24;
  box-shadow: inset 0 0 0 2px #f59e0b;
}

@keyframes current-pulse {
  0%, 100% { background-color: #fffbeb; }
  50% { background-color: #fef3c7; }
}
.dark-theme @keyframes current-pulse {
  0%, 100% { background-color: rgba(245, 158, 11, 0.15); }
  50% { background-color: rgba(245, 158, 11, 0.25); }
}

td.current-active::after { display: none; } /* Removido em favor da animação de fundo */

@keyframes pulse-border {
  0% { box-shadow: inset 0 0 0 0 rgba(79, 70, 229, 0.4); }
  70% { box-shadow: inset 0 0 0 4px rgba(79, 70, 229, 0); }
  100% { box-shadow: inset 0 0 0 0 rgba(79, 70, 229, 0); }
}

/* Destaque para os cabeçalhos de dia (TH) atuais */
table tr th.current-active {
  background-color: var(--primary) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  border-bottom: 4px solid var(--accent);
  z-index: 45;
  position: relative;
}

th.current-active::before {
  content: '⭐'; /* Estrela indicando o dia atual */
  margin-right: 8px;
  display: inline-block;
  animation: bounce-pin 1s ease infinite;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2));
}

/* Seta removida pois agora o emoji está alinhado ao texto */
th.current-active::after {
  display: none;
}

@keyframes bounce-pin {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Destaque sutil para a linha inteira do horário atual */
table tr.current-active {
  background-color: rgba(79, 70, 229, 0.08) !important; 
  position: relative;
  /* Cria uma borda superior e inferior na linha inteira */
  box-shadow: inset 0 2px 0 0 var(--primary), inset 0 -2px 0 0 var(--primary);
}

/* Destaque para a COLUNA inteira do dia atual */
table.current-day-1 .day-cell-1,
table.current-day-2 .day-cell-2,
table.current-day-3 .day-cell-3,
table.current-day-4 .day-cell-4,
table.current-day-5 .day-cell-5 {
  background-color: rgba(79, 70, 229, 0.03);
  border-left: 1px solid rgba(79, 70, 229, 0.1);
  border-right: 1px solid rgba(79, 70, 229, 0.1);
}
.dark-theme table.current-day-1 .day-cell-1,
.dark-theme table.current-day-2 .day-cell-2,
.dark-theme table.current-day-3 .day-cell-3,
.dark-theme table.current-day-4 .day-cell-4,
.dark-theme table.current-day-5 .day-cell-5 {
  background-color: rgba(79, 70, 229, 0.08) !important;
}

.dark-theme table tr.current-active {
  background-color: rgba(245, 158, 11, 0.12) !important;
  box-shadow: inset 0 2px 0 0 #f59e0b, inset 0 -2px 0 0 #f59e0b;
}

/* Estilo específico para a célula de horário quando ativa */
table tr:not(.recreio) td.current-active:first-child {
  background: linear-gradient(135deg, #f59e0b, #ea580c) !important;
  color: white;
  /* Adiciona uma barra de destaque branca à esquerda para enfatizar o horário */
  border-left: 8px solid var(--primary) !important;
  box-shadow: 5px 0 15px rgba(234, 88, 12, 0.4);
  border-right: 1px solid rgba(255,255,255,0.2) !important;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 30;
}

/* Ponto pulsante de "Live" na célula de hora */
td.current-active:first-child::before {
  content: '';
  width: 8px;
  height: 8px;
  background-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: pulse-live 1.5s infinite;
}

@keyframes pulse-live {
  0% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.5; }
  100% { transform: scale(0.9); opacity: 1; }
}

.toolbar {
  margin: 0; /* Remove todas as margens, o espaçamento é dado pelo padding-bottom do wrapper */
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Rolagem suave no iOS */
  background: var(--bg-header);
  backdrop-filter: blur(12px) saturate(180%);
  padding: 12px 0; /* O padding horizontal é dado pelo .top-area-sticky-wrapper */
  border-radius: 16px; /* Mantém o border-radius */
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-sm);
  align-items: center;
  scrollbar-width: none; /* Esconde scrollbar no Firefox */
}

.toolbar::-webkit-scrollbar {
  display: none; /* Esconde scrollbar no Chrome/Safari para manter o visual limpo */
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field {
  padding: 10px 16px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 0.85rem;
  min-width: 250px;
  min-width: 160px;
  outline: none;
  transition: border-color 0.2s;
  padding-right: 30px; /* Espaço para o botão de limpar */
}
.search-field:focus { border-color: var(--primary); }

.clear-search-btn {
  position: absolute;
  right: 5px;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #94a3b8;
  display: none; /* Escondido por padrão */
}
.search-field:not(:placeholder-shown) + .clear-search-btn {
  display: block; /* Mostra quando o input tem texto */
}

.time-counter {
  font-weight: 800;
  font-size: 1.05rem;
  font-size: 0.9rem;
  color: #fff !important;
  background: linear-gradient(135deg, #f59e0b, #d97706) !important;
  font-variant-numeric: tabular-nums;
  padding: 6px 16px;
  padding: 4px 10px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin: 0 5px;
}

.current-date-time {
  font-size: 1.15rem;
  font-size: 1rem;
  font-weight: 800;
  color: #ffffff !important;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover)) !important;
  padding: 6px 16px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
  display: flex;
  align-items: center;
}

/* Barra de progresso da aula atual */
.progress-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  z-index: 9999;
  background: rgba(79, 70, 229, 0.1);
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 1s linear;
}

/* Indicador de salvamento */
#save-indicator {
  margin-left: auto;
  font-size: 0.85rem;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.3s;
}

.btn {
  padding: 8px 14px;
  padding: 6px 10px;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  white-space: nowrap;
}

.year-badge {
  background: var(--pd-color);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-success {
  background: #28a745;
  color: white;
}
.btn:hover {
  transform: translateY(-2px); /* Efeito de elevação mais pronunciado */
  filter: brightness(1.1);
  box-shadow: var(--shadow-sm);
}

.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--bg-header); /* Usa o fundo do cabeçalho para consistência */
  color: var(--text-main); /* Cor do texto principal do tema */
  padding: 12px 24px;
  font-size: 0.9em;
  display: flex;
  gap: 32px;
  z-index: 1000;
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.status-item {
  border-right: 1px solid #555;
  padding-right: 15px;
}

.status-info-right {
  margin-left: auto; /* Empurra para o canto direito */
  font-size: 0.85em;
  color: var(--text-muted); /* Usa a cor de texto mutada do tema */
  opacity: 0.8;
  white-space: nowrap;
}

/* Ajustes para Telas Pequenas (Mobile) */
@media (max-width: 768px) {
  .top-area-sticky-wrapper {
    padding: 10px 10px 8px 10px;
  }
  
  div[id^="section-"] {
    padding: 0 10px;
  }

  .header-titles h1 {
    font-size: 1.1rem;
  }

  .main-header {
    padding: 5px 10px; /* Ajusta o padding lateral para mobile */
  }
}

.header-highlight {
  background-color: var(--primary) !important;
  color: white !important;
}
th[title] {
  cursor: help;
  text-decoration: underline dotted #aaa;
}

/* Custom Scrollbar */
.table-container::-webkit-scrollbar {
  height: 8px;
}
.table-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
}
.legend-item:hover { background-color: var(--hl-color); }
.legend-item.active {
  background-color: var(--border-color);
  font-weight: 700;
}
.box {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
}

@keyframes highlightPulse {
  0% { box-shadow: inset 0 0 0 2px #22c55e; }
  50% { box-shadow: inset 0 0 0 4px #4ade80; }
  100% { box-shadow: inset 0 0 0 2px #22c55e; }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  @page {
    size: landscape;
    margin: 10mm;
  }

  .main-header,
  .toolbar,
  .legend,
  .actions,
  .status-bar,
  .zoom-controls,
  .toast-container,
  .modal-overlay,
  .top-area-sticky-wrapper, /* Esconde o wrapper sticky na impressão */
  .progress-container,
  button,
  #save-indicator {
    display: none !important;
  }
  body {
    padding: 0;
    background-color: white !important;
    color: #333 !important; /* Darker text for better readability */
  }
  h2 {
    margin-top: 0;
    color: #333 !important; /* Ensure h2 is also dark */
  }
  /* Força uma quebra de página entre as divisões de período (Manhã e Tarde) na impressão */
  div[id^="section-"] + div[id^="section-"] {
    page-break-before: always;
    break-before: page;
  }
  table {
    page-break-inside: avoid;
    break-inside: avoid;
    font-size: 11pt; /* Increased font size for better readability */
    width: 100% !important;
    table-layout: fixed !important; /* Use fixed layout for consistent column widths */
  }
  th, td {
    padding: 8px 4px !important; /* Adjust padding for print */
    border: 1px solid #ccc !important; /* Clearer borders */
    color: #333 !important; /* Ensure all text in cells is dark */
  }
  th:first-child, tr:not(.recreio) td:first-child {
    background-color: #f0f0f0 !important; /* Slightly shaded first column */
    color: #333 !important;
    box-shadow: none !important; /* Remove shadows */
  }
  thead th {
    background-color: #e0e0e0 !important; /* Darker header background */
    color: #333 !important;
    border-bottom: 2px solid #999 !important; /* Stronger header border */
  }
  .table-container {
    overflow: visible;
    box-shadow: none;
    border: 1px solid #000;
    display: block !important;
  }
  td[contenteditable="true"] {
    background-color: transparent !important;
  }
  /* Specific overrides for various colored/highlighted elements */
  .recreio {
    background: #f0f0f0 !important; /* Light gray for recreio */
    color: #555 !important;
  }
  .day-divider {
    border-right: 2px solid #999 !important; /* Stronger day divider */
  }
  .current-active, .match-highlight, .category-select, .conflict-error {
    background-color: transparent !important; /* Remove all dynamic highlights */
    box-shadow: none !important;
    outline: none !important;
    color: #333 !important;
    animation: none !important;
  }
  .current-active::before, .current-active::after {
    display: none !important; /* Remove active indicators */
  }
  td[data-teacher]::after {
    color: #555 !important; /* Ensure teacher name is visible */
  }
}

/* Modal de Gerenciamento de Professores */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.teacher-list-container {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px;
}

.teacher-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
}
.teacher-item:last-child { border-bottom: none; }

.teacher-info {
  display: flex;
  flex-direction: column;
}
.teacher-sigla { font-weight: 700; color: var(--primary); font-size: 0.85rem; }
.teacher-nome { font-size: 0.95rem; color: var(--text-main); }

.modal-form {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 10px;
  border-top: 2px solid var(--border-color);
  align-items: end;
}

.modal-form input {
  width: 100%;
  padding: 10px;
}

.modal-form .btn-primary {
  height: 42px;
  white-space: nowrap;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

/* Sistema de Toasts */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text-main);
  padding: 12px 24px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.9rem;
  animation: toast-in 0.3s ease-out forwards;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.conflict-badge {
  background: #ef4444;
  color: white;
  padding: 6px 12px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  transition: transform 0.2s;
}
.conflict-badge:hover { transform: scale(1.05); background: #dc2626; }

/* Estilos para o Modal de Atalhos */
.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.shortcut-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}
.shortcut-key {
  background: var(--hl-color);
  padding: 4px 8px;
  border-radius: 6px;
  font-family: monospace;
  font-weight: 700;
  border: 1px solid var(--border-color);
}

.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes toast-in {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}