:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --bg-dark: #0f172a;
  --sidebar-bg: #1e293b;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --purple-light: #ede9fe;
  --success: #10b981;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f1f5f9;
  color: var(--text-main);
  line-height: 1.5;
}

/* Helpers */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-green { color: var(--primary); }
.text-yellow { color: var(--warning); }
.text-red { color: var(--danger); }
.text-purple { color: var(--purple); }
.text-primary { color: var(--info); }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mx-2 { margin-left: 0.5rem; margin-right: 0.5rem; }
.p-3 { padding: 1rem; }

/* Login */
.login-wrapper {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-card {
  background: white;
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-circle {
  width: 64px;
  height: 64px;
  background: var(--primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 1rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.sidebar {
  width: 270px;
  background: var(--sidebar-bg);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 10;
}

.sidebar-brand {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  border-bottom: 1px solid #334155;
}

.sidebar-brand h3 {
  font-size: 1.1rem;
  line-height: 1.2;
}

.sidebar-menu {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.4rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
  border-left: 4px solid transparent;
}

.menu-item > div, .menu-item > span:first-of-type {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-item:hover, .menu-item.active {
  color: #ffffff;
  background: #334155;
  border-left-color: var(--primary);
}

.sidebar-footer {
  padding: 1.25rem;
  border-top: 1px solid #334155;
}

.server-status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 1rem;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 0 rgba(16, 185, 129, 0.4);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.main-content {
  margin-left: 270px;
  flex: 1;
  padding: 2rem;
  min-width: 0;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.topbar-right {
  display: flex;
  gap: 1rem;
}

.status-pill {
  padding: 0.4rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.status-connected { background: var(--primary-light); color: var(--primary-dark); }
.status-disconnected { background: #fee2e2; color: #991b1b; }
.status-qr { background: #fef3c7; color: #92400e; }
.status-running { background: #dbeafe; color: #1e40af; }
.status-idle { background: #f1f5f9; color: #475569; }

/* Tabs */
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.card-body {
  padding: 1.5rem;
}

/* WhatsApp Banner */
.wa-connect-card {
  border-left: 5px solid var(--primary);
  padding: 1.5rem;
}

.wa-connect-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wa-info {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.wa-icon-large {
  width: 52px;
  height: 52px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 2rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box-wrapper {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--border);
}

.qr-inner {
  display: inline-block;
  background: white;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
}

.qr-inner img {
  width: 240px;
  height: 240px;
  display: block;
}

.qr-hint {
  margin-top: 0.5rem;
  font-weight: 500;
  color: var(--text-main);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
}

.stat-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.bg-blue { background: #dbeafe; color: #1e40af; }
.bg-green { background: #d1fae5; color: #065f46; }
.bg-yellow { background: #fef3c7; color: #92400e; }
.bg-red { background: #fee2e2; color: #991b1b; }
.bg-purple { background: #f3e8ff; color: #6b21a8; }
.bg-gray { background: #f1f5f9; color: #475569; }

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th, .table td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
}

.table tr:hover td {
  background: #f8fafc;
}

.pagination-footer {
  padding: 1rem 1.25rem;
  background: #f8fafc;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Forms & Buttons */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .col {
  flex: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: #059669; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: white; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: #f8fafc; }
.btn-outline-danger { background: transparent; border-color: #f87171; color: #f87171; }
.btn-outline-danger:hover { background: var(--danger); color: white; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; align-items: center; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* Dropzone & Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: white;
  width: 90%;
  max-width: 520px;
  border-radius: 16px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-lg { max-width: 720px; }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.upload-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #f8fafc;
}

.upload-dropzone:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone-icon {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.tags-helper {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag-pill {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: #334155;
}

.tag-pill:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.bg-purple-pill {
  background: var(--purple-light);
  color: var(--purple);
  border-color: #c4b5fd;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.anti-ban-rules-strip {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.checkbox-container {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: #f8fafc;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  font-size: 0.9rem;
}

/* ==================== 2-WAY LIVE INBOX ==================== */
.inbox-container {
  display: flex;
  height: calc(100vh - 150px);
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.inbox-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.inbox-search {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
}

.inbox-conv-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.15s;
}

.inbox-conv-item:hover, .inbox-conv-item.active {
  background: #e2e8f0;
}

.conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
  font-size: 1.1rem;
}

.conv-details {
  flex: 1;
  min-width: 0;
}

.conv-details h5 {
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-details p {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
}

.chat-contact-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-messages-stream {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #f8fafc;
}

.chat-bubble {
  max-width: 65%;
  padding: 0.65rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
}

.chat-bubble-in {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-bubble-out {
  align-self: flex-end;
  background: #dcf8c6;
  border-bottom-right-radius: 2px;
}

.bubble-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 0.25rem;
}

.chat-input-bar {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  background: white;
}

/* ==================== CAMPAIGN SCHEDULE CALENDAR ==================== */
.calendar-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f8fafc;
  padding: 0.75rem 0;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.calendar-grid-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border);
  border-top: none;
}

.calendar-cell {
  min-height: 90px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem;
  background: white;
  font-size: 0.85rem;
}

.calendar-cell:nth-child(7n) {
  border-right: none;
}

.calendar-cell.other-month {
  background: #f8fafc;
  color: #cbd5e1;
}

.calendar-cell.today {
  background: #f0fdf4;
}

.calendar-cell-date {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.cal-event-pill {
  background: #dbeafe;
  color: #1e40af;
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  font-size: 0.72rem;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.cal-event-pill.daily {
  background: #fef3c7;
  color: #92400e;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { width: 70px; }
  .sidebar-brand div, .menu-item span, .server-status-pill, .sidebar-footer button span { display: none; }
  .main-content { margin-left: 70px; padding: 1rem; }
  .grid-2col { grid-template-columns: 1fr; }
  .inbox-sidebar { width: 100px; }
  .conv-details { display: none; }
}
