:root {
  --azul:#004C97;
  --borda:#e0e0e0;
  --cinza:#f5f5f5;
  --texto:#111;
}

* {
  box-sizing:border-box;
  font-family:'Segoe UI',sans-serif;
}

body {
  background:var(--cinza);
  color:var(--texto);
  margin:0;
}

header {
  background:#fff;
  padding:16px 20px;
  border-bottom:1px solid var(--borda);
}

.brand {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.brand img {
  height:56px;
  object-fit:contain;
}

.titulo {
  font-size:20px;
  font-weight:700;
  color:var(--azul);
  text-align:center;
}

.muted {
  font-size:12px;
  color:#555;
  text-align:center;
}

.tabs {
  display:flex;
  gap:8px;
  padding:10px 20px;
  background:#fff;
  border-bottom:1px solid var(--borda);
  flex-wrap:wrap;
}

.tabbtn {
  border:1px solid var(--borda);
  background:#fff;
  padding:8px 14px;
  border-radius:8px;
  cursor:pointer;
}

.tabbtn.active {
  background:var(--azul);
  color:#fff;
  border-color:var(--azul);
}

main {
  padding:18px 20px;
  max-width:1200px;
  margin:auto;
}

.card {
  background:#fff;
  border:1px solid var(--borda);
  border-radius:10px;
  padding:16px;
  margin-bottom:20px;
}

.grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:12px;
}

label {
  font-size:12px;
  color:#555;
}

input,select {
  width:100%;
  padding:9px;
  border:1px solid var(--borda);
  border-radius:8px;
  font-size:14px;
}

.btn {
  border:none;
  background:var(--azul);
  color:#fff;
  padding:9px 14px;
  border-radius:8px;
  cursor:pointer;
  font-weight:600;
}

.btn.sec {
  background:#fff;
  color:var(--azul);
  border:1px solid var(--azul);
}

.actions {
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

/* ===== TABELAS ===== */
table {
  width:100%;
  border-collapse:collapse;
  margin-top:10px;
}

th, td {
  padding:8px;
  border-bottom:1px solid var(--borda);
  text-align:center;
  font-size:13.5px; /* fonte levemente menor */
  vertical-align:middle;
}

/* Ajuste final de proporções das colunas */
#tabelaItens th:nth-child(1),
#tabelaItens td:nth-child(1) { width:42%; text-align:left; } /* Descrição (aumentado) */
#tabelaItens th:nth-child(2),
#tabelaItens td:nth-child(2) { width:9%; text-align:center; } /* Peças/Pallet (reduzido) */
#tabelaItens th:nth-child(3),
#tabelaItens td:nth-child(3) { width:14%; text-align:right; } /* Valor Unitário (reduzido) */
#tabelaItens th:nth-child(4),
#tabelaItens td:nth-child(4) { width:9%; text-align:center; } /* Quantidade (reduzido) */
#tabelaItens th:nth-child(5),
#tabelaItens td:nth-child(5) { width:14%; text-align:right; } /* Total Material (reduzido) */
#tabelaItens th:nth-child(6),
#tabelaItens td:nth-child(6) { width:6%; text-align:center; }  /* Total Pallets (reduzido) */
#tabelaItens th:nth-child(7),
#tabelaItens td:nth-child(7) { width:6%; text-align:center; }  /* Ações (reduzido) */

td:first-child select {
  width:100%;
  max-width:100%;
  text-align:left;
  white-space:nowrap; /* impede quebra de linha */
  overflow:hidden;
  text-overflow:ellipsis; /* adiciona reticências se for MUITO longo */
  font-size:13px;
  padding:6px 8px;
}

th {
  background:#f0f4f9;
  font-weight:700;
  color:var(--azul);
}

tfoot td {
  font-weight:700;
  background:#f8f8f8;
}

.right {
  text-align:right;
}

.no-print {
  display:table-cell;
}

/* ===== Rodapé fixo ===== */
footer.rodape-fixo {
  text-align:center;
  font-size:11px;
  color:#555;
  font-style:italic;
  margin-top:20px;
  padding:8px;
  border-top:1px solid #ddd;
  background:#fafafa;
  position:fixed;
  bottom:0;
  left:0;
  right:0;
}

/* ===== IMPRESSÃO / PDF ===== */
@media print {
  footer.rodape-fixo {
    position:relative;
    bottom:0;
    background:transparent;
    border-top:none;
    color:#555;
  }

  /* Oculta botões e campos desnecessários */
  .tabs, .no-print, .btn,
  #km, #freteKm, label[for="km"], label[for="freteKm"] {
    display:none!important;
  }

  .card {
    border:none;
    box-shadow:none;
    padding:0;
  }

  main {
    padding:0 8mm;
    width:190mm;
  }

  th, td {
    border:1px solid #ccc;
    font-size:12.8px;
    padding:6px;
    vertical-align:middle;
  }

  th {
    background:#f3f6fb;
  }

  /* Mantém as mesmas proporções no PDF */
  #tabelaItens th:nth-child(1),
  #tabelaItens td:nth-child(1) { width:42%; text-align:left; }
  #tabelaItens th:nth-child(2),
  #tabelaItens td:nth-child(2) { width:9%; text-align:center; }
  #tabelaItens th:nth-child(3),
  #tabelaItens td:nth-child(3) { width:14%; text-align:right; }
  #tabelaItens th:nth-child(4),
  #tabelaItens td:nth-child(4) { width:9%; text-align:center; }
  #tabelaItens th:nth-child(5),
  #tabelaItens td:nth-child(5) { width:14%; text-align:right; }
  #tabelaItens th:nth-child(6),
  #tabelaItens td:nth-child(6) { width:6%; text-align:center; }
  #tabelaItens th:nth-child(7),
  #tabelaItens td:nth-child(7) { width:6%; text-align:center; }

  /* Select aparece como texto puro e mantém 1 linha */
  td:first-child select {
    border:none;
    background:transparent;
    appearance:none;
    -webkit-appearance:none;
    pointer-events:none;
    width:100%;
    font-size:12.8px;
    line-height:1.1;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
}

/* ===== Configuração da página A4 ===== */
@page {
  size:A4 portrait;
  margin:10mm;
}
