/* OptiSales Analytics — estilos
   Tokens de cor no :root; as cores de categoria seguem a entidade (nunca a posição). */

:root {
  color-scheme: light;

  --brand-900: #0f2557;
  --brand-700: #1b3f8f;
  --brand-500: #2a5bd7;
  --brand-100: #e6edfc;
  --brand-050: #f2f6fe;
  --accent-300: #5fd3a6;

  --page: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink-1: #0f172a;
  --ink-2: #475069;
  --ink-3: #7a8299;
  --line: #e4e7ee;
  --line-strong: #cfd4df;
  --focus: #2a5bd7;

  /* Séries (slots categóricos 1–3 da paleta validada) */
  --cat-arm: #2a78d6;
  --cat-sol: #eb6834;
  --cat-len: #1baf7a;
  --series-1: #2a78d6;

  --warn-bg: #fff6e5;
  --warn-ink: #7a4a00;
  --danger-ink: #a12a2a;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink-1);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.container { width: 100%; max-width: 1320px; margin: 0 auto; padding: 0 24px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip-link:focus { left: 8px; }

/* ---------- Topo ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark { width: 40px; height: 40px; flex: none; }
.brand__name { font-weight: 750; font-size: 18px; letter-spacing: -.01em; color: var(--brand-900); }
.brand__name span { font-weight: 500; color: var(--brand-500); }
.brand__tagline { font-size: 12.5px; color: var(--ink-3); }

.demo-badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn-ink);
  font-size: 13px; font-weight: 600; border: 1px solid #f5dfb3;
}
.demo-badge svg { width: 16px; height: 16px; flex: none; }

/* ---------- Cabeçalho da página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 28px 0 16px; }
h1 { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.page-head__sub { color: var(--ink-2); margin-top: 4px; font-size: 14px; }

/* ---------- Cartões ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Filtros ---------- */
.filters {
  position: sticky; top: 8px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 28px;
  padding: 14px 18px; margin-bottom: 16px;
}
.filters__group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.filters__label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); width: 100%; }
.filters__error { width: 100%; color: var(--danger-ink); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  padding: 6px 12px; border-radius: 999px; font-size: 13.5px; color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { background: var(--brand-050); border-color: var(--brand-500); color: var(--brand-700); }
.chip[aria-pressed="true"] { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }

.date-range { display: flex; align-items: center; gap: 8px; }
.date-range__sep { color: var(--ink-3); }
.field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); }
.field input {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 6px 8px; background: var(--surface); color: var(--ink-1); font-size: 13.5px;
  font-variant-numeric: tabular-nums; transition: border-color .15s, box-shadow .15s;
}
.field input:hover { border-color: var(--brand-500); }
.field input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }

.segmented { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; }
.segmented button {
  display: inline-flex; align-items: center; gap: 7px;
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font-size: 13.5px; color: var(--ink-2); transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button:hover { background: var(--surface); color: var(--ink-1); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--brand-900); font-weight: 650; box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; flex: none; }
.dot--arm { background: var(--cat-arm); }
.dot--len { background: var(--cat-len); }
.dot--sol { background: var(--cat-sol); }

.btn-ghost {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: transparent; color: var(--brand-500);
  padding: 6px 10px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  transition: background .15s;
}
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost:hover { background: var(--brand-050); }
.btn-ghost:disabled { color: var(--ink-3); cursor: default; background: transparent; }

.load-error { padding: 16px 18px; margin-bottom: 16px; color: var(--danger-ink); border-color: #f1c4c4; background: #fff7f7; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand-500); opacity: .85; }
.kpi__label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.kpi__value { font-size: 28px; font-weight: 750; letter-spacing: -.02em; margin: 6px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi__hint { font-size: 12.5px; color: var(--ink-3); }
.kpi__value.is-updating { animation: pulse .35s ease; }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }

/* ---------- Painéis ---------- */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 32px; }
.panel { padding: 18px 20px; display: flex; flex-direction: column; min-width: 0; }
.panel--wide { grid-column: span 2; }
.panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.panel__sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }

.chart-box { position: relative; width: 100%; }
.chart-box--tall { height: 300px; }
.chart-box--top { flex: 1; min-height: 300px; }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: -4px 0 10px; font-size: 12.5px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 4px; padding: 16px; background: var(--surface); color: var(--ink-3); font-size: 14px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
}
.empty strong { color: var(--ink-2); font-size: 14.5px; }
.empty[hidden] { display: none; }

/* ---------- Tabela ---------- */
.panel__head--table { flex-wrap: wrap; }
.search { position: relative; flex: 0 1 280px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 10px 8px 34px; font-size: 14px; background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.search input:hover { border-color: var(--brand-500); }
.search input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }

.search-note {
  display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--brand-700);
  background: var(--brand-050); border-radius: var(--radius-sm); padding: 7px 10px; margin-bottom: 10px;
}
.search-note svg { width: 15px; height: 15px; flex: none; }
.search-note.is-active { background: var(--brand-100); font-weight: 600; }

.table-wrap { position: relative; overflow-x: auto; min-height: 120px; }
.orders { width: 100%; border-collapse: collapse; font-size: 14px; }
.orders th { text-align: left; border-bottom: 1px solid var(--line-strong); padding: 0; white-space: nowrap; }
.orders th button {
  width: 100%; text-align: inherit; background: none; border: 0; padding: 9px 12px;
  font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em;
}
.orders th button:hover { color: var(--ink-1); }
.orders th button::after { content: "↕"; margin-left: 6px; opacity: .35; font-size: 11px; }
.orders th[aria-sort="ascending"] button::after { content: "↑"; opacity: 1; }
.orders th[aria-sort="descending"] button::after { content: "↓"; opacity: 1; }
.orders th.num, .orders td.num { text-align: right; }
.orders td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.orders tbody tr { transition: background .12s; }
.orders tbody tr:hover { background: var(--brand-050); }
.orders td.id { font-weight: 600; color: var(--brand-700); }
.orders mark { background: #fde68a; color: inherit; border-radius: 3px; padding: 0 1px; }
.empty--table { position: static; min-height: 160px; margin-top: 8px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.pager__nav { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.btn-icon {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 18px; line-height: 1; transition: background .15s, border-color .15s;
}
.btn-icon:hover:not(:disabled) { background: var(--brand-050); border-color: var(--brand-500); }
.btn-icon:disabled { opacity: .4; cursor: default; }

/* ---------- Rodapé ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--ink-3); font-size: 12.5px; padding: 18px 0 24px; }
.site-footer p + p { margin-top: 4px; }
.site-footer strong { color: var(--ink-2); }

/* ---------- Página 404 ---------- */
.brand--link { color: inherit; text-decoration: none; }
.container.not-found { display: flex; justify-content: center; padding-top: 64px; padding-bottom: 96px; min-height: calc(100vh - 160px); }
.not-found__card { max-width: 520px; width: 100%; padding: 40px 32px; text-align: center; align-self: flex-start; }
.not-found__code { font-size: 64px; font-weight: 800; letter-spacing: -.04em; line-height: 1; color: var(--brand-500); margin-bottom: 12px; }
.not-found__text { color: var(--ink-2); margin: 10px 0 24px; }
.not-found__btn {
  display: inline-block; background: var(--brand-700); color: #fff; text-decoration: none; font-weight: 600;
  padding: 10px 18px; border-radius: var(--radius-sm); transition: background .15s;
}
.not-found__btn:hover { background: var(--brand-900); }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .panel--wide { grid-column: auto; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .topbar__inner { flex-wrap: wrap; padding: 10px 0; }
  .demo-badge { font-size: 12px; }
  h1 { font-size: 22px; }
  .filters { position: static; padding: 14px; gap: 14px; }
  .filters__group { width: 100%; }
  .date-range { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .date-range__sep { display: none; }
  .field { flex-direction: column; align-items: stretch; gap: 2px; min-width: 0; }
  .field input { width: 100%; min-width: 0; }
  .orders { font-size: 13px; }
  .orders td { padding: 9px 6px; }
  .orders th { white-space: normal; vertical-align: bottom; }
  .orders th button { padding: 8px 6px; font-size: 11px; letter-spacing: .03em; line-height: 1.25; }
  .orders th button::after { margin-left: 3px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1 1 auto; justify-content: center; padding: 7px 8px; }
  .btn-ghost { margin-left: 0; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi__value { font-size: 20px; }
  .kpi__hint { font-size: 11.5px; }
  .panel { padding: 14px; }
  .chart-box--tall { height: 250px; }
  .search { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
