
/* ==========================================================================
   TIPOGRAFIA E ESCALA GLOBAL HARMONIZADA (COMPACTA ZERO SCROLL)
   ========================================================================== */
html {
  zoom: 1.5;
  height: 100%;
  font-size: 13.5px;
  color-scheme: light dark;
}

/* Telemóveis e tablets: sem ampliação, para caber mais conteúdo no ecrã */
@media (max-width: 1023px) {
  html {
    zoom: 1;
  }
}

@media print {
  html {
    zoom: 1 !important;
  }
}

body {
  min-height: 100%;
}

/* Compatibilidade perfeita de unidades de viewport com zoom: 1.5 */
.h-screen {
  height: 100% !important;
}
.max-h-screen {
  max-height: 100% !important;
}
.min-h-screen {
  min-height: 100% !important;
}

/* Scrollbar ultra-fina e discreta para contentores que necessitem de scroll horizontal */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.4);
  border-radius: 9999px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
}

/* Distribuição 100% uniforme dos 9 blocos na grelha de horários (zero scroll e altura idêntica) */
.grelha-tabela-semanal {
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  height: 100% !important;
  border-collapse: collapse !important;
}

.grelha-tabela-semanal thead {
  flex-shrink: 0 !important;
  width: 100% !important;
}

.grelha-tabela-semanal thead tr {
  display: grid !important;
  grid-template-columns: 6.5rem repeat(5, minmax(0, 1fr)) !important;
  width: 100% !important;
}

#corpoGrelhaSemanal {
  display: grid !important;
  grid-template-rows: repeat(9, minmax(0, 1fr)) !important;
  flex: 1 1 0% !important;
  height: 100% !important;
  min-height: 0 !important;
  width: 100% !important;
}

#corpoGrelhaSemanal tr {
  display: grid !important;
  grid-template-columns: 6.5rem repeat(5, minmax(0, 1fr)) !important;
  height: 100% !important;
  min-height: 0 !important;
  width: 100% !important;
}

#corpoGrelhaSemanal td {
  height: 100% !important;
  min-height: 0 !important;
  padding: 1px 2px !important;
}

#corpoGrelhaSemanal td:first-child {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
}

#corpoGrelhaSemanal .drop-slot {
  height: 100% !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.875rem;
  line-height: 1.35;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Assegurar que controlos de formulário e tabelas herdam e escalam a tipografia proporcionalmente */
input, select, textarea, button, optgroup {
  font-family: inherit;
}

html:not(.dark) body {
  background-color: #f1f5f9;
  color: #0f172a;
}

html.dark body {
  background-color: #0b132b;
  color: #f8fafc;
}

html:not(.dark) input:not([type="checkbox"]):not([type="radio"]),
html:not(.dark) select,
html:not(.dark) textarea {
  background-color: #ffffff !important;
  color: #0f172a !important;
  border: 1px solid #cbd5e1 !important;
}

html:not(.dark) input::placeholder,
html:not(.dark) textarea::placeholder {
  color: #64748b !important;
}

html.dark input:not([type="checkbox"]):not([type="radio"]),
html.dark select,
html.dark textarea {
  background-color: #131d36 !important;
  color: #f8fafc !important;
  border: 1px solid #334155 !important;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #94a3b8 !important;
}

html.dark select option {
  background-color: #131d36 !important;
  color: #f8fafc !important;
}

input[type="date"] {
  cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.85;
  display: block;
}

html.dark input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.2);
  opacity: 0.9;
}

.drag-card {
  cursor: grab;
  user-select: none;
  /* Permite deslizar o banco e a grelha em qualquer direção a partir de um cartão (sem zoom por duplo toque) */
  touch-action: manipulation;
}

.drag-card:active {
  cursor: grabbing;
  transform: scale(0.97);
}

.drop-slot.drag-over {
  background-color: rgba(59, 130, 246, 0.25) !important;
  outline: 2px dashed #3b82f6 !important;
}

/* ==========================================================================
   CARTÕES DE AULA COM CORES FIXAS E COERENTES EM QUALQUER TEMA (24 CORES DISTINTAS)
   ========================================================================== */
.cartao-cor-0  { background-color: #fef3c7 !important; border-color: #f59e0b !important; color: #78350f !important; } /* Amber */
.cartao-cor-1  { background-color: #d1fae5 !important; border-color: #10b981 !important; color: #064e3b !important; } /* Emerald */
.cartao-cor-2  { background-color: #e0f2fe !important; border-color: #0ea5e9 !important; color: #0c4a6e !important; } /* Sky */
.cartao-cor-3  { background-color: #f3e8ff !important; border-color: #a855f7 !important; color: #581c87 !important; } /* Purple */
.cartao-cor-4  { background-color: #ffe4e6 !important; border-color: #f43f5e !important; color: #881337 !important; } /* Rose */
.cartao-cor-5  { background-color: #ccfbf1 !important; border-color: #14b8a6 !important; color: #134e4a !important; } /* Teal */
.cartao-cor-6  { background-color: #ffedd5 !important; border-color: #f97316 !important; color: #7c2d12 !important; } /* Orange */
.cartao-cor-7  { background-color: #e0e7ff !important; border-color: #6366f1 !important; color: #312e81 !important; } /* Indigo */
.cartao-cor-8  { background-color: #cffafe !important; border-color: #06b6d4 !important; color: #164e63 !important; } /* Cyan */
.cartao-cor-9  { background-color: #ecfccb !important; border-color: #84cc16 !important; color: #365314 !important; } /* Lime */
.cartao-cor-10 { background-color: #fae8ff !important; border-color: #d946ef !important; color: #701a75 !important; } /* Fuchsia */
.cartao-cor-11 { background-color: #dbeafe !important; border-color: #3b82f6 !important; color: #1e3a8a !important; } /* Blue */
.cartao-cor-12 { background-color: #fce7f3 !important; border-color: #ec4899 !important; color: #831843 !important; } /* Pink */
.cartao-cor-13 { background-color: #ede9fe !important; border-color: #8b5cf6 !important; color: #4c1d95 !important; } /* Violet */
.cartao-cor-14 { background-color: #fef9c3 !important; border-color: #eab308 !important; color: #713f12 !important; } /* Yellow */
.cartao-cor-15 { background-color: #dcfce7 !important; border-color: #22c55e !important; color: #14532d !important; } /* Green */
.cartao-cor-16 { background-color: #fee2e2 !important; border-color: #ef4444 !important; color: #7f1d1d !important; } /* Red */
.cartao-cor-17 { background-color: #d5faf2 !important; border-color: #0d9488 !important; color: #042f2e !important; } /* Mint */
.cartao-cor-18 { background-color: #fed7aa !important; border-color: #ea580c !important; color: #431407 !important; } /* Coral */
.cartao-cor-19 { background-color: #e9d5ff !important; border-color: #9333ea !important; color: #3b0764 !important; } /* Lavender */
.cartao-cor-20 { background-color: #f1f5f9 !important; border-color: #64748b !important; color: #0f172a !important; } /* Slate */
.cartao-cor-21 { background-color: #f5f5f4 !important; border-color: #78716c !important; color: #1c1917 !important; } /* Warm Gray */
.cartao-cor-22 { background-color: #e0f7fa !important; border-color: #00acc1 !important; color: #004d40 !important; } /* Seafoam */
.cartao-cor-23 { background-color: #fff1f2 !important; border-color: #e11d48 !important; color: #4c0519 !important; } /* Crimson Light */

/* Aliases de compatibilidade legada */
.cartao-cor-amber   { background-color: #fef3c7 !important; border-color: #f59e0b !important; color: #78350f !important; }
.cartao-cor-emerald { background-color: #d1fae5 !important; border-color: #10b981 !important; color: #064e3b !important; }
.cartao-cor-sky     { background-color: #e0f2fe !important; border-color: #0ea5e9 !important; color: #0c4a6e !important; }
.cartao-cor-purple  { background-color: #f3e8ff !important; border-color: #a855f7 !important; color: #581c87 !important; }
.cartao-cor-rose    { background-color: #ffe4e6 !important; border-color: #f43f5e !important; color: #881337 !important; }
.cartao-cor-teal    { background-color: #ccfbf1 !important; border-color: #14b8a6 !important; color: #134e4a !important; }
.cartao-cor-orange  { background-color: #ffedd5 !important; border-color: #f97316 !important; color: #7c2d12 !important; }
.cartao-cor-indigo  { background-color: #e0e7ff !important; border-color: #6366f1 !important; color: #312e81 !important; }
.cartao-cor-cyan    { background-color: #cffafe !important; border-color: #06b6d4 !important; color: #164e63 !important; }
.cartao-cor-lime    { background-color: #ecfccb !important; border-color: #84cc16 !important; color: #365314 !important; }

/* Cartão com cor de perfil dinâmica (predefinido a branco com texto escuro e contorno) */
.cartao-cor-perfil {
  background-color: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}

/* ==========================================================================
   COMBOBOX E DROPDOWNS PESQUISÁVEIS
   ========================================================================== */
.searchable-select-container {
  vertical-align: middle;
}

.searchable-select-menu {
  animation: fadeInDropdown 0.12s ease-out;
}

@keyframes fadeInDropdown {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
/* ==========================================================================
   TELEMÓVEL (movel.js): MENU ☰, VISTA POR DIA E MARCAÇÃO POR TOQUE
   ========================================================================== */
.btn-menu-movel,
.btn-filtros-movel,
.barra-vista-dia {
  display: none;
}

/* Cartão selecionado no modo de toque */
.toque-selecionado {
  outline: 3px solid #f59e0b !important;
  outline-offset: 1px;
  box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.35) !important;
}

.barra-toque-selecao {
  position: fixed;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.5rem;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  background: #0f172a;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.barra-toque-selecao[hidden] {
  display: none;
}
.barra-toque-selecao button {
  flex-shrink: 0;
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  background: #e11d48;
  color: #fff;
  font-weight: 700;
}

/* Telemóveis e tablets: os grupos de controlos quebram linha em vez de sair do ecrã */
@media (max-width: 1023px) {
  main .flex-wrap.shrink-0 {
    flex-shrink: 1 !important;
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 639px) {
  /* --- Cabeçalho compacto com menu ☰ --- */
  .btn-menu-movel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
  }
  header > div > nav {
    display: none !important;
  }
  html.menu-movel-aberto header > div > nav {
    display: flex !important;
    order: 3;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding: 0.25rem 0 0.4rem;
  }
  html.menu-movel-aberto header > div > nav > * {
    padding: 0.6rem 0.75rem !important;
    font-size: 0.85rem !important;
  }
  header > div > div:last-child > button,
  header > div > div:last-child > a {
    min-height: 2.25rem;
    min-width: 2.25rem;
  }

  /* --- A página desliza na vertical em vez de comprimir a grelha --- */
  body.h-screen {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  body > main {
    overflow: visible !important;
  }
  .grelha-tabela-semanal {
    height: auto !important;
  }
  #corpoGrelhaSemanal {
    height: auto !important;
    grid-template-rows: repeat(9, minmax(3rem, auto)) !important;
  }

  /* --- Filtros recolhíveis --- */
  .btn-filtros-movel {
    display: block;
    width: 100%;
    min-height: 2.25rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #1e3a8a;
    font-size: 0.8rem;
    font-weight: 700;
    text-align: left;
  }
  html.dark .btn-filtros-movel {
    background: #1e293b;
    border-color: #334155;
    color: #bfdbfe;
  }
  [data-filtros-movel]:not(.filtros-abertos) {
    display: none !important;
  }

  /* --- Controlos e filtros cabem na largura do ecrã --- */
  main select,
  main input[type="date"],
  main .relative > button {
    max-width: 100%;
  }
  main [id^="menuDropdown"],
  main .searchable-select-menu {
    max-width: calc(100vw - 2rem) !important;
  }
  #btnSemanaAnterior,
  #btnSemanaAtual,
  #btnSemanaSeguinte {
    padding: 0.4rem 0.7rem !important;
  }
  #txtPeriodoSemana {
    white-space: normal !important;
  }

  /* --- Separadores do Painel de Gestão com deslocação lateral --- */
  #navAbasGestao {
    overflow-x: auto;
  }
  #navAbasGestao .aba-btn {
    flex: 0 0 auto !important;
    min-width: 6.5rem;
  }
  [class*="top-[42px]"] {
    position: static !important;
  }

  /* --- Janelas modais ocupam o ecrã e deslizam na vertical --- */
  .fixed.inset-0.z-50 {
    align-items: flex-start !important;
    overflow-y: auto;
    padding: 0.5rem !important;
  }

  /* --- Barra Semana | Seg … Sex --- */
  .barra-vista-dia {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    overflow-x: auto;
    flex-shrink: 0;
  }
  .barra-vista-dia button {
    flex: 1 0 auto;
    min-height: 2.25rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e3a8a;
    font-size: 0.8rem;
    font-weight: 700;
  }
  html.dark .barra-vista-dia button {
    background: #1e293b;
    border-color: #334155;
    color: #bfdbfe;
  }
  .barra-vista-dia button.ativo,
  html.dark .barra-vista-dia button.ativo {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
  }

  /* Só o dia escolhido fica visível */
  table[data-dia-visivel="0"] [data-dia]:not([data-dia="0"]),
  table[data-dia-visivel="1"] [data-dia]:not([data-dia="1"]),
  table[data-dia-visivel="2"] [data-dia]:not([data-dia="2"]),
  table[data-dia-visivel="3"] [data-dia]:not([data-dia="3"]),
  table[data-dia-visivel="4"] [data-dia]:not([data-dia="4"]),
  table[data-dia-visivel="0"] #corpoGrelhaSemanal [data-dia]:not([data-dia="0"]),
  table[data-dia-visivel="1"] #corpoGrelhaSemanal [data-dia]:not([data-dia="1"]),
  table[data-dia-visivel="2"] #corpoGrelhaSemanal [data-dia]:not([data-dia="2"]),
  table[data-dia-visivel="3"] #corpoGrelhaSemanal [data-dia]:not([data-dia="3"]),
  table[data-dia-visivel="4"] #corpoGrelhaSemanal [data-dia]:not([data-dia="4"]) {
    display: none !important;
  }
  table[data-dia-visivel].grelha-tabela-semanal thead tr,
  table[data-dia-visivel] #corpoGrelhaSemanal tr {
    grid-template-columns: 6.5rem minmax(0, 1fr) !important;
  }

  /* --- Visão Geral: coluna da turma fixa e grelha com deslocação lateral --- */
  #tabelaGrelhaGeral {
    min-width: 1500px;
  }
  #tabelaGrelhaGeral[data-dia-visivel] {
    min-width: 960px;
  }
  #tabelaGrelhaGeral[data-dia-visivel] #linhaCabecalhoDias th[data-dia] {
    text-align: left !important;
    padding-left: 0.5rem !important;
  }
  #linhaCabecalhoDias > th:first-child,
  #corpoGrelhaGeral td:first-child {
    position: sticky;
    left: 0;
    z-index: 15;
    width: 6.5rem !important;
    min-width: 6.5rem !important;
  }

  /* --- Indisponibilidades: coluna do docente mais estreita --- */
  #grelhaIndisponibilidades th:first-child,
  #grelhaIndisponibilidades td:first-child {
    min-width: 7rem !important;
    max-width: 9rem;
    white-space: normal !important;
  }
  #grelhaIndisponibilidades[data-dia-visivel] td[data-dia] {
    min-width: 2.25rem;
    height: 2.25rem;
  }
}
