/* ═══════════════════════════════════════════════════════════════
   Mr RobotyBR — Supabase-Inspired Light Design System
   ═══════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --bg-body: #f8f9fa;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #fafbfc;
  --bg-input: #f1f3f5;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-light: #eff6ff;
  --accent-glow: rgba(59,130,246,0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --sidebar-text: #64748b;
  --sidebar-active: #2563eb;
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.main-content {
  margin-left: 260px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 { font-size: 15px; font-weight: 600; }

.page-content {
  padding: 24px;
  flex: 1;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Sidebar ─────────────────────────────── */
.sidebar-brand {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: -0.3px;
}

.sidebar-brand .brand-sub {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 2px;
}

.sidebar-loja {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-loja label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  display: block;
}

.sidebar-loja select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.sidebar-loja select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }

.nav-section { padding: 0 14px; margin-bottom: 2px; }

.nav-section-title {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 14px 6px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover { background: var(--accent-light); color: var(--accent-dark); }

.nav-item.active {
  background: var(--accent-light);
  color: var(--sidebar-active);
  font-weight: 600;
}

.nav-item .icon { 
  width: 16px; 
  height: 16px; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  opacity: 0.75;
}
.nav-item .icon svg { width: 100%; height: 100%; }
.nav-item:hover .icon { opacity: 1; }
.nav-item.active .icon { opacity: 1; }

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

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.4); }

/* ── Stats Cards ─────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  position: relative;
}

.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
  color: var(--text-primary);
}

.stat-card .stat-icon {
  position: absolute;
  top: 16px; right: 18px;
  font-size: 22px;
  opacity: 0.5;
}

/* ── Card ─────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title { font-size: 14px; font-weight: 600; }

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }

.btn-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Inputs ─────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: all var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
}

/* ── Tables ─────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

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

td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:hover td { background: #f8fafc; }

/* ── Badge ─────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #ecfdf5; color: #059669; }
.badge-warning { background: #fffbeb; color: #d97706; }
.badge-danger  { background: #fef2f2; color: #dc2626; }
.badge-info    { background: #eff6ff; color: #2563eb; }

/* ── Toggle ─────────────────────────────── */
.toggle { position: relative; width: 40px; height: 22px; cursor: pointer; }
.toggle input { display: none; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #e2e8f0;
  border-radius: 22px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Chat ────────────────────────────────── */
.chat-container { display: flex; height: calc(100vh - 140px); }

.chat-contacts {
  width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.chat-messages { flex: 1; display: flex; flex-direction: column; }
.chat-messages-body { flex: 1; overflow-y: auto; padding: 16px; background: #f8fafc; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.contact-item:hover, .contact-item.active { background: var(--accent-light); }

.contact-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 13px; font-weight: 600; }
.contact-last { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.message-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-user {
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.message-assistant {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
  margin-left: auto;
}

.message-time { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* ── WhatsApp ────────────────────────────── */
.wa-status-card { text-align: center; padding: 36px; }
.wa-status-icon { font-size: 56px; margin-bottom: 12px; }

.pairing-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--accent-dark);
  background: var(--accent-light);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  padding: 20px 28px;
  display: inline-block;
  margin: 12px 0;
}

/* ── Modal ─────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

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

.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

/* ── Range ─────────────────────────────── */
.range-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent-dark);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  margin-top: 6px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ── RAG / Upload ────────────────────────── */
.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: all var(--transition);
}

.doc-item:hover { background: #f8fafc; }
.doc-icon { font-size: 18px; margin-right: 10px; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
}

.upload-zone:hover { border-color: var(--accent); background: var(--accent-light); }

/* ── Empty State ─────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }
.empty-state p { font-size: 14px; }

/* ── Spinner ─────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 0.25s ease;
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
}

.toast-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #059669; }
.toast-error { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Mobile ─────────────────────────────── */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .chat-container { flex-direction: column; height: auto; }
  .chat-contacts { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
  .page-content { padding: 14px; }
}

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

/* ── Scrollbar ─────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }