/* =============================================
   MULTI-CHANNEL AI CHATBOT - Admin Dashboard
   Premium Dark Theme with Glassmorphism
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ━━━ CSS Variables ━━━ */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(255, 255, 255, 0.08);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(99, 102, 241, 0.5);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-dim: #475569;

  --accent-indigo: #6366f1;
  --accent-indigo-hover: #818cf8;
  --accent-indigo-glow: rgba(99, 102, 241, 0.15);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.15);
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.15);
  --accent-rose: #f43f5e;
  --accent-rose-glow: rgba(244, 63, 94, 0.15);
  --accent-sky: #0ea5e9;
  --accent-sky-glow: rgba(14, 165, 233, 0.15);
  --accent-violet: #8b5cf6;

  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-success: linear-gradient(135deg, #10b981, #06b6d4);
  --gradient-warning: linear-gradient(135deg, #f59e0b, #f97316);
  --gradient-danger: linear-gradient(135deg, #f43f5e, #e11d48);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ━━━ Reset & Base ━━━ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

/* Animated background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 20% 20%, rgba(99, 102, 241, 0.06), transparent),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(139, 92, 246, 0.04), transparent),
    radial-gradient(ellipse 50% 50% at 50% 50%, rgba(16, 185, 129, 0.02), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ━━━ Layout ━━━ */
.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ━━━ Sidebar ━━━ */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.sidebar-logo .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--gradient-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.sidebar-logo .logo-text {
  display: flex;
  flex-direction: column;
}

.sidebar-logo .logo-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-logo .logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-indigo-glow);
  color: var(--accent-indigo-hover);
  border-color: rgba(99, 102, 241, 0.15);
}

.nav-item .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

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

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border-subtle);
}

.server-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* ━━━ Main Content ━━━ */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 28px 32px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ━━━ Page Sections ━━━ */
.page-section {
  display: none;
}

.page-section.active {
  display: block;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ━━━ Stats Cards ━━━ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  backdrop-filter: blur(12px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
}

.stat-card.indigo::before {
  background: var(--gradient-primary);
}

.stat-card.emerald::before {
  background: var(--gradient-success);
}

.stat-card.amber::before {
  background: var(--gradient-warning);
}

.stat-card.rose::before {
  background: var(--gradient-danger);
}

.stat-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
}

.stat-card.indigo .stat-icon {
  background: var(--accent-indigo-glow);
}

.stat-card.emerald .stat-icon {
  background: var(--accent-emerald-glow);
}

.stat-card.amber .stat-icon {
  background: var(--accent-amber-glow);
}

.stat-card.rose .stat-icon {
  background: var(--accent-rose-glow);
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 4px;
}

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

/* ━━━ Cards ━━━ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  overflow: hidden;
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-light);
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-body {
  padding: 22px;
}

/* ━━━ Settings Form ━━━ */
.settings-grid {
  display: grid;
  gap: 20px;
}

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
}

.settings-section:hover {
  border-color: var(--border-light);
}

.settings-section-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 14px;
}

.settings-section-header .section-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.settings-section-header .section-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.settings-section-header .section-info p {
  font-size: 12px;
  color: var(--text-muted);
}

.settings-section-body {
  padding: 20px 22px;
  display: grid;
  gap: 16px;
}

/* Form Elements */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-group label .required {
  color: var(--accent-rose);
  font-size: 11px;
}

.form-group .help-text {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.form-group .help-text a {
  color: var(--accent-indigo-hover);
  text-decoration: none;
}

.form-group .help-text a:hover {
  text-decoration: underline;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input,
.input-wrapper select,
.input-wrapper textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  transition: var(--transition);
  outline: none;
}

.input-wrapper input:focus,
.input-wrapper select:focus,
.input-wrapper textarea:focus {
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.input-wrapper select option,
select option {
  background: var(--bg-secondary, #1e1e2e);
  color: var(--text-primary, #e0e0e0);
  padding: 8px 12px;
}

.input-wrapper input::placeholder {
  color: var(--text-dim);
}

.input-wrapper .input-icon {
  position: absolute;
  right: 10px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  padding: 4px;
}

.input-wrapper .input-icon:hover {
  color: var(--text-primary);
}

.input-wrapper input[type="password"] {
  padding-right: 40px;
  font-family: monospace;
}

.input-wrapper input[type="text"].mono {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  letter-spacing: 0.5px;
}

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

/* ━━━ Buttons ━━━ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  outline: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-success {
  background: var(--gradient-success);
  color: white;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.btn-outline:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn-danger {
  background: var(--gradient-danger);
  color: white;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12.5px;
}

.btn-lg {
  padding: 13px 28px;
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-group {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* ━━━ Toast Notifications ━━━ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 420px;
  animation: slideIn 0.35s ease;
  backdrop-filter: blur(16px);
}

.toast.success {
  border-left: 3px solid var(--accent-emerald);
}

.toast.error {
  border-left: 3px solid var(--accent-rose);
}

.toast.warning {
  border-left: 3px solid var(--accent-amber);
}

.toast.info {
  border-left: 3px solid var(--accent-sky);
}

.toast .toast-icon {
  font-size: 20px;
}

.toast .toast-message {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.4;
}

.toast .toast-close {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  padding: 2px;
  transition: var(--transition);
}

.toast .toast-close:hover {
  color: var(--text-primary);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }

  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ━━━ Status Badges ━━━ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-success {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
}

.badge-warning {
  background: var(--accent-amber-glow);
  color: var(--accent-amber);
}

.badge-danger {
  background: var(--accent-rose-glow);
  color: var(--accent-rose);
}

.badge-info {
  background: var(--accent-sky-glow);
  color: var(--accent-sky);
}

/* ━━━ Test Chat ━━━ */
.chat-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  height: calc(100vh - 180px);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 10px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.5;
  animation: bubbleIn 0.3s ease;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(5px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--gradient-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  align-self: flex-start;
  background: var(--bg-glass-hover);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

.chat-bubble .bubble-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

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

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  outline: none;
  transition: var(--transition);
}

.chat-input-area input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.chat-platform-selector {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.platform-tab {
  padding: 6px 16px;
  border-radius: 100px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.platform-tab:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

.platform-tab.active {
  background: var(--accent-indigo-glow);
  color: var(--accent-indigo-hover);
  border-color: rgba(99, 102, 241, 0.2);
}

/* ━━━ Conversations Table ━━━ */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.data-table tr:hover td {
  background: var(--bg-glass);
}

.data-table .platform-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ━━━ Config Status Indicator ━━━ */
.config-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.config-status.configured {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
}

.config-status.not-configured {
  background: var(--accent-amber-glow);
  color: var(--accent-amber);
}

/* ━━━ Loading Spinner ━━━ */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ━━━ Responsive ━━━ */
@media (max-width: 1024px) {
  .sidebar {
    width: 70px;
  }

  .sidebar .logo-text,
  .sidebar .nav-label,
  .sidebar .nav-section-title,
  .sidebar .server-status span {
    display: none;
  }

  .sidebar-header {
    padding: 16px 12px;
  }

  .sidebar-nav {
    padding: 12px 8px;
  }

  .nav-item {
    justify-content: center;
    padding: 11px;
  }

  .main-content {
    margin-left: 70px;
  }

  .chat-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main-content {
    padding: 16px;
  }

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

/* ━━━ Typing indicator ━━━ */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}