:root {
  --primary: #2e7d5e;
  --primary-dark: #24634a;
  --primary-light: #e6f2ee;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d5dae1;
  --danger: #b3261e;
  --danger-light: #fdecea;
  --warning: #8a5a00;
  --warning-light: #fdf3e2;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.1), 0 1px 2px rgba(16, 24, 40, 0.06);
  --appbar-h: 60px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 16px; }
h3 { font-size: 15px; font-weight: 600; margin: 24px 0 12px; }
.muted { color: var(--text-muted); }
.right { text-align: right; }

/* ---------- AppBar ---------- */
.appbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff; font-weight: 700; font-size: 16px;
}
.brand-name { font-size: 19px; font-weight: 700; color: var(--primary); letter-spacing: .2px; }
.brand-org {
  margin-left: 8px; padding-left: 12px;
  border-left: 1px solid var(--border-strong);
  font-size: 15px; font-weight: 500; color: var(--text);
}
.metric { font-size: 34px; font-weight: 700; margin: 6px 0 2px; }
.progress { height: 10px; background: #eef1f4; border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; }
.card-highlight { border-color: #f0d9a8; background: #fffdf6; }
.metric-warn { color: var(--warning); }

/* ---------- Detalhes (lista rótulo/valor) ---------- */
.details { display: flex; flex-direction: column; }
.detail {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.detail:last-child { border-bottom: none; }
.detail-label { color: var(--text-muted); font-size: 13px; }
@media (max-width: 620px) {
  .detail { grid-template-columns: 1fr; gap: 2px; }
}
.appbar-right { display: flex; align-items: center; gap: 16px; }
.org-switch { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.org-switch select {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: var(--text);
}
.user { font-size: 13px; color: var(--text-muted); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--appbar-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.side-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

/* Tooltip (histórico) */
.tip { position: relative; cursor: help; border-bottom: 1px dotted var(--text-muted); }
.tip-content {
  display: none;
  position: absolute;
  z-index: 40;
  left: 0; top: 100%;
  margin-top: 6px;
  width: max-content;
  max-width: 300px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
}
.tip:hover .tip-content, .tip:focus .tip-content { display: block; }
.side-label {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px;
}
.side-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 2px;
}
.side-item:hover { background: #f3f4f6; text-decoration: none; }
.side-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.side-item svg { width: 18px; height: 18px; flex: none; }

/* ---------- Content ---------- */
.content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--appbar-h) + 28px) 32px 48px;
  min-height: 100vh;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head .muted { margin: 4px 0 0; }
.page-actions { display: flex; gap: 10px; flex: none; }

/* ---------- Compact form grid ---------- */
.campaign-filter { max-width: 460px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Modal (<dialog>) ---------- */
dialog.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: calc(100% - 32px);
  max-width: 720px;
  color: var(--text);
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.28);
}
dialog.modal.modal-lg { max-width: 980px; }
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
button.x {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 8px; border-radius: 6px;
}
button.x:hover { color: var(--text); background: #f3f4f6; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.card-actions { display: flex; gap: 10px; margin-top: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 18px; }
.grid .card { margin: 0; }

/* ---------- Forms ---------- */
form { display: flex; flex-direction: column; gap: 14px; }
label.field, .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 94, 0.15);
}
input[type="file"] { padding: 8px; background: #fafbfc; }
textarea { resize: vertical; min-height: 72px; font-family: inherit; }
.thumb { display: block; max-width: 160px; max-height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); margin-top: 8px; }
/* Comprovantes de pagamento */
.receipts { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.receipt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.receipt img { width: 160px; height: 160px; object-fit: cover; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

/* ---------- Dropzone (upload de imagem) ---------- */
.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 16px;
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  background: #fafbfc;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.dragging { border-color: var(--primary); background: var(--primary-light); }
.dropzone.has-image { border-style: solid; border-color: var(--border); }
.dropzone input[type="file"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.dropzone-preview { max-width: 100%; max-height: 180px; border-radius: 8px; object-fit: contain; }
.dropzone-hint { font-size: 13px; color: var(--text-muted); }
.dropzone.has-image .dropzone-hint { font-size: 12px; }

/* ---------- Buttons ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover, button:hover { background: var(--primary-dark); text-decoration: none; }
.btn-ghost, button.link {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
  font-weight: 500;
}
.btn-ghost:hover, button.link:hover { background: #f3f4f6; color: var(--text); }
button.link { border-color: transparent; padding: 6px 10px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f1e17; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbfc; }
.inline { display: inline-flex; flex-direction: row; gap: 8px; align-items: center; }
.inline input, .inline select { padding: 7px 9px; font-size: 13px; width: auto; }
.inline button { padding: 7px 12px; font-size: 13px; }

/* ---------- Badges / alerts ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: #eef1f4; color: var(--text-muted);
}
.badge-active, .badge-PUBLISHED { background: var(--primary-light); color: var(--primary-dark); }
.badge-inactive, .badge-CLOSED, .badge-ARCHIVED { background: #eef1f4; color: var(--text-muted); }
.badge-DRAFT { background: #eef1f4; color: #475467; }
.badge-PAUSED { background: var(--warning-light); color: var(--warning); }
.badge-PENDING_PAYMENT { background: var(--warning-light); color: var(--warning); }
.badge-AWAITING_RECONCILIATION { background: #e0e7ff; color: #3730a3; }
.badge-PAID { background: var(--primary-light); color: var(--primary-dark); }
.badge-EXPIRED, .badge-CANCELLED { background: #eef1f4; color: var(--text-muted); }
.alert {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #f6cfca;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 14px;
}

/* ---------- Auth (login/signup) ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: linear-gradient(160deg, #eef3f1 0%, #f4f6f8 60%);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 8px 30px rgba(16, 24, 40, 0.08);
}
.auth-card .brand { justify-content: center; margin-bottom: 20px; }
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card .muted { text-align: center; }
.auth-card form { margin-top: 8px; }
.auth-card .btn, .auth-card button { width: 100%; }

/* ---------- Menu lateral no celular (hambúrguer + gaveta) ---------- */
.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px;
  border-radius: 8px;
}
.nav-toggle svg { width: 20px; height: 20px; display: block; }
.sidebar-backdrop {
  position: fixed;
  top: var(--appbar-h); left: 0; right: 0; bottom: 0;
  background: rgba(16, 24, 40, 0.45);
  z-index: 25;
  display: none;
}
.sidebar-backdrop.show { display: block; }

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  /* A sidebar vira gaveta (não desaparece) */
  .sidebar {
    display: flex;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 35;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; padding-left: 16px; padding-right: 16px; }
  .appbar { padding: 0 12px; gap: 10px; }
  .brand-org { display: none; }
  .appbar-right .user { display: none; }
}

@media (max-width: 720px) {
  /* Tabelas: rolagem horizontal em vez de estourar o layout */
  .card, .modal-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-actions { flex-wrap: wrap; }
}

/* ---------- Página pública da campanha ---------- */
.pub-container { max-width: 920px; margin: 0 auto; padding: 0 20px; }
/* Página estreita (ex.: pedido): cabeçalho com a MESMA largura do conteúdo. */
.pub-narrow { max-width: 640px; margin: 0 auto; padding: 0 20px; }
/* Página da campanha: cabeçalho e banner (imagem) na largura do texto, não de lado a lado. */
.pub-wrap { max-width: 920px; margin: 0 auto; padding: 0 20px; }
/* Cabeçalho público: sem card — só a logo e o nome da organização em destaque. */
.pub-wrap .pub-header, .pub-narrow .pub-header { background: transparent; border: none; border-radius: 0; margin-top: 26px; }
.pub-wrap .pub-hero { border-radius: 12px; overflow: hidden; margin-top: 16px; }
.pub-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.pub-header-inner { display: flex; align-items: center; gap: 14px; height: auto; padding: 6px 0; }
.pub-logo { height: 40px; width: auto; object-fit: contain; }
.pub-org { font-weight: 800; font-size: 30px; line-height: 1.15; letter-spacing: -0.01em; }
.pub { padding-bottom: 40px; }
.pub-hero { background: #eef1f4; }
.pub-hero-img { display: block; width: 100%; max-height: 380px; object-fit: cover; }
.pub-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.pub-title-row h1 { margin: 0; }
.pub-desc { font-size: 16px; color: #374151; margin: 12px 0 0; white-space: pre-line; }
.pub-goal { margin: 10px 0 0; }
.pub h2 { margin-top: 32px; }
.pub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.pub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
}
.pub-card-img { width: 100%; height: 170px; object-fit: cover; background: #eef1f4; }
.pub-card-body { padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.pub-card-name { font-weight: 600; }
.pub-price { font-size: 18px; font-weight: 700; color: var(--primary-dark); margin-top: 4px; }
.pub-footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: 28px 20px; }
.pub-empty { text-align: center; padding: 80px 20px; }
.pub-order { margin-top: 26px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow-sm); }
.pub-order h3 { margin-top: 0; }

/* Fluxo do pedido */
.pub-flow { margin-top: 26px; }
.flow { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.flow li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow-sm); }
.flow li div { font-size: 13px; }
.flow-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 999px; background: var(--primary); color: #fff; font-weight: 700; margin-bottom: 8px; }
@media (max-width: 720px) { .flow { grid-template-columns: 1fr; } }

/* Stepper de quantidade */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; width: max-content; }
.stepper button { background: #f3f4f6; color: var(--text); border: 0; padding: 8px 14px; font-size: 16px; cursor: pointer; border-radius: 0; width: auto; }
.stepper button:hover { background: #e5e7eb; }
.stepper input { width: 60px; text-align: center; border: 0; border-left: 1px solid var(--border-strong); border-right: 1px solid var(--border-strong); border-radius: 0; padding: 8px 4px; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Datas em destaque */
.date { display: inline-block; background: var(--primary-light); color: var(--primary-dark); font-weight: 600; font-size: 16px; padding: 2px 8px; border-radius: 6px; }
.pickup-location { font-size: 18px; font-weight: 700; color: var(--primary-dark); margin: 4px 0 8px; }
/* Leitura de QR na entrega */
.scan { margin-top: 12px; background: #0f172a; border-radius: 12px; overflow: hidden; min-height: 220px; display: grid; place-items: center; }
.scan video { width: 100%; max-height: 380px; object-fit: cover; display: block; }

/* Total do pedido */
.order-total { margin-top: 18px; font-size: 18px; }
.order-total strong { color: var(--primary-dark); font-size: 22px; }

/* Pix */
.pix { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-top: 12px; }
.pix-qr { width: 260px; height: 260px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.pix-copy { flex: 1; min-width: 240px; }
.pix-copy textarea { font-family: monospace; font-size: 12px; word-break: break-all; }
.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
code { background: #f3f4f6; padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.tabs { display: flex; gap: 6px; background: #eef1f4; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs a { flex: 1; text-align: center; padding: 8px 10px; border-radius: 7px; font-weight: 600; color: var(--text-muted); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.dev-logins { border: 1px dashed var(--border-strong); border-radius: 8px; padding: 12px; margin-bottom: 16px; background: #fafbfc; }
.dev-logins .field { font-size: 12px; }
.filter-row { display: flex; flex-direction: row; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; width: 100%; }
.filter-row input[name="q"] { flex: 1; min-width: 240px; }
/* Filtro de pedidos: nome numa linha; status de pagamento e de entrega cada um na sua linha */
.filter-orders { flex-direction: column; align-items: stretch; gap: 10px; }
.filter-orders input[name="q"] { width: 100%; min-width: 0; }
.status-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip-group-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); min-width: 74px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 13px; font-weight: 600; color: #111827; background: #f3f4f6; cursor: pointer; user-select: none;
}
.chip input { display: none; }
.chip:hover { filter: brightness(0.97); }
/* Selecionado: fundo saturado + anel interno + negrito */
.chip:has(input:checked) { font-weight: 700; box-shadow: inset 0 0 0 2px rgba(17, 24, 39, 0.6); }
/* Cores por status (pagamento + entrega) — texto preto para dar impacto */
.chip-PENDING_PAYMENT { background: #ffe7b8; border-color: #f0c869; }
.chip-AWAITING_RECONCILIATION { background: #dbe3ff; border-color: #a5b4fc; }
.chip-PAID { background: #c8ecd8; border-color: #7fc9a3; }
.chip-EXPIRED { background: #e2e8ef; border-color: #b9c3cf; }
.chip-CANCELLED { background: #f8c9c4; border-color: #e79c94; }
.chip-NOT_DELIVERED { background: #e2e8ef; border-color: #b9c3cf; }
.chip-PARTIALLY_DELIVERED { background: #ffe7b8; border-color: #f0c869; }
.chip-DELIVERED { background: #c8ecd8; border-color: #7fc9a3; }
.chip-PENDING_PAYMENT:has(input:checked) { background: #ffcf70; border-color: #c78e00; }
.chip-AWAITING_RECONCILIATION:has(input:checked) { background: #b4c4ff; border-color: #4f46e5; }
.chip-PAID:has(input:checked) { background: #93dcb8; border-color: #2e7d5e; }
.chip-EXPIRED:has(input:checked) { background: #cbd5e1; border-color: #64748b; }
.chip-CANCELLED:has(input:checked) { background: #f2a49c; border-color: #b3261e; }
.chip-NOT_DELIVERED:has(input:checked) { background: #cbd5e1; border-color: #64748b; }
.chip-PARTIALLY_DELIVERED:has(input:checked) { background: #ffcf70; border-color: #c78e00; }
.chip-DELIVERED:has(input:checked) { background: #93dcb8; border-color: #2e7d5e; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 14px; }
.wa { display: inline-flex; align-items: center; gap: 6px; color: #128c7e; text-decoration: none; font-weight: 500; }
.wa:hover { text-decoration: none; color: #0b6b60; }
.wa svg { flex: none; }
.notice {
  background: #eef4ff;
  color: #1d4ed8;
  border: 1px solid #d6e2ff;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 18px 0;
  font-size: 14px;
}
