:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-text: #e2e8f0;
  --primary: #16a34a;
  --primary-hover: #15803d;
  --secondary: #e2e8f0;
  --danger: #dc2626;
  --warning: #d97706;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: #94a3b8; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item {
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: left;
  padding: 11px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.sidebar-status {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 14px;
  font-size: 12px;
}
.status-pill { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #ef4444; }
.status-pill.connected .dot { background: #22c55e; }
.status-pill.qr_required .dot { background: #f59e0b; }
.status-meta { color: #94a3b8; }

.main-content {
  flex: 1;
  padding: 28px;
  min-width: 0;
}

.wa-mirror-pane {
  width: 440px;
  min-width: 280px;
  max-width: 900px;
  position: relative;
  background: #0f172a;
  color: #e2e8f0;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.mirror-resizer {
  position: absolute;
  left: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 20;
}
.mirror-resizer:hover {
  background: rgba(22, 163, 74, 0.5);
}
.mirror-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
  font-size: 14px;
}
.mirror-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  background: #111b21;
}
#wa-mirror-img {
  width: 145%;
  max-width: none;
  margin-left: -45%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  cursor: pointer;
}
@media (max-width: 1200px) {
  .wa-mirror-pane { width: 100%; height: 420px; }
}

.view { display: none; }
.view.active { display: block; }
.view-header { margin-bottom: 22px; }
.view-header h1 { margin: 0 0 6px; font-size: 24px; }
.view-header p { margin: 0; color: var(--muted); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 18px; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
input[type="text"], input[type="datetime-local"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--text); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: #0284c7; color: #fff; }

.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; }
.toolbar.wrap { flex-wrap: wrap; }

.groups-checklist {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.group-check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-bottom: 1px solid #f1f5f9;
}
.group-check-item:last-child { border-bottom: none; }

.image-preview { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.image-preview img { max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--border); }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
}
.badge.sent { background: #dcfce7; color: #166534; }
.badge.error { background: #fee2e2; color: #991b1b; }
.badge.review { background: #fef3c7; color: #92400e; }
.badge.ready { background: #dbeafe; color: #1e40af; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}
.stat-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.stat-label { display: block; font-size: 12px; color: var(--muted); }
.stat-box strong { font-size: 22px; }

.progress-wrap { height: 12px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.progress-bar { height: 100%; background: var(--primary); transition: width 0.3s; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal-box {
  background: #fff;
  padding: 24px;
  border-radius: 12px;
  width: 92%;
  max-width: 480px;
}

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }
