/*
  Sistema de Escalas - Estilos
  Versão: 2.7
*/

/* Variáveis de Cores */
:root {
  --pm-gold: #ffd966;
  --pm-gold-dark: #bf9000;
  --pm-blue: #1e3a5f;
  --pm-red: #f8d7da;
  --pm-green: #d4edda;
  --pm-gray: #e5e7eb;
}

/* Esconde conteúdo até verificar auth */
body.auth-loading {
  visibility: hidden;
}

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

body {
  font-family: "Carlito", "Calibri", Arial, sans-serif;
  background-color: #f3f4f6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Helper para conteúdo principal expandir */
.main-content {
  /* flex: 1; */
  width: 100%;
}

/* Forms */
.form-input,
.form-select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--pm-gold-dark);
  box-shadow: 0 0 0 2px rgba(191, 144, 0, 0.2);
}

/* Buttons */
.btn {
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.9;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
a.btn {
  text-decoration: none;
}
.btn-primary {
  background: var(--pm-blue);
  color: white;
}
.btn-active {
  background: var(--pm-gold);
  color: black;
}
.btn-secondary {
  background: var(--pm-gray);
  color: #374151;
}
.btn-success {
  background: #16a34a;
  color: white;
}
.btn-danger {
  background: #dc2626;
  color: white;
}

/* Cards */
.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 24px;
}

/* Navbar */
.navbar {
  background: var(--pm-blue);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.navbar-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar-brand {
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-version {
  font-size: 12px;
  background: var(--pm-gold);
  color: black;
  padding: 2px 8px;
  border-radius: 4px;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: 16px;
}

.navbar-user {
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  opacity: 0.9;
  display: inline-flex;
  flex-direction: column;
  line-height: 1.2;
  max-width: 220px;
}

.navbar-user-nome {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lotacao do usuario logado: menor e discreta, para nao competir com o nome */
.navbar-user-unidade {
  font-size: 11px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.alert-error {
  background: var(--pm-red);
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-success {
  background: var(--pm-green);
  color: #155724;
  border: 1px solid #c3e6cb;
}

/* Loading */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

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

/* Tabs */
.tab-btn {
  padding: 8px 16px;
  font-weight: bold;
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: #666;
}

.tab-btn.active {
  border-color: var(--pm-gold-dark);
  color: var(--pm-gold-dark);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.table th {
  background: #f9fafb;
  font-weight: 600;
  text-align: center !important;
}

.table tr:hover {
  background: #f9fafb;
}

/* Tabela Compacta (Edição) */
.table-compact th,
.table-compact td {
  padding: 4px !important;
  vertical-align: middle;
}

.table-compact input,
.table-compact textarea {
  font-size: 13px;
}

/* Utils */
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.mt-2 {
  margin-top: 8px;
}
.mt-4 {
  margin-top: 16px;
}
.mt-6 {
  margin-top: 24px;
}
.mb-2 {
  margin-bottom: 8px;
}
.mb-4 {
  margin-bottom: 16px;
}
.mb-6 {
  margin-bottom: 24px;
}
.hidden {
  display: none !important;
}

/* Footer */
.footer {
  text-align: center;
  padding: 32px;
  color: #9ca3af;
  font-size: 12px;
}

/* Status Auto-save */
.status-salvo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.3s;
}

.status-salvo.salvando {
  background: #fef3c7;
  color: #92400e;
}
.status-salvo.salvo {
  background: #d1fae5;
  color: #065f46;
}
.status-salvo.erro {
  background: #fee2e2;
  color: #991b1b;
}
.status-salvo.pendente {
  background: #e5e7eb;
  color: #6b7280;
}

/* Estilos de Impressão - Tabelas */
.print-table {
  width: 100% !important;
  border-collapse: collapse !important;
}

.print-table td,
.print-table th {
  border: 1px solid #000 !important;
  vertical-align: middle !important;
}

/* Escala Mensal */
.print-table-mensal {
  table-layout: fixed !important;
  font-size: 11px !important;
}

.print-table-mensal td,
.print-table-mensal th {
  padding: 0 2px !important;
  line-height: 1.1 !important;
}

.print-table-mensal tr {
  height: 20px !important;
}

/* Escala ISEO */
.print-table-iseo {
  font-size: 12px !important;
}

.print-table-iseo td,
.print-table-iseo th {
  padding: 4px 8px !important;
}

/* Escala Diária */
.print-table-diaria {
  font-size: 12px !important;
}

.print-table-diaria td,
.print-table-diaria th {
  padding: 1px 2px !important;
  line-height: 1.05 !important;
  text-align: center !important;
}

.print-table-diaria td.no-border-top {
  border-top: hidden !important;
}

.print-table-diaria td.cell-left {
  text-align: left !important;
}

.print-table-diaria td.cell-center {
  vertical-align: middle !important;
  text-align: center !important;
}
/* Larguras fixas para colunas de impressão (ISEO e Audiências) */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(1) {
  width: 25%;
} /* Evento */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(2) {
  width: 25%;
} /* Local */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(3) {
  width: 15%;
} /* Horário */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(4) {
  width: 10%;
} /* Viatura */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(5) {
  width: 15%;
} /* Militares */
#viewSecaoIseo .print-table-diaria thead tr:nth-child(2) th:nth-child(6) {
  width: 10%;
} /* RG */

#viewSecaoAudiencias .print-table-diaria thead tr:nth-child(2) th:nth-child(1) {
  width: 30%;
} /* Militar */
#viewSecaoAudiencias .print-table-diaria thead tr:nth-child(2) th:nth-child(2) {
  width: 15%;
} /* RG */
#viewSecaoAudiencias .print-table-diaria thead tr:nth-child(2) th:nth-child(3) {
  width: 15%;
} /* Horário */
#viewSecaoAudiencias .print-table-diaria thead tr:nth-child(2) th:nth-child(4) {
  width: 40%;
} /* Local */

/* Classes auxiliares impressão */
.overlap-top {
  margin-top: -1px !important;
}
.bg-pm-gold {
  background-color: #ffd966 !important;
}
.bg-pm-red {
  background-color: #f8d7da !important;
}
.bg-pm-green {
  background-color: #d4edda !important;
}

/* ============================================================
   VISUALIZAÇÃO EM TELA (Modo Visualizar)
   ============================================================ */
.print-wrapper {
  display: table;
  width: 100%;
  /* min-height: 100vh; Removido para não forçar espaço extra vazio ao final na tela */
}
.print-header {
  display: table-header-group;
}
.print-footer {
  display: table-footer-group; /* Aparece após o conteúdo na tela */
}
.print-body {
  display: table-row-group;
}
/* Conteúdo alinhado no topo — sem height:100% para evitar espaçamento com múltiplos <tr> */
.print-body > tr > td {
  vertical-align: top;
}
.print-header-content,
.print-footer-content {
  padding: 8px 0;
  text-align: center;
}

/* Garante centralização mesmo em filhos block <p> e <div> gerados por JS
   (text-align nem sempre herda de table-footer-group para filhos block) */
.print-footer-content p,
.print-footer-content div {
  text-align: center;
}

/* Oculta elementos exclusivos de impressão na tela */
.no-screen {
  display: none !important;
}

/* ============================================================
   AVISO DE MUDANÇA NO CADASTRO (sincronia-cadastro.js)
   ============================================================ */
.aviso-cadastro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 14px;
}

/* ============================================================
   AVISO DE NOVA VERSÃO (atualizacao.js)
   ============================================================ */
/* Bloqueio de atualização: cobre a tela inteira e não tem saída além de atualizar,
   porque seguir com o código antigo contra a API nova gera erro sem explicação. */
.bloqueio-atualizacao {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
}

.bloqueio-caixa {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
}

.bloqueio-titulo {
  font-size: 20px;
  color: #1e3a8a;
  margin: 0 0 12px;
}

.bloqueio-mensagem {
  color: #374151;
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 20px;
}

.bloqueio-caixa .btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

/* ============================================================
   DIÁLOGOS (ui-dialog.js) — substituem alert/confirm/prompt
   ============================================================ */
.dialogo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 16px;
}

.dialogo-caixa {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
}

.dialogo-titulo {
  font-size: 18px;
  margin: 0 0 12px;
}

.dialogo-mensagem {
  color: #374151;
  font-size: 15px;
  line-height: 1.55;
  margin: 0;
  overflow-wrap: anywhere;
}

.dialogo-caixa .form-input {
  margin-top: 14px;
}

.dialogo-acoes {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ============================================================
   IMPRESSÃO — @media print
   Usa table-header-group / table-footer-group nativos.
   O browser reserva espaço automaticamente para o tfoot ao paginar.
   ============================================================ */
@media print {
  html,
  body {
    height: auto !important;
    min-height: auto !important;
    margin: 0;
    padding: 0;
  }

  body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    display: block !important;
  }

  .no-print {
    display: none !important;
  }

  #documento {
    box-shadow: none !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .print-wrapper {
    display: table !important;
    min-height: auto !important;
    height: auto !important;
    width: 100% !important;
  }

  /* ESTRATÉGIA DOUBLE-FOOTER:
     1. .print-footer (tfoot): display:table-footer-group
        - Reserva espaço físico na página (previne sobreposição)
        - visibility: hidden (não mostra nada, só ocupa espaço)
     2. .print-footer-fixed (div fora da tabela): position:fixed
        - Mostra o rodapé visualmente no fundo da página
     3. Resultado: Paginação correta + Rodapé fixo visual */

  /* 1. O Espaçador (tfoot) */
  .print-footer {
    display: table-footer-group !important;
    visibility: hidden !important;
    border: none !important;
  }

  /* Garante que NENHUM filho do spacer tenha borda ou visibilidade */
  .print-footer * {
    visibility: hidden !important;
    border: none !important;
  }

  /* 2. O Visual (div fixo) */
  .print-footer-fixed {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    background: white !important;
    z-index: 1000 !important;
    /* Copia estilos do conteúdo para garantir match visual */
  }

  .print-footer-fixed .print-footer-content {
    border-top: 1px solid #ccc; /* Borda visível no elemento fixo */
  }

  .print-footer .print-footer-content {
    border: none !important; /* Sem borda no espaçador */
  }

  /* Centraliza conteúdo em ambos */
  .print-footer-content,
  .print-footer-content p,
  .print-footer-content div {
    text-align: center !important;
  }

  .print-body {
    display: table-row-group !important;
  }

  .print-body > tr > td {
    vertical-align: top;
  }

  .print-header-text p {
    margin: 2px 0;
  }

  .print-header-content {
    padding-bottom: 12px;
  }

  .print-footer-content {
    padding-top: 12px;
    border-top: 1px solid #ccc;
    background: white;
  }
}

/* Admin - Hierarquia e Unidades */
.unit-row-root {
  background: #f8f9fa;
  border-bottom: 2px solid #e5e7eb;
}
.unit-row-child {
  border-bottom: 1px solid #eee;
}
.unit-sigla-root {
  font-weight: 700;
  color: #1f2937;
}
.unit-sigla-child {
  font-weight: 500;
  color: #4b5563;
}
.unit-inactive {
  color: #dc2626;
  font-size: 10px;
  margin-left: 5px;
  font-weight: normal;
}

/* Badges de Tipo (Admin) */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: bold;
  text-align: center;
  min-width: 60px;
  text-transform: uppercase;
}

/* Cores específicas para os Tipos */
.badge-primary {
  background-color: #e0f2fe;
  color: #0369a1; /* Azul claro (CPOR/CPOE) */
  border: 1px solid #bae6fd;
}

.badge-success {
  background-color: #dcfce7;
  color: #15803d; /* Verde (BPM) */
  border: 1px solid #bbf7d0;
}

.badge-warning {
  background-color: #fef9c3;
  color: #a16207; /* Amarelo (CIA) */
  border: 1px solid #fde047;
}
.badge-danger {
  background-color: #fee2e2;
  color: #b91c1c; /* Vermelho (COPOM) */
  border: 1px solid #fecaca;
}

.badge-secondary {
  background-color: #f3f4f6;
  color: #4b5563; /* Cinza (Outros) */
  border: 1px solid #e5e7eb;
}

/* Botões Ícone (Clean) */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  opacity: 0.7;
  transition: all 0.2s;
  border-radius: 4px;
}

.btn-icon:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.05); /* Leve fundo ao passar o mouse */
  transform: scale(1.05);
}

/* Feedback visual de última edição */
.audit-info {
  font-size: 11px;
  color: rgba(
    255,
    255,
    255,
    0.9
  ); /* Branco com leve transparência para barra azul */
  font-style: italic;
  display: block;
  margin-top: 16px;
}

/* UI Refinements */
.import-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f9ff;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #bae6fd;
}

.input-time {
  text-align: center;
  font-family: monospace;
}

/* Layout Centralizado com Fundo Azul */
body.page-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a365d 0%, #2d3748 100%);
}

/* Escala Diária - Edição */
.config-panel {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

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

.config-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.config-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.section-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.section-title {
  font-weight: bold;
  color: var(--pm-blue);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.efetivo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.efetivo-table th,
.efetivo-table td {
  border: 1px solid #ddd;
  padding: 6px 8px;
  text-align: left;
}

.efetivo-table th {
  background: #f1f5f9;
  font-weight: 600;
}

.efetivo-table input,
.efetivo-table textarea {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
}

.efetivo-table textarea {
  resize: vertical;
  min-height: 40px;
}

.btn-add-row {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px dashed #0369a1;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.btn-add-row:hover {
  background: #bae6fd;
}

.btn-remove-row {
  background: none;
  border: none;
  color: #dc2626;
  cursor: pointer;
  font-size: 16px;
}

.brasao-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brasao-preview {
  width: 80px;
  height: 80px;
  border: 1px dashed #ccc;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f9fafb;
}

.brasao-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Escala Diária - Visualização */
.doc-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 12px 16px;
}

.doc-header-text {
  text-align: center;
}
.doc-header-text p {
  margin: 2px 0;
}
.doc-brasao img {
  max-height: 70px;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
}

.doc-table th,
.doc-table td {
  border: 1px solid #000;
  padding: 4px 6px;
}

.doc-table th {
  background: #f0f0f0;
  font-weight: bold;
  text-align: center;
}

.doc-section-title {
  background: #e5e5e5;
  font-weight: bold;
  text-align: center;
  padding: 4px;
}

.doc-textarea {
  white-space: pre-wrap;
  padding: 8px 16px;
  font-size: 11px;
}

.doc-assinatura {
  text-align: center;
  margin: 64px 0 16px; /* Aumentado de 32px para 64px para evitar proximidade com o conteúdo */
}

.doc-assinatura-linha {
  display: inline-block;
  border-top: 1px solid #000;
  padding-top: 4px;
  min-width: 250px;
}

.doc-rodape {
  text-align: center;
  font-size: 10px;
  border-top: 1px solid #ccc;
  padding: 8px 16px;
  margin-top: 16px;
}
