* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #1a237e, #283593);
  color: white;
  padding: 2rem;
  text-align: center;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  max-width: 100%;
  text-align: left;
}

.school-logo,
.school-logo-fallback {
  width: 76px;
  height: 76px;
  flex: 0 0 76px;
  object-fit: contain;
}

.school-logo {
  display: block;
}

.school-logo-fallback {
  display: grid;
  place-content: center;
  font-size: 2.8rem;
  text-align: center;
}

.school-logo[hidden],
.school-logo-fallback[hidden] {
  display: none;
}

.brand-copy h1 {
  margin-bottom: 0.3rem;
}

header h1 {
  font-size: 1.8rem;
  margin-bottom: 0.3rem;
}

header .subtitle {
  font-size: 1rem;
  opacity: 0.9;
}

@media (max-width: 560px) {
  header {
    padding: 1.4rem 1rem;
  }

  .brand-lockup {
    gap: 0.7rem;
  }

  .school-logo,
  .school-logo-fallback {
    width: 54px;
    height: 54px;
    flex-basis: 54px;
  }

  .brand-copy h1 {
    font-size: 1.25rem;
  }

  header .subtitle {
    font-size: 0.85rem;
  }
}

nav {
  background: #283593;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.nav-btn {
  background: transparent;
  border: 2px solid transparent;
  color: #e8eaf6;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.3);
}

.nav-btn.active {
  background: #3949ab;
  border-color: #5c6bc0;
  color: white;
}

main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

.tab h2 {
  color: #1a237e;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.card h3 {
  color: #283593;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header h3 {
  margin-bottom: 0;
}

.hint {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.assignment-exam-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  background: #eef3ff;
  border-left: 4px solid #3949ab;
  border-radius: 6px;
  color: #283593;
}

.assignment-exam-summary span {
  color: #53627c;
}

.assignment-count {
  color: #546e7a;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.room-selection-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
  min-height: 3rem;
}

.room-selection-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid #d7dce8;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.room-selection-item:hover,
.room-selection-item:has(input:checked) {
  border-color: #3949ab;
  background: #f3f5ff;
}

.room-selection-item input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #3949ab;
}

.room-selection-item strong,
.room-selection-item small {
  display: block;
}

.room-selection-item small {
  margin-top: 0.2rem;
  color: #667085;
}

.assignment-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.assignment-toolbar .btn-primary:disabled {
  background: #b0b7c8;
  cursor: not-allowed;
}

.assignment-empty {
  width: 100%;
  padding: 1rem;
  color: #667085;
  background: #f8f9fb;
  border-radius: 6px;
  text-align: center;
}

.print-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.print-toolbar h2 {
  margin-bottom: 0.4rem;
}

.print-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.print-controls label {
  color: #555;
  font-size: 0.85rem;
  font-weight: 700;
}

.print-controls input,
.print-controls select {
  min-width: 180px;
  padding: 0.72rem 0.9rem;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  background: #fff;
  color: #1f2937;
  font-size: 0.95rem;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.print-controls input:focus,
.print-controls select:focus {
  outline: none;
  border-color: #3949ab;
  box-shadow: 0 0 0 3px rgba(57, 73, 171, 0.12);
}

.print-controls button:disabled {
  background: #b0b7c8;
  color: white;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .print-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .print-controls {
    width: 100%;
  }

  .print-controls input,
  .print-controls select,
  .print-controls button {
    width: 100%;
  }
}

.listagem-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #dfe3eb;
}

.listagem-tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: #546e7a;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

.listagem-tab.active {
  border-bottom-color: #3949ab;
  color: #283593;
}

.stats-grid-listagem {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.5rem;
}

.stats-grid-listagem .stat-card {
  padding: 1rem;
  border-top-width: 3px;
}

.stats-grid-listagem .stat-card p {
  font-size: 1.8rem;
}

.print-document {
  background: white;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.listagem-cabecalho {
  border-bottom: 2px solid #283593;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  text-align: center;
}

.listagem-logo,
.listagem-logo-fallback {
  width: 58px;
  height: 58px;
  margin: 0 auto 0.45rem;
  object-fit: contain;
}

.listagem-logo-fallback {
  display: grid;
  place-content: center;
  font-size: 2rem;
}

.listagem-logo[hidden],
.listagem-logo-fallback[hidden] {
  display: none;
}

.listagem-cabecalho h1 {
  color: #1a237e;
  font-size: 1.35rem;
}

.listagem-cabecalho h2 {
  color: #283593;
  font-size: 1.1rem;
  margin: 0.35rem 0;
}

.listagem-cabecalho p {
  color: #555;
}

.listagem-folha {
  margin-bottom: 2rem;
}

.listagem-folha h2 {
  color: #283593;
  font-size: 1.15rem;
  margin-bottom: 0.7rem;
}

.listagem-folha table {
  font-size: 0.86rem;
}

.listagem-folha td small {
  display: block;
  color: #667085;
  margin-top: 0.15rem;
}

.assinatura-linha {
  min-width: 180px;
  border-bottom: 1px solid #555;
}

.listagem-vazia {
  color: #667085;
  padding: 1.2rem;
  text-align: center;
}

.vigilancia-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0.5rem 0 1rem;
}

.vigilancia-progress span {
  padding: 0.55rem 0.8rem;
  background: #f4f6fa;
  border: 1px solid #e0e5ef;
  border-radius: 6px;
  color: #53627c;
  font-size: 0.85rem;
}

#form-vigilancia-manual button:disabled {
  background: #b0b7c8;
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
  padding: 0.6rem 0.8rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #3949ab;
  box-shadow: 0 0 0 3px rgba(57, 73, 171, 0.1);
}

.btn-primary {
  background: #3949ab;
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #283593;
}

.btn-danger {
  background: #d32f2f;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-danger:hover {
  background: #b71c1c;
}

.btn-secondary {
  background: #e8eaf6;
  color: #283593;
  border: none;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.drag-handle {
  display: inline-block;
  cursor: grab;
  color: #6b7280;
  margin-right: 0.35rem;
  user-select: none;
}

tr.drag-over {
  background: #eef3ff;
}

tr.dragging {
  opacity: 0.55;
}

.professores-pesquisa {
  margin: 0.75rem 0 1rem;
  max-width: 440px;
}

.professores-pesquisa label {
  display: block;
  margin-bottom: 0.3rem;
  color: #555;
  font-size: 0.85rem;
  font-weight: 600;
}

.professores-pesquisa input {
  box-sizing: border-box;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.95rem;
}

.professores-pesquisa input:focus {
  outline: none;
  border-color: #3949ab;
  box-shadow: 0 0 0 3px rgba(57, 73, 171, 0.1);
}

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

th {
  background: #f5f5f5;
  color: #555;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

th.sortable:hover {
  background: #e8eaf6;
  color: #283593;
}

.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.7rem;
  opacity: 0.5;
}

th.sortable.sort-asc .sort-indicator::after {
  content: '▲';
  opacity: 1;
}

th.sortable.sort-desc .sort-indicator::after {
  content: '▼';
  opacity: 1;
}

tr:hover {
  background: #f8f9ff;
}

.resultado {
  margin-top: 1rem;
  padding: 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.resultado.sucesso {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.resultado.erro {
  background: #fbe9e7;
  color: #c62828;
  border: 1px solid #ffab91;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-top: 4px solid #3949ab;
}

.stat-card h3 {
  color: #666;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.stat-card p {
  font-size: 2.5rem;
  font-weight: 700;
  color: #1a237e;
}

.dashboard-alerts {
  margin-top: 1.5rem;
}

.dashboard-alerts-lista {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 260px;
  overflow-y: auto;
}

.dashboard-alerts-vazio {
  color: #667085;
  font-size: 0.9rem;
}

.dashboard-alerta {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.7rem 0.8rem;
  background: #fff8e1;
  border-left: 4px solid #f9a825;
  border-radius: 6px;
}

.dashboard-alerta strong,
.dashboard-alerta small {
  display: block;
}

.dashboard-alerta strong {
  color: #5d4037;
  font-size: 0.9rem;
  font-weight: 600;
}

.dashboard-alerta small {
  color: #795548;
  margin-top: 0.25rem;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  position: relative;
}

.modal-content-wide {
  max-width: 900px;
}

.indisponibilidades-lista {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.indisponibilidade-linha {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 3fr auto;
  gap: 0.5rem;
  align-items: center;
}

.indisponibilidade-linha input,
.indisponibilidade-linha select {
  min-width: 0;
  padding: 0.55rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
}

.indisponibilidades-resumo {
  display: inline-block;
  min-width: 4.5rem;
  margin-right: 0.35rem;
  color: #555;
  font-size: 0.85rem;
}

.modal-content h3 {
  color: #283593;
  margin-bottom: 1.5rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  font-size: 1.8rem;
  color: #999;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #d32f2f;
}

.btn-secondary {
  background: #546e7a;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #455a64;
}

@media (max-width: 700px) {
  .indisponibilidade-linha {
    grid-template-columns: 1fr 1fr auto;
  }

}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  body {
    background: white;
  }

  body > header,
  body > nav,
  main > section:not(#tab-listagens),
  #tab-listagens > .print-toolbar,
  #tab-listagens > .listagem-tabs,
  #resultado-listagem,
  .dashboard-alerts,
  .listagem-folha button {
    display: none !important;
  }

  main,
  #tab-listagens,
  .print-document {
    display: block !important;
    max-width: none;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }

  .print-document[hidden] {
    display: block !important;
  }

  .print-document .listagem-folha[hidden] {
    display: none !important;
  }

  .listagem-folha {
    break-after: page;
    margin: 0;
  }

  .listagem-folha:last-child {
    break-after: auto;
  }

  .print-document table {
    width: 100%;
  }

  .print-document th,
  .print-document td {
    border-color: #777;
    padding: 7px 9px;
  }
}

.btn-secondary.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #323232;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 1000;
  max-width: 350px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.sucesso {
  background: #2e7d32;
}

.toast.erro {
  background: #c62828;
}

@media (max-width: 768px) {
  header h1 {
    font-size: 1.3rem;
  }

  nav {
    flex-direction: column;
    align-items: stretch;
  }

  .nav-btn {
    text-align: center;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .card-header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }
}

.grupo-checkboxes {
  display: flex;
  gap: 1rem;
  min-height: 42px;
  align-items: center;
  padding: 0 0.8rem;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.grupo-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  cursor: pointer;
}

.form-group .grupo-checkboxes input {
  width: auto;
  min-height: 0;
  padding: 0;
  box-shadow: none;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(16, 34, 54, 0.72);
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  width: min(100%, 460px);
  padding: 1.75rem 2rem;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

.auth-card h2 { margin-top: 0; }
.auth-form { display: grid; gap: 0.55rem; margin-top: 1.25rem; }
.auth-form[hidden] { display: none; }
.auth-form input { padding: 0.7rem; border: 1px solid #b8c1cc; border-radius: 6px; font: inherit; }
.auth-link { margin-top: 1rem; border: 0; background: transparent; color: #1c5d99; text-decoration: underline; cursor: pointer; }
.auth-error { min-height: 1.25rem; margin: 1rem 0 0; color: #b42318; }
.auth-logout { white-space: nowrap; }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.user-status {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.user-status.active { background: #dff5e3; color: #1b6d32; }
.user-status.inactive { background: #fbe3e3; color: #a12626; }
.user-protected { color: #5a4b00; font-size: 0.85rem; font-weight: 600; }
