/* ============================================
   DESIGN TOKENS & CUSTOM PROPERTIES
   ============================================ */

:root {
  --primary: #6366F1;
  --primary-dark: #4F46E5;
  --primary-light: #EEF2FF;
  --sidebar-bg: #0F172A;
  --sidebar-hover: #1E293B;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --transition: 0.15s ease-in-out;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */

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

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
}

/* ============================================
   LAYOUT
   ============================================ */

.page-layout {
  display: flex;
  min-height: 100vh;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: white;
  padding: 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 16px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.logo-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin: 4px 0;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: all var(--transition);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: white;
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 18px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.logout-btn {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

/* ============================================
   HEADINGS & TEXT
   ============================================ */

h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* ============================================
   FORMS & INPUTS
   ============================================ */

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  transition: all var(--transition);
}

input[type="text"]::placeholder,
input[type="email"]::placeholder,
input[type="password"]::placeholder,
input[type="number"]::placeholder,
input[type="search"]::placeholder,
textarea::placeholder {
  color: var(--text-secondary);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.search-box {
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  padding: 10px 14px;
}

/* ============================================
   BUTTONS
   ============================================ */

button,
.btn {
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
.btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

button:active,
.btn:active {
  transform: translateY(0);
}

button.secondary {
  background: var(--text-secondary);
  color: white;
}

button.secondary:hover {
  background: #475569;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #DC2626;
}

button.success {
  background: var(--success);
}

button.success:hover {
  background: #059669;
}

.btn-link {
  background: none;
  color: var(--primary);
  padding: 0;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition);
  display: inline;
}

.btn-link:hover {
  color: var(--primary-dark);
  transform: none;
  box-shadow: none;
}

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: all var(--transition);
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  margin: 0;
}

/* ============================================
   STATS & KPI CARDS
   ============================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
  transition: all var(--transition);
}

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

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.stat-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 8px;
}

.stat-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

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

/* ============================================
   TABLES
   ============================================ */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  overflow: hidden;
}

th {
  background: var(--bg);
  padding: 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tr:hover {
  background: var(--bg);
}

/* ============================================
   MODALS
   ============================================ */

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ============================================
   MESSAGES & ALERTS
   ============================================ */

.message {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.message.success {
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.message.error {
  background: #FEE2E2;
  color: #7F1D1D;
  border: 1px solid #FECACA;
}

.message.info {
  background: #DBEAFE;
  color: #0C2340;
  border: 1px solid #93C5FD;
}

.message.warning {
  background: #FEF3C7;
  color: #78350F;
  border: 1px solid #FDE68A;
}

/* ============================================
   TOGGLE SWITCH
   ============================================ */

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #CBD5E1;
  border-radius: 24px;
  transition: 0.3s;
}

.slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
  background: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* ============================================
   BOT TOGGLE GROUP
   ============================================ */

.bot-toggle-group {
  display: flex;
  gap: 16px;
  align-items: center;
}

.bot-toggle-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.bot-toggle-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ============================================
   CONVERSATIONS & CHAT
   ============================================ */

.conversas-layout {
  display: flex;
  gap: 20px;
  height: calc(100vh - 180px);
}

.conversas-panel {
  width: 340px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conversas-panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.conversas-panel-header h2 {
  margin: 0 0 12px 0;
  font-size: 20px;
}

.conversas-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

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

.conversa-item:hover {
  background: var(--bg);
}

.conversa-item.active {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}

.conversa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.conversa-info {
  flex: 1;
  min-width: 0;
}

.conversa-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.conversa-nome {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.conversa-hora {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.conversa-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.chat-window {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-header-actions {
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-info h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.chat-header-info small {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 2px;
}

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

.no-conversa-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
}

.no-conversa-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.no-conversa-state h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

.no-conversa-state p {
  font-size: 14px;
  max-width: 300px;
}

.message-wrapper {
  display: flex;
  margin-bottom: 8px;
}

.message-wrapper.sent {
  justify-content: flex-end;
}

.message-wrapper.received {
  justify-content: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  max-width: 70%;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
}

.message-wrapper.sent .message-bubble {
  background: var(--primary);
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.message-wrapper.received .message-bubble {
  background: white;
  color: var(--text-primary);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
}

.message-wrapper.sent .message-time {
  color: rgba(255, 255, 255, 0.8);
  text-align: right;
}

.message-wrapper.received .message-time {
  color: var(--text-secondary);
}

.chat-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  background: var(--surface);
}

.chat-input-area input {
  flex: 1;
  border-radius: 24px;
  padding: 10px 16px;
  border: 1px solid var(--border);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
  padding: 0;
}

.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5);
}

.send-btn:active {
  transform: scale(0.94);
  box-shadow: none;
}

/* ============================================
   PAGINATION
   ============================================ */

.pagination {
  display: flex;
  gap: 6px;
  margin-top: 24px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
}

.page-btn {
  padding: 8px 12px;
  min-width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
}

.page-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.page-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ============================================
   UTILITIES & MISC
   ============================================ */

.container {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 600px;
  margin: 0 auto;
}

.loader {
  border: 3px solid var(--bg);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.status.online {
  background: var(--success);
}

.status.offline {
  background: var(--danger);
}

.status.loading {
  background: var(--warning);
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.success {
  background: #DCFCE7;
  color: #166534;
}

.badge.danger {
  background: #FEE2E2;
  color: #991B1B;
}

.badge.warning {
  background: #FEF3C7;
  color: #92400E;
}

.badge.info {
  background: #DBEAFE;
  color: #0C2340;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .page-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .sidebar-logo {
    padding: 16px 20px;
    border-bottom: none;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .sidebar-nav {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    padding: 12px;
    gap: 4px;
  }

  .nav-item {
    flex: 1;
    min-width: 120px;
    margin: 0;
    padding: 8px 12px;
    font-size: 13px;
  }

  .nav-label {
    display: none;
  }

  .sidebar-footer {
    padding: 12px;
    border-top: none;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
  }

  .logout-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .main-content {
    padding: 20px;
  }

  .conversas-layout {
    flex-direction: column;
    gap: 12px;
    height: auto;
  }

  .conversas-panel {
    width: 100%;
    max-height: 300px;
  }

  .chat-window {
    height: calc(100vh - 450px);
    min-height: 300px;
  }

  .message-bubble {
    max-width: 85%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  .page-subtitle {
    font-size: 13px;
  }
}
