/* ============================
   VARIÁVEIS E ESTILOS GERAIS
   ============================ */
:root {
  --bg: #071427;
  --card: #0b1220;
  --muted: #9aa7bf;
  --accent: #06b6d4;
  --danger-ash: rgba(255, 99, 71, 0.12);
  --danger-border: rgba(255, 99, 71, 0.25);
}

body {
  margin: 0;
  background: linear-gradient(180deg, #071028 0%, #071827 100%);
  color: #e6eef8;
  font-family: Inter, system-ui, Arial, sans-serif;
}

header {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.container {
  padding: 18px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card {
  background: var(--card);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

select,
input,
button {
  background: transparent;
  border: 1px solid #1f2937;
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  outline: none;
}

button {
  background: var(--accent);
  color: #041018;
  border: 0;
  cursor: pointer;
}

.info-icon {
  font-size: 13px;
  color: #9ca3af; /* cinza suave */
  cursor: help;
  margin-left: 4px;
}

/* ============================
   ESTILOS DA TABELA E RESPONSIVIDADE
   ============================ */
.table-container {
  width: 100%;
  overflow: auto;
  max-height: 520px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  /* Garante que o container seja o contexto de scroll */
  display: block;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  /* Remove margens que podem deslocar o sticky */
  margin: 0;
}

th,
td {
  padding: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  /* A cor deve ser exatamente a do fundo do card para não parecer transparente */
  background-color: #0b1220 !important;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  z-index: 10;
  /* O box-shadow cria a ilusão de uma borda que não "rola" */
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.1);
}

/* Fix para garantir que o cabeçalho não suba em navegadores baseados em Chromium */
thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.numeric {
  text-align: right;
}

.qty-input {
  width: 50px !important;
  padding: 6px 8px !important;
  border: 1px solid #444 !important;
  border-radius: 3px !important;
  background-color: #0f1419 !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  text-align: center !important;
}

.qty-input:focus {
  outline: none !important;
  border-color: #4a90e2 !important;
}

.percent-input {
  width: 50px !important;
  padding: 6px 8px !important;
  border: 1px solid #444 !important;
  border-radius: 3px !important;
  background-color: #0f1419 !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  text-align: center !important;
}

.percent-input:focus {
  outline: none !important;
  border-color: #4a90e2 !important;
}

.outlier-row {
  background-color: rgba(239, 68, 68, 0.15) !important; /* Vermelho mais visível */
  color: #fca5a5; /* Texto levemente avermelhado */
}

.outlier-row td {
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
}

.obs-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Linha pendente */
.pending-row {
  background: rgba(250, 204, 21, 0.08);
  opacity: 0.85;
}

.pending-row:hover {
  background: rgba(250, 204, 21, 0.12);
}

td.pending-cell {
  color: #facc15;
  font-style: italic;
}

/* Célula não encontrado */
td.not-found-cell {
  color: #fb923c;
  font-style: italic;
  font-weight: 500;
}

.calib-select {
  width: 50px !important;
  padding: 6px 8px !important;
  border: 1px solid #444 !important;
  border-radius: 3px !important;
  background-color: #0f1419 !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  text-align: center !important;
  cursor: pointer;
}

.calib-select:focus {
  outline: none !important;
  border-color: #4a90e2 !important;
}

.calib-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================
   ESTILOS DE ORDENAÇÃO (SORT)
   ============================ */
.sortable {
  cursor: pointer;
  position: relative;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.sortable::after {
  content: '';
  position: absolute;
  right: 6px;
  top: 50%;
  margin-top: -7px;
  border: 4px solid transparent;
  opacity: 0.3;
}

.sortable.sort-asc::after {
  border-bottom-color: var(--accent);
  opacity: 1;
}

.sortable.sort-desc::after {
  border-top-color: var(--accent);
  opacity: 1;
}

/* ============================
   ESTILOS DO INTERRUPTOR (TOGGLE SWITCH)
   ============================ */
.title-container {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 20px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
}

#controls-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 8px 0;
  margin-bottom: 0 !important;
}

#controls-container > * {
  flex-shrink: 0;
  white-space: nowrap;
}

#controls-container > div {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

#controls-container > strong {
  font-size: 13px;
  margin-left: 8px;
}

#controls-container > span {
  font-size: 12px;
}

#controls-container > input {
  flex-shrink: 0;
  padding: 4px !important;
}

.toggle-switch-container {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
}

.toggle-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 0;
  white-space: nowrap;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  flex-wrap: nowrap;
}

.radio-label input[type="radio"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.percent-input {
  width: 50px !important;
  padding: 6px 8px !important;
  border: 1px solid #444 !important;
  border-radius: 3px !important;
  background-color: #0f1419 !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  text-align: center !important;
}

.percent-input:focus {
  outline: none !important;
  border-color: #4a90e2 !important;
}



/* ============================
   ESTILOS DA JANELA MODAL
   ============================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card);
  padding: 24px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 90%;
  max-width: 500px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  box-sizing: border-box;
  overflow-y: auto;
  max-height: 90vh;
}

.modal-content h4 {
  margin-top: 0;
  color: var(--accent);
}

.modal-content p {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  margin: 0 0 16px 0;
  line-height: 1.4;
}

.form-group {
  margin-bottom: 16px;
}

.form-group[style*="display: flex"] {
  flex-wrap: wrap;
  align-items: flex-start;
}

.toggle-label {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  flex: 1;
  min-width: 200px;
}

.form-group label {
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--muted);
}

.form-group input {
  width: 100%;
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* ============================
   TOOLTIP PARA LABEL
   ============================ */
label[title] {
  cursor: help;
  position: relative;
}

label[title]:hover {
  text-decoration: underline dotted;
}

/* ============================
   ESTILOS PARA A TABELA DE RELATÓRIO (MATRIZ)
   ============================ */
.report-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 11px;
    background-color: #0b1220;
}

.report-table th, .report-table td {
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 6px 8px;
    text-align: center;
    color: #e6eef8;
}

.report-table thead th {
    background-color: #071427 !important;
    position: sticky;
    z-index: 20;
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.1);
}

/* Cabeçalho triplo sticky */
.report-table thead tr:nth-child(1) th { top: 0; z-index: 23; height: 35px; }
.report-table thead tr:nth-child(2) th { top: 35px; z-index: 22; height: 35px; }
.report-table thead tr:nth-child(3) th { top: 70px; z-index: 21; height: 35px; }

.report-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Fixar as duas primeiras colunas (ID e Produto) */
.report-table td:nth-child(1), 
.report-table td:nth-child(2) {
    position: sticky;
    left: 0;
    background-color: #0b1220;
    z-index: 10;
    text-align: left;
    box-shadow: 1px 0 0 rgba(255, 255, 255, 0.1);
}

.report-table td:nth-child(1) { left: 0; width: 40px; }
.report-table td:nth-child(2) { left: 40px; min-width: 200px; }

.report-table th:nth-child(1),
.report-table th:nth-child(2) {
    left: 0;
    z-index: 30;
}
.report-table thead tr:nth-child(1) th:nth-child(1) { left: 0; z-index: 35; }
.report-table thead tr:nth-child(2) th:nth-child(1) { left: 0; z-index: 34; }
.report-table thead tr:nth-child(3) th:nth-child(1) { left: 0; z-index: 33; }
