/*
  Identidade visual exclusiva do painel "Gestão de Fornecedores" (Sourcing).
  Conceito: "Scorecard de consultoria" — fundo bege claro, terracota +
  azul-ardósia como par de acento, títulos em Sora. Fornecedores aparecem
  como cards de scorecard com selo de nota (A/B/C/D) em destaque, no lugar
  de mais um gráfico de barras. Tema escuro: ardósia escura com terracota.

  Arquivo autossuficiente: não depende de dashboard-shared.css. Continua
  usando dashboard-shared.js (tema, formatação pt-BR, defaults do
  Chart.js) — por isso os tokens abaixo reaproveitam os MESMOS NOMES lidos
  por esse script (--text-primary, --series-1..8, --gridline etc.), com
  valores próprios desta identidade.
*/

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

  --page-plane: #f3ecdd;
  --surface-1: #fdf9f0;
  --surface-2: #f6ecda;
  --text-primary: #2c2620;
  --text-secondary: #665c4d;
  --text-muted: #93887a;
  --gridline: #e6dac0;
  --baseline: #cabfa4;
  --border-ring: rgba(44, 38, 32, 0.1);
  --success-text: #2f7d5c;

  /* Par de acento pedido no briefing */
  --terracota: #c1613f;
  --terracota-soft: #f4ded2;
  --ardosia: #3c5566;
  --ardosia-soft: #dee6ea;

  /* Categórico — ordem fixa, nunca ciclar. Paleta terrosa/consultoria,
     sem reaproveitar verde/amarelo/vermelho puros de status. */
  --series-1: #c1613f; /* terracota — acento primário */
  --series-2: #3c5566; /* azul-ardósia — acento secundário */
  --series-3: #96703c; /* ocre/bronze */
  --series-4: #7f97a6; /* azul-acinzentado claro */
  --series-5: #8c4a63; /* vinho/malva */
  --series-6: #6b5b7a; /* roxo-acinzentado */
  --series-7: #2d4356; /* azul profundo */
  --series-8: #d98a6a; /* terracota clara / salmão */

  /* Status — reservado, nunca usado como cor de série */
  --status-good: #2f7d5c;
  --status-warning: #b8862c;
  --status-serious: #a8571f;
  --status-critical: #c0392b;

  /* Selos de nota do scorecard — reaproveitam os tokens de status,
     mesmo significado (bom -> crítico) em toda a página */
  --grade-a: var(--status-good);
  --grade-b: var(--ardosia);
  --grade-c: var(--status-warning);
  --grade-d: var(--status-critical);

  --font-display: "Sora", "Inter", system-ui, sans-serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-card: 18px;
  --radius-tile: 14px;
  --shadow-card: 0 1px 2px rgba(44, 38, 32, 0.06), 0 20px 40px -26px rgba(60, 85, 102, 0.28);
}

/* ---------- Tokens — tema escuro automático pelo SO ---------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane: #12181d;
    --surface-1: #1b2329;
    --surface-2: #212b32;
    --text-primary: #f3ece1;
    --text-secondary: #c3b9a8;
    --text-muted: #8f9aa3;
    --gridline: #2c3944;
    --baseline: #3c4a56;
    --border-ring: rgba(243, 236, 225, 0.09);
    --success-text: #4fae82;

    --terracota: #e08a5e;
    --terracota-soft: #3a2a22;
    --ardosia: #6f93aa;
    --ardosia-soft: #1d2c34;

    --series-1: #e08a5e;
    --series-2: #6f93aa;
    --series-3: #c99a52;
    --series-4: #9db3c0;
    --series-5: #b06e88;
    --series-6: #8f7ba3;
    --series-7: #5c85a3;
    --series-8: #e8a988;

    --status-good: #4fae82;
    --status-warning: #d9a441;
    --status-serious: #c9723a;
    --status-critical: #e2685c;

    --grade-a: var(--status-good);
    --grade-b: var(--ardosia);
    --grade-c: var(--status-warning);
    --grade-d: var(--status-critical);

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

/* ---------- Tokens — tema escuro (toggle manual, persistido em localStorage) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane: #12181d;
  --surface-1: #1b2329;
  --surface-2: #212b32;
  --text-primary: #f3ece1;
  --text-secondary: #c3b9a8;
  --text-muted: #8f9aa3;
  --gridline: #2c3944;
  --baseline: #3c4a56;
  --border-ring: rgba(243, 236, 225, 0.09);
  --success-text: #4fae82;

  --terracota: #e08a5e;
  --terracota-soft: #3a2a22;
  --ardosia: #6f93aa;
  --ardosia-soft: #1d2c34;

  --series-1: #e08a5e;
  --series-2: #6f93aa;
  --series-3: #c99a52;
  --series-4: #9db3c0;
  --series-5: #b06e88;
  --series-6: #8f7ba3;
  --series-7: #5c85a3;
  --series-8: #e8a988;

  --status-good: #4fae82;
  --status-warning: #d9a441;
  --status-serious: #c9723a;
  --status-critical: #e2685c;

  --grade-a: var(--status-good);
  --grade-b: var(--ardosia);
  --grade-c: var(--status-warning);
  --grade-d: var(--status-critical);

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

/* ---------- Reset mínimo ---------- */
* { box-sizing: border-box; }
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 ---------- */
.sc-shell { min-height: 100vh; display: flex; flex-direction: column; }

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

.sc-titles { min-width: 0; }
.sc-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--terracota);
  margin: 0 0 2px;
}
.sc-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

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

/* ---------- Filtros ---------- */
.sc-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px; }
.sc-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: 10px;
  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: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.dash-filter-chip[aria-pressed="true"] { background: var(--terracota); color: #fff9f2; }
.dash-filter-chip:not([aria-pressed="true"]):hover { color: var(--terracota); }

.sc-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: 10px;
  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='%2393887a' 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;
}

/* ---------- KPI (estilo "relatório", faixa lateral colorida) ---------- */
.sc-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.sc-stat-tile {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-left: 4px solid var(--terracota);
  border-radius: var(--radius-tile);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  min-width: 0;
}
.sc-stat-tile:nth-child(2n) { border-left-color: var(--ardosia); }
.sc-stat-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; }
.sc-stat-value-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.sc-stat-value {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}
.sc-stat-delta { font-size: 12.5px; font-weight: 700; display: inline-flex; align-items: center; gap: 2px; }
.sc-stat-delta .material-symbols-outlined { font-size: 14px; }
.sc-stat-delta.is-good { color: var(--success-text); }
.sc-stat-delta.is-bad { color: var(--status-critical); }
.sc-stat-delta.is-neutral { color: var(--text-muted); }
.sc-stat-sub { font-size: 11.5px; color: var(--text-muted); margin: 6px 0 0; }

.sc-sparkline-wrap { position: relative; margin-top: 10px; width: 100%; height: 26px; }
.sc-sparkline-wrap canvas { width: 100% !important; height: 100% !important; }

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

.sc-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sc-card-title { font-family: var(--font-display); font-size: 15px; font-weight: 700; margin: 0; }
.sc-card-caption { font-size: 12px; color: var(--text-muted); margin: 3px 0 0; }
.sc-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.sc-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: 8px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.sc-icon-btn:hover { color: var(--terracota); border-color: var(--terracota); }
.sc-icon-btn[aria-pressed="true"] { color: var(--terracota); border-color: var(--terracota); }

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

.sc-canvas-wrap { position: relative; width: 100%; flex: 1; min-height: 250px; }
.sc-canvas-wrap canvas { width: 100% !important; height: 100% !important; }

.sc-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; 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; }

/* Rótulos de quadrante desenhados no canvas herdam a fonte via JS; aqui só
   uma legenda textual auxiliar abaixo do gráfico de matriz, reforçando
   acessibilidade (a leitura por cor sozinha nunca é suficiente). */
.sc-quadrant-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.sc-quadrant-note strong { color: var(--text-secondary); }

/* ---------- Meter (cobertura de contingência) ---------- */
.sc-meter-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.sc-meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.sc-meter-fill { height: 100%; border-radius: 999px; background: var(--ardosia); }
.sc-summary-list { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sc-summary-list li { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; gap: 8px; }
.sc-summary-list span:first-child { color: var(--text-secondary); }
.sc-summary-list strong { font-weight: 700; color: var(--text-primary); }

/* ---------- Scorecards de fornecedor (selo de nota A/B/C/D) ---------- */
.sc-scorecard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.sc-scorecard {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-ring);
  border-radius: 14px;
  padding: 14px 16px;
}
.sc-scorecard-seal {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  color: #fff9f2;
}
.sc-scorecard-seal--a { background: var(--grade-a); }
.sc-scorecard-seal--b { background: var(--grade-b); }
.sc-scorecard-seal--c { background: var(--grade-c); }
.sc-scorecard-seal--d { background: var(--grade-d); }
.sc-scorecard-body { min-width: 0; }
.sc-scorecard-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-scorecard-meta { font-size: 11.5px; color: var(--text-muted); margin: 0; }
.sc-scorecard-meta strong { color: var(--text-secondary); font-weight: 700; }

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

.sc-section-title { font-family: var(--font-display); font-size: 15px; font-weight: 700; margin: 0 0 3px; }
.sc-section-caption { font-size: 12px; color: var(--text-muted); margin: 0 0 14px; }

/* ---------- Rodapé ---------- */
.sc-footer {
  margin-top: 24px;
  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) {
  .sc-topbar { padding: 12px 16px; }
  .sc-title { font-size: 15px; }
  .sc-main { padding: 16px 14px; }
  .sc-stat-value { font-size: 21px; }
  .sc-card { padding: 16px 14px 12px; }
}
