@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --success: #059669;
  --success-hover: #047857;
  --success-light: #ecfdf5;
  --success-border: #a7f3d0;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --danger-border: #fecaca;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --warning-border: #fde68a;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-subtle: #f1f5f9;
  --sidebar-bg: #0b1329;
  --sidebar-border: #17254b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

[hidden],
#app-shell[hidden],
.shell[hidden],
#auth[hidden],
.mobile-bottom-nav[hidden] {
  display: none !important;
}

body {
  background: var(--bg-body);
  color: var(--text-main);
  font: 14px/1.5 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}

/* =========================================================
   ESTRUTURA GERAL (SHELL & SIDEBAR)
   ========================================================= */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.shell[hidden] {
  display: none !important;
}

aside {
  padding: 24px 16px;
  background: var(--sidebar-bg);
  color: #dbe8ff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.aside-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 16px 8px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  color: #38bdf8;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

nav#main-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 18px;
  overflow-y: auto;
  flex: 1;
}

nav .nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
  padding: 14px 12px 6px 12px;
  font-weight: 800;
}

nav a, nav button {
  background: transparent;
  text-align: left;
  color: #94a3b8;
  border: 0;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font: 600 13px/1.4 'Manrope', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: all 0.15s ease;
}

nav a:hover, nav button:hover {
  background: #162548;
  color: #ffffff;
}

nav a.active, nav button.active {
  background: #1d3466;
  color: #ffffff;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #38bdf8;
}

aside .aside-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.api-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.aside-bottom small {
  color: #94a3b8;
  font-weight: 600;
  font-size: 12px;
}

button.logout {
  background: transparent;
  color: #f87171;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid #334155;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

button.logout:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* =========================================================
   CABEÇALHO SUPERIOR (MAIN HEADER)
   ========================================================= */
main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

main header {
  height: 72px;
  padding: 0 32px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius-md);
  color: var(--text-main);
  cursor: pointer;
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.4px;
}

header small {
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success-border);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

section#view-container {
  max-width: 1240px;
  padding: 28px 32px;
  flex: 1;
}

/* =========================================================
   ELEMENTOS DE UI (BOTÕES, CARDS, PAINÉIS, FORMS)
   ========================================================= */
.hero {
  padding: 24px 28px;
  border-radius: var(--radius-lg);
  color: #fff;
  background: linear-gradient(135deg, #1e40af, #2563eb 60%, #3b82f6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 10px 20px -5px rgba(37, 99, 235, 0.25);
  margin-bottom: 24px;
}

.hero small, .hero p {
  color: #dbeafe;
  margin: 4px 0;
}

.hero strong {
  display: block;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -1px;
}

.hero button {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.hero button:hover {
  background: #f8fafc;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.metrics article {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.metrics article:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metrics small {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metrics b {
  display: block;
  font-size: 24px;
  font-weight: 800;
  margin-top: 6px;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.panel {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 16px 0;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: -0.3px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin: 18px 0;
}

.cards article {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.cards article:hover {
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.cards h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

/* =========================================================
   BOTÕES E ENTRADAS MODERNAS
   ========================================================= */
button, .btn {
  border: 0;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  font: 700 13px 'Manrope', sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  min-height: 42px;
  text-decoration: none;
}

button:hover {
  background: var(--primary-hover);
}

button:active {
  transform: scale(0.98);
}

button.secondary {
  background: #ffffff;
  color: #334155;
  border: 1px solid #cbd5e1;
}

button.secondary:hover {
  background: var(--bg-subtle);
  border-color: #94a3b8;
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.danger:hover {
  background: var(--danger-hover);
}

button.success {
  background: var(--success);
  color: #fff;
}

button.success:hover {
  background: var(--success-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

label, form {
  display: grid;
  gap: 6px;
}

form {
  gap: 16px;
}

input, select, textarea {
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 11px 14px;
  background: #ffffff;
  font: inherit;
  font-size: 14px;
  color: var(--text-main);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.collect {
  max-width: 600px;
}

.collect input {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-pending, .badge-queued { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-processing, .badge-running { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge-sent, .badge-accepted { background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe; }
.badge-delivered, .badge-approved, .badge-completed { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-read { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge-failed, .badge-cancelled, .badge-rejected { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-active { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-blocked { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 800;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

td {
  padding: 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}

tr:hover td {
  background: #f8fafc;
}

.subnav {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
  padding-bottom: 2px;
  overflow-x: auto;
}

.subnav button {
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  padding: 10px 16px;
  border-bottom: 2px solid transparent;
  font-weight: 600;
  white-space: nowrap;
}

.subnav button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 800;
}

.subnav button:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: 10px 0;
  display: flex;
}

.progress-bar span {
  height: 100%;
  transition: width 0.3s ease;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #0f172a;
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 9999;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

#toast.on {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#toast.bad {
  background: var(--danger);
}

/* =========================================================
   WHATSAPP MOCKUP BUBBLE & VAR PILLS
   ========================================================= */
.wa-preview-wrapper {
  background: #efeae2;
  border: 1px solid #d1d7db;
  border-radius: 16px;
  padding: 18px;
  max-width: 420px;
  margin: 14px 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.wa-bubble {
  background: #ffffff;
  border-radius: 12px 12px 12px 3px;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.15);
  overflow: hidden;
  font-size: 14px;
  line-height: 1.45;
  color: #111b21;
}

.wa-header-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid #e9edef;
}

.wa-header-text {
  font-weight: 800;
  padding: 12px 14px 4px 14px;
  color: #111b21;
  font-size: 15px;
}

.wa-body {
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.wa-footer {
  padding: 0 14px 6px 14px;
  font-size: 11px;
  color: #667781;
}

.wa-time {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding: 0 12px 6px 12px;
  font-size: 11px;
  color: #667781;
}

.wa-buttons {
  border-top: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
}

.wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  color: #00a884;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  border-top: 1px solid #f0f2f5;
  background: #ffffff;
  cursor: pointer;
  text-align: center;
}

.wa-btn:hover {
  background: #f8fafc;
}

.var-pill {
  display: inline-block;
  background: #e0f2fe;
  color: #0284c7;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 12px;
  margin: 0 2px;
  border: 1px solid #bae6fd;
}

/* =========================================================
   BARRA DE NAVEGAÇÃO MOBILE (BOTTOM BAR & DRAWER)
   ========================================================= */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 50;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  flex: 1;
  transition: all 0.15s ease;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 95;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* =========================================================
   MODAL APRESENTAR QR CODE EM TELA CHEIA (CAMPO / MOBILE)
   ========================================================= */
.qr-present-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 19, 41, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.qr-present-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.qr-present-img-wrap {
  background: #ffffff;
  padding: 12px;
  border-radius: 16px;
  border: 2px solid var(--border);
  box-shadow: var(--shadow-md);
  display: inline-flex;
}

.qr-present-img-wrap img {
  width: min(72vw, 260px);
  height: min(72vw, 260px);
  display: block;
}

.qr-present-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  margin: 0;
}

.qr-present-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

/* =========================================================
   RESPONSIVIDADE (MOBILE & TABLET)
   ========================================================= */
@media (max-width: 768px) {
  .shell {
    display: block;
  }

  .shell[hidden] {
    display: none !important;
  }

  aside {
    position: fixed;
    top: 0;
    left: 0;
    width: 290px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
  }

  aside.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  main header {
    padding: 0 16px;
    height: 64px;
  }

  header h1 {
    font-size: 18px;
  }

  section#view-container {
    padding: 16px 14px 84px 14px; /* Padding inferior para não cobrir a bottom bar */
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 20px;
  }

  .hero strong {
    font-size: 30px;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .panel {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  /* Otimização de toque em formulários mobile */
  input, select, textarea {
    font-size: 16px !important; /* Previne auto-zoom no Safari iOS */
    padding: 13px 14px;
  }

  button, .btn {
    min-height: 48px;
    font-size: 14px;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wa-preview-wrapper {
    max-width: 100%;
    padding: 14px;
  }
}
