/* Variáveis e Reset */
:root {
  --primary: #2f2f2f;
  --primary-hover: #1f1f1f;
  --bg-color: #d4d0c8;
  --text-main: #111111;
  --text-muted: #4b4b4b;
  --border-color: #7f7f7f;
  --bg-card: #efefef;
  --bg-header: #dfdfdf;
  --radius: 0;
  --radius-sm: 0;
  --shadow: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  padding: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Tipografia e Headers */
header {
  text-align: center;
  padding: 20px 0;
}
h1 { font-size: 2.2rem; color: var(--primary); margin-bottom: 8px; }
h2 { font-size: 1.5rem; margin-bottom: 16px; border-bottom: 2px solid var(--bg-header); padding-bottom: 8px; }
h3 { font-size: 1.2rem; margin-bottom: 12px; }

/* Cards e Layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.grid-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.summary-item {
  text-align: center;
  padding: 16px;
  background: var(--bg-header);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.summary-item span { display: block; font-size: 2rem; font-weight: bold; color: var(--primary); }

/* Inputs e Botões */
.form-group {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}
input[type="text"], input[type="number"], input[type="file"], input[type="datetime-local"], select {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  padding-top: 8px; /* Ajuste para input file */
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  font-size: 1rem;
  background: #ffffff;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px #ffffff;
}

button {
  height: 40px;
  padding: 0 20px;
  background-color: #e1e1e1;
  color: #111111;
  border: 1px solid #7f7f7f;
  border-radius: var(--radius-sm);
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  font-size: 1rem;
  font-weight: 400;
  cursor: pointer;
  box-shadow: inset -1px -1px 0 #9b9b9b, inset 1px 1px 0 #ffffff;
}
button:hover { background-color: #d8d8d8; }
button:active {
  box-shadow: inset 1px 1px 0 #9b9b9b, inset -1px -1px 0 #ffffff;
}
button.secondary {
  background-color: #e1e1e1;
  color: var(--text-main);
  border: 1px solid #7f7f7f;
}
button.secondary:hover { background-color: #d8d8d8; }

/* Status e Helpers */
.status-msg {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  display: none;
}
.status-msg.loading { display: block; background: #efefef; color: #2f2f2f; border: 1px solid var(--border-color); }
.status-msg.success { display: block; background: #e8e8e8; color: #1f1f1f; border: 1px solid var(--border-color); }
.status-msg.error { display: block; background: #ececec; color: #1f1f1f; border: 1px solid var(--border-color); }

.help-text { font-size: 0.9rem; color: var(--text-muted); margin-top: 12px; }
details summary { cursor: pointer; color: var(--primary); font-weight: 500; }
details p, details ol { margin-top: 8px; padding-left: 20px; }

/* Painel de Filtros */
#filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.filter-col label { display: block; font-size: 0.9rem; font-weight: bold; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-range { display: flex; flex-direction: column; gap: 8px; }

/* Tabela de Dados */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.9rem;
  white-space: nowrap;
}
th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}
th {
  background-color: var(--bg-header);
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  font-weight: 700;
  color: #1a1a1a;
  position: sticky;
  top: 0;
}
tr:nth-child(even) { background-color: #f3f3f3; }
tr:hover { background-color: #e8e8e8; }

/* Paginação */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 0.95rem;
}
.pagination-controls { display: flex; gap: 8px; }

/* Relatório */
#report-section { margin-top: 24px; }
.report-actions { display: flex; gap: 12px; margin-bottom: 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stat-card { background: var(--bg-color); padding: 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); }
.stat-row { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border-color); padding: 4px 0; font-size: 0.95rem; }
.stat-row:last-child { border-bottom: none; }

.report-doc {
  background: #efefef;
  border: 1px solid var(--border-color);
  border-radius: 0;
  padding: 20px;
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  color: #111111;
}

.report-header-block {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.report-title {
  margin: 0;
  font-size: 1.8rem;
  color: #111111;
  font-weight: 700;
}

.report-subtitle {
  margin: 6px 0 0 0;
  color: #3f3f3f;
  font-size: 0.95rem;
}

.report-generated-at {
  padding: 6px 10px;
  border-radius: 0;
  background: #dfdfdf;
  color: #2f2f2f;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.report-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.report-meta-item {
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 0;
  background: #e7e7e7;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.report-meta-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #4b4b4b;
  font-weight: 700;
}

.report-meta-value {
  font-size: 1rem;
  color: #111111;
  font-weight: 700;
}

.report-section-block {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 0;
  background: #efefef;
}

.report-section-title {
  margin: 0 0 8px 0;
  font-size: 1.05rem;
  color: #111111;
  border: none;
  padding: 0;
}

.report-section-note {
  margin: 0 0 10px 0;
  color: #3f3f3f;
  font-size: 0.88rem;
}

.report-filters-text {
  margin: 0;
  font-size: 0.9rem;
  color: #1f1f1f;
  line-height: 1.45;
}

.report-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.report-kpi-card {
  border: 1px solid var(--border-color);
  border-radius: 0;
  background: #e7e7e7;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.report-kpi-label {
  font-size: 0.8rem;
  color: #4b4b4b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
}

.report-kpi-value {
  font-size: 1.6rem;
  color: #111111;
  line-height: 1.1;
}

.report-kpi-note {
  font-size: 0.78rem;
  color: #3f3f3f;
}

.report-table-wrap {
  border: 1px solid var(--border-color);
  border-radius: 0;
  overflow: hidden;
  overflow-x: auto;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  background: #efefef;
  white-space: normal;
}

.report-table th,
.report-table td {
  border-bottom: 1px solid #bdbdbd;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 0.84rem;
  color: #111111;
}

.report-table th {
  background: #dcdcdc;
  color: #111111;
  font-weight: 700;
}

.report-table tbody tr:nth-child(even) {
  background: #e6e6e6;
}

.report-table tbody tr:last-child td {
  border-bottom: none;
}

.report-empty-cell {
  text-align: center !important;
  color: #4b4b4b !important;
  padding: 18px !important;
}

.report-table-detailed td:last-child {
  min-width: 260px;
}

.pdf-avoid-break {
  break-inside: avoid-page;
  page-break-inside: avoid;
}

@media (max-width: 820px) {
  .report-title { font-size: 1.45rem; }
  .report-header-block { flex-direction: column; align-items: flex-start; }
  .report-generated-at { white-space: normal; }
  .report-table th, .report-table td { font-size: 0.8rem; }
}

.hidden { display: none !important; }

/* Animação Spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(0,0,0,0.1); border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
  margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Impressão */
@media print {
  body { background: white; padding: 0; }
  .container { max-width: 100%; gap: 12px; }
  .no-print, header, #input-section, #filter-section, .report-actions, .pagination { display: none !important; }
  #report-section { display: block !important; }
  .card { border: none; box-shadow: none; padding: 0; }
  table { font-size: 10px; }
  th, td { padding: 6px; white-space: normal; }
  .report-doc { border: none; border-radius: 0; padding: 0; }
  .report-section-block { break-inside: avoid-page; page-break-inside: avoid; margin-top: 10px; padding: 10px; }
  .report-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .report-kpi-card { break-inside: avoid-page; page-break-inside: avoid; }
  .report-table th, .report-table td { font-size: 9.5px; padding: 5px 6px; }
  .report-generated-at { font-size: 10px; }
}
