/* Tokens fiéis ao shadcn/ui (estilo "new-york", ver ui.shadcn.com/docs/theming) —
   mesma paleta neutra, mesmo raio, mesma tipografia/spacing de componente.
   --primary/--destructive são os únicos valores que fujem do neutro padrão do
   shadcn: mantive o vermelho da marca Way em vez do preto neutro deles. */
:root {
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) * 1.4);

  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --card-foreground: #0a0a0a;
  --popover: #ffffff;
  --popover-foreground: #0a0a0a;

  --primary: #d61d22;
  --primary-foreground: #ffffff;
  --secondary: #f5f5f5;
  --secondary-foreground: #171717;
  --muted: #f5f5f5;
  --muted-foreground: #737373;
  --accent: #f5f5f5;
  --accent-foreground: #171717;
  --destructive: #dc2626;
  --destructive-foreground: #ffffff;

  --border: #e5e5e5;
  --input: #e5e5e5;
  --ring: #a3a3a3;

  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --warn: #b45309;
  --warn-bg: #fffbeb;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #0a0a0a;
    --foreground: #fafafa;
    --card: #171717;
    --card-foreground: #fafafa;
    --popover: #171717;
    --popover-foreground: #fafafa;

    --primary: #ff6b6f;
    --primary-foreground: #2a0000;
    --secondary: #262626;
    --secondary-foreground: #fafafa;
    --muted: #262626;
    --muted-foreground: #a3a3a3;
    --accent: #262626;
    --accent-foreground: #fafafa;
    --destructive: #f87171;
    --destructive-foreground: #2a0000;

    --border: rgba(255, 255, 255, 0.1);
    --input: rgba(255, 255, 255, 0.15);
    --ring: #737373;

    --ok: #4ade80;
    --ok-bg: #052e16;
    --warn: #fbbf24;
    --warn-bg: #451a03;
  }
}
:root[data-theme="dark"] {
  --background: #0a0a0a; --foreground: #fafafa; --card: #171717; --card-foreground: #fafafa;
  --popover: #171717; --popover-foreground: #fafafa; --primary: #ff6b6f; --primary-foreground: #2a0000;
  --secondary: #262626; --secondary-foreground: #fafafa; --muted: #262626; --muted-foreground: #a3a3a3;
  --accent: #262626; --accent-foreground: #fafafa; --destructive: #f87171; --destructive-foreground: #2a0000;
  --border: rgba(255,255,255,0.1); --input: rgba(255,255,255,0.15); --ring: #737373;
  --ok: #4ade80; --ok-bg: #052e16; --warn: #fbbf24; --warn-bg: #451a03;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); }

/* ---------- topbar ---------- */

header.topbar {
  background: var(--card);
  color: var(--foreground);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
header.topbar h1 { font-size: 14px; margin: 0; font-weight: 600; }
header.topbar .store-name { font-size: 12px; color: var(--muted-foreground); }
header.topbar .actions { display: flex; gap: 6px; align-items: center; }
header.topbar select {
  width: auto;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: var(--background);
  color: var(--foreground);
  font: inherit;
  font-size: 13px;
}

/* ---------- botões (shadcn Button: rounded-md, h-9, px-4, text-sm font-medium) ---------- */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-foreground);
  transition: background-color 0.15s ease, opacity 0.15s ease;
}
button:hover, .btn:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Ghost — sem preenchimento, sem borda; ação secundária (editar, cancelar,
   ativar/desativar, encerrar, recusar, abas). Equivalente ao Button
   variant="ghost" do shadcn: hover:bg-accent, nada além disso. */
.text-btn {
  background: transparent;
  color: var(--foreground);
  padding: 0 12px;
  height: 32px;
}
.text-btn:hover { background: var(--accent); opacity: 1; }
.text-btn.on-error, .text-btn.on-dev { color: var(--destructive); }
.text-btn.on-error:hover, .text-btn.on-dev:hover { background: var(--destructive); color: var(--destructive-foreground); }

/* mantidos por compatibilidade com HTML/JS existente — mapeados pra ghost */
button.secondary, button.ghost { background: transparent; color: var(--foreground); padding: 0 12px; height: 32px; }
button.secondary:hover, button.ghost:hover { background: var(--accent); opacity: 1; }

header.topbar .text-btn:hover { background: var(--accent); }

/* ---------- aviso de "agindo como loja" (modo dev) ---------- */

.dev-banner {
  background: var(--warn-bg);
  color: var(--warn);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}
.dev-banner .text-btn { color: var(--warn); }
.dev-banner .text-btn:hover { background: color-mix(in srgb, var(--warn) 15%, transparent); }

main { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- abas ---------- */

nav.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin: 16px 0;
  border-bottom: 1px solid var(--border);
}
nav.tabs button {
  background: none;
  color: var(--muted-foreground);
  border-radius: 0;
  height: auto;
  padding: 8px 4px;
  margin-right: 20px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
nav.tabs button.active { color: var(--foreground); border-bottom-color: var(--primary); }
nav.tabs button:hover { background: none; opacity: 1; color: var(--foreground); }
nav.tabs .badge {
  background: var(--destructive); color: var(--destructive-foreground); border-radius: var(--radius-sm); font-size: 11px;
  padding: 1px 6px; margin-left: 4px; font-weight: 600;
}

section.panel { display: none; }
section.panel.active { display: block; }

/* ---------- superfícies (shadcn Card: rounded-xl border shadow-sm) ---------- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 20px;
  margin-bottom: 16px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.product-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 14px;
}
.product-card .photo-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.product-card .photo {
  width: 100%; height: 100px; object-fit: cover; border-radius: var(--radius-md);
  background: var(--muted);
}
.product-card .photo.placeholder {
  display: flex; align-items: center; justify-content: center; color: var(--muted-foreground); font-size: 12px;
}
.product-card .name { font-weight: 600; font-size: 14px; }
.product-card .meta { font-size: 12px; color: var(--muted-foreground); }
.product-card .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }

/* ---------- badges de status (shadcn Badge: rounded-md, NÃO pill) ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.tag.ok { background: var(--ok-bg); color: var(--ok); border-color: currentColor; }
.tag.atencao { background: var(--warn-bg); color: var(--warn); border-color: currentColor; }
.tag.critico, .tag.vencido { background: color-mix(in srgb, var(--destructive) 10%, var(--background)); color: var(--destructive); border-color: currentColor; }

.empty { color: var(--muted-foreground); font-size: 13px; padding: 24px 0; text-align: center; }

/* ---------- formulários (shadcn Input: h-9 rounded-md border, focus ring) ---------- */

form.stack { display: flex; flex-direction: column; gap: 16px; }
label { font-size: 13px; font-weight: 500; color: var(--foreground); display: block; margin-bottom: 6px; }
input, select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 13px;
  background: var(--background);
  color: var(--foreground);
}
input[type="file"] { height: auto; padding: 8px 12px; }
input:focus, select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 50%, transparent);
}

/* ---------- diálogo (shadcn Dialog: rounded-lg, shadow-lg) ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}
.modal h3 { margin-top: 0; font-size: 16px; font-weight: 600; }

.error-msg { color: var(--destructive); font-size: 13px; }
.success-msg { color: var(--ok); font-size: 13px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-row input, .filter-row select { width: auto; flex: 1; min-width: 140px; }

/* ---------- tabela ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
table th { color: var(--muted-foreground); font-weight: 500; font-size: 12px; }
table tbody tr:hover { background: var(--accent); }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--muted);
}
.login-card { max-width: 360px; width: 100%; text-align: center; }
.login-card h1 { color: var(--foreground); font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-card p.subtitle { color: var(--muted-foreground); font-size: 13px; margin-top: 0; margin-bottom: 24px; }

.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor;
  border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin: usuários, logs e analytics ---------- */

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.section-heading h3 { margin: 0; font-size: 16px; font-weight: 600; }
.section-heading h4 { margin: 0; }
.meta { color: var(--muted-foreground); font-size: 12px; margin: 2px 0 0; }

.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--muted);
}
.segmented .text-btn { height: 30px; }
.segmented .text-btn.active { background: var(--background); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.check-row input { width: 16px; height: 16px; }

.log-list { display: grid; gap: 8px; }
.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--background);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--background);
}
.stat span { display: block; color: var(--muted-foreground); font-size: 12px; }
.stat strong { display: block; margin-top: 4px; font-size: 22px; line-height: 1.1; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.chart-grid h4 { margin: 0 0 8px; font-size: 13px; }
.bar-chart { display: grid; gap: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) 2fr 34px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.bar-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted-foreground);
}
.bar-track {
  height: 9px;
  border-radius: var(--radius-sm);
  background: var(--muted);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: var(--bar-width);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--warn));
  animation: growBar 650ms ease-out both;
  transform-origin: left;
}
.bar-value { text-align: right; font-weight: 600; }
@keyframes growBar {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (max-width: 760px) {
  .section-heading { flex-direction: column; }
  .stats-grid, .chart-grid { grid-template-columns: 1fr; }
  .log-item { align-items: flex-start; flex-direction: column; }
}
