/* =============================================
   WhatsBot Pro — Design System v3.1
   ============================================= */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2233;
  --bg-card-hover: #1f2937;
  --bg-input: #0f1724;
  --border: #2a3548;
  --border-focus: #6366f1;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.15);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.15);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.15);
  --purple: #a855f7;
  --orange: #f97316;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.2s ease;
  --font: 'Inter', -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a0e17 0%, #1a1040 50%, #0a0e17 100%);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo i {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 12px;
  display: block;
}
.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.error-text { color: var(--red); font-size: 13px; margin-top: 12px; text-align: center; }

/* ---- Forms ---- */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="time"],
input[type="url"],
input[type="search"],
input:not([type]),
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea { min-height: 100px; resize: vertical; }

/* Form row helper */
.form-row {
  display: flex;
  gap: 16px;
}
.form-row .form-group { flex: 1; }

/* ---- Toggle Switch (replaces ugly checkboxes) ---- */
.toggle-field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.toggle-field .toggle-label {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.toggle-field .toggle-sublabel {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-switch .toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: var(--transition);
}
.toggle-switch .toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: white;
}
.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,0.05); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 14px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

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

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  z-index: 100;
}
.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}
.sidebar-header i { font-size: 24px; }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

/* Sidebar section divider */
.sidebar-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 16px 16px 6px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  position: relative;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: white; box-shadow: 0 4px 16px var(--accent-glow); }
.nav-item i { width: 20px; text-align: center; font-size: 16px; }
.nav-item .badge {
  position: absolute;
  right: 12px;
  background: var(--red);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }

/* ---- Topbar ---- */
.topbar {
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}
.topbar h2 { font-size: 18px; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.user-name { font-size: 14px; color: var(--text-secondary); }
.menu-toggle { display: none; background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; }

/* ---- Content ---- */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.content-area { flex: 1; padding: 24px; overflow-y: auto; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: var(--transition);
}
.card:hover { border-color: rgba(99,102,241,0.3); }
.card + .card { margin-top: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Section header inside settings/messages pages */
.section-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.section-icon.green  { background: var(--green-bg);  color: var(--green); }
.section-icon.blue   { background: var(--blue-bg);   color: var(--blue); }
.section-icon.purple { background: rgba(168,85,247,0.15); color: var(--purple); }
.section-icon.yellow { background: var(--yellow-bg);  color: var(--yellow); }
.section-icon.orange { background: rgba(249,115,22,0.15); color: var(--orange); }
.section-icon.red    { background: var(--red-bg);     color: var(--red); }

/* ---- Stat Cards ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.blue { background: var(--blue-bg); color: var(--blue); }
.stat-icon.yellow { background: var(--yellow-bg); color: var(--yellow); }
.stat-icon.red { background: var(--red-bg); color: var(--red); }
.stat-icon.purple { background: rgba(168,85,247,0.15); color: var(--purple); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: var(--bg-card-hover); }

/* Action column fix — ensures buttons stay on one line and don't get cut off */
td .actions-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

/* ---- Tags/Badges ---- */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-yellow { background: var(--yellow-bg); color: var(--yellow); }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tag-purple { background: rgba(168,85,247,0.15); color: var(--purple); }

/* ---- Chat ---- */
.chat-layout { display: flex; height: calc(100vh - 112px); gap: 0; margin: -24px; }
.chat-list {
  width: 340px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}
.chat-list-header { padding: 16px; border-bottom: 1px solid var(--border); }
.chat-list-header input { width: 100%; }
.chat-list-items { flex: 1; overflow-y: auto; }
.chat-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.chat-item:hover { background: var(--bg-card); }
.chat-item.active { background: var(--bg-card); border-left: 3px solid var(--accent); }
.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 14px; }
.chat-item-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-meta { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; }

.chat-panel { flex: 1; display: flex; flex-direction: column; }
.chat-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
}
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.incoming {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.chat-msg.outgoing {
  align-self: flex-end;
  background: var(--accent);
  color: white;
}
.chat-msg .msg-time { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 4px; }
.chat-msg.incoming .msg-time { color: var(--text-muted); }
.chat-msg .msg-sender { font-size: 11px; font-weight: 600; margin-bottom: 2px; }
.chat-msg.outgoing .msg-sender { color: rgba(255,255,255,0.8); }

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  background: var(--bg-secondary);
}
.chat-input-area input { flex: 1; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 16px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { opacity: 1; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modalSlideIn 0.25s ease;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h2 { font-size: 20px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ---- Toolbar ---- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }

/* ---- Empty State ---- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 16px; }

/* ---- Toast ---- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast-success { background: var(--green); color: white; }
.toast-error { background: var(--red); color: white; }
.toast-info { background: var(--blue); color: white; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- Page Header (for pages with description) ---- */
.page-header {
  margin-bottom: 24px;
}
.page-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* ---- Messages Page Cards ---- */
.msg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  transition: var(--transition);
}
.msg-card:hover { border-color: rgba(99,102,241,0.3); }
.msg-card + .msg-card { margin-top: 12px; }
.msg-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.msg-card .msg-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -260px; height: 100vh; z-index: 200; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .chat-layout { flex-direction: column; }
  .chat-list { width: 100%; height: 300px; }
  .form-row { flex-direction: column; gap: 0; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Animations ---- */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Mode Tags ---- */
.mode-bot { background: var(--blue-bg); color: var(--blue); }
.mode-ai { background: rgba(168,85,247,0.15); color: var(--purple); }
.mode-manual { background: var(--yellow-bg); color: var(--yellow); }
.mode-paused { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.mode-closed { background: var(--red-bg); color: var(--red); }
.mode-external { background: rgba(249,115,22,0.15); color: var(--orange); }

/* ---- Days Selector (for business hours) ---- */
.days-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.day-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.day-btn:hover { border-color: var(--accent); color: var(--accent); }
.day-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* ---- Divider ---- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ---- Chart ---- */
#chart-area {
  position: relative;
}

/* ---- Code inline ---- */
code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ---- Connection indicator pulse ---- */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.card [style*="border-radius:50%"][style*="box-shadow"] {
  animation: pulse-dot 2s infinite;
}

