:root {
  --azul: #0a2a66;
  --azul-claro: #1d4ed8;
  --amarelo: #ffc400;
  --preto: #111418;
  --cinza: #6b7280;
  --borda: #e5e7eb;
  --bg: #f4f6fb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--preto); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--azul); color: #fff; padding: 14px 24px;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo {
  font-weight: 800; letter-spacing: 2px; font-size: 22px;
  background: var(--amarelo); color: var(--preto); padding: 2px 10px; border-radius: 4px;
}
.subtitle { font-size: 14px; opacity: .85; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.off { background: #9ca3af; }
.dot.qr { background: var(--amarelo); }
.dot.on { background: #22c55e; }

.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  max-width: 1000px; margin: 24px auto; padding: 0 16px;
}
.card {
  background: #fff; border: 1px solid var(--borda); border-radius: 12px;
  padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card.wide { grid-column: 1 / -1; }
h2 { font-size: 17px; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; color: var(--azul); }
.num {
  background: var(--azul); color: #fff; width: 24px; height: 24px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.muted { color: var(--cinza); font-size: 13px; margin-bottom: 14px; }
.small { font-size: 12px; }
code { background: #eef1f7; padding: 1px 5px; border-radius: 4px; color: var(--azul-claro); font-size: 12px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn {
  border: none; border-radius: 8px; padding: 10px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: .15s;
}
.btn.primary { background: var(--azul); color: #fff; }
.btn.primary:hover { background: var(--azul-claro); }
.btn.ghost { background: #eef1f7; color: var(--azul); }
.btn.danger { background: #fee2e2; color: #b91c1c; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.qrbox {
  display: flex; align-items: center; justify-content: center;
  height: 220px; border: 2px dashed var(--borda); border-radius: 10px; margin-top: 8px;
}
.qrbox img { width: 200px; height: 200px; }
.qrplaceholder { color: var(--cinza); font-size: 13px; text-align: center; padding: 0 20px; }

textarea, input[type=text] {
  width: 100%; border: 1px solid var(--borda); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; margin-top: 6px; resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--amarelo); border-color: transparent; }

.counter { margin-top: 12px; font-size: 14px; }
.progress-wrap { margin-bottom: 8px; }
.progress { background: #e5e7eb; height: 14px; border-radius: 8px; overflow: hidden; }
.bar { background: var(--amarelo); height: 100%; width: 0%; transition: width .3s; }
.stats { display: flex; gap: 22px; margin-top: 10px; font-size: 14px; }

.log {
  margin-top: 14px; background: var(--preto); color: #d1fae5; border-radius: 8px;
  padding: 12px; font-family: 'Courier New', monospace; font-size: 12px;
  height: 120px; overflow-y: auto; white-space: pre-wrap;
}

@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }

/* Instances */
.instances-container { margin-top: 15px; display: flex; flex-direction: column; gap: 10px; }
.wa-instance { display: flex; flex-direction: column; background: #fafafa; border: 1px solid var(--borda); padding: 10px; border-radius: 8px; }
.wa-instance-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.wa-instance-title { font-weight: 600; font-size: 14px; }
.wa-instance-qr { align-self: center; background: white; padding: 5px; border-radius: 5px; border: 1px dashed var(--borda); }
.wa-instance-qr img { max-width: 150px; max-height: 150px; }

/* Templates */
#templatesBox { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Modal Dashboard */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); align-items: center; justify-content: center; }
.modal:not(.hidden) { display: flex; }
.modal-content { background-color: #fff; padding: 25px; border-radius: 12px; width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; position: relative; }
.close-btn { position: absolute; right: 20px; top: 15px; font-size: 24px; cursor: pointer; color: var(--cinza); }
.dash-kpis { display: flex; justify-content: space-around; margin: 20px 0; background: var(--bg); padding: 15px; border-radius: 8px; }
.kpi { font-size: 16px; font-weight: 600; text-align: center; display: flex; flex-direction: column; gap: 5px; }
.kpi span { font-size: 24px; font-weight: 800; }
.kpi.success { color: #16a34a; }
.kpi.danger { color: #dc2626; }
.dash-errors { margin-top: 15px; max-height: 250px; overflow-y: auto; border: 1px solid var(--borda); border-radius: 8px; }
#errorsTable { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
#errorsTable th, #errorsTable td { padding: 10px; border-bottom: 1px solid var(--borda); }
#errorsTable th { background: #f8fafc; position: sticky; top: 0; }

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: #ffffff;
  color: var(--preto);
  border-left: 5px solid var(--azul-claro);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 12px 18px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease-out forwards, fadeOut 0.3s ease-in 3.7s forwards;
}
.toast.error {
  border-left-color: #ef4444;
}
.toast.success {
  border-left-color: #10b981;
}
.toast.warning {
  border-left-color: var(--amarelo);
}
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}
