/* =====================================================================
   Mercado no Lápis — complementos ao design system do Spark Admin (spark.css)
   Mantém tokens, raios e sombras do template; adiciona apenas o que o
   domínio precisa (alertas de preço, leitor de QR, gráficos).
   ===================================================================== */

:root {
  /* Semântica de preço: subir é ruim (vermelho), cair é bom (verde). */
  --price-up: #DC2626;
  --price-up-bg: #FEF2F2;
  --price-down: #15803D;
  --price-down-bg: #F0FDF4;
  --price-flat: #6C7E75;
}

/* `hidden` sempre vence utilitários como .d-flex */
[hidden] { display: none !important; }
/* Formas decorativas dos cards não geram rolagem horizontal no celular */
.main-wrapper { min-width: 0; overflow-x: clip; }

/* ---------- Marca / avatar ---------- */
.sidebar-brand { font-size: 1.12rem; white-space: nowrap; letter-spacing: -0.02em; }
.mt-brand-mark { border-radius: 9px; flex-shrink: 0; }
body.sidebar-minimized .sidebar-brand .mt-brand-mark { margin: 0 auto; }
.footer-logo img { border-radius: 4px; vertical-align: -3px; }

.mt-avatar {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-lime); color: var(--brand-forest-dark);
  font-weight: 800; font-size: .85rem; letter-spacing: .02em;
}
.mt-avatar-sm { width: 32px; height: 32px; border-radius: 10px; font-size: .75rem; }
a.btn-quick-action { text-decoration: none; }
a.btn-quick-action:hover { color: #fff; background: var(--brand-forest-light); }

/* ---------- Cards de métrica ---------- */
.mt-stat-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-lime-translucent); color: var(--brand-forest-medium); font-size: 1.15rem;
}
.mt-stat-foot { font-size: .8rem; color: var(--text-muted-green); }
.mt-num { font-variant-numeric: tabular-nums; }

.mt-trend { display: inline-flex; align-items: center; gap: .3rem; font-weight: 700; font-size: .8rem; padding: .2rem .55rem; border-radius: 999px; }
.mt-trend.up     { color: var(--price-up);   background: var(--price-up-bg); }
.mt-trend.down   { color: var(--price-down); background: var(--price-down-bg); }
.mt-trend.stable { color: var(--price-flat); background: #EEF2F0; }
.mt-trend.new    { color: #1D4ED8; background: #EFF6FF; }

/* ---------- Alertas de preço ---------- */
.mt-alert-col-title { display: flex; align-items: center; gap: .5rem; font-size: .95rem; font-weight: 700; margin-bottom: .75rem; }
.mt-alert-col-title .dot { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }
.mt-alert-col-title.up .dot   { background: var(--price-up-bg); color: var(--price-up); }
.mt-alert-col-title.down .dot { background: var(--price-down-bg); color: var(--price-down); }

.mt-price-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem .85rem; border-radius: var(--radius-md); border: 1px solid var(--border-light);
  margin-bottom: .5rem; text-decoration: none; color: inherit; transition: border-color .2s, box-shadow .2s;
}
.mt-price-row:hover { border-color: rgba(7, 47, 31, .25); box-shadow: var(--shadow-sm); color: inherit; }
.mt-price-row .name { font-weight: 600; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-price-row .sub  { font-size: .76rem; color: var(--text-muted-green); }
.mt-price-row .right { text-align: right; flex-shrink: 0; }

.mt-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted-green); }
.mt-empty i { font-size: 2.2rem; color: var(--brand-forest-light); opacity: .5; display: block; margin-bottom: .5rem; }

/* ---------- Gráficos ---------- */
.mt-chart-box { position: relative; height: 290px; }
.mt-chart-box.tall { height: 380px; }
@media (max-width: 576px) { .mt-chart-box.tall { height: 300px; } }

/* ---------- Leitor de QR Code ---------- */
.mt-tabs { display: flex; gap: .35rem; background: #EEF2F0; padding: .3rem; border-radius: var(--radius-lg); overflow-x: auto; }
.mt-tabs button {
  flex: 1 0 auto; border: 0; background: transparent; padding: .55rem .9rem; border-radius: var(--radius-md);
  font-weight: 600; font-size: .84rem; color: var(--text-muted-green); white-space: nowrap;
}
.mt-tabs button.active { background: #fff; color: var(--text-main); box-shadow: var(--shadow-sm); }
.mt-tabs button i { margin-right: .35rem; }

.mt-scanner {
  position: relative; background: var(--brand-forest-dark); border-radius: var(--radius-xl);
  overflow: hidden; aspect-ratio: 4 / 3; max-height: 420px; width: 100%;
}
.mt-scanner #qr-reader { width: 100%; height: 100%; }
.mt-scanner #qr-reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.mt-scanner-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 1.5rem; gap: .75rem; pointer-events: none;
}
.mt-scanner-overlay > * { pointer-events: auto; }
.mt-scanner-frame {
  position: absolute; top: 50%; left: 50%; width: min(62%, 280px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 20px; pointer-events: none; border: 3px solid var(--brand-lime);
  box-shadow: 0 0 0 9999px rgba(5, 28, 18, .45);
}
.mt-scanner-frame::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: var(--brand-lime); opacity: .75; animation: mt-scan 2.2s ease-in-out infinite;
}
@keyframes mt-scan { 0%, 100% { transform: translateY(-60px); } 50% { transform: translateY(60px); } }
@media (prefers-reduced-motion: reduce) { .mt-scanner-frame::after { animation: none; } }
.mt-scanner.is-idle .mt-scanner-frame { display: none; }

.mt-dropzone {
  border: 2px dashed rgba(7, 47, 31, .2); border-radius: var(--radius-xl); padding: 2rem 1rem; text-align: center;
  cursor: pointer; transition: border-color .2s, background .2s; display: block;
}
.mt-dropzone:hover, .mt-dropzone.drag { border-color: var(--brand-forest-medium); background: var(--brand-lime-translucent); }
.mt-dropzone i { font-size: 2rem; color: var(--brand-forest-medium); }

.mt-result { border-radius: var(--radius-xl); padding: 1.25rem; border: 1px solid var(--border-light); }
.mt-result.ok     { background: var(--price-down-bg); border-color: #BBF7D0; }
.mt-result.queued { background: #FFFBEB; border-color: #FDE68A; }
.mt-result.fail   { background: var(--price-up-bg); border-color: #FECACA; }

.mt-steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.mt-steps li { counter-increment: s; position: relative; padding-left: 2.2rem; margin-bottom: .8rem; font-size: .875rem; }
.mt-steps li::before {
  content: counter(s); position: absolute; left: 0; top: -1px; width: 1.6rem; height: 1.6rem; border-radius: 8px;
  background: var(--brand-lime); color: var(--brand-forest-dark); font-weight: 800; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Análise: seletor de produtos ---------- */
.mt-picker { position: relative; }
.mt-suggest {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px); background: #fff; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto; padding: .35rem; display: none;
}
.mt-suggest.show { display: block; }
.mt-suggest button {
  display: flex; width: 100%; justify-content: space-between; gap: 1rem; border: 0; background: transparent;
  padding: .6rem .75rem; border-radius: var(--radius-md); text-align: left; font-size: .875rem;
}
.mt-suggest button:hover, .mt-suggest button.focus { background: #F1F5F3; }
.mt-suggest small { color: var(--text-muted-green); white-space: nowrap; }

.mt-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.mt-chip {
  display: inline-flex; align-items: center; gap: .45rem; padding: .35rem .45rem .35rem .7rem; border-radius: 999px;
  background: #F1F5F3; font-size: .82rem; font-weight: 600; max-width: 100%;
}
.mt-chip .swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.mt-chip span.label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.mt-chip button { border: 0; background: transparent; padding: 0 .2rem; color: var(--text-muted-green); line-height: 1; }
.mt-chip button:hover { color: var(--price-up); }

.mt-seg { display: inline-flex; background: #EEF2F0; padding: .25rem; border-radius: var(--radius-md); gap: .2rem; }
.mt-seg button { border: 0; background: transparent; padding: .35rem .7rem; border-radius: 8px; font-size: .8rem; font-weight: 600; color: var(--text-muted-green); }
.mt-seg button.active { background: #fff; color: var(--text-main); box-shadow: var(--shadow-sm); }

.mt-legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: .8rem; color: var(--text-muted-green); }
.mt-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.mt-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---------- Tabelas ---------- */
.table-custom td.num, .table-custom th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-custom .wrap { white-space: normal; min-width: 220px; }
.mt-table-card { padding: 0; }
.table-compact th, .table-compact td { padding: .85rem .8rem; }
.table-compact th:first-child, .table-compact td:first-child { padding-left: 1.25rem; }
.table-compact .wrap { min-width: 180px; }
.mt-table-card .card-header { padding: 1.5rem 1.75rem 0 !important; }
.mt-pagination .page-link { border-radius: 8px !important; margin: 0 2px; border: 0; color: var(--text-main); font-weight: 600; }
.mt-pagination .page-item.active .page-link { background: var(--brand-forest-medium); color: #fff; }

/* ---------- Diversos ---------- */
.btn-custom-lime { background: var(--brand-lime); border-color: var(--brand-lime); color: var(--brand-forest-dark); }
.btn-custom-lime:hover { background: var(--brand-lime-hover); color: var(--brand-forest-dark); }
textarea.form-control-custom { min-height: 180px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.text-muted-green { color: var(--text-muted-green) !important; }
.fw-800 { font-weight: 800; }
.min-w-0 { min-width: 0; }
.mt-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere; }
.alert-green-card .btn-custom-lime { position: relative; z-index: 2; }

@media (max-width: 768px) {
  .main-wrapper { padding: 1rem; }
  .btn-quick-action span { display: none; }
  .card { padding: 1.25rem; }
  .mt-table-card .card-header { padding: 1.25rem 1.25rem 0 !important; }
}
