/* =========================================
   VARIÁVEIS DE CORES (IDENTIDADE MC CONSULTORIA)
   ========================================= */
:root {
  /* Amarelo Ouro - Cor Principal (Destaques, Botões) */
  --primary: #FFC107;       
  --primary-hover: #D4AF37; 
  
  /* Preto Absoluto - Cor Secundária (Texto, Elementos Fortes) */
  --dark: #000000;
  
  /* Cores de Apoio */
  --secondary: #ffffff;
  --bg-body: #f1f5f9;       
  --gray: #64748b;
  --gray-light: #e2e8f0;
  
  /* Status */
  --danger: #ef4444;
  --success: #10b981;
}

/* =========================================
   RESET E BASE
   ========================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--dark);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-weight: 600;
  color: var(--dark);
}

a { text-decoration: none; color: inherit; }

/* Utilitários de Controle de Acesso e Layout */
.admin-only {
  display: none; /* Escondido por padrão, JS ativa se for admin */
}

/* =========================================
   LAYOUT E CONTAINERS
   ========================================= */
.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--secondary);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--gray-light);
}

/* =========================================
   CABEÇALHO (HEADER)
   ========================================= */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  background: var(--secondary);
  padding: 16px;
  border-radius: 12px;
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.logo {
  height: 56px;
  width: auto;
  object-fit: contain;
}

.top h1 {
  font-size: 18px;
  margin: 0;
  color: var(--dark);
}

.lead {
  color: var(--gray);
  font-size: 13px;
}

/* Status de Autenticação no Header */
#authStatusContainer {
  text-align: right; 
  width: 100%;
}

/* =========================================
   LOGIN OVERLAY
   ========================================= */
#loginOverlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-body);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

#loginCard {
  background: var(--secondary);
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 400px;
  text-align: center;
  border-top: 4px solid var(--primary); 
}

#loginCard h2 {
  margin-bottom: 24px;
  font-size: 20px;
}

/* =========================================
   TABELA E RELATÓRIOS
   ========================================= */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  white-space: nowrap; /* Garante scroll horizontal no mobile */
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0; /* Impede botões de encolherem demais */
}

.tab-btn:hover {
  background: rgba(0,0,0,0.05);
  color: var(--dark);
}

.tab-btn.active {
  background: var(--dark);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Wrapper de tabela para scroll responsivo */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
  border: 1px solid #eee;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px; /* Força scroll horizontal em telas pequenas */
}

th {
  text-align: left;
  padding: 12px;
  background: #f8fafc;
  color: var(--gray);
  font-weight: 600;
  border-bottom: 2px solid var(--gray-light);
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--gray-light);
  color: var(--dark);
}

tbody tr:nth-child(even) { background-color: #f8fafc; }
tbody tr:hover { background-color: var(--gray-light); cursor: default; }

/* =========================================
   FORMULÁRIOS
   ========================================= */
.form-row { margin-bottom: 16px; }

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-light);
  border-radius: 6px;
  font-size: 14px;
  color: var(--dark);
  background: #fff;
  transition: border-color 0.2s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2);
}

input[readonly] {
  background-color: #f8fafc;
  color: var(--gray);
  cursor: not-allowed;
}

/* =========================================
   BOTÕES
   ========================================= */
.actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn.primary {
  background-color: var(--primary);
  color: var(--dark);
  box-shadow: 0 2px 4px rgba(234, 179, 8, 0.3);
}
.btn.primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}
.btn.primary:active { transform: translateY(0); }

.btn.ghost {
  background: transparent;
  color: var(--gray);
  border: 1px solid var(--gray-light);
}
.btn.ghost:hover {
  background: #f1f5f9;
  color: var(--dark);
  border-color: var(--gray);
}

.btn.alt {
  background: var(--dark);
  color: var(--primary);
}
.btn.alt:hover { opacity: 0.9; }

.btn.small {
  padding: 4px 8px;
  font-size: 12px;
}

.loader {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: var(--dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
}

.btn.loading .loader { display: block; }
.btn.loading span { display: none; }
.btn.loading { pointer-events: none; opacity: 0.8; }

@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   VISUALIZAÇÃO DO DOCUMENTO (PREVIEW) - ATUALIZADO
   ========================================= */
.grid-main {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
}

.sticky-preview {
  position: sticky;
  top: 20px;
}

.doc {
  background: #fff;
  border: 1px solid #e2e8f0;
  padding: 24px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  color: #000;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

/* Novo layout de Header para evitar quebra no mobile */
.doc-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.doc-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

#logoPreview {
  width: 80px;
  height: auto;
  object-fit: contain;
}

.doc-company-info {
  flex: 1;
}

/* Informações Meta (Data, Hora, Usuario) */
.doc-meta-info {
  text-align: right;
  font-size: 11px;
  color: #444;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Separador pontilhado via CSS (seguro para mobile) */
.doc-separator {
  border-bottom: 2px dashed #000;
  margin: 10px 0 15px 0;
  width: 100%;
}

.doc-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.doc-label {
  font-weight: bold;
  font-size: 11px;
  text-transform: uppercase;
  color: #444;
}

.doc-val {
  font-weight: bold;
  font-size: 14px;
}

.doc-big {
  font-size: 18px;
  font-weight: bold;
  color: #000;
}

.signature-box {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* =========================================
   KPI CARDS (RELATÓRIOS)
   ========================================= */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--gray-light);
}

.kpi-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--dark);
  color: #fff;
  padding: 16px;
  border-radius: 8px;
  text-align: center;
  border-bottom: 4px solid var(--primary);
}

.kpi-label {
  font-size: 12px;
  opacity: 0.8;
  text-transform: uppercase;
  margin-bottom: 4px;
  color: var(--primary);
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
}

/* =========================================
   MEDIA QUERIES (RESPONSIVIDADE COMPLETA)
   ========================================= */
@media (max-width: 768px) {
  /* Layout Global */
  .grid-main { 
    display: block !important; 
    grid-template-columns: 1fr; 
  }
  
  /* Cabeçalho */
  .top {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
  }
  .top .logo { margin-right: 0; margin-bottom: 10px; }
  #authStatusContainer { text-align: center !important; margin-top: 5px; }

  /* Formulários */
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Preview */
  .sticky-preview {
    position: relative !important;
    width: 100% !important;
    top: auto !important;
    margin-top: 30px;
    border-top: 2px dashed #ccc;
    padding-top: 20px;
  }

  /* Inputs amigáveis para touch */
  input, select, button {
    min-height: 48px; /* Altura mínima para dedo */
    font-size: 16px !important; /* Evita zoom automático no iPhone */
  }

  /* Modal Fullscreen */
  .modal-card {
    width: 95% !important;
    margin: 10px;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* Responsividade específica para o cabeçalho do recibo (telas muito pequenas) */
@media (max-width: 480px) {
  .doc-header-main {
    flex-direction: column;
    text-align: center;
  }
  
  .doc-meta-info {
    text-align: center;
    margin-top: 5px;
    border-top: 1px solid #eee;
    padding-top: 5px;
  }
}

/* =========================================
   NOTIFICAÇÕES (SNACKBAR)
   ========================================= */
#snackbar {
  visibility: hidden;
  min-width: 250px;
  background-color: var(--dark);
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 12px;
  position: fixed;
  z-index: 10000;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  font-size: 14px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#snackbar.show {
  visibility: visible;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} }
@keyframes fadeout { from {bottom: 30px; opacity: 1;} to {bottom: 0; opacity: 0;} }

/* =========================================
   MODAL
   ========================================= */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 5000; /* Abaixo do Login e Snackbar */
  opacity: 0;
  transition: opacity 0.3s;
}

.modal-overlay.show { opacity: 1; }

.modal-card {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  border-top: 4px solid var(--primary);
}