/*
  Identidade visual exclusiva do painel "Saving & OTIF" (Procurement).
  Conceito: "Executive Clean de verdade" — branco amplo, muito respiro,
  navy + um único acento azul-royal. Título em Manrope (700/800), corpo em
  Inter. HERO no topo com o saving acumulado em destaque; os demais KPIs
  ficam discretos, em linha de texto, não em tiles grandes.

  Este arquivo é autossuficiente: não depende de dashboard-shared.css.
  Continua dependendo de dashboard-shared.js só pelos helpers de tema,
  formatação pt-BR e defaults do Chart.js — por isso os tokens abaixo
  (--text-primary, --series-1..8, --gridline etc.) têm os MESMOS NOMES
  usados pelo shared.js, só que com valores próprios desta identidade.
*/

/* ---------- Tokens — tema claro ---------- */
:root {
  color-scheme: light;

  --page-plane: #f6f7fb;
  --surface-1: #ffffff;
  --surface-2: #eef1fa;
  --text-primary: #0d1b34;
  --text-secondary: #4b5768;
  --text-muted: #8993a4;
  --gridline: #e6e9f2;
  --baseline: #c7cedb;
  --border-ring: rgba(13, 27, 52, 0.09);
  --success-text: #16794f;

  /* Acento único de marca — usado com moderação, nunca decorativo à toa */
  --accent: #2952e3;
  --accent-soft: #e8edfd;

  /* Categórico — ordem fixa, nunca ciclar. Família navy/azul dominante
     (identidade da marca), com hues extras só para série auxiliares
     (linha de meta, marcadores). Nenhum reaproveita verde/amarelo/
     vermelho de status. */
  --series-1: #2952e3; /* azul-royal — acento principal (realizado) */
  --series-2: #64748b; /* slate — referência / meta */
  --series-3: #0d1b34; /* navy profundo */
  --series-4: #7c9cf0; /* azul claro */
  --series-5: #b08900; /* âmbar */
  --series-6: #0f766e; /* teal */
  --series-7: #7c3aed; /* violeta */
  --series-8: #be123c; /* rosa-vinho */

  /* Status — reservado, nunca usado como cor de série */
  --status-good: #16794f;
  --status-warning: #b9770e;
  --status-serious: #a8571f;
  --status-critical: #b42318;

  --font-display: "Manrope", "Inter", system-ui, sans-serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-card: 22px;
  --radius-tile: 16px;
  --shadow-card: 0 1px 2px rgba(13, 27, 52, 0.05), 0 24px 48px -28px rgba(41, 82, 227, 0.28);
}

/* ---------- Tokens — tema escuro (marinho profundo), automático pelo SO ---------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane: #060b18;
    --surface-1: #0e1830;
    --surface-2: #101d3a;
    --text-primary: #f4f6fb;
    --text-secondary: #aab4c8;
    --text-muted: #7683a0;
    --gridline: #1c2843;
    --baseline: #2b3b5e;
    --border-ring: rgba(255, 255, 255, 0.09);
    --success-text: #34d399;

    --accent: #5b7fff;
    --accent-soft: #172352;

    --series-1: #5b7fff;
    --series-2: #94a3c4;
    --series-3: #c7d2fe;
    --series-4: #3652b5;
    --series-5: #e8b93a;
    --series-6: #2dd4c4;
    --series-7: #a78bfa;
    --series-8: #fb7185;

    --status-good: #34d399;
    --status-warning: #f2b84b;
    --status-serious: #f0895c;
    --status-critical: #f87171;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 24px 48px -28px rgba(0, 0, 0, 0.55);
  }
}

/* ---------- Tokens — tema escuro (toggle manual, persistido em localStorage) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane: #060b18;
  --surface-1: #0e1830;
  --surface-2: #101d3a;
  --text-primary: #f4f6fb;
  --text-secondary: #aab4c8;
  --text-muted: #7683a0;
  --gridline: #1c2843;
  --baseline: #2b3b5e;
  --border-ring: rgba(255, 255, 255, 0.09);
  --success-text: #34d399;

  --accent: #5b7fff;
  --accent-soft: #172352;

  --series-1: #5b7fff;
  --series-2: #94a3c4;
  --series-3: #c7d2fe;
  --series-4: #3652b5;
  --series-5: #e8b93a;
  --series-6: #2dd4c4;
  --series-7: #a78bfa;
  --series-8: #fb7185;

  --status-good: #34d399;
  --status-warning: #f2b84b;
  --status-serious: #f0895c;
  --status-critical: #f87171;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 24px 48px -28px rgba(0, 0, 0, 0.55);
}

/* ---------- Reset mínimo ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
img, canvas { max-width: 100%; }

/* ---------- Estrutura ---------- */
.pc-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.pc-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-ring);
}
.pc-topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.pc-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-ring);
  white-space: nowrap;
}
.pc-back .material-symbols-outlined { font-size: 16px; }
.pc-back:hover { color: var(--accent); border-color: var(--accent); }

.pc-titles { min-width: 0; }
.pc-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 2px;
}
.pc-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pc-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.pc-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 11px 5px 8px;
  border-radius: 999px;
}
.pc-badge .material-symbols-outlined { font-size: 14px; }
.pc-badge--good { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 12%, transparent); }
.pc-badge--warning { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 18%, transparent); }
.pc-badge--serious { color: var(--status-serious); background: color-mix(in srgb, var(--status-serious) 18%, transparent); }
.pc-badge--critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 12%, transparent); }

.pc-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border-ring);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.pc-theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

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

/* ---------- Filtros ---------- */
.pc-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
}
.pc-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: 999px;
  padding: 4px;
  /* Em telas estreitas os 4 chips não cabem: rola dentro do grupo em vez de gerar scroll horizontal na página. */
  max-width: 100%;
  overflow-x: auto;
}
.dash-filter-chip {
  appearance: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.dash-filter-chip[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
}
.dash-filter-chip:not([aria-pressed="true"]):hover { color: var(--text-primary); }

.pc-filter-select {
  appearance: none;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: 999px;
  padding: 8px 30px 8px 14px;
  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='%238993a4' 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;
}

/* ---------- HERO ---------- */
.pc-hero {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 36px 40px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}
@media (min-width: 900px) {
  .pc-hero { grid-template-columns: 1.35fr 1fr; align-items: center; padding: 44px 48px; }
}

.pc-hero-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0 0 10px;
}
.pc-hero-number {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin: 0;
  line-height: 1;
  font-size: clamp(44px, 9vw, 84px);
}
.pc-hero-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  margin: 14px 0 0;
}
.pc-hero-delta .material-symbols-outlined { font-size: 16px; }
.pc-hero-delta.is-good { color: var(--success-text); }
.pc-hero-delta.is-bad { color: var(--status-critical); }
.pc-hero-delta.is-neutral { color: var(--text-muted); }

.pc-hero-context {
  margin: 18px 0 0;
  max-width: 46ch;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.pc-hero-sparkline {
  position: relative;
  width: 100%;
  height: 40px;
  margin-top: 20px;
}
.pc-hero-sparkline canvas { width: 100% !important; height: 100% !important; }

.pc-hero-kpis {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--gridline);
  padding-top: 4px;
}
@media (min-width: 900px) {
  .pc-hero-kpis { border-top: none; border-left: 1px solid var(--gridline); padding-top: 0; padding-left: 32px; }
}
.pc-hero-kpi {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gridline);
}
.pc-hero-kpi:last-child { border-bottom: none; }
.pc-hero-kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
}
.pc-hero-kpi-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
}
.pc-hero-kpi-sub {
  display: block;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Grade de cards ---------- */
.pc-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.pc-card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 22px 22px 18px;
  grid-column: span 12;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.pc-card--6 { grid-column: span 12; }
@media (min-width: 860px) { .pc-card--6 { grid-column: span 6; } }
.pc-card--block { margin-bottom: 14px; }

.pc-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.pc-card-title {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.pc-card-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px 0 0;
}
.pc-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.pc-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-ring);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.pc-icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.pc-icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

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

.pc-canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 240px;
}
.pc-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.pc-canvas-wrap.pc-canvas-wrap--donut { min-height: 200px; max-width: 260px; margin: 0 auto; }
.pc-canvas-wrap.pc-canvas-wrap--bullet { min-height: 200px; }

.pc-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 12px;
  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; border-radius: 3px; flex-shrink: 0; }

/* ---------- Painel resumo (ao lado do anel de OTIF) ---------- */
.pc-summary-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.pc-summary-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  gap: 8px;
}
.pc-summary-list span:first-child { color: var(--text-secondary); }
.pc-summary-list strong { font-weight: 700; color: var(--text-primary); }

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

/* ---------- Card de tabela detalhada / addendum ---------- */
.pc-section-title {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  margin: 0 0 3px;
}
.pc-section-caption { font-size: 12px; color: var(--text-muted); margin: 0 0 14px; }

/* ---------- Rodapé ---------- */
.pc-footer {
  margin-top: 26px;
  padding-top: 16px;
  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) {
  .pc-topbar { padding: 12px 16px; }
  .pc-title { font-size: 16px; }
  .pc-main { padding: 18px 16px 16px; }
  .pc-hero { padding: 24px 20px; }
  .pc-card { padding: 18px 16px 14px; }
}
