/* ================================================================
   PaintLab AI — Matérias-Primas · API Railway
   Fonte única de verdade: paintlab-backend-production.up.railway.app
================================================================ */

/* ── Layout wrapper ─────────────────────────────────────────── */
#page-raw-materials .mp-page-wrapper {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0;
  max-width: 1400px;
}

/* ── Cabeçalho ──────────────────────────────────────────────── */
.mp-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.mp-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mp-header-title h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.mp-header-title h2 i { color: var(--primary); }

.mp-api-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  background: linear-gradient(135deg, rgba(20,65,150,0.12), rgba(77,127,212,0.12));
  border: 1px solid rgba(20,65,150,0.25);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.3px;
}

.mp-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mp-sync-btn i { transition: transform 0.4s; }
.mp-sync-btn:hover i { transform: rotate(180deg); }

/* ── Barra de Status de Conexão ─────────────────────────────── */
.mp-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s ease;
  flex-wrap: wrap;
}

/* Estado: carregando */
.mp-status-bar.status-loading {
  background: rgba(77,127,212,0.06);
  border-color: rgba(77,127,212,0.2);
  color: #6366f1;
}
.mp-status-bar.status-loading .mp-status-dot i { color: #6366f1; }

/* Estado: conectado OK */
.mp-status-bar.status-ok {
  background: rgba(22,163,74,0.06);
  border-color: rgba(22,163,74,0.2);
  color: var(--text-sub);
}
.mp-status-bar.status-ok .mp-status-dot i {
  color: #16a34a;
  font-size: 9px;
  animation: pulseDot 2s ease-in-out infinite;
}

/* Estado: erro */
.mp-status-bar.status-error {
  background: rgba(220,38,38,0.06);
  border-color: rgba(220,38,38,0.2);
  color: #dc2626;
}
.mp-status-bar.status-error .mp-status-dot i { color: #dc2626; }

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

.mp-status-label { font-weight: 700; }
.mp-status-sep   { opacity: 0.4; }

.mp-status-ts {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.75;
}

.mp-status-endpoint {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.5;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Cards de Estatísticas ──────────────────────────────────── */
.mp-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mp-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
}

.mp-stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}

.mp-stat-card.stat-blue::before   { background: linear-gradient(90deg, #144196, #4d7fd4); }
.mp-stat-card.stat-green::before  { background: linear-gradient(90deg, #16a34a, #4ade80); }
.mp-stat-card.stat-orange::before { background: linear-gradient(90deg, #d97706, #fbbf24); }
.mp-stat-card.stat-red::before    { background: linear-gradient(90deg, #dc2626, #f87171); }

.mp-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.mp-stat-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.stat-blue   .mp-stat-icon { background: rgba(20,65,150,0.1);  color: #144196; }
.stat-green  .mp-stat-icon { background: rgba(22,163,74,0.1);  color: #22c55e; }
.stat-orange .mp-stat-icon { background: rgba(217,119,6,0.1);  color: #f59e0b; }
.stat-red    .mp-stat-icon { background: rgba(220,38,38,0.1);  color: #ef4444; }

.mp-stat-body  { flex: 1; min-width: 0; }
.mp-stat-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.mp-stat-value {
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ── Filtros ────────────────────────────────────────────────── */
.mp-filters-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

/* Campo de busca */
.mp-search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.mp-search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

.mp-search-input {
  width: 100%;
  padding: 9px 36px 9px 38px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.mp-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20,65,150,0.12);
  background: var(--bg-input, var(--bg-card));
}

.mp-search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
  transition: color 0.15s;
}
.mp-search-clear:hover { color: var(--danger); }

/* Grupo de filtro de custo */
.mp-cost-group {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.mp-cost-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mp-filter-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.mp-filter-input {
  width: 110px;
  padding: 9px 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.mp-filter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20,65,150,0.12);
}

.mp-cost-sep {
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 300;
  padding-bottom: 7px;
}

/* Botão limpar filtros */
.mp-clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  height: 38px;
  align-self: flex-end;
}

.mp-clear-btn:hover {
  background: rgba(220,38,38,0.06);
  border-color: rgba(220,38,38,0.3);
  color: #dc2626;
}

/* ── Barra de ordenação + contagem ──────────────────────────── */
.mp-sort-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mp-sort-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mp-sort-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.mp-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.mp-sort-btn:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(20,65,150,0.05);
}

.mp-sort-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(20,65,150,0.3);
}

.mp-sort-arrow {
  font-size: 9px;
  opacity: 0.6;
  transition: transform 0.2s;
}

.mp-sort-btn.sort-desc .mp-sort-arrow { transform: rotate(180deg); opacity: 1; }
.mp-sort-btn.sort-asc  .mp-sort-arrow { transform: rotate(0deg);   opacity: 1; }

.mp-count-badge {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Container da tabela ────────────────────────────────────── */
.mp-table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow);
}

.mp-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Loading overlay ────────────────────────────────────────── */
.mp-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  gap: 10px;
  border-radius: var(--radius);
}

[data-theme="dark"] .mp-loading-overlay {
  background: rgba(15,23,42,0.82);
}

.mp-loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: mpSpin 0.65s linear infinite;
}

.mp-loading-overlay span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

@keyframes mpSpin {
  to { transform: rotate(360deg); }
}

/* ── Tabela ─────────────────────────────────────────────────── */
.mp-mysql-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  table-layout: auto;
}

/* Cabeçalho sticky */
.mp-mysql-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.mp-mysql-table thead th {
  background: var(--bg-hover);
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.th-sortable {
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.th-sortable:hover { color: var(--primary); background: rgba(20,65,150,0.04); }

.th-sort-icon {
  margin-left: 5px;
  font-size: 9px;
  opacity: 0.3;
  transition: opacity 0.2s, transform 0.2s;
}

.th-active { color: var(--primary) !important; }
.th-active .th-sort-icon  { opacity: 1; }
.th-asc    .th-sort-icon  { transform: rotate(0deg); }
.th-desc   .th-sort-icon  { transform: rotate(180deg); }

/* ── Linhas ─────────────────────────────────────────────────── */
.mp-row { transition: background 0.1s, transform 0.1s; }

.mp-row-even { background: var(--bg-card); }
.mp-row-odd  { background: var(--bg-hover); }

.mp-row:hover {
  background: rgba(20,65,150,0.05) !important;
  transform: translateX(3px);
}

[data-theme="dark"] .mp-row:hover {
  background: rgba(77,127,212,0.08) !important;
}

/* Células */
.mp-mysql-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light, rgba(0,0,0,0.06));
  vertical-align: middle;
  color: var(--text);
}

[data-theme="dark"] .mp-mysql-table td {
  border-bottom-color: rgba(255,255,255,0.05);
}

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

/* Coluna Código */
.mp-col-code { width: 110px; min-width: 90px; }

.mp-code-badge {
  display: inline-block;
  padding: 3px 9px;
  background: rgba(20,65,150,0.08);
  color: var(--primary);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  letter-spacing: 0.4px;
  border: 1px solid rgba(20,65,150,0.15);
}

[data-theme="dark"] .mp-code-badge {
  background: rgba(77,127,212,0.15);
  color: #4d7fd4;
  border-color: rgba(77,127,212,0.25);
}

/* Coluna Nome */
.mp-col-name { min-width: 200px; }

.mp-name-text {
  color: var(--text);
  font-weight: 500;
  line-height: 1.4;
}

mark.mp-highlight {
  background: rgba(251,191,36,0.35);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 700;
}

[data-theme="dark"] mark.mp-highlight { background: rgba(251,191,36,0.22); }

/* Coluna Custo */
.mp-col-cost {
  width: 160px;
  min-width: 130px;
  text-align: right;
  white-space: nowrap;
}

.mp-cost-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Cores de custo */
.cost-medium  .mp-cost-value { color: #b45309; }
.cost-high    .mp-cost-value { color: #dc2626; }
.cost-very-high .mp-cost-value { color: #b91c1c; font-size: 14px; }

[data-theme="dark"] .cost-medium  .mp-cost-value { color: #fbbf24; }
[data-theme="dark"] .cost-high    .mp-cost-value { color: #f87171; }
[data-theme="dark"] .cost-very-high .mp-cost-value { color: #fca5a5; }

.mp-cost-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-left: 7px;
}

.mp-cost-badge-high {
  background: rgba(220,38,38,0.1);
  color: #dc2626;
  border: 1px solid rgba(220,38,38,0.2);
}

.mp-cost-badge-med {
  background: rgba(180,83,9,0.1);
  color: #b45309;
  border: 1px solid rgba(180,83,9,0.2);
}

[data-theme="dark"] .mp-cost-badge-high { background: rgba(220,38,38,0.18); color: #f87171; }
[data-theme="dark"] .mp-cost-badge-med  { background: rgba(251,191,36,0.15); color: #fbbf24; }

/* ── Estado vazio / erro ────────────────────────────────────── */
.mp-empty-state {
  text-align: center !important;
  padding: 60px 20px !important;
}

.mp-empty-icon {
  font-size: 44px;
  margin-bottom: 14px;
  color: var(--text-muted);
  opacity: 0.35;
}

.mp-error-icon { opacity: 0.65; color: var(--danger); }

.mp-empty-state p {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.mp-empty-state small {
  color: var(--text-xmuted, var(--text-muted));
  font-size: 12.5px;
  opacity: 0.8;
}

/* ── Rodapé da tabela (info + paginação) ────────────────────── */
.mp-pagination-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-hover);
  flex-wrap: wrap;
  gap: 10px;
}

.mp-footer-info {
  font-size: 13px;
  color: var(--text-muted);
}

.mp-footer-info strong { color: var(--text); }

/* ── Paginação ──────────────────────────────────────────────── */
.mp-pagination {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
}

.mp-page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-sub, var(--text-muted));
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mp-page-btn:hover:not(:disabled):not(.active) {
  background: rgba(20,65,150,0.08);
  border-color: var(--primary);
  color: var(--primary);
}

.mp-page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(20,65,150,0.3);
}

.mp-page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.mp-page-ellipsis {
  color: var(--text-muted);
  padding: 0 3px;
  font-size: 15px;
}

/* ── Botão label oculto no mobile ───────────────────────────── */
@media (max-width: 600px) {
  .mp-btn-label { display: none; }
}

/* ── Responsividade ─────────────────────────────────────────── */
@media (max-width: 1100px) {
  .mp-stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .mp-header-row    { flex-direction: column; align-items: flex-start; }
  .mp-header-actions { width: 100%; justify-content: flex-end; }
  .mp-stats-row     { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mp-filters-row   { flex-direction: column; gap: 10px; }
  .mp-search-wrap   { min-width: unset; width: 100%; }
  .mp-cost-group    { width: 100%; }
  .mp-filter-input  { width: 100%; flex: 1; }
  .mp-clear-btn     { width: 100%; justify-content: center; }
  .mp-sort-row      { flex-direction: column; align-items: flex-start; }
  .mp-status-endpoint { display: none; }
  .mp-mysql-table   { font-size: 12.5px; }
  .mp-stat-value    { font-size: 18px; }
}

@media (max-width: 480px) {
  .mp-stats-row  { grid-template-columns: 1fr; }
  .mp-status-ts  { display: none; }
  .mp-status-sep { display: none; }

  /* Esconde código na tabela em telas muito pequenas */
  .mp-col-code,
  .mp-mysql-table thead th:first-child { display: none; }

  .mp-pagination-row { flex-direction: column; align-items: flex-start; }
  .mp-page-btn { min-width: 30px; height: 30px; font-size: 12px; }
}
