/* ============================================================
   Grupo Fresh Food — Painel Logístico iFood
   Tokens seguem a paleta de referência do método dataviz,
   com acento de marca (verde Fresh Food) no cromo.
   ============================================================ */
:root {
  color-scheme: light;
  --brand: #227a43;
  --brand-strong: #1a5f34;
  --brand-ink: #ffffff;

  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f4f4f1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.16);

  /* categorical (validado) */
  --s1: #2a78d6; /* blue   */
  --s2: #1baf7a; /* aqua   */
  --s3: #eda100; /* yellow */
  --s4: #008300; /* green  */
  --s8: #eb6834; /* orange */

  /* sequencial azul (heatmap) */
  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;
  --seq-700: #0d366b;

  /* status */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;

  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-weight: 500; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--brand);
  color: var(--brand-ink);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 1px 0 var(--border);
}
.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img {
  height: 44px;
  width: auto;
  display: block;
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.82;
  font-weight: 600;
}
.brand-txt h1 { font-size: 18px; color: var(--brand-ink); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}
.badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}
.badge.live .dot { background: #7dffa8; box-shadow: 0 0 0 3px rgba(125,255,168,0.3); }
.badge.snap .dot { background: #ffd76b; box-shadow: 0 0 0 3px rgba(255,215,107,0.3); }

.icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 9px;
  height: 34px;
  padding: 0 12px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.22); }
.icon-btn.ghost {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text-secondary);
}
.icon-btn.ghost:hover { background: var(--surface-1); }

/* ---------- Filters ---------- */
.filters {
  position: sticky;
  top: 62px;
  z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.filters-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.field select, .field input {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 8px 12px;
  min-width: 150px;
  height: 38px;
  transition: border-color 0.15s;
}
.field select:focus, .field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
.filters-spacer { flex: 1 1 auto; }
.coverage-note { font-size: 12px; color: var(--muted); text-align: right; align-self: center; }
.coverage-note b { color: var(--text-secondary); font-weight: 650; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; height: 38px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 40px; height: 23px; border-radius: 999px;
  background: var(--axis); position: relative; transition: background 0.18s; flex: none;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 19px; height: 19px;
  border-radius: 50%; background: #fff; transition: transform 0.18s; box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.switch-label { font-size: 13px; color: var(--text-secondary); font-weight: 550; }

/* ---------- Layout ---------- */
.wrap { max-width: 1360px; margin: 0 auto; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 15.5px; }
.card-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.chart { width: 100%; }
.chart-tall { min-height: 340px; }

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .kpi-row { grid-template-columns: 1fr; } }
.kpi {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.kpi-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.kpi-value { font-size: 34px; font-weight: 680; letter-spacing: -0.02em; line-height: 1; }
.kpi-value .unit { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.kpi-foot { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.kpi-delta { font-size: 12.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 3px; }
.kpi-delta.good { color: var(--good-ink); }
.kpi-delta.bad { color: var(--critical); }
.kpi-delta.flat { color: var(--muted); }
.kpi-delta-note { font-size: 11.5px; color: var(--muted); }

/* bloco de tendência (mini gráfico com referência) */
.kpi-trend { margin-top: auto; padding-top: 11px; border-top: 1px solid var(--grid); display: flex; flex-direction: column; gap: 3px; }
.kpi-trend-cap { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; }
.kpi-trend svg { width: 100%; height: auto; display: block; }
.kpi-trend-ends { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); font-weight: 550; }
.legend-key { width: 18px; height: 3px; border-radius: 2px; flex: none; }
.legend-key.sq { width: 12px; height: 12px; border-radius: 3px; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; color: var(--text-secondary);
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 7px; cursor: pointer; transition: all 0.14s;
}
.seg button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }

/* ---------- SVG chart chrome ---------- */
svg { display: block; width: 100%; overflow: visible; }
.ax-line { stroke: var(--axis); stroke-width: 1; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.ax-txt { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.ax-txt.tab { font-variant-numeric: tabular-nums; }
.val-lbl { fill: var(--text-secondary); font-size: 11px; font-weight: 600; font-family: var(--font); }
.val-lbl.strong { fill: var(--text-primary); }
.ref-line { stroke: var(--text-secondary); stroke-width: 1.5; stroke-dasharray: 4 4; }
.hit { fill: transparent; cursor: pointer; }
.crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  font-size: 12.5px;
  min-width: 150px;
  max-width: 280px;
  color: var(--text-secondary);
}
.tt-title { font-weight: 680; color: var(--text-primary); margin-bottom: 6px; font-size: 13px; }
.tt-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 2px 0; }
.tt-key { display: inline-flex; align-items: center; gap: 6px; }
.tt-stroke { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.tt-val { font-weight: 680; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 9px 12px; text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
.data-table thead th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 2;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 700; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--border-strong);
}
.data-table thead th:first-child { background: var(--surface-2); z-index: 3; }
.data-table thead th .arrow { opacity: 0.4; font-size: 9px; margin-left: 3px; }
.data-table thead th.sorted .arrow { opacity: 1; }
.data-table tbody tr { border-bottom: 1px solid var(--grid); }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr:hover td:first-child { background: var(--surface-2); }
.data-table td.num { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.data-table .store { font-weight: 600; color: var(--text-primary); }
.rede-tag {
  font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; margin-left: 7px;
  vertical-align: middle; letter-spacing: 0.02em;
}
.rede-tag.sub { background: color-mix(in srgb, var(--s1) 16%, transparent); color: var(--s1); }
.rede-tag.sal { background: color-mix(in srgb, var(--s8) 16%, transparent); color: var(--s8); }

.sem {
  display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums;
  justify-content: flex-end; font-weight: 600;
}
.sem-ico { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sem-good .sem-ico { background: var(--good); }
.sem-warn .sem-ico { background: var(--warning); }
.sem-crit .sem-ico { background: var(--critical); }
.sem-good { color: var(--good-ink); }
.sem-crit { color: var(--critical); }

.delta-cell { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta-cell.good { color: var(--good-ink); }
.delta-cell.bad { color: var(--critical); }

/* ---------- Footer ---------- */
.foot { color: var(--muted); font-size: 12px; line-height: 1.5; padding: 4px 2px 30px; }
.foot p { margin: 4px 0; max-width: 900px; }
.foot-dim { opacity: 0.75; }

/* loading / empty */
.loading { opacity: 0.5; transition: opacity 0.2s; }
.empty-msg { color: var(--muted); font-size: 13px; padding: 40px 12px; text-align: center; }
