/* ==========================================================
   Nexbot Saude - CRM
   Design clean e clinical, voltado para a area da saude.
   Variaveis sao injetadas em runtime por theme-loader.js
   ========================================================== */

:root {
  --primary:    #2563eb;
  --primary-dk: #1e40af;
  --accent:     #10b981;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --text:       #0f172a;
  --text-soft:  #64748b;
  --border:     #e2e8f0;
  --danger:     #dc2626;
  --warning:    #f59e0b;
  --success:    #16a34a;
  --shadow:     0 1px 3px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.04);
  --radius:     12px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: var(--primary);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
}
button:hover { background: var(--primary-dk); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
button.danger { background: var(--danger); }
button.ghost  { background: transparent; color: var(--text-soft); }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ============== VIEWS (login / app) ============== */
.view { display: none; min-height: 100vh; }
.view.active { display: flex; }

#view-login {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
}

.login-card {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 360px;
  max-width: 90vw;
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; color: var(--primary); }
.login-card .subtitle { color: var(--text-soft); margin-bottom: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .error { color: var(--danger); margin-top: 12px; min-height: 1em; }

/* ============== APP SHELL ============== */
#view-app { display: none; }
#view-app.active { display: flex; }

#sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  flex-shrink: 0;
}

#sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
#sidebar .brand img { width: 32px; height: 32px; border-radius: 6px; object-fit: contain; }
#sidebar .brand img:not([src]), #sidebar .brand img[src=""] { display: none; }
#sidebar .brand span { font-weight: 700; color: var(--primary); font-size: 16px; }

#sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s;
}
.nav-btn:hover { background: var(--bg); }
.nav-btn.active { background: rgba(37,99,235,0.1); color: var(--primary); }

#sidebar .user-info {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}
#sidebar .user-info button { background: transparent; color: var(--text-soft); padding: 6px; font-size: 13px; }
#sidebar .user-info button:hover { color: var(--danger); }

#content { flex: 1; padding: 28px; overflow-y: auto; max-width: 100%; }

.content-view { display: none; }
.content-view.active { display: block; }

.content-view h2 {
  font-size: 22px;
  margin-bottom: 20px;
  color: var(--text);
}

/* ============== TABLE / CARDS ============== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table th, .table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th { background: var(--bg); font-weight: 600; color: var(--text-soft); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-pill.scheduled  { background: #dbeafe; color: #1e40af; }
.status-pill.confirmed  { background: #dcfce7; color: #166534; }
.status-pill.cancelled  { background: #fee2e2; color: #991b1b; }
.status-pill.completed  { background: #e2e8f0; color: #334155; }
.status-pill.no_show    { background: #fef3c7; color: #92400e; }
.status-pill.paid       { background: #dcfce7; color: #166534; }
.status-pill.pending    { background: #fef3c7; color: #92400e; }
.status-pill.failed     { background: #fee2e2; color: #991b1b; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-soft);
}

/* ============== TABS ============== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  background: transparent;
  color: var(--text-soft);
  border-radius: 0;
  padding: 10px 16px;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-weight: 500;
}
.tab:hover { background: transparent; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============== FORM ROW ============== */
.form-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
.form-row label { font-weight: 500; color: var(--text-soft); }
.form-row .actions { grid-column: 2; display: flex; gap: 8px; }

/* ============== TOAST ============== */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 240px;
  font-size: 13px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============== MODAL ============== */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}
#modal-overlay.hidden { display: none; }
#modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
#modal-card h3 { margin-bottom: 16px; }
#modal-body { margin-bottom: 20px; }
#modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ============== CHAT ============== */
.chat-layout { display: grid; grid-template-columns: 280px 1fr 240px; gap: 12px; height: calc(100vh - 120px); }
.chat-list-panel { background: var(--surface); border-radius: var(--radius); overflow-y: auto; display: flex; flex-direction: column; }
.chat-filters { display: flex; gap: 4px; padding: 8px 8px 4px; flex-shrink: 0; }
.filter-pill { background: var(--bg); color: var(--text-soft); padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.filter-pill.active { background: var(--primary); color: #fff; }
.filter-pill:hover:not(.active) { background: var(--border); }
.chat-search-wrap { padding: 4px 8px 6px; flex-shrink: 0; }
.chat-search-wrap input { font-size: 13px; padding: 7px 10px; }
#chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.chat-item { padding: 10px; border-radius: 8px; cursor: pointer; }
.chat-item:hover, .chat-item.active { background: var(--bg); }
.chat-item .name { font-weight: 600; font-size: 13px; }
.chat-item .preview { font-size: 12px; color: var(--text-soft); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chat-conversation { background: var(--surface); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.chat-conv-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.btn-handoff { background: var(--warning); color: #fff; padding: 6px 14px; font-size: 12px; }
.btn-handoff:hover { background: #d97706; }
.chat-messages { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 70%; margin-bottom: 8px; font-size: 13px; word-break: break-word; }
.msg.user { background: var(--bg); align-self: flex-start; }
.msg.assistant { background: var(--primary); color: white; align-self: flex-end; }
.msg .meta { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.chat-detail-panel { background: var(--surface); border-radius: var(--radius); overflow-y: auto; }
.detail-panel { padding: 14px; }
.detail-panel h4 { font-size: 13px; text-transform: uppercase; color: var(--text-soft); letter-spacing: 0.5px; margin-bottom: 12px; }
.detail-row { display: flex; flex-direction: column; margin-bottom: 10px; font-size: 13px; }
.detail-label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; }

/* ============== PILLS ============== */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill-sm { font-size: 11px; padding: 2px 7px; }
.status-confirmed  { background: #dcfce7; color: #166534; }
.status-scheduled  { background: #dbeafe; color: #1e40af; }
.status-handoff    { background: #fef3c7; color: #92400e; }
.status-active-sm  { background: #dcfce7; color: #166534; }

/* ============== USERS ============== */
.users-grid { display: flex; flex-direction: column; gap: 10px; max-width: 680px; }
.user-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; display: flex; align-items: center; gap: 14px; }
.user-card.inactive { opacity: 0.55; }
.user-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-info-block { flex: 1; }
.user-name { font-weight: 600; font-size: 14px; }
.user-email { font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.user-actions { display: flex; gap: 8px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }

/* ============== HORARIO ============== */
.horario-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.horario-row input[type=checkbox] { width: auto; flex-shrink: 0; }
.horario-row input[type=time] { width: 100px; padding: 6px 8px; font-size: 13px; }

.hidden { display: none !important; }

/* ============== REPORTS ============== */
.report-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
}
.report-card-icon  { font-size: 22px; margin-bottom: 6px; }
.report-card-value { font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1; margin-bottom: 4px; }
.report-card-label { font-size: 12px; color: var(--text-soft); }
.report-tables     { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

/* ============== CHAT ENHANCEMENTS ============== */
.chat-conv-title   { font-weight: 600; font-size: 15px; }
.chat-conv-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.btn-bot-toggle {
  background: var(--accent);
  color: #fff;
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
}
.btn-bot-toggle:hover { background: #059669; }
.btn-bot-toggle.bot-paused { background: var(--text-soft); }
.btn-bot-toggle.bot-paused:hover { background: #475569; }

.assign-select {
  padding: 5px 8px;
  font-size: 12px;
  height: 32px;
  width: auto;
}

.assigned-badge {
  font-size: 11px;
  color: var(--text-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

/* ── Detail tabs ── */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  gap: 0;
}
.detail-tab {
  background: transparent;
  color: var(--text-soft);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 0;
  margin-bottom: -1px;
  cursor: pointer;
}
.detail-tab:hover { background: transparent; color: var(--text); }
.detail-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.detail-tab-panel { display: none; }
.detail-tab-panel.active { display: block; }

/* ── Notes ── */
.note-item {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  font-size: 13px;
}
.note-item:last-child { border-bottom: none; }
.note-meta { font-size: 11px; color: var(--text-soft); margin-top: 4px; }
.note-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.note-form textarea { font-size: 13px; resize: vertical; }

/* ── Labels panel ── */
.label-pills-container { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; margin-bottom: 10px; }
.label-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}
.label-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  padding: 0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  font-weight: 700;
}
.label-remove:hover { color: #fff; background: transparent; }

.label-add-row { display: flex; gap: 8px; align-items: center; }
.label-add-row select { flex: 1; font-size: 12px; padding: 6px 8px; height: 34px; }

/* ── Label dots in session list ── */
.label-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Message input bar ── */
.msg-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  align-items: center;
}
.msg-input-bar select {
  width: auto;
  flex-shrink: 0;
  font-size: 12px;
  padding: 7px 8px;
  height: 36px;
  min-width: 0;
  max-width: 120px;
}
.msg-input-bar input {
  flex: 1;
  font-size: 13px;
  padding: 7px 10px;
  height: 36px;
}
.msg-input-bar button {
  padding: 7px 14px;
  font-size: 13px;
  height: 36px;
  flex-shrink: 0;
}

/* ── Settings: Labels tab ── */
.label-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.label-manage-row:last-child { border-bottom: none; }
.label-manage-name { flex: 1; font-size: 13px; font-weight: 500; }
.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

/* ── Settings: Templates tab ── */
.template-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.template-row:last-child { border-bottom: none; }
.template-row-info { flex: 1; }

/* ============== CAMPAIGNS ============== */
.campaign-labels-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}
.campaign-label-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  user-select: none;
}
.campaign-label-option input[type=checkbox] { width: auto; }
.campaign-label-option:hover { background: var(--bg); }

.campaign-preview {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
}
.campaign-preview span { font-size: 22px; font-weight: 700; }

/* ============== PILL STATUS (reports) ============== */
.status-completed { background: #e2e8f0; color: #334155; }

/* ============== MEDIA MESSAGES ============== */
.msg-media-img {
  max-width: 260px;
  max-height: 220px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
  margin-top: 4px;
}
.msg-audio {
  max-width: 260px;
  display: block;
  margin-top: 4px;
  border-radius: 8px;
}
.msg-media-video {
  max-width: 260px;
  max-height: 180px;
  border-radius: 10px;
  display: block;
  margin-top: 4px;
}
.msg-doc-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 4px;
}

/* ============== REPORTS CHARTS ============== */
.report-charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

/* ============== SEQUENCES ============== */
.seq-card { margin-bottom: 16px; }
.seq-steps-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.seq-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
}
.seq-step-num {
  font-weight: 700;
  color: var(--primary);
  min-width: 18px;
}
.seq-step-delay {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}
.seq-step-msg {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seq-step-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
