/* LucroSmart dashboard
   Base visual: minimalismo editorial (canvas quente, bordas 1px, pastéis só para status).
   Gráficos: método dataviz. Paleta categórica validada com validate_palette.js
   claro  (superfície #ffffff): #0b7a43, #2a78d6, #eda100  -> todos os checks passam, --pairs all
   escuro (superfície #161816): #25a864, #3987e5, #c98500  -> todos os checks passam, --pairs all
   Raio: cards 12px, inputs 8px, botões 6px, só tags de status são pill. */

:root {
  --canvas: #f7f6f3;
  --surface: #ffffff;
  --line: #eaeaea;
  --grid: #efeeea;
  --axis: #d6d5cf;
  --text: #111111;
  --text-2: #2f3437;
  --muted: #6b6a66;
  --wash: rgba(17, 17, 17, 0.045);

  --s1: #0b7a43;
  --s2: #2a78d6;
  --s3: #eda100;
  --on-s1: #ffffff;
  --on-s2: #ffffff;
  --on-s3: #111111;
  --prev: #a9a8a2;

  --btn-bg: #111111;
  --btn-bg-hover: #333333;
  --btn-text: #ffffff;

  --good-bg: #edf3ec; --good-fg: #346538;
  --bad-bg: #fdebec;  --bad-fg: #9f2f2d;
  --warn-bg: #fbf3db; --warn-fg: #956400;
  --info-bg: #e1f3fe; --info-fg: #1f6c9f;

  --r-card: 12px;
  --r-input: 8px;
  --r-btn: 6px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --font-ui: "Geist", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --font-serif: "Newsreader", "Playfair Display", Georgia, serif;
  --font-mono: "Geist Mono", "SF Mono", ui-monospace, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --canvas: #0f110f;
  --surface: #161816;
  --line: rgba(255, 255, 255, 0.09);
  --grid: #232623;
  --axis: #353933;
  --text: #ecefeb;
  --text-2: #c4c8c2;
  --muted: #8a8d88;
  --wash: rgba(255, 255, 255, 0.06);

  --s1: #25a864;
  --s2: #3987e5;
  --s3: #c98500;
  --on-s1: #ffffff;
  --on-s2: #ffffff;
  --on-s3: #111111;
  --prev: #4d504a;

  --btn-bg: #ecefeb;
  --btn-bg-hover: #ffffff;
  --btn-text: #111111;

  --good-bg: rgba(37, 168, 100, 0.14); --good-fg: #6fd69b;
  --bad-bg: rgba(230, 103, 103, 0.14); --bad-fg: #f09a9a;
  --warn-bg: rgba(201, 133, 0, 0.16);  --warn-fg: #e8b44d;
  --info-bg: rgba(57, 135, 229, 0.16); --info-fg: #8dbcf5;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0f110f; --surface: #161816; --line: rgba(255, 255, 255, 0.09); --grid: #232623; --axis: #353933;
    --text: #ecefeb; --text-2: #c4c8c2; --muted: #8a8d88; --wash: rgba(255, 255, 255, 0.06);
    --s1: #25a864; --s2: #3987e5; --s3: #c98500; --prev: #4d504a;
    --btn-bg: #ecefeb; --btn-bg-hover: #ffffff; --btn-text: #111111;
    --good-bg: rgba(37, 168, 100, 0.14); --good-fg: #6fd69b;
    --bad-bg: rgba(230, 103, 103, 0.14); --bad-fg: #f09a9a;
    --warn-bg: rgba(201, 133, 0, 0.16);  --warn-fg: #e8b44d;
    --info-bg: rgba(57, 135, 229, 0.16); --info-fg: #8dbcf5;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text);
  font-family: var(--font-ui); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, figure { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--s2); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

kbd {
  font-family: var(--font-mono); font-size: 11px; line-height: 1; padding: 3px 5px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--canvas); color: var(--muted);
}

/* ---------- estrutura ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--canvas); overflow-y: auto;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-weight: 600; font-size: 16px; letter-spacing: -0.02em; }
.logo-mark { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--btn-bg); color: var(--btn-text); font-size: 15px; }
.logo b { color: var(--s1); font-weight: 600; }

.search { position: relative; }
.search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; }
.search input {
  width: 100%; height: 36px; padding: 0 56px 0 34px; border: 1px solid var(--line); border-radius: var(--r-input);
  background: var(--surface); outline: none; transition: border-color 0.2s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--text-2); }
.search .keys { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: flex; gap: 3px; pointer-events: none; }

.nav-group { display: grid; gap: 2px; }
.nav-title { padding: 0 10px 6px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.nav-link {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--r-input);
  color: var(--text-2); font-weight: 500; transition: background-color 0.2s, color 0.2s;
}
.nav-link i { font-size: 17px; color: var(--muted); transition: color 0.2s; }
.nav-link:hover { background: var(--wash); }
.nav-link[aria-current="page"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); color: var(--text); }
.nav-link[aria-current="page"] i { color: var(--text); }
.side-foot { margin-top: auto; display: grid; gap: 12px; }
.user { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--r-input); border: 1px solid var(--line); background: var(--surface); }
.user img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--wash); }
.user b { display: block; font-weight: 600; line-height: 1.2; }
.user span { font-size: 12px; color: var(--muted); }

.main { min-width: 0; padding: 32px clamp(20px, 3.4vw, 48px) 80px; max-width: 1360px; width: 100%; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.top h1 { font-family: var(--font-serif); font-weight: 500; font-size: clamp(30px, 3.4vw, 40px); line-height: 1.1; letter-spacing: -0.03em; }
.top p { color: var(--muted); margin-top: 6px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn.menu-btn { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--r-btn); font-weight: 500; white-space: nowrap; transition: background-color 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--btn-bg); color: var(--btn-text); }
.btn-primary:hover { background: var(--btn-bg-hover); }
.btn-ghost { border: 1px solid var(--line); background: var(--surface); }
.btn-ghost:hover { background: var(--wash); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-input); border: 1px solid var(--line); background: var(--surface); font-size: 16px; color: var(--text-2); transition: background-color 0.2s; }
.icon-btn:hover { background: var(--wash); }
.icon-btn[aria-pressed="true"] { background: var(--wash); color: var(--text); }
.theme-btn .ph-sun { display: none; }
:root[data-theme="dark"] .theme-btn .ph-sun { display: inline; }
:root[data-theme="dark"] .theme-btn .ph-moon { display: none; }

/* ---------- filtros ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 28px 0 20px; }
.filters .spacer { flex: 1; }
.field-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: var(--r-input); background: var(--surface); font-weight: 500; transition: border-color 0.2s;
}
.field-btn:hover, .field-btn[aria-expanded="true"] { border-color: var(--axis); }
.field-btn i { color: var(--muted); font-size: 15px; }
select.field-btn { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 256 256' fill='%238a8d88'%3E%3Cpath d='M213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
.pop-wrap { position: relative; }
.pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 260px; padding: 6px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
}
.pop[hidden] { display: none; }
.opt { display: flex; align-items: center; justify-content: space-between; width: 100%; height: 36px; padding: 0 10px; border-radius: 6px; text-align: left; transition: background-color 0.15s; }
.opt:hover, .opt:focus-visible { background: var(--wash); }
.opt i { font-size: 16px; opacity: 0; }
.opt[aria-selected="true"] i { opacity: 1; }
.pop-foot { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.custom { display: grid; gap: 8px; padding: 10px 6px 6px; }
.custom[hidden] { display: none; }
.custom label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.custom input { height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-input); background: var(--canvas); }
.custom .err { color: var(--bad-fg); font-size: 12px; min-height: 1em; }

/* ---------- grade e cards ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; transition: opacity 0.18s; }
.grid.loading { opacity: 0.55; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 24px;
  min-width: 0; transition: box-shadow 0.25s, border-color 0.25s;
}
.card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); }
.label { color: var(--muted); font-size: 13px; }
.card-title { font-weight: 600; font-size: 14px; letter-spacing: -0.005em; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.c-hero { grid-column: span 8; }
.c-wallet { grid-column: span 4; display: flex; flex-direction: column; gap: 20px; }
.c-tile { grid-column: span 3; }
.c-prod { grid-column: span 6; }
.c-origin { grid-column: span 6; }
.c-sales { grid-column: span 12; }

.hero-fig { font-weight: 600; font-size: clamp(40px, 5vw, 56px); line-height: 1.05; letter-spacing: -0.04em; margin-top: 6px; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 500; }
.delta.good { color: var(--good-fg); }
.delta.bad { color: var(--bad-fg); }
.delta.flat { color: var(--muted); }
.delta-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.delta-row .label { font-size: 13px; }

.legend { display: flex; gap: 16px; align-items: center; color: var(--text-2); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.key-line { width: 14px; height: 2px; border-radius: 2px; background: var(--s1); }
.key-line.prev { background: var(--prev); }
.head-actions { display: flex; align-items: center; gap: 12px; }

.chart-box { position: relative; margin-top: 20px; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-box svg:focus-visible { outline-offset: 6px; }
.ax text { fill: var(--muted); font-family: var(--font-ui); font-size: 11.5px; }
.ax .g { stroke: var(--grid); stroke-width: 1; }
.ax .base { stroke: var(--axis); stroke-width: 1; }
.s-cur { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.s-prev { fill: none; stroke: var(--prev); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.s-area { fill: var(--s1); opacity: 0.1; }
.dot-cur { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.dot-prev { fill: var(--prev); stroke: var(--surface); stroke-width: 2; }
.cross { stroke: var(--axis); stroke-width: 1; }
.peak { fill: var(--text-2); font-size: 11.5px; font-weight: 500; }
@media (prefers-reduced-motion: no-preference) {
  .s-cur.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.4s var(--ease) forwards; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.tip {
  position: absolute; z-index: 20; pointer-events: none; min-width: 180px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06); font-size: 12.5px;
  opacity: 0; transform: translateY(4px); transition: opacity 0.12s, transform 0.12s;
}
.tip.on { opacity: 1; transform: none; }
.tip .t-date { color: var(--muted); margin-bottom: 6px; }
.tip .t-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tip .t-row + .t-row { margin-top: 4px; }
.tip .t-key { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.tip .t-val { font-weight: 600; color: var(--text); }
.tip .sw { width: 10px; height: 10px; border-radius: 2px; }

/* tabela (gêmea do gráfico e últimas vendas) */
.table-wrap { overflow-x: auto; margin-top: 16px; }
.table-wrap.scroll { max-height: 300px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 0 12px 10px 0; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 14px 12px 14px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--wash); }
th.r, td.r { text-align: right; padding-right: 0; }
td .muted { color: var(--muted); }
td .pay { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.buyer b { display: block; font-weight: 500; line-height: 1.3; }
.buyer span { font-size: 12px; color: var(--muted); }
.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 9999px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase;
}
.tag i { font-size: 12px; }
.tag.good { background: var(--good-bg); color: var(--good-fg); }
.tag.bad { background: var(--bad-bg); color: var(--bad-fg); }
.tag.warn { background: var(--warn-bg); color: var(--warn-fg); }
.link { font-weight: 500; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.link:hover { color: var(--text); }
.link i { transition: transform 0.25s var(--ease); }
.link:hover i { transform: translateX(3px); }

/* carteira + meta */
.c-wallet .big { font-weight: 600; font-size: 32px; letter-spacing: -0.03em; line-height: 1.1; margin-top: 4px; }
.kv { display: grid; gap: 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; }
.c-wallet .btns { display: flex; gap: 8px; }
.c-wallet .btns .btn { flex: 1; }
.hr { height: 1px; background: var(--line); border: 0; margin: 0; }
.meter { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--s1) 16%, var(--surface)); overflow: hidden; margin-top: 12px; }
.meter > i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--s1); transition: width 0.9s var(--ease); }
.meter-note { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.meter-note b { color: var(--text); font-weight: 500; }

/* tiles */
.tile .value { font-weight: 600; font-size: 28px; letter-spacing: -0.03em; line-height: 1.15; margin-top: 8px; }
.tile .delta-row { margin-top: 6px; }
.spark { display: block; width: 100%; height: 40px; margin-top: 16px; overflow: visible; }
.spark .l { fill: none; stroke: var(--prev); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark .c { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linecap: round; }
.spark .d { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }

/* barras por produto */
.bars { display: grid; gap: 4px; margin-top: 20px; }
.brow { display: grid; grid-template-columns: 148px minmax(0, 1fr); align-items: center; gap: 12px; padding: 6px 0; border-radius: 6px; outline-offset: 2px; }
.brow .name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .track { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brow .bar { height: 20px; border-radius: 0 4px 4px 0; background: var(--s1); transition: width 0.7s var(--ease), opacity 0.2s, filter 0.2s; min-width: 2px; }
.brow .val { font-weight: 500; white-space: nowrap; }
.brow.dim .bar { background: var(--prev); }
.brow:hover .bar, .brow:focus-visible .bar { filter: brightness(1.12); }
.note { margin-top: 14px; font-size: 12.5px; color: var(--muted); }

/* origem */
.stack { display: flex; gap: 2px; height: 36px; margin-top: 22px; }
.seg { display: grid; place-items: center; min-width: 2px; font-size: 12px; font-weight: 600; border-radius: 4px; transition: width 0.7s var(--ease), filter 0.2s; outline-offset: 2px; }
.seg:hover, .seg:focus-visible { filter: brightness(1.12); }
.seg[data-k="direct"] { background: var(--s1); color: var(--on-s1); }
.seg[data-k="aff"] { background: var(--s2); color: var(--on-s2); }
.seg[data-k="co"] { background: var(--s3); color: var(--on-s3); }
.leg-rows { margin-top: 20px; }
.leg-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 52px; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.leg-row .sw { width: 10px; height: 10px; border-radius: 2px; }
.leg-row .nm { color: var(--text-2); }
.leg-row .pc { text-align: right; color: var(--muted); }
.leg-row b { font-weight: 500; }

/* entrada ao rolar */
@media (prefers-reduced-motion: no-preference) {
  .js .rv { opacity: 0; transform: translateY(12px); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); transition-delay: calc(var(--i, 0) * 80ms); }
  .js .rv.in { opacity: 1; transform: none; }
}

/* ---------- responsivo ---------- */
@media (max-width: 1180px) {
  .c-hero, .c-wallet { grid-column: span 12; }
  .c-wallet { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: 24px; }
  .c-wallet .hr { display: none; }
  .c-tile { grid-column: span 6; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 40; inset: 0 auto 0 0; width: 280px; transform: translateX(-102%); transition: transform 0.35s var(--ease); background: var(--canvas); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.3); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
  .scrim.on { opacity: 1; pointer-events: auto; }
  .icon-btn.menu-btn { display: grid; }
  .c-prod, .c-origin { grid-column: span 12; }
  .main { padding-top: 20px; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; }
  .top-actions .btn-primary { display: none; }
  .c-wallet { display: flex; }
  .c-tile { grid-column: span 12; }
  .card { padding: 20px; }
  .brow { grid-template-columns: 110px minmax(0, 1fr); }
  .filters .spacer { display: none; }
  .head-actions { width: 100%; justify-content: space-between; }
}
@media (min-width: 901px) { .scrim { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition-duration: 0.01ms !important; animation: none !important; } .meter > i { transition: none; } }
@media print { .side, .filters, .top-actions { display: none; } .app { display: block; } }
