/* ==========================================================================
   DESIGN SYSTEM & ESTILIZAÇÃO - GERADOR DE OFÍCIOS DPEMA
   ========================================================================== */

/* Fontes */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Outfit:wght@300;400;500;600;700;800&display=swap');

/* Variáveis e Temas */
:root {
  /* Cores Institucionais DPEMA */
  --primary: #005a2b;
  --primary-hover: #004421;
  --primary-light: rgba(0, 90, 43, 0.08);
  --primary-light-focus: rgba(0, 90, 43, 0.15);
  --accent: #c09d52;
  --accent-hover: #a8833e;
  --danger: #e11d48;
  --danger-hover: #be123c;
  --danger-light: rgba(225, 29, 72, 0.08);

  /* Tema Claro (Padrão) */
  --bg-app: #f0f4f1;
  --bg-sidebar: #ffffff;
  --text-main: #141f19;
  --text-muted: #5e7066;
  --border: #e0e8e4;
  --border-focus: #005a2b;
  --surface-card: #f8faf9;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-paper: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --scrollbar-thumb: #cbd5e1;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

[data-theme="dark"] {
  /* Tema Escuro */
  --bg-app: #0e1210;
  --bg-sidebar: #151a17;
  --text-main: #f0f4f1;
  --text-muted: #94a39b;
  --border: #2c3832;
  --border-focus: #00a852;
  --surface-card: #1d2621;
  --primary-light: rgba(0, 168, 82, 0.12);
  --primary-light-focus: rgba(0, 168, 82, 0.2);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-paper: 0 15px 35px rgba(0, 0, 0, 0.5);
  --scrollbar-thumb: #3b4d45;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  transition: background var(--transition-normal);
}

/* Scrollbar Personalizada */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Layout Principal */
.app-container {
  display: flex;
  width: 100%;
  height: 100vh;
}

/* Painel Lateral (Sidebar) */
.sidebar {
  width: 420px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: var(--shadow-md);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

/* Cabeçalho da Sidebar */
.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand img {
  height: 38px;
  width: auto;
}

.brand h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

[data-theme="dark"] .brand h1 {
  color: var(--text-main);
}

/* Botão Tema */
.theme-toggle {
  background: var(--surface-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Abas de Navegação */
.tabs-navigation {
  display: flex;
  padding: 8px 16px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.tab-btn {
  flex: 1;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .tab-btn:hover {
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  background: var(--bg-sidebar);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .tab-btn.active {
  color: #00a852;
}

/* Área de Conteúdo da Sidebar (Scroll) */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Formulários e Componentes */
.form-section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-group {
  margin-bottom: 20px;
}

.form-group-row {
  display: flex;
  gap: 12px;
}

.form-group-row > .form-group {
  flex: 1;
}

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--bg-sidebar);
}

/* Quantidade Input Control */
.qty-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.qty-btn {
  background: var(--surface-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.qty-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

#quantidade {
  text-align: center;
  width: 60px;
  font-weight: 700;
}

/* Selector Toggle (Pré-preenchido vs Em Branco) */
.toggle-selector {
  display: flex;
  background: var(--bg-app);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
}

.toggle-option {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  text-transform: uppercase;
}

.toggle-option.active {
  background: var(--bg-sidebar);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .toggle-option.active {
  color: #00a852;
}

/* Botões do Painel */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background var(--transition-fast), transform var(--transition-fast);
  box-shadow: 0 4px 10px rgba(0, 90, 43, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-secondary:hover {
  color: var(--text-main);
  background: var(--surface-card);
  border-color: var(--text-muted);
}

/* Alertas e Hints */
.hint-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.hint-bold {
  font-weight: 700;
  color: var(--text-main);
}

/* Cadastro de Defensores Card */
.defender-form {
  background: var(--surface-card);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.defender-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.defender-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast);
}

.defender-item:hover {
  border-color: var(--primary);
}

.defender-info {
  display: flex;
  flex-direction: column;
}

.defender-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.defender-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.btn-delete svg {
  width: 16px;
  height: 16px;
}

.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

/* Área da Direita - Visualização de Impressão */
.preview-container {
  flex: 1;
  background: #525659; /* Cor cinza padrão de leitores PDF */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  scroll-behavior: smooth;
  height: 100vh;
}

[data-theme="dark"] .preview-container {
  background: #181a1c;
}

/* Barra de Dicas do Preview */
.preview-header-bar {
  width: 210mm;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: #fff;
  font-size: 0.8rem;
  opacity: 0.85;
}

.preview-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   ESTILOS DO DOCUMENTO FÍSICO (A4 PAPER-LIKE)
   Sempre Fundo Branco e Texto Preto, independente do Dark Mode!
   ========================================================================== */
.pagina-oficio {
  width: 210mm;
  min-height: 297mm;
  padding: 20mm 20mm; /* Margens padrão ABNT */
  font-family: 'Times New Roman', Times, serif;
  font-size: 11pt;
  color: #000000;
  background: #ffffff;
  box-shadow: var(--shadow-paper);
  margin-bottom: 30px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform var(--transition-normal);
}

/* Linha Superior (Número do Ofício) */
.doc-num {
  font-size: 9.5pt;
  text-align: right;
  margin-bottom: 2px;
  font-weight: bold;
}

/* Topo do Ofício (Logo) */
.doc-topo {
  text-align: center;
  margin-bottom: 15px;
}

.doc-topo img {
  height: 52px;
  width: auto;
}

/* Títulos do Documento */
.doc-title {
  font-size: 13pt;
  font-weight: bold;
  text-align: center;
  margin: 5px 0 2px;
  text-decoration: underline;
  text-transform: uppercase;
}

.doc-subtitle {
  font-size: 11pt;
  font-weight: bold;
  text-align: center;
  margin-bottom: 15px;
  text-transform: uppercase;
}

/* Formulário de Linhas Estáveis (Padrão Oficial) */
.f-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  margin-bottom: 6px;
  width: 100%;
}

.f-lbl {
  white-space: nowrap;
  font-size: 11pt;
  padding-bottom: 1px;
}

.f-ln {
  flex: 1;
  border-bottom: 0.8pt solid #000000;
  height: 22px; /* Altura aumentada para melhor acomodação vertical */
  min-width: 20px;
  word-break: break-all;
  font-size: 11pt;
  font-weight: bold;
  padding: 0 4px 1px 4px;
  vertical-align: bottom;
  box-sizing: border-box;
}

.f-ln.filled {
  height: auto !important; /* Destrava a altura fixa para permitir elevação do texto */
  border-bottom: 0.5px solid #b8c2bc !important; /* Linha discreta ultra fina */
  padding-bottom: 6px !important; /* Eleva o texto em 6px acima da linha */
  font-weight: bold;
}

.check-container {
  margin: 14px 0;
  font-size: 11pt;
  display: flex;
  align-items: center;
  gap: 12px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.check-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border: 0.8pt solid #000000;
  font-weight: bold;
  font-size: 8pt;
  line-height: 1;
}

/* Corpo do Texto */
.corpo {
  font-size: 11pt;
  text-align: justify;
  margin: 15px 0;
  line-height: 1.4;
}

.declaro {
  font-size: 11pt;
  text-align: justify;
  margin-bottom: 20px;
}

.cidade-data {
  text-align: center;
  margin: 15px 0 25px;
  font-size: 11pt;
}

/* Assinaturas */
.sig-area {
  margin-top: 15px;
}

.sig-def-block {
  text-align: center;
  margin-bottom: 25px;
}

.sig-block {
  text-align: center;
  margin-bottom: 20px;
}

.sig-space {
  height: 40px;
}

.sig-line {
  border-top: 0.8pt solid #000000;
  margin: 0 auto 5px;
}

.sig-line.def {
  width: 320px;
}

.sig-line.req {
  width: 420px;
}

.sig-def-line {
  border-top: 0.8pt solid #000000;
  width: 280px;
  margin: 12px auto 4px;
}

.sig-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 40px;
  margin-bottom: 12px;
}

.sig-req-col {
  flex: 1;
  text-align: center;
}

.sig-req-line {
  border-bottom: 0.8pt solid #000000;
  width: 100%;
  height: 24px;
  margin-bottom: 6px;
}

.sig-thumb-col {
  width: 120px;
  text-align: center;
}

.polegar-box {
  width: 110px;
  height: 135px;
  border: 0.8pt solid #000000;
  border-radius: 8px;
  margin: 0 auto 5px;
}

.cpf-line-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 6px;
}

.cpf-ln-small {
  width: 160px;
  border-bottom: 0.8pt solid #000000;
  height: 16px;
  font-weight: bold;
  padding: 0 4px;
}

.nota-legal {
  text-align: right;
  font-size: 8pt;
  font-style: italic;
  margin-top: 4px;
  color: #333333;
}

/* Rodapé Oficial (Logo Verde/Dourada) */
.doc-footer {
  margin-top: 0;
  padding-top: 10px;
  border-top: 1.5pt solid var(--primary);
  text-align: center;
}

/* Espaçador Dinâmico do Rodapé */
.footer-spacer {
  display: block;
  height: 0;
  width: 100%;
}

.doc-footer-text {
  font-size: 8pt;
  color: #000000;
  line-height: 1.4;
}

/* Modal Customizado (Interface Administrativa) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.modal-content {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  transition: transform var(--transition-normal);
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-main);
}

.modal-text {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-btns {
  display: flex;
  gap: 12px;
}

.modal-btns button {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-modal-primary {
  background: var(--primary);
  color: #ffffff;
  border: none;
}

.btn-modal-primary:hover {
  background: var(--primary-hover);
}

.btn-modal-secondary {
  background: var(--surface-card);
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-modal-secondary:hover {
  border-color: var(--text-muted);
}

/* ==========================================================================
   ESTILOS DE IMPRESSÃO
   ========================================================================== */
@media print {
  @page {
    size: A4;
    margin: 20mm 20mm;
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    overflow: visible !important;
  }

  .sidebar,
  .preview-header-bar,
  .modal-overlay,
  .no-print {
    display: none !important;
  }

  .preview-container {
    background: #ffffff !important;
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
    display: block !important;
  }

  /* Todas as páginas de ofício */
  .pagina-oficio {
    width: 100% !important;
    height: calc(var(--pages, 1) * 257mm) !important; /* Altura exata em múltiplos de página útil A4 */
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
    display: block !important;
    page-break-after: always !important;
    break-after: page !important;
    overflow: hidden !important;
  }

  /* Evitar quebras de parágrafo no meio */
  .pagina-oficio p,
  .pagina-oficio .corpo,
  .pagina-oficio .declaro {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    orphans: 3;
    widows: 3;
  }

  /* Manter as assinaturas juntas */
  .pagina-oficio .sig-area {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-top: 15px !important;
    margin-bottom: 0 !important;
  }

  .pagina-oficio .sig-area > div,
  .pagina-oficio .sig-def-block,
  .pagina-oficio .sig-bottom-row,
  .pagina-oficio .sig-block {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Reduz espaçamento entre blocos de assinatura no print */
  .pagina-oficio .sig-block {
    margin-bottom: 20px !important;
  }
  .pagina-oficio .sig-space {
    height: 40px !important;
  }

  .pagina-oficio .sig-def-block {
    margin-bottom: 25px !important;
  }

  /* Rodapé Oficial no fluxo de cada documento (posicionado pelo espaçador) */
  .pagina-oficio .doc-footer {
    position: static !important;
    margin-top: 0 !important;
    display: block !important;
    padding-top: 8px !important;
    border-top: 1.5pt solid #005a2b !important;
    text-align: center !important;
    background: #ffffff !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .doc-footer-text {
    font-size: 7.5pt !important;
    color: #000 !important;
    line-height: 1.4 !important;
  }

  /* Última página: evita quebra depois */
  .pagina-oficio:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }
}
