/* ═══════════════════════════════════════════════════════════
   PAINEL AGENTE IA — Design System (padrão Grupo Lopes CRM)
   Azul corporativo #1E40AF / accent verde #16A34A · tema claro+escuro
   Compartilhado entre painel-agente.html e admin.html
   ═══════════════════════════════════════════════════════════ */

:root {
  --primary:        #1E40AF;
  --primary-hover:  #1D3A9F;
  --primary-light:  #EFF6FF;
  --accent:         #16A34A;
  --accent-hover:   #15803D;
  --accent-light:   #F0FDF4;

  --bg:             #F1F5F9;
  --surface:        #FFFFFF;
  --surface-2:      #F8FAFC;
  --border:         #E2E8F0;
  --border-strong:  #CBD5E1;

  --text:           #0F172A;
  --text-2:         #475569;
  --text-muted:     #94A3B8;

  --sidebar-bg:     #0F172A;
  --sidebar-text:   #CBD5E1;
  --sidebar-hover:  #1E293B;
  --sidebar-active: #1E40AF;
  --sidebar-label:  #64748B;

  --red:    #DC2626;
  --red-light: #FEF2F2;
  --orange: #D97706;
  --orange-light: #FFFBEB;
  --green:  #16A34A;
  --green-light: #F0FDF4;
  --blue:   #2563EB;
  --blue-light: #EFF6FF;
  --purple: #7C3AED;
  --purple-light: #F5F3FF;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);

  --sidebar-w:          240px;
  --sidebar-collapsed-w: 72px;
  --topbar-h:           60px;
  --transition: 200ms ease;
}

[data-theme="dark"] {
  --bg:          #0A0F1C;
  --surface:     #111827;
  --surface-2:   #1F2937;
  --border:      #1F2937;
  --border-strong: #374151;
  --text:        #F1F5F9;
  --text-2:      #94A3B8;
  --text-muted:  #64748B;
  --sidebar-bg:  #060B14;
  --sidebar-hover: #111827;
  --primary-light: #1e293b;
  --accent-light: #14241a;
  --green-light: #14241a;
  --blue-light: #16233b;
  --orange-light: #2a2113;
  --red-light: #2a1717;
  --purple-light: #1f1a30;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

/* ═══════════════════════ SIDEBAR ═══════════════════════ */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  transition: width var(--transition), min-width var(--transition);
  overflow: hidden; position: relative; z-index: 100;
}
#sidebar.collapsed { width: var(--sidebar-collapsed-w); min-width: var(--sidebar-collapsed-w); }
#sidebar.collapsed .sidebar-header { padding: 20px 8px 16px; justify-content: center; }
#sidebar.collapsed .brand { display: none; }
#sidebar.collapsed #btn-sidebar-collapse { margin: 0 auto; }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.brand-icon {
  width: 36px; height: 36px; min-width: 36px;
  background: var(--primary); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.brand-text { overflow: hidden; }
.brand-name { display: block; color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { display: block; color: var(--sidebar-label); font-size: 11px; white-space: nowrap; }
#btn-sidebar-collapse {
  background: none; border: none; cursor: pointer; color: var(--sidebar-label);
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: var(--transition); flex-shrink: 0;
}
#btn-sidebar-collapse:hover { background: var(--sidebar-hover); color: #fff; }
#btn-sidebar-collapse svg { width: 16px; height: 16px; transition: transform var(--transition); }
#sidebar.collapsed #btn-sidebar-collapse svg { transform: rotate(180deg); }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; overflow-x: hidden; }
.nav-group { margin-bottom: 20px; }
.nav-label {
  display: block; color: var(--sidebar-label); font-size: 10px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; padding: 0 8px 6px;
  white-space: nowrap; overflow: hidden; transition: opacity var(--transition);
}
#sidebar.collapsed .nav-label { opacity: 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--radius); color: var(--sidebar-text); text-decoration: none;
  font-size: 13.5px; font-weight: 500; transition: var(--transition);
  white-space: nowrap; position: relative; cursor: pointer; margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item span:not(.nav-badge) { overflow: hidden; text-overflow: ellipsis; transition: var(--transition); }
#sidebar.collapsed .nav-item span:not(.nav-badge) { opacity: 0; width: 0; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 99px; min-width: 18px; text-align: center; flex-shrink: 0;
}
.nav-badge[data-count="0"] { display: none; }
#sidebar.collapsed .nav-badge { opacity: 0; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-footer button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  background: none; border: none; color: var(--sidebar-text); cursor: pointer;
  border-radius: var(--radius); font-size: 13px; font-weight: 500; transition: var(--transition);
  white-space: nowrap; overflow: hidden;
}
.sidebar-footer button:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-footer svg { width: 18px; height: 18px; flex-shrink: 0; }
#sidebar.collapsed .sidebar-footer span { opacity: 0; width: 0; }

/* ═══════════════════════ MAIN ═══════════════════════ */
#main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
#page-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.search-box {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; width: 300px;
  transition: var(--transition);
}
.search-box:focus-within { border-color: var(--primary); background: var(--surface); }
.search-box svg { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.search-box input { flex: 1; border: none; outline: none; background: transparent; font-size: 13px; color: var(--text); }
.badge-live { display: flex; align-items: center; gap: 6px; background: var(--green-light); color: var(--accent); font-size: 11px; font-weight: 600; padding: 5px 10px; border-radius: 20px; }
.badge-live .dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-2); transition: var(--transition); }
.icon-btn:hover { background: var(--surface-2); color: var(--primary); }
.icon-btn svg { width: 16px; height: 16px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

#content { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ═══════════════════════ BUTTONS ═══════════════════════ */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px;
  border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--red-light); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: #FEE2E2; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-primary svg, .btn-secondary svg, .btn-danger svg { width: 15px; height: 15px; }

/* ═══════════════════════ CARDS ═══════════════════════ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h2 { font-size: 14px; font-weight: 700; color: var(--text); }
.card-body { padding: 20px; }

/* ═══════════════════════ STAT CARDS ═══════════════════════ */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); transition: var(--transition); }
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--blue-light); color: var(--blue); }
.stat-icon.green { background: var(--green-light); color: var(--green); }
.stat-icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-icon.red { background: var(--red-light); color: var(--red); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

/* ═══════════════════════ FORMS ═══════════════════════ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.form-group input, .form-group select, .form-group textarea {
  padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  font-size: 13px; color: var(--text); background: var(--surface); outline: none;
  transition: var(--transition); font-family: inherit; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-group textarea { resize: vertical; }
.form-group small { font-size: 11px; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ═══════════════════════ TOGGLE ═══════════════════════ */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border-strong); border-radius: 24px; transition: var(--transition); }
.toggle-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: var(--transition); }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ═══════════════════════ STATUS BADGE ═══════════════════════ */
.status-badge { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; background: var(--surface-2); color: var(--text-muted); }
.status-badge.connected { background: var(--green-light); color: var(--accent); }
.status-badge.disconnected { background: var(--red-light); color: var(--red); }
.status-badge.checking { background: var(--orange-light); color: var(--orange); }

/* ═══════════════════════ MODAL ═══════════════════════ */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px); z-index: 200; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity var(--transition); }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 480px; max-height: 86vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); transform: scale(.96); transition: transform var(--transition); }
.modal-overlay.open .modal { transform: scale(1); }
.modal-lg { width: 760px; }
.modal-sm { width: 380px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close { width: 30px; height: 30px; border: none; background: var(--surface-2); border-radius: 7px; cursor: pointer; font-size: 18px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ═══════════════════════ TOAST ═══════════════════════ */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--sidebar-bg); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .25s ease; border-left: 3px solid var(--accent); }
.toast.error { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ═══════════════════════ EMPTY ═══════════════════════ */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 42px; height: 42px; margin: 0 auto 12px; opacity: .35; }
.empty-state p { font-size: 13px; }
.empty-state-small { text-align: center; padding: 24px; color: var(--text-muted); font-size: 13px; }

/* utils */
.text-muted { color: var(--text-muted); }
.mt-12 { margin-top: 12px; }
.hidden { display: none !important; }
