/* ===== Base ===== */
:root {
  --bg: #0a0a0a;
  --card: #171717;
  --border: #262626;
  --text: #ededed;
  --muted: #a3a3a3;
  --orange: #f97316;
  --orange-dark: #ea580c;
  --green: #22c55e;
  --red: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  padding: 1rem;
  -webkit-font-smoothing: antialiased;
}
@media (min-width: 768px) {
  body {
    padding: 2rem;
  }
}

.wrap {
  max-width: 88rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}
.pad {
  padding: 1.25rem;
}
.muted {
  color: var(--muted);
}
.sm {
  font-size: 0.8125rem;
}
.strong {
  font-weight: 600;
}
.accent {
  color: var(--orange);
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}
h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 1rem;
}

/* ===== Header ===== */
.head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
}
@media (min-width: 900px) {
  .head {
    flex-direction: row;
  }
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
}

.select {
  background: #000;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.8125rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.select:focus,
.select:hover {
  border-color: var(--orange);
}

.btn {
  background: var(--orange);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 0.55rem 1.1rem;
  border-radius: 0.375rem;
  font-weight: 600;
  font-size: 0.875rem;
  transition: background 0.15s;
}
.btn:hover {
  background: var(--orange-dark);
}
.btn:active {
  transform: translateY(1px);
}

/* ===== Badge ===== */
.badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.75rem;
  color: var(--muted);
  background: #111;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.3rem 0.75rem;
}
.badge-warn {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
}

/* ===== Grids ===== */
.grid {
  display: grid;
  gap: 1rem;
}
.kpis {
  grid-template-columns: 1fr;
}
.charts {
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1024px) {
  .kpis {
    grid-template-columns: repeat(4, 1fr);
  }
  .charts {
    grid-template-columns: repeat(2, 1fr);
  }
  .span-2 {
    grid-column: span 2;
  }
}

/* ===== KPI Cards ===== */
.kpi {
  border-top: 4px solid var(--orange);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.15s,
    border-color 0.15s;
}
.kpi:hover {
  transform: translateY(-2px);
}

.kpi-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi-value {
  margin-top: 0.5rem;
  font-size: 1.875rem;
  font-weight: 700;
  color: #fff;
}
.kpi-value.accent {
  color: var(--orange);
}
.kpi-value-sm {
  font-size: 1.375rem;
}
.kpi-sub {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--muted);
}
.kpi-diff {
  font-size: 0.75rem;
  margin-top: 0.55rem;
  font-weight: 500;
}

.diff-up {
  color: var(--green);
}
.diff-down {
  color: var(--red);
}
.diff-neutral {
  color: var(--muted);
}

/* ===== Charts ===== */
.chart-box {
  position: relative;
  width: 100%;
  height: 18rem;
}
.span-2 .chart-box {
  height: 20rem;
}

/* ===== Tabela ===== */
.table-scroll {
  overflow-x: auto;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  white-space: nowrap;
}
.tbl thead th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.tbl tbody td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid #1f1f1f;
}
.tbl tbody tr[data-month] {
  cursor: pointer;
  transition: background 0.12s;
}
.tbl tbody tr[data-month]:hover {
  background: #1f1f1f;
}
.row-active {
  background: rgba(249, 115, 22, 0.08);
  box-shadow: inset 3px 0 0 var(--orange);
}
.row-total td {
  font-weight: 700;
  color: #fff;
  background: #101010;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

/* ===== Footer ===== */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
}
@media (min-width: 768px) {
  .footer {
    flex-direction: row;
    justify-content: space-between;
    text-align: right;
  }
}
.footer-logos {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo {
  height: 2.5rem;
  width: auto;
  object-fit: contain;
  opacity: 0.9;
  transition: opacity 0.15s;
}
.logo:hover {
  opacity: 1;
}
.logo-tolazzai {
  height: 1.5rem;
}
.logo-prosd {
  height: 5.4rem;
}

.divider {
  width: 1px;
  height: 1.75rem;
  background: var(--border);
}
.footer-text p {
  line-height: 1.6;
}

/* ==== MOBILE ==== */
@media (max-width: 640px) {
  body {
    padding: 0.75rem;
  }
  .wrap {
    gap: 1rem;
  }

  h1 {
    font-size: 1.25rem;
  }
  h3 {
    font-size: 0.9375rem;
  }

  /* Filtros ocupam largura total e empilham */
  .head-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .head-actions label {
    display: none;
  }
  .select,
  .btn {
    width: 100%;
  }

  /* KPIs mais compactos */
  .kpi {
    padding: 0.9rem;
  }
  .kpi-value {
    font-size: 1.5rem;
  }
  .kpi-value-sm {
    font-size: 1.125rem;
  }

  /* Gráficos com altura reduzida */
  .chart-box,
  .span-2 .chart-box {
    height: 14rem;
  }

  /* Tabela: dica de scroll horizontal */
  .table-scroll {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tbl {
    font-size: 0.75rem;
  }
  .tbl thead th,
  .tbl tbody td {
    padding: 0.5rem 0.6rem;
  }

  /* Footer */
  .footer {
    padding: 1.15rem;
    gap: 0.85rem;
  }
  .footer-logos {
    flex-wrap: wrap;
    justify-content: center;
  }
  .logo-tolazzai {
    height: 1.6rem;
  }
  .logo-prosd {
    height: 2.6rem;
  }
}
.chip-box:empty {
  display: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--orange);
  background: rgba(249, 115, 22, 0.1);
  border: 1px solid rgba(249, 115, 22, 0.4);
  border-radius: 9999px;
  padding: 0.3rem 0.4rem 0.3rem 0.8rem;
}
.chip button {
  background: rgba(249, 115, 22, 0.2);
  border: none;
  color: var(--orange);
  cursor: pointer;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  line-height: 1;
  font-size: 0.85rem;
}
.chip button:hover {
  background: var(--orange);
  color: #fff;
}
.pdf-mode .chip-box {
  display: none !important;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.card-head h3 {
  margin-bottom: 0;
}
.btn-ghost {
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.45);
  color: var(--orange);
  padding: 0.35rem 0.8rem;
  font-size: 0.75rem;
  border-radius: 9999px;
}
.btn-ghost:hover {
  background: var(--orange);
  color: #fff;
}
.pdf-mode #btnShowAll {
  display: none !important;
}

/* ==== Exportar PDF ==== */
/* ===== Botão outline ===== */
.btn-outline {
  background: transparent;
  border: 1px solid var(--orange);
  color: var(--orange);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(249, 115, 22, 0.12);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ===== Cabeçalho exclusivo do PDF ===== */
.print-header {
  display: none;
}
.print-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  color: var(--text);
}
.print-header p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ===== Estado de captura ===== */
.pdf-mode {
  width: 1180px !important;
  max-width: none !important;
}
.pdf-mode .head-actions {
  display: none !important;
}
.pdf-mode .print-header {
  display: block !important;
  padding: 0 0.25rem 0.5rem;
}
.pdf-mode .card {
  break-inside: avoid;
  page-break-inside: avoid;
}
.pdf-mode .kpis {
  grid-template-columns: repeat(4, 1fr) !important;
}
.pdf-mode .charts {
  grid-template-columns: repeat(2, 1fr) !important;
}
.pdf-mode .span-2 {
  grid-column: span 2 !important;
}
.pdf-mode .chart-box,
.pdf-mode .span-2 .chart-box {
  height: 15rem !important;
}
.pdf-mode .table-scroll {
  overflow: visible !important;
}
.pdf-mode .row-active {
  box-shadow: none !important;
}

/* Container fora da tela durante a captura em mobile */
/* Palco de captura: dentro da viewport, apenas invisível */
.pdf-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 1180px;
  background: #0a0a0a;
  padding: 1.25rem;
  z-index: -1;
  opacity: 0;
  pointer-events: none;
}

/* ===== Overlay de progresso ===== */
.pdf-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(3px);
  color: var(--text);
  font-size: 0.875rem;
}
.pdf-spinner {
  width: 2.25rem;
  height: 2.25rem;
  border: 3px solid rgba(249, 115, 22, 0.25);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: pdfspin 0.8s linear infinite;
}
@keyframes pdfspin {
  to {
    transform: rotate(360deg);
  }
}
