/*
  Identidade visual — "Custos de Frete & Frota Frigorificada".
  Conceito: painel operacional/industrial (cabine de comando de frota).
  Azul-petróleo (marca/estrutura) + laranja de sinalização de segurança
  (destaque/alerta). Light = cinza-concreto claro (piso de galpão). Dark =
  petróleo escuro (turno noturno). Títulos em Barlow Condensed, caixa alta,
  tracking largo — remete a placa/sinalização industrial. Cards com canto
  reto (sem arredondamento) e borda esquerda grossa colorida, como um
  compartimento de painel de instrumentos.

  Arquivo independente: não referencia dashboard-shared.css. Continua
  carregando dashboard-shared.js (helpers de tema/formatação/tabela/chips),
  por isso define todos os tokens que aquele script espera.
*/

:root {
  color-scheme: light;

  /* ---------- Tokens exigidos pelo dashboard-shared.js ---------- */
  --text-primary: #142630;
  --text-secondary: #3f5560;
  --text-muted: #74868d;
  --surface-1: #f6f5f0;
  --gridline: #d9d4c8;
  --baseline: #b8b1a1;

  --series-1: #0f6a8c; /* azul-petróleo — série principal */
  --series-2: #f2600c; /* laranja de segurança — série secundária */
  --series-3: #6a4c93; /* violeta */
  --series-4: #b56575; /* rosa-terracota */
  --series-5: #3d5a80; /* azul-ardósia */
  --series-6: #8c5e2a; /* marrom-ferrugem */
  --series-7: #4c7a70; /* verde-azulado apagado */
  --series-8: #9c8f4e; /* cáqui/dourado apagado */

  --status-good: #2f8f5b;
  --status-warning: #c98a12;
  --status-serious: #c1521b;
  --status-critical: #a33232;

  /* ---------- Tokens próprios do tema ---------- */
  --page-plane: #e9e6de; /* cinza-concreto */
  --surface-2: #eeece3;
  --border-ring: rgba(20, 38, 48, 0.16);
  --petroleo: #0f3b4c;
  --petroleo-deep: #0a2530;
  --safety-orange: #f2600c;
  --shadow-card: 0 1px 0 rgba(20, 38, 48, 0.06), 0 6px 16px rgba(20, 38, 48, 0.06);

  --font-title: "Barlow Condensed", "Inter", system-ui, sans-serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --text-primary: #eaf4f6;
    --text-secondary: #aec4c9;
    --text-muted: #7d979d;
    --surface-1: #0e2b34;
    --gridline: #1d434e;
    --baseline: #2b5560;

    --series-1: #4fb3d1;
    --series-2: #ff7f2e;
    --series-3: #a688d1;
    --series-4: #d98a9c;
    --series-5: #7fa0c4;
    --series-6: #c98b4a;
    --series-7: #6fa89f;
    --series-8: #c4b378;

    --status-good: #3fae74;
    --status-warning: #e0a83b;
    --status-serious: #e07a44;
    --status-critical: #d65b5b;

    --page-plane: #071a20;
    --surface-2: #123641;
    --border-ring: rgba(234, 244, 246, 0.14);
    --petroleo: #123c4c;
    --petroleo-deep: #071820;
    --safety-orange: #ff7f2e;
    --shadow-card: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 20px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --text-primary: #eaf4f6;
  --text-secondary: #aec4c9;
  --text-muted: #7d979d;
  --surface-1: #0e2b34;
  --gridline: #1d434e;
  --baseline: #2b5560;

  --series-1: #4fb3d1;
  --series-2: #ff7f2e;
  --series-3: #a688d1;
  --series-4: #d98a9c;
  --series-5: #7fa0c4;
  --series-6: #c98b4a;
  --series-7: #6fa89f;
  --series-8: #c4b378;

  --status-good: #3fae74;
  --status-warning: #e0a83b;
  --status-serious: #e07a44;
  --status-critical: #d65b5b;

  --page-plane: #071a20;
  --surface-2: #123641;
  --border-ring: rgba(234, 244, 246, 0.14);
  --petroleo: #123c4c;
  --petroleo-deep: #071820;
  --safety-orange: #ff7f2e;
  --shadow-card: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 20px rgba(0, 0, 0, 0.35);
}

/* ---------- Reset ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-title); }

/* ---------- Layout geral ---------- */

.opx-shell { display: flex; flex-direction: column; min-height: 100vh; }

.opx-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 28px;
}

/* ---------- Cabeçalho: console escuro com faixa de sinalização ---------- */

.opx-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--petroleo-deep);
  color: #eef6f7;
  border-bottom: 3px solid var(--safety-orange);
}

.opx-hazard-strip {
  height: 6px;
  background-image: repeating-linear-gradient(
    -45deg,
    var(--safety-orange) 0 10px,
    var(--petroleo) 10px 20px
  );
}

.opx-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  max-width: 1440px;
  margin: 0 auto;
}

.opx-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.opx-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: #cfe3ea;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  white-space: nowrap;
}
.opx-back:hover { color: #fff; border-color: var(--safety-orange); }
.opx-back .material-symbols-outlined { font-size: 16px; }

.opx-titles { min-width: 0; }

.opx-eyebrow {
  font-family: var(--font-title);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--safety-orange);
  margin: 0 0 2px;
}

.opx-title {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ffffff;
}

.opx-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.opx-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #cfe3ea;
  white-space: nowrap;
}
.opx-badge .material-symbols-outlined { font-size: 14px; }

.opx-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #cfe3ea;
  cursor: pointer;
  font-family: inherit;
}
.opx-theme-toggle:hover { color: #fff; border-color: var(--safety-orange); }

/* ---------- Filtros ---------- */

.opx-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
}

.opx-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  padding: 3px;
}

.dash-filter-chip {
  appearance: none;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.dash-filter-chip[aria-pressed="true"] {
  background: var(--petroleo);
  color: #fff;
}
.dash-filter-chip:not([aria-pressed="true"]):hover { color: var(--text-primary); }

.opx-select {
  appearance: none;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  padding: 8px 30px 8px 12px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2374868d' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---------- Painel de instrumentos (KPIs) ---------- */

.opx-instrument-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.opx-instrument {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-left: 6px solid var(--series-1);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  min-width: 0;
}
.opx-instrument--accent { border-left-color: var(--series-2); }
.opx-instrument--warning { border-left-color: var(--status-warning); }
.opx-instrument--good { border-left-color: var(--status-good); }

.opx-instrument-label {
  font-family: var(--font-title);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.opx-instrument-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex-wrap: wrap;
}
.opx-instrument-num {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.opx-instrument-unit {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.opx-instrument-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}
.opx-instrument-delta .material-symbols-outlined { font-size: 14px; }
.opx-instrument-delta.is-good { color: var(--status-good); }
.opx-instrument-delta.is-neutral { color: var(--text-muted); }

.opx-instrument-target {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

.opx-progress {
  height: 7px;
  background: var(--gridline);
}
.opx-progress-fill {
  height: 100%;
  background: var(--status-good);
}
.opx-progress-fill.is-warning { background: var(--status-warning); }
.opx-progress-fill.is-critical { background: var(--status-critical); }

/* ---------- Tira de status da frota ---------- */

.opx-fleet-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-left: 6px solid var(--petroleo);
  margin-bottom: 16px;
}
.opx-fleet-item {
  padding: 12px 16px;
  border-left: 1px solid var(--border-ring);
}
.opx-fleet-item:first-child { border-left: none; }
.opx-fleet-item-label {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.opx-fleet-item-value {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.opx-badge--good { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.opx-badge--warning { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 20%, transparent); }
.opx-badge--serious { color: var(--status-serious); background: color-mix(in srgb, var(--status-serious) 18%, transparent); }
.opx-badge--critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }
.opx-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
}
.opx-status-chip .material-symbols-outlined { font-size: 14px; }

/* ---------- Grade de cards ---------- */

.opx-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.opx-card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-left: 5px solid var(--petroleo);
  box-shadow: var(--shadow-card);
  padding: 16px 16px 12px;
  grid-column: span 12;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.opx-card--accent { border-left-color: var(--safety-orange); }
.opx-card--6 { grid-column: span 12; }
.opx-card--7 { grid-column: span 12; }
.opx-card--5 { grid-column: span 12; }
@media (min-width: 820px) {
  .opx-card--6 { grid-column: span 6; }
  .opx-card--7 { grid-column: span 7; }
  .opx-card--5 { grid-column: span 5; }
}

.opx-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.opx-card-title {
  font-family: var(--font-title);
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin: 0;
}
.opx-card-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px 0 0;
}

.opx-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-ring);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.opx-icon-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.opx-icon-btn[aria-pressed="true"] { color: var(--text-primary); border-color: var(--petroleo); }

.dash-chart-body.is-hidden { display: none; }

.opx-canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 240px;
}
.opx-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.opx-canvas-wrap--tall { min-height: 300px; }

.dash-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.dash-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dash-legend-swatch { width: 10px; height: 10px; flex-shrink: 0; }

/* ---------- Tabelas (par de acessibilidade) ---------- */

.opx-table-wrap { display: none; overflow-x: auto; margin-top: 8px; }
.opx-table-wrap.is-visible { display: block; }
.opx-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 420px; }
.opx-table caption { text-align: left; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.opx-table th, .opx-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.opx-table th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Rodapé ---------- */

.opx-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-ring);
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Responsivo ---------- */

@media (max-width: 480px) {
  .opx-title { font-size: 17px; }
  .opx-instrument-num { font-size: 22px; }
  .opx-main { padding: 14px; }
  .opx-header-inner { padding: 10px 14px; }
  .opx-eyebrow { letter-spacing: 0.08em; }
}
