/* Painel administrativo do Mercado Leve — mesma identidade do app. */
:root {
  --verde: #4ade80;
  --verde-600: #22c55e;
  --verde-txt: #15803d;
  --profundo: #0f766e;
  --profundo-700: #115e59;
  --amarelo: #fbbf24;
  --amarelo-50: #fffbeb;
  --off: #f8faf7;
  --card: #ffffff;
  --grafite: #1f2937;
  --muted: #5f6b7a;
  --line: #e3ebe5;
  --grid: #eef2ef;
  --claro: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #40598a;
  --info-bg: #eaf0fb;
  /* Séries categóricas (validadas: CVD e contraste sobre branco) */
  --s-extract: #0d9488;
  --s-meal: #d97706;
  --s-diet: #4f46e5;
  --s-identify: #db2777;
  --s-receipt: #0891b2;
  --s-list: #65a30d;
  --radius: 16px;
  --shadow: 0 8px 24px -14px rgba(15, 118, 110, 0.28);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--off);
  color: var(--grafite);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] {
  display: none !important;
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}
h2 {
  font-size: 17px;
  font-weight: 800;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.num {
  font-variant-numeric: tabular-nums;
}
:focus-visible {
  outline: 3px solid var(--amarelo);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Marca */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand__name {
  font-weight: 900;
  font-size: 19px;
  letter-spacing: -0.02em;
}
.brand__name span {
  color: var(--verde-txt);
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    transform 0.12s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn--primary {
  background: var(--profundo);
  color: #fff;
}
.btn--primary:hover {
  background: var(--profundo-700);
}
.btn--ghost {
  background: var(--card);
  border-color: var(--line);
  color: var(--grafite);
}
.btn--ghost:hover {
  background: var(--claro);
}
.btn--danger {
  background: var(--bad-bg);
  color: var(--bad);
}
.btn--danger:hover {
  background: #fecaca;
}
.btn--sm {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 13px;
}
.btn--block {
  width: 100%;
}
.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 800;
  color: var(--profundo);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Campos */
.field {
  display: grid;
  gap: 4px;
  font-weight: 700;
  font-size: 14px;
}
input,
select,
textarea {
  font: inherit;
  font-weight: 600;
  color: var(--grafite);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  min-height: 40px;
  width: 100%;
}
textarea {
  resize: vertical;
  min-height: 80px;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--verde);
  outline-offset: 0;
  border-color: var(--verde);
}
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
  font-weight: 700;
}
.switch:last-child {
  border-bottom: 0;
}
.switch input {
  appearance: none;
  width: 44px;
  min-height: 0;
  height: 26px;
  border-radius: 99px;
  background: #d1d5db;
  border: 0;
  padding: 0;
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background-color 0.18s ease;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}
.switch input:checked {
  background: var(--profundo);
}
.switch input:checked::after {
  transform: translateX(18px);
}

.error {
  color: var(--bad);
  font-weight: 700;
  margin: 0;
}
.notice {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
}
.notice--warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.notice--info {
  background: var(--info-bg);
  color: var(--info);
}
.notice--ok {
  background: var(--claro);
  color: var(--verde-txt);
}

/* Boot e login */
.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--off);
}
.login__card {
  width: 100%;
  max-width: 400px;
  display: grid;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login__card h1 {
  font-size: 24px;
  font-weight: 900;
  margin-top: 8px;
}
.login__card .muted {
  margin: -8px 0 4px;
}

/* Estrutura */
.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: var(--card);
  border-right: 1px solid var(--line);
}
.nav {
  display: grid;
  gap: 2px;
}
.nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--grafite);
  text-decoration: none;
  font-weight: 700;
}
.nav a:hover {
  background: var(--off);
}
.nav a[aria-current="page"] {
  background: var(--claro);
  color: var(--profundo);
}
.side__foot {
  margin-top: auto;
  display: grid;
  gap: 6px;
  justify-items: start;
  word-break: break-all;
}
.main {
  min-width: 0;
  padding: 24px 28px 48px;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.top h1 {
  font-size: 26px;
  font-weight: 900;
}
.top__actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.seg {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 32px;
}
.seg button[aria-pressed="true"] {
  background: var(--profundo);
  color: #fff;
}
@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .side {
    min-width: 0;
  }
  .side {
    position: static;
    height: auto;
    gap: 12px;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    margin: 0 -16px;
    padding: 0 16px;
    scrollbar-width: none;
  }
  .nav a {
    white-space: nowrap;
  }
  .side__foot {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin: 0;
  }
  .main {
    padding: 18px 16px 40px;
  }
}

/* Grade e cartões */
.view {
  display: grid;
  gap: 16px;
}
.grid {
  display: grid;
  gap: 16px;
}
.grid--kpi {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
.grid--4 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.card__head p {
  margin: 0;
}

/* KPI */
.kpi {
  display: grid;
  gap: 2px;
}
.kpi__label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}
.kpi__value {
  font-size: 30px;
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.kpi__sub {
  font-size: 13px;
  color: var(--muted);
}
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 800;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.delta--up {
  background: var(--claro);
  color: var(--verde-txt);
}
.delta--down {
  background: var(--bad-bg);
  color: var(--bad);
}
.delta--flat {
  background: var(--grid);
  color: var(--muted);
}

/* Gráficos */
.chart {
  position: relative;
  width: 100%;
}
.chart svg {
  display: block;
  overflow: visible;
}
.chart .grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}
.chart .axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.chart .hit {
  fill: transparent;
  cursor: crosshair;
}
.chart .crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  font-weight: 700;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--grafite);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 10px;
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.tooltip b {
  font-weight: 900;
}
.data-table {
  margin-top: 8px;
}
.data-table summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  color: var(--profundo);
}

/* Barras horizontais (funil, ranking, classificação) */
.hbars {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.hbars li {
  display: grid;
  gap: 4px;
}
.hbars__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  font-size: 14px;
}
.hbars__row span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbars__track {
  height: 10px;
  border-radius: 99px;
  background: var(--grid);
  overflow: hidden;
}
.hbars__fill {
  height: 100%;
  border-radius: 99px;
  background: var(--verde-600);
  min-width: 2px;
}

/* Tabelas */
.table-wrap {
  overflow-x: auto;
  margin: 0 -18px;
  padding: 0 18px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
tr:last-child td {
  border-bottom: 0;
}
tbody tr.clickable {
  cursor: pointer;
}
tbody tr.clickable:hover {
  background: var(--off);
}
td.right,
th.right {
  text-align: right;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.tag--ok {
  background: var(--claro);
  color: var(--verde-txt);
}
.tag--warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.tag--bad {
  background: var(--bad-bg);
  color: var(--bad);
}
.tag--info {
  background: var(--info-bg);
  color: var(--info);
}
.tag--muted {
  background: var(--grid);
  color: var(--muted);
}
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar input {
  max-width: 320px;
}
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 13px;
}

/* Formulários de configuração */
.form {
  display: grid;
  gap: 12px;
}
.form__row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form__foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.preview {
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--info-bg);
  color: var(--info);
}
.preview--warning {
  background: var(--warn-bg);
  color: var(--warn);
}
.preview b {
  display: block;
}

/* Status do sistema */
.checks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.checks li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
  font-weight: 700;
}
.checks li:last-child {
  border-bottom: 0;
}

/* Gaveta de detalhe */
.drawer {
  margin: 0 0 0 auto;
  height: 100vh;
  max-height: 100vh;
  width: min(440px, 100vw);
  border: 0;
  padding: 24px;
  background: var(--card);
  box-shadow: -20px 0 40px -20px rgba(0, 0, 0, 0.3);
}
.drawer::backdrop {
  background: rgba(31, 41, 55, 0.35);
}
.drawer[open] {
  animation: drawer-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .drawer[open] {
    animation: none;
  }
}
.drawer__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.drawer__head h2 {
  font-size: 19px;
  word-break: break-all;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.stats div {
  background: var(--off);
  border-radius: 12px;
  padding: 10px;
}
.stats b {
  display: block;
  font-size: 22px;
  font-weight: 900;
}
.stats span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 14px;
}
.dl dt {
  color: var(--muted);
  font-weight: 700;
}
.dl dd {
  margin: 0;
  font-weight: 700;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--grafite);
  color: #fff;
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 16px 30px -12px rgba(0, 0, 0, 0.4);
}

/* Esqueleto de carregamento */
.skeleton {
  height: 120px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #eef2ef 0%, #f6f8f6 50%, #eef2ef 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}
.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}
