:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(28, 36, 56, 0.95);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(56, 189, 248, 0.3);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #25d366; /* WhatsApp Green */
  --primary-hover: #1ebd5a;
  --accent-cyan: #38bdf8;
  --accent-purple: #818cf8;
  --accent-rose: #f43f5e;
  --accent-amber: #fbbf24;
  --radius-lg: 14px;
  --radius-md: 8px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(37, 211, 102, 0.07) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.07) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(129, 140, 248, 0.04) 0px, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header */
.app-header {
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 7px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #128c7e);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.brand-icon svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
}

.brand-title {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}

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

/* User pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.user-avatar {
  width: 26px;
  height: 26px;
  background: var(--accent-purple);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

.btn-logout:hover {
  color: var(--accent-rose);
}

/* Main Container */
.main-content {
  flex: 1;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* KPIs Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
}

.kpi-card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
}

.kpi-card:hover {
  transform: translateY(-1px);
  border-color: var(--border-glow);
  background: var(--bg-card-hover);
}

.kpi-info h4 {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 2px;
  font-weight: 600;
}

.kpi-info .kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.05;
}

.kpi-info .kpi-subtext {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.kpi-icon.blue { background: rgba(56, 189, 248, 0.12); color: var(--accent-cyan); }
.kpi-icon.green { background: rgba(37, 211, 102, 0.12); color: var(--primary); }
.kpi-icon.purple { background: rgba(129, 140, 248, 0.12); color: var(--accent-purple); }
.kpi-icon.rose { background: rgba(244, 63, 94, 0.12); color: var(--accent-rose); }
.kpi-icon.amber { background: rgba(251, 191, 36, 0.12); color: var(--accent-amber); }

/* Control Bar */
.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: rgba(37, 211, 102, 0.15);
  color: var(--primary);
  border: 1px solid rgba(37, 211, 102, 0.3);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: #0b0f19;
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 15px rgba(37, 211, 102, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-glow);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border-color: rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: var(--accent-rose);
  color: #fff;
}

/* Luckysheet Container */
.sheet-container-wrapper {
  flex: 1;
  height: calc(100vh - 195px);
  min-height: 450px;
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #ffffff;
  box-shadow: var(--shadow-glow);
}

#luckysheet {
  margin: 0px;
  padding: 0px;
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0px;
  top: 0px;
}

/* Garantir que os nomes das abas inferiores do Luckysheet nunca fiquem cortados */
#luckysheet-sheet-area,
.luckysheet-sheet-area {
  height: 32px !important;
  line-height: 28px !important;
  padding-top: 2px !important;
  padding-bottom: 2px !important;
  box-sizing: border-box !important;
}

.luckysheet-sheets-item {
  height: 26px !important;
  line-height: 24px !important;
  padding: 0 12px !important;
  vertical-align: middle !important;
  display: inline-flex !important;
  align-items: center !important;
}

.luckysheet-sheets-item-name {
  line-height: 22px !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  padding-bottom: 1px !important;
}

/* Luckysheet Text Visibility and Input Fix */
#luckysheet,
#luckysheet *,
#luckysheet-input-box,
#luckysheet-input-box *,
.luckysheet-cell-input,
.luckysheet-cell-input *,
.luckysheet-rich-text-editor,
.luckysheet-rich-text-editor *,
#luckysheet-functionbox-cell,
#luckysheet-functionbox-cell *,
.luckysheet-wa-editor,
.luckysheet-wa-editor *,
.luckysheet-context-menu,
.luckysheet-context-menu * {
  color: #000000;
}

#luckysheet-input-box,
.luckysheet-cell-input,
.luckysheet-rich-text-editor,
#luckysheet-functionbox-cell {
  color: #000000 !important;
  caret-color: #000000 !important;
}

#luckysheet-input-box * {
  color: #000000 !important;
}


/* Simulator Tab */
.simulator-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  min-height: 500px;
}

.sim-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sim-panel h3 {
  font-size: 1.05rem;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.form-input, .form-textarea, .form-select {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.2);
}

.sim-logs {
  background: #06090e;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: Consolas, Monaco, monospace;
  font-size: 0.8rem;
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
  color: #38bdf8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #111827;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-glow);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.qr-display {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 220px;
  background: #ffffff;
  padding: 16px;
  border-radius: var(--radius-md);
  margin: 10px 0;
}

.qr-display img {
  max-width: 200px;
  height: auto;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--primary); }
.toast.error { border-left: 4px solid var(--accent-rose); }
.toast.info { border-left: 4px solid var(--accent-cyan); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Cadence Live Active Progress Banner */
.cadence-active-banner {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.15) 0%, rgba(99, 102, 241, 0.15) 100%);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 16px;
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.2);
  animation: banner-pulse 2.5s infinite ease-in-out;
  backdrop-filter: blur(10px);
}

@keyframes banner-pulse {
  0%, 100% {
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.35);
  }
  50% {
    box-shadow: 0 0 30px rgba(56, 189, 248, 0.5);
    border-color: rgba(56, 189, 248, 0.8);
  }
}

.cadence-banner-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cadence-banner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.cadence-pulse-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background-color: #38bdf8;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 10px #38bdf8;
  animation: dot-pulse 1.2s infinite ease-in-out;
}

@keyframes dot-pulse {
  0%, 100% {
    transform: scale(0.9);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.3);
    opacity: 1;
    box-shadow: 0 0 14px #38bdf8;
  }
}

.cadence-badge {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #38bdf8;
  text-transform: uppercase;
}

.cadence-banner-timer {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.25);
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cadence-banner-body {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.cadence-lead-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lead-highlight {
  font-size: 0.95rem;
  font-weight: 600;
  color: #f8fafc;
}

.lead-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cadence-progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
  flex: 1;
  max-width: 360px;
}

.cadence-progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cadence-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8 0%, #10b981 100%);
  border-radius: 999px;
  transition: width 0.4s ease;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.cadence-progress-percent {
  font-size: 0.85rem;
  font-weight: 700;
  color: #10b981;
  min-width: 35px;
  text-align: right;
}

.kpi-icon.teal { background: rgba(13, 148, 136, 0.15); color: #14b8a6; }
.kpi-icon.cyan { background: rgba(6, 182, 212, 0.15); color: #06b6d4; }

/* -------------------------------------------------------------
   VISUAL DASHBOARD SECTION (High-End Analytics)
   ------------------------------------------------------------- */
.dashboard-visual-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.3s ease-in-out;
}

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

.dash-hero-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  border-left: 4px solid var(--primary);
}

.dash-hero-title h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-hero-title p {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin: 0;
}

.dash-hero-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  color: #10b981;
}

.sync-time {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.chart-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 380px;
}

.chart-card:hover {
  border-color: rgba(56, 189, 248, 0.25);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 12px;
}

.chart-card-header h4 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
}

.chart-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--accent-cyan);
  white-space: nowrap;
}

.chart-canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 270px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-legend-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: #cbd5e1;
}

.legend-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* Detailed Stage Table */
.dash-table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.dash-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.dash-table-header h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f1f5f9;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.2);
}

.dash-stage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.dash-stage-table th {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.dash-stage-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
}

.dash-stage-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.stage-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  font-weight: 700;
  font-size: 0.78rem;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.stage-rate-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-rate-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  max-width: 120px;
}

.stage-rate-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #10b981);
}

@media (max-width: 960px) {
  .charts-grid { grid-template-columns: 1fr; }
  .simulator-wrapper { grid-template-columns: 1fr; }
  .control-bar { flex-direction: column; align-items: stretch; }
  .action-buttons { flex-direction: column; }
}
