/* ============================================================
   WA Disparador - Design overhaul
   Loaded last to unify the existing interface without touching app logic.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg2: #111827;
  --bg3: #172033;
  --bg4: #202b3f;
  --surface: #121a28;
  --surface-2: #182235;
  --surface-3: #202c42;
  --border: rgba(148, 163, 184, 0.16);
  --border2: rgba(148, 163, 184, 0.26);
  --text: #f8fafc;
  --text2: #b6c2d3;
  --text3: #7c8da5;
  --accent: #14b8a6;
  --accent-dim: rgba(20, 184, 166, 0.14);
  --accent-glow: 0 12px 32px rgba(20, 184, 166, 0.18);
  --primary: #14b8a6;
  --purple: #8b5cf6;
  --green: #22c55e;
  --green-wa: #25d366;
  --blue: #38bdf8;
  --red: #f43f5e;
  --amber: #f59e0b;
  --indigo: #818cf8;
  --teal: #14b8a6;
  --green-dim: rgba(34, 197, 94, 0.14);
  --blue-dim: rgba(56, 189, 248, 0.14);
  --red-dim: rgba(244, 63, 94, 0.12);
  --amber-dim: rgba(245, 158, 11, 0.13);
  --purple-dim: rgba(139, 92, 246, 0.14);
  --indigo-dim: rgba(129, 140, 248, 0.14);
  --teal-dim: rgba(20, 184, 166, 0.14);
  --sidebar: 272px;
  --r: 10px;
  --r-sm: 8px;
  --r-lg: 12px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.42);
}

html {
  font-size: 14px;
}

body {
  background:
    linear-gradient(180deg, rgba(56, 189, 248, 0.06), transparent 320px),
    var(--bg);
  color: var(--text);
}

body,
button,
input,
select,
textarea {
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.46);
  background-clip: padding-box;
}

.sidebar {
  background: rgba(13, 19, 31, 0.98);
  border-right: 1px solid var(--border);
  box-shadow: none;
}

.sidebar-logo {
  min-height: 82px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #0b1524;
  border: 1px solid rgba(37, 211, 102, 0.26);
  box-shadow: 0 10px 28px rgba(37, 211, 102, 0.12);
}

.logo-name {
  font-size: 0.98rem;
  font-weight: 750;
}

.logo-tag {
  color: #67e8f9;
  letter-spacing: 0.08em;
}

.sidebar-nav {
  gap: 4px;
  padding: 14px 12px;
}

.nav-item {
  min-height: 42px;
  border-radius: 8px;
  color: var(--text2);
  font-weight: 600;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.24), rgba(56, 189, 248, 0.14));
  color: #ecfeff;
  border: 1px solid rgba(45, 212, 191, 0.28);
  box-shadow: inset 3px 0 0 #14b8a6;
}

.nav-icon {
  width: 19px;
  height: 19px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  background: rgba(5, 10, 20, 0.2);
}

.connection-badge {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
}

.main-content {
  padding: 28px;
  width: calc(100vw - var(--sidebar));
  max-width: calc(100vw - var(--sidebar));
  overflow-x: hidden;
}

.page-header {
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 1.55rem;
  font-weight: 780;
}

.page-subtitle {
  color: var(--text3);
}

.card,
.stat-card,
.chart-card,
.template-card,
.modal,
.unofficial-conn-card,
#unofficial-form-card,
.chip-slot,
.wa-mockup,
.context-menu,
.toast {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 80px), var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: none;
}

.card:hover,
.stat-card:hover,
.template-card:hover,
.chip-slot:hover {
  border-color: var(--border2);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.18);
  transform: none;
}

.card.card-inner {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.card-title,
.card-title-sm,
.template-name,
.progress-title {
  color: var(--text);
  font-weight: 720;
}

.card-desc,
.form-hint,
.template-meta,
.upload-hint {
  color: var(--text3);
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat-card {
  min-height: 120px;
  padding: 18px;
  overflow: hidden;
}

.stat-card::before {
  height: 3px;
  opacity: 0.9;
}

.stat-card[class*='stat-'] {
  background: var(--surface);
}

.stat-card[class*='stat-'] .stat-label {
  color: var(--text3);
}

.stat-card[class*='stat-'] .stat-value {
  color: var(--text);
}

.stat-icon,
.stat-card[class*='stat-'] .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 1.75rem;
}

.charts-grid {
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-card,
.card,
.tab-section {
  min-width: 0;
}

.tab-section:not(.active),
.tab-chat-section:not(.active) {
  display: none !important;
}

.tab-section.active {
  display: block !important;
}

.tab-chat-section.active {
  display: flex !important;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
}

.table {
  background: var(--surface);
}

.table thead {
  background: rgba(148, 163, 184, 0.08);
}

.table th {
  color: var(--text3);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table td {
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  color: var(--text2);
}

.table tbody tr:hover td {
  background: rgba(20, 184, 166, 0.06);
}

.badge,
.unofficial-badge,
.chip-warmup-badge,
.class-badge {
  border: 1px solid currentColor;
  border-color: color-mix(in srgb, currentColor 28%, transparent);
  border-radius: 999px;
}

.btn {
  min-height: 38px;
  border-radius: 8px;
  font-weight: 680;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, #14b8a6, #0ea5e9);
  border-color: transparent;
  color: white;
  box-shadow: 0 12px 24px rgba(14, 165, 233, 0.16);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #0f766e, #0284c7);
  box-shadow: 0 16px 32px rgba(14, 165, 233, 0.22);
}

.btn-ghost,
.btn-icon,
.modal-close,
.eye-btn {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  color: var(--text2);
}

.btn-ghost:hover,
.btn-icon:hover,
.modal-close:hover,
.eye-btn:hover {
  background: rgba(148, 163, 184, 0.14);
  border-color: var(--border2);
  color: var(--text);
}

.btn-danger-sm,
.btn-icon--red {
  background: var(--red-dim);
  border: 1px solid rgba(244, 63, 94, 0.28);
  color: #fb7185;
}

.form-label {
  color: var(--text2);
  font-weight: 680;
}

.form-input,
.form-select,
.form-textarea,
.form-control,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
  background: rgba(7, 12, 22, 0.58);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: rgba(45, 212, 191, 0.75);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16);
}

.type-toggle,
.chat-tabs {
  background: rgba(7, 12, 22, 0.52);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.type-btn,
.chat-tab-btn {
  border-radius: 7px;
}

.type-btn.active,
.chat-tab-btn.active {
  background: rgba(20, 184, 166, 0.22);
  color: #ccfbf1;
  box-shadow: none;
}

.upload-zone,
.dropzone {
  background: rgba(7, 12, 22, 0.38);
  border: 1px dashed rgba(148, 163, 184, 0.34);
  border-radius: 12px;
}

.upload-zone:hover,
.upload-zone.drag-over,
.upload-zone.dragover,
.dropzone.dragover {
  background: rgba(20, 184, 166, 0.08);
  border-color: rgba(45, 212, 191, 0.6);
}

.templates-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.campaign-grid,
.two-col-layout,
.single-layout,
.unofficial-layout {
  gap: 18px;
}

.progress-card {
  padding: 22px;
}

.prog-bar-wrap,
.rate-bar,
.chip-daily-bar {
  background: rgba(148, 163, 184, 0.14);
  border-radius: 999px;
}

.prog-bar,
.rate-fill,
.chip-daily-fill {
  background: linear-gradient(90deg, #14b8a6, #38bdf8);
  border-radius: 999px;
}

.modal-overlay {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
}

.modal {
  overflow: hidden;
}

.modal-header {
  background: rgba(148, 163, 184, 0.06);
  border-bottom: 1px solid var(--border);
}

.modal-body {
  background: transparent;
}

#modal-user .modal > div:first-child,
#modal-user [style*="linear-gradient(135deg, var(--primary), #8B5CF6)"] {
  background: linear-gradient(135deg, #0f766e, #1d4ed8) !important;
}

.toast-container,
#toast-container {
  top: 18px;
  right: 18px;
}

.toast {
  border-left: 4px solid var(--blue);
}

.light-mode {
  color-scheme: light;
  --bg: #eef3f8;
  --bg2: #ffffff;
  --bg3: #f5f8fb;
  --bg4: #e8eef5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef3f8;
  --border: rgba(15, 23, 42, 0.12);
  --border2: rgba(15, 23, 42, 0.2);
  --text: #0f172a;
  --text2: #334155;
  --text3: #64748b;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.light-mode body,
body.light-mode {
  background:
    linear-gradient(180deg, rgba(20, 184, 166, 0.08), transparent 320px),
    var(--bg);
}

.light-mode .sidebar,
body.light-mode .sidebar {
  background: rgba(255, 255, 255, 0.96);
}

.light-mode .form-input,
.light-mode .form-select,
.light-mode .form-textarea,
.light-mode .form-control,
.light-mode input[type="text"],
.light-mode input[type="password"],
.light-mode input[type="number"],
.light-mode input[type="email"],
.light-mode select,
.light-mode textarea {
  background: #ffffff;
}

/* Chat surface */
:root {
  --ch-bg: #0b111b;
  --ch-sidebar: #101827;
  --ch-header: #121c2c;
  --ch-input-bg: #101827;
  --ch-green: #14b8a6;
  --ch-green-glow: rgba(20, 184, 166, 0.22);
  --ch-bubble-out: linear-gradient(135deg, #0f766e, #0891b2);
  --ch-bubble-in: #172033;
  --ch-text-dark: #f8fafc;
  --ch-text-mid: #b6c2d3;
  --ch-text-light: #7c8da5;
  --ch-border: rgba(148, 163, 184, 0.16);
  --ch-active-bg: rgba(20, 184, 166, 0.12);
  --ch-hover-bg: rgba(148, 163, 184, 0.08);
}

.tab-chat-section {
  height: 100vh !important;
}

.chat-layout {
  background: var(--ch-bg) !important;
}

.conv-pane,
.crm-pane {
  background: var(--ch-sidebar) !important;
}

.conv-pane-head {
  padding: 18px 18px 8px !important;
}

.conv-pane-title {
  font-size: 1.15rem !important;
  font-weight: 760 !important;
}

.conv-search {
  border-radius: 8px !important;
  background: rgba(7, 12, 22, 0.62) !important;
}

.conv-item {
  margin: 3px 10px !important;
  border-radius: 8px !important;
  border: 1px solid transparent !important;
}

.conv-item:hover {
  transform: none !important;
  border-color: rgba(148, 163, 184, 0.12) !important;
}

.conv-item.active {
  box-shadow: inset 3px 0 0 var(--ch-green);
}

.conv-item.active::before {
  display: none !important;
}

.conv-avatar,
.chat-avatar {
  border-radius: 50% !important;
}

.chat-head {
  min-height: 64px !important;
  background: rgba(18, 28, 44, 0.98) !important;
}

.chat-messages {
  background:
    linear-gradient(180deg, rgba(56, 189, 248, 0.035), transparent 280px),
    var(--ch-bg) !important;
}

.msg-bubble {
  border-radius: 10px !important;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16) !important;
}

.msg-row.inbound .msg-bubble {
  background: var(--ch-bubble-in) !important;
  border: 1px solid rgba(148, 163, 184, 0.14) !important;
}

.msg-row.outbound .msg-bubble {
  background: var(--ch-bubble-out) !important;
}

.chat-input-box,
.chat-input-bar {
  background: var(--ch-input-bg) !important;
  border-top: 1px solid var(--ch-border) !important;
}

.chat-textarea {
  background: rgba(7, 12, 22, 0.6) !important;
  border: 1px solid var(--ch-border) !important;
  border-radius: 10px !important;
}

.chat-send-btn {
  background: linear-gradient(135deg, #14b8a6, #0ea5e9) !important;
  border-radius: 10px !important;
}

.crm-header {
  min-height: 64px;
}

.crm-pane select,
.crm-pane input[type="text"] {
  border-radius: 8px !important;
}

.kanban-board {
  gap: 14px;
  padding-bottom: 18px;
}

.kanban-column {
  background: var(--surface-2) !important;
  border: 1px solid var(--border);
  border-radius: 12px !important;
}

.kanban-col-header {
  color: var(--text) !important;
  border-bottom-color: var(--border) !important;
}

.kanban-card {
  background: var(--surface) !important;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 10px !important;
  box-shadow: none !important;
}

.kanban-card-title {
  color: var(--text) !important;
}

.kanban-card-subtitle {
  color: var(--text3) !important;
}

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

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  :root {
    --sidebar: 268px;
  }

  .main-content {
    max-width: 100vw;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .charts-grid,
  .campaign-grid,
  .two-col-layout,
  .single-layout,
  .unofficial-layout {
    grid-template-columns: 1fr !important;
  }

  .chat-layout {
    min-width: 0;
  }

  .conv-pane {
    width: 36vw !important;
    min-width: 280px !important;
  }
}

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

  .mobile-header {
    padding: 10px 0 14px;
    gap: 10px;
  }

  .mobile-header .btn {
    flex: 1;
    justify-content: center;
  }

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

  .modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .tab-chat-section.active {
    height: calc(100vh - 58px) !important;
  }

  .conv-pane {
    width: 100% !important;
    min-width: 0 !important;
  }
}
