/* ==========================================================================
   1. RESET & VARIÁVEIS
   ========================================================================== */
:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --text-dark: #333;
  --text-muted: #666;
  --border-color: #e0e0e0;
  --bg-light: #f8f9fa;
  --white: #ffffff;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: #f0f2f5;
  color: var(--text-dark);
  font-size: 14px;
  line-height: 1.5;
  padding-bottom: 60px; /* Espaço para footer se houver */
}

/* ==========================================================================
   2. NAVBAR
   ========================================================================== */
.navbar {
  background-color: var(--white);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.back-button a {
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}
.back-button a:hover { color: var(--primary-color); }

.logo {
  flex: 1;
  display: flex;
  justify-content: center;
}
.logo-img {
  height: 40px;
  object-fit: contain;
}

.clock {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-color);
  background: #e3f2fd;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.user-email {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 15px;
  display: none; /* Escondido em mobile por padrão */
}

@media (min-width: 768px) {
  .user-email { display: block; }
}

/* ==========================================================================
   3. FORMULÁRIO PRINCIPAL
   ========================================================================== */
#formRDO {
  width: 100%;
  max-width: 1200px;
  margin: 20px auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 25px;
}

h2, h3 {
  color: var(--text-dark);
  margin-bottom: 20px;
  font-weight: 700;
}

h2 { border-bottom: 2px solid var(--bg-light); padding-bottom: 10px; }
h3 { font-size: 1.1rem; color: #444; margin-top: 30px; }

/* Grid System para Inputs */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 15px;
}

.form-group {
  flex: 1;
  min-width: 250px; /* Garante que quebre linha em telas pequenas */
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-weight: 600;
  font-size: 0.85rem;
  color: #555;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1rem; /* Importante para não dar zoom no iPhone */
  font-family: inherit;
  transition: border-color 0.2s;
  background-color: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

textarea { resize: vertical; }

.file-hint {
  font-size: 0.8rem;
  color: #888;
  margin-top: 4px;
}

/* ==========================================================================
   4. TABELA RESPONSIVA (Pedidos a Entregar)
   ========================================================================== */
.pedidos-wrapper {
  width: 100%;
  overflow-x: auto; /* Rolagem horizontal vital para mobile */
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--white);
  margin-top: 10px;
}

table {
  width: 100%;
  min-width: 1000px; /* Força a largura para garantir layout correto */
  border-collapse: collapse;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #eee;
  white-space: nowrap; /* Evita quebra de linha feia */
  font-size: 0.9rem;
}

th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: #444;
  position: sticky;
  top: 0;
}

tr:hover { background-color: #f1f7ff; }

/* Botões dentro da tabela */
.btn-doc-pedido {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.btn-doc-pedido:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  background: #f0f7ff;
}
.btn-doc-pedido.edit {
  background: #e3f2fd;
  color: var(--primary-color);
  border-color: #90caf9;
}

.status-entrega-select {
  padding: 6px;
  font-size: 0.85rem;
  border-radius: 4px;
}

/* ==========================================================================
   5. LISTAS DINÂMICAS (Materiais / Equipamentos)
   ========================================================================== */
/* Botões de Adicionar */
button[onclick^="add"] {
  background-color: var(--bg-light);
  border: 1px dashed #bbb;
  color: var(--text-dark);
  padding: 10px 15px;
  border-radius: 6px;
  width: 100%;
  cursor: pointer;
  font-weight: 600;
  margin-top: 10px;
  transition: all 0.2s;
}
button[onclick^="add"]:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  background-color: #f0f7ff;
}

/* --- OVERRIDES PARA AS LINHAS INJETADAS PELO JS --- */
/* O JS injeta styles inline com grid. Precisamos forçar o comportamento mobile */

@media (max-width: 768px) {
  /* Força as linhas a virarem Cards empilhados */
  .mat-row, .eqp-row, .team-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    background: #fff;
    border: 1px solid #eee;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
  }

  /* Ajusta a imagem dentro da linha */
  .mat-imagem-wrap, .eqp-imagem-wrap {
    width: 100% !important;
    height: 150px !important;
    margin-bottom: 5px;
  }

  /* Ajusta os inputs para 100% de largura */
  .mat-row input, .eqp-row input, .team-row input {
    width: 100% !important;
  }

  /* Botão de excluir vira um bloco vermelho */
  .mat-del, .eqp-del, .team-del {
    width: 100% !important;
    background-color: #ffebee !important;
    color: var(--danger-color);
    padding: 10px !important;
    margin-top: 5px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .mat-del::after, .eqp-del::after, .team-del::after {
    content: " Remover Item";
    margin-left: 5px;
    font-weight: 600;
  }
}

/* ==========================================================================
   6. PREVIEWS DE ARQUIVOS
   ========================================================================== */
#previewContainer, #notaFiscalPreview {
  margin-top: 15px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
}

.img-preview-item {
  position: relative;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 8px;
  overflow: hidden;
}

/* ==========================================================================
   7. MODAIS (Upload Boleto, Produtos)
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  display: flex; /* O JS controla display: none/flex */
  align-items: center;
  justify-content: center;
  padding: 15px; /* Espaço nas bordas em mobile */
  backdrop-filter: blur(2px);
}

/* Container interno da modal */
.modal > div {
  background: #fff;
  padding: 25px;
  border-radius: 12px;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  animation: slideUp 0.3s ease-out;
  max-height: 90vh; /* Evita que a modal estoure a altura da tela */
  overflow-y: auto;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Ajustes específicos do JS injetado */
#produtosModalCard {
  width: 95% !important;
  height: 80vh !important;
  max-width: 800px !important;
}

#produtosGrid {
  grid-template-columns: 1fr !important; /* 1 coluna no mobile */
}
@media (min-width: 600px) {
  #produtosGrid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
  }
}

/* ==========================================================================
   8. FOOTER / AÇÕES
   ========================================================================== */
.form-actions {
  display: flex;
  gap: 15px;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.form-actions button {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.form-actions button:active { transform: scale(0.98); }

button[type="submit"] {
  background-color: var(--success-color);
  color: white;
  box-shadow: 0 4px 10px rgba(40, 167, 69, 0.3);
}

button[type="reset"] {
  background-color: #f1f3f5;
  color: #555;
}

/* ==========================================================================
   9. MOBILE OVERRIDES FINAIS
   ========================================================================== */
@media (max-width: 600px) {
  #formRDO { padding: 15px; margin: 10px auto; }
  
  .form-row { flex-direction: column; gap: 15px; }
  .form-group { min-width: 100%; }
  
  .clock { display: none; } /* Esconde relógio se faltar espaço */
  
  /* Ajuste no Preview de imagens para ocupar 2 colunas */
  #previewContainer {
    grid-template-columns: repeat(2, 1fr);
  }
}
/* ==========================================================================
   AJUSTE DE LARGURA DESKTOP (95%)
   ========================================================================== */
@media (min-width: 1024px) {
  #formRDO {
    /* Sobrescreve o limite de 1200px */
    max-width: 95% !important; 
    width: 95% !important;
    
    /* Garante que esteja centralizado */
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* Garante que o container da tabela interna também cresça */
  .pedidos-wrapper {
    width: 100%;
  }
}
/* ==========================================================================
   UPLOAD MODERNO (Imagens & Notas Fiscais)
   ========================================================================== */

/* 1. Estilização do Container da Seção */
.section {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 25px;
  margin-bottom: 25px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.section h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 1.1rem;
  color: #1e293b; /* Azul escuro quase preto */
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Adiciona um ícone visual via CSS antes do título */
.section h3::before {
  content: '';
  display: block;
  width: 4px;
  height: 18px;
  background-color: var(--primary-color);
  border-radius: 2px;
}

/* 2. O Input de Arquivo (A "Caixa" tracejada) */
input[type="file"] {
  width: 100%;
  padding: 30px 20px; /* Espaço interno grande */
  border: 2px dashed #cbd5e1; /* Borda tracejada cinza */
  border-radius: 10px;
  background-color: #f8fafc; /* Fundo muito leve */
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  position: relative;
  font-size: 0.95rem;
  color: #64748b;
}

/* Efeito Hover na caixa */
input[type="file"]:hover {
  border-color: var(--primary-color); /* Fica azul */
  background-color: #f0f9ff; /* Fundo azul bem clarinho */
}

/* 3. O Botão "Escolher Arquivo" dentro do input */
input[type="file"]::file-selector-button {
  margin-right: 15px;
  padding: 10px 20px;
  border: none;
  background-color: var(--primary-color);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s;
  box-shadow: 0 2px 5px rgba(0, 123, 255, 0.2);
}

input[type="file"]::file-selector-button:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

/* 4. Texto de Dica (Formatos aceitos) */
.file-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: #94a3b8; /* Cinza médio */
  font-weight: 500;
}
/* Ícone de info antes da dica */
.file-hint::before {
  content: 'ⓘ';
  font-weight: bold;
  font-size: 14px;
}

/* 5. Área de Preview (Melhorias no Grid) */
#previewContainer, #notaFiscalPreview {
  margin-top: 20px;
  display: grid;
  /* Cria colunas automáticas que não ficam menores que 160px */
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); 
  gap: 16px;
}

/* Card Individual do Arquivo */
.img-preview-item, 
#notaFiscalPreview > div {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}

.img-preview-item:hover, 
#notaFiscalPreview > div:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-color: #cbd5e1;
}

/* Imagem/Embed dentro do card */
.img-preview-item img, 
#notaFiscalPreview img,
#notaFiscalPreview embed {
  border-radius: 6px;
  border: 1px solid #f1f5f9;
  background-color: #f8fafc;
  object-fit: cover;
  width: 100%;
  /* Força altura fixa para ficarem alinhados */
  height: 140px; 
}

/* Nome do arquivo */
.img-preview-item div:nth-child(2),
#notaFiscalPreview div:nth-child(1) {
  font-size: 0.8rem;
  color: #475569;
  font-weight: 600;
  margin: 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Botão Remover */
.img-preview-item button {
  margin-top: auto; /* Empurra para o fundo */
  background-color: #fee2e2 !important;
  color: #ef4444 !important;
  border-radius: 6px !important;
  font-size: 0.8rem !important;
  padding: 6px !important;
  width: 100%;
  transition: background 0.2s;
}
.img-preview-item button:hover {
  background-color: #fecaca !important;
  color: #dc2626 !important;
}
/* ==========================================================================
   AJUSTE DE ROLAGEM HORIZONTAL (Mobile)
   ========================================================================== */

/* Container da Tabela */
.pedidos-wrapper {
  width: 100%;
  overflow-x: auto; /* Habilita rolagem horizontal */
  -webkit-overflow-scrolling: touch; /* Rolagem suave no iOS */
  
  /* Garante que o container respeite a largura da tela */
  max-width: 100vw; 
  display: block; /* Garante comportamento de bloco */
  white-space: nowrap; /* Impede quebra de linha nas células */
  
  /* Espaçamento para a sombra não cortar */
  padding-bottom: 10px;
  margin-bottom: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}

/* Força a tabela a ter uma largura mínima para ativar o scroll */
#tabelaPedidosEntrega {
  min-width: 800px; /* Ajuste conforme a quantidade de colunas */
  width: 100%;
}

/* ==========================================================================
   BARRA DE ROLAGEM VISÍVEL (Estilização Customizada)
   ========================================================================== */

/* Funciona em Chrome, Edge, Safari e Android Webview */
.pedidos-wrapper::-webkit-scrollbar {
  height: 8px; /* Altura da barra horizontal */
}

.pedidos-wrapper::-webkit-scrollbar-track {
  background: #f1f1f1; 
  border-radius: 4px;
}

.pedidos-wrapper::-webkit-scrollbar-thumb {
  background: #c1c1c1; /* Cor da barra */
  border-radius: 4px;
  border: 2px solid #f1f1f1; /* Cria um efeito de padding */
}

.pedidos-wrapper::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8; /* Cor ao passar o mouse/dedo */
}

/* Ajuste específico para Firefox (se necessário) */
.pedidos-wrapper {
  scrollbar-width: thin;
  scrollbar-color: #c1c1c1 #f1f1f1;
}

/* ==========================================================================
   DICA VISUAL (Opcional mas Recomendado)
   ========================================================================== */
/* Adiciona uma sombra na direita para indicar que tem mais conteúdo */
.pedidos-wrapper {
  background: 
    linear-gradient(to right, white 30%, rgba(255,255,255,0)),
    linear-gradient(to right, rgba(255,255,255,0), white 70%) 0 100%,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.2), rgba(0,0,0,0)),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.2), rgba(0,0,0,0)) 0 100%;
  background-repeat: no-repeat;
  background-color: white;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-attachment: local, local, scroll, scroll;
}

.modal-rdo {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; z-index: 10001;
}
.modal-content-rdo {
    background: white; width: 90%; max-width: 800px; max-height: 80vh;
    border-radius: 16px; overflow: hidden; display: flex; flex-direction: column;
}
.modal-header { padding: 20px; background: #f8fafc; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
.modal-filters { padding: 15px; background: #f1f5f9; display: flex; gap: 10px; }
.modal-filters input { flex: 2; padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; }
.modal-filters select { flex: 1; padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

#listaProdutosModal tr:hover, #listaEquipeModal tr:hover {
    background-color: #f0f7ff;
}

/* --- CARD DE PEDIDO PENDENTE (Layout Novo) --- */
.pedido-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 15px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}
.pc-header {
    background: #f8fafc;
    padding: 10px 15px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pc-body {
    padding: 15px;
}
.pc-item-row {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr; /* Item, Qtd, Valor */
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px dashed #f1f5f9;
    font-size: 12px;
}
.pc-footer {
    padding: 10px 15px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.badge-status {
    background: #e0f2fe; color: #0284c7; 
    padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase;
}

/* Estado visual quando o pedido foi marcado para entrega (Staging) */
.pedido-card.marcado-entregue {
    border: 2px solid #10b981;
    background-color: #f0fdf4;
}
.pedido-card.marcado-entregue .pc-header {
    background: #d1fae5;
}

/* Estilo da linha de data dinâmica na modal */
.row-data-boleto {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: #f8fafc; 
    padding: 8px; 
    border: 1px solid #e2e8f0; 
    border-radius: 6px;
    margin-bottom: 5px;
}

/* Lista de arquivos dentro da modal */
.file-list-item {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    background: #f8fafc; 
    padding: 8px 12px; 
    border: 1px solid #e2e8f0; 
    border-radius: 6px; 
    margin-top: 5px;
    font-size: 12px;
}
.file-list-item span {
    display: flex; 
    align-items: center; 
    gap: 6px; 
    color: #334155;
    font-weight: 500;
}
.btn-remove-file {
    color: #ef4444; 
    background: none; 
    border: none; 
    cursor: pointer; 
    font-weight: bold;
    font-size: 14px;
}
.btn-remove-file:hover { color: #b91c1c; }