/* ====================================================================
   TOKENS
   ==================================================================== */
:root {
  --canvas: #F6F7F9;
  --surface: #FFFFFF;
  --surface-sunken: #FBFBFC;
  --line: #E7E9EE;
  --line-strong: #D8DBE2;

  --ink: #171A21;
  --ink-soft: #4E5562;
  --slate: #868D99;

  --jade: #0E8F6E;
  --jade-deep: #0A6E56;
  --jade-soft: #E4F4EE;

  --amber: #EFA23B;
  --amber-soft: #FCF0DC;

  --coral: #E1484D;
  --coral-soft: #FBE8E8;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --topbar-h: 56px;

  --shadow-sm: 0 1px 2px rgba(23, 26, 33, 0.04), 0 1px 1px rgba(23, 26, 33, 0.03);
  --shadow-md: 0 8px 24px rgba(23, 26, 33, 0.06);
  --shadow-lg: 0 12px 32px rgba(23, 26, 33, 0.12);

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }

a { color: var(--jade-deep); }

/* ====================================================================
   SHELL / SIDEBAR / TOPBAR
   ==================================================================== */
.app-shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }

/* 👉 CORREÇÃO: a sidebar agora é SEMPRE um painel flutuante por cima do
   conteúdo (nunca mais empurra o conteúdo pro lado, nem em telas
   largas) — controlada só pelo botão "☰" na barra de título superior.
   Sempre inicia fechada; abrir mostra um fundo escurecido e
   desfocado atrás dela (.sidebar-backdrop), e clicar num item do menu
   fecha ela automaticamente, em QUALQUER tamanho de tela. Isso também
   garante que o conteúdo sempre usa 100% da largura disponível — antes,
   com a sidebar "empurrando" por padrão em telas largas, sobrava um
   respiro de 250px que nem sempre valia a pena (mesmo com a sidebar
   fechada de novo, o layout já tinha calculado a área do conteúdo). */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  height: calc(100vh - var(--topbar-h));
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  box-shadow: var(--shadow-lg);
}
.sidebar.sidebar-open { transform: translateX(0); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--jade), var(--jade-deep));
  flex-shrink: 0;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.sidebar-brand-text h1 { font-size: 15px; margin: 0; font-weight: 600; line-height: 1.2; }
.sidebar-brand-text span { font-size: 12px; color: var(--slate); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--surface-sunken); color: var(--ink); }
.nav-item.active { background: var(--jade-soft); color: var(--jade-deep); font-weight: 600; }
.nav-item.active svg { opacity: 1; }

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -17px;
  top: 50%;
  transform: translateY(-50%);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--canvas);
  border: 1px solid var(--line);
}

.sidebar-footer { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }

.sidebar-status {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 10px 18px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.sidebar-run-btn { width: 100%; }

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 60px;
  max-width: 1100px;
}

/* 👉 NOVIDADE: barra de título superior fixa, presente em qualquer
   tamanho de tela — é onde mora o botão "☰" que abre/fecha a sidebar.
   Substitui o antigo botão flutuante que só existia em celulares. */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1002;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-topbar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.app-topbar-toggle-btn:hover { background: var(--surface-sunken); }

.app-topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.app-topbar-brand .brand-mark { width: 24px; height: 24px; border-radius: 7px; }
.app-topbar-brand .brand-mark::after { inset: 6px; }

.app-topbar-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
  flex-shrink: 0;
}

.app-topbar-page-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 👉 CORREÇÃO: fundo escurecido E DESFOCADO atrás da sidebar — agora
   aparece em QUALQUER tamanho de tela (antes só em telas estreitas;
   em telas largas a sidebar empurrava o conteúdo em vez de flutuar por
   cima, então esse fundo nunca aparecia lá). */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(23, 26, 33, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 999;
}
.sidebar-backdrop.visible { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h2 { font-size: 22px; margin: 0; font-weight: 600; }
.topbar-sub { color: var(--slate); font-size: 13px; margin: 4px 0 0; }

.topbar-action-manual { display: none; }
.content:has(#view-manual.active) .topbar-action-manual { display: inline-flex; }

/* 👉 NOVIDADE: a tela "Envio Manual" tem tabelas com bastante coluna
   (produto, categoria, preços, IA, motivo, data, ações) — o card ocupa
   TODA a largura disponível (sem teto de max-width), em vez do
   max-width padrão (1100px) ou de uma fração fixa da tela, pra
   aproveitar o espaço em branco em qualquer tamanho de janela. */
.content:has(#view-manual.active) { max-width: none; }

.live-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--slate); }

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--jade);
  animation: pulse 1.8s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.view { display: none; }
.view.active { display: block; }

/* ====================================================================
   CARDS / GRID (Dashboard)
   ==================================================================== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.card-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--slate); font-weight: 600; }
.card-value { font-size: 19px; font-weight: 600; word-break: break-all; font-family: var(--font-display); }
.card-sub { font-size: 12.5px; color: var(--slate); }
.mono { font-family: var(--font-mono); font-size: 14px; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.status-dot.on { background: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); animation: statusPulse 2.2s infinite ease-in-out; }
.status-dot.off { background: var(--coral); box-shadow: 0 0 0 3px var(--coral-soft); }
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--jade-soft); }
  50% { box-shadow: 0 0 0 6px var(--jade-soft); }
}

/* 👉 NOVIDADE: card de status do robô com destaque de cor conforme o
   estado (ativo/pausado) + toggle switch no lugar do botão simples. */
.robot-card {
  border-left: 4px solid var(--line-strong);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.robot-card.is-on {
  border-left-color: var(--jade);
  background: linear-gradient(180deg, var(--jade-soft) 0%, var(--surface) 60%);
}
.robot-card.is-off {
  border-left-color: var(--coral);
  background: linear-gradient(180deg, var(--coral-soft) 0%, var(--surface) 60%);
}
.robot-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.robot-status-sub { font-size: 12px; color: var(--slate); }

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background 0.2s ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(23, 26, 33, 0.3);
}
.switch input:checked + .switch-slider { background: var(--jade); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: 0.55; cursor: not-allowed; }

/* Mantidos para compatibilidade — não usados mais no card do robô,
   mas outros trechos do painel podem reaproveitar. */
.btn-sm { padding: 6px 14px; font-size: 12.5px; width: fit-content; margin-top: 4px; }
.btn-stop { background: var(--coral-soft); color: #9C2B2F; }
.btn-stop:hover { background: #F6D2D2; }
.btn-start { background: var(--jade-soft); color: var(--jade-deep); }
.btn-start:hover { background: #D4EEE4; }

/* ====================================================================
   PANELS / BOTÕES / TABELA DE RESULTADOS
   ==================================================================== */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
.panel h2 { font-size: 15.5px; margin: 0 0 16px; font-weight: 600; }
.panel-head h2 { margin: 0; }
.panel-desc { font-size: 13px; color: var(--slate); margin: -10px 0 16px; }

.btn {
  background: var(--jade);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--jade-deep); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line-strong); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-sunken); }

.results { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.results th {
  text-align: left;
  color: var(--slate);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}
.results td { padding: 11px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.results tr:last-child td { border-bottom: none; }

.empty { color: var(--slate); font-style: italic; }
.status-ok { color: var(--jade-deep); }
.status-error { color: var(--coral); }

.hint { color: var(--slate); font-size: 13px; margin-top: 10px; }
.hint code { background: var(--surface-sunken); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); }

.warnings {
  background: var(--coral-soft);
  border: 1px solid #F3C6C6;
  color: #9C2B2F;
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-size: 13.5px;
  margin-bottom: 20px;
  line-height: 1.6;
}

.hidden { display: none; }
.footer { text-align: center; color: var(--slate); font-size: 12px; margin-top: 24px; }

/* ====================================================================
   RESPONSIVO (shell)
   ==================================================================== */
@media (max-width: 900px) {
  .content { padding: 20px 18px 50px; }
}

@media (max-width: 700px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .toast-container { left: 12px; right: 12px; top: 12px; } .toast { max-width: none; } }
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } }

/* ====================================================================
   👉 NOVIDADE: tabelas (.results) em formato de cartão em telas
   pequenas — em vez de espremer colunas (produto/categoria/preços
   cortados, como acontecia em "Envio Manual" e "Fila de Envios" no
   celular), cada linha vira um cartão com "rótulo: valor" empilhado.
   Os rótulos vêm de data-label="" em cada <td> (já adicionados nas
   tabelas de Envio Manual e Fila de Envios).
   ==================================================================== */
@media (max-width: 700px) {
  table.results thead { display: none; }
  table.results, table.results tbody, table.results tr, table.results td {
    display: block;
    width: 100%;
  }
  table.results tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 4px 14px;
    background: var(--surface);
  }
  table.results tr:last-child { margin-bottom: 0; }
  table.results td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    text-align: right;
  }
  table.results td:last-child { border-bottom: none; }
  table.results td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex-shrink: 0;
  }

  /* 1ª coluna (produto): ocupa a linha toda, sem rótulo — a
     imagem + título já deixam claro do que se trata o cartão. */
  table.results td:first-child {
    display: block;
    text-align: left;
    padding-top: 14px;
  }
  table.results td:first-child::before { content: none; }

  /* Linhas de estado vazio ("Nenhuma promoção...", "Carregando...")
     não viram cartão — ficam centralizadas, como uma mensagem só. */
  table.results tr:has(td.empty) {
    border: none;
    background: none;
    padding: 0;
    margin-bottom: 0;
  }
  table.results td.empty {
    display: block;
    text-align: center;
    border-bottom: none;
    padding: 14px 0;
  }
  table.results td.empty::before { content: none; }

  /* Células de "Ações" costumam ter 2-4 botões — em vez de espremer
     tudo numa linha ao lado do rótulo, o rótulo vira um mini-título e
     os botões quebram linha livremente logo abaixo. */
  table.results td[data-label="Ações"] {
    display: block;
    text-align: left;
  }
  table.results td[data-label="Ações"]::before {
    display: block;
    margin-bottom: 8px;
  }
  table.results td[data-label="Ações"] > * {
    margin: 0 6px 6px 0;
  }
}

@media (max-width: 480px) {
  .sidebar { width: 80vw; max-width: 290px; }
}

@media (max-width: 380px) {
  .sidebar { width: 86vw; }
}
/* ====================================================================
   👉 NOVIDADE: barra de rolagem moderna (horizontal e vertical) em
   todo o painel — Chrome/Edge/Safari via ::-webkit-scrollbar,
   Firefox via scrollbar-width/scrollbar-color.
   ==================================================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--line-strong);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--slate);
}