/* ==========================================================================
   DESIGN SYSTEM & CUSTOM VARIABLES
   ========================================================================== */
:root {
  --font-main: 'Plus Jakarta Sans', sans-serif;

  /* Colors */
  --bg-app: hsl(224, 32%, 8%);
  --bg-card: rgba(22, 28, 45, 0.65);
  --border-card: rgba(255, 255, 255, 0.08);
  --border-card-hover: rgba(139, 92, 246, 0.3);
  
  --text-primary: hsl(210, 38%, 95%);
  --text-secondary: hsl(211, 25%, 72%);
  --text-muted: hsl(211, 15%, 50%);

  /* Accents */
  --accent-purple: hsl(263, 85%, 65%);
  --accent-purple-glow: rgba(139, 92, 246, 0.25);
  --accent-blue: hsl(217, 91%, 60%);
  --accent-cyan: hsl(190, 90%, 50%);
  --accent-orange: hsl(24, 95%, 58%);
  --accent-green: hsl(142, 72%, 50%);
  --accent-danger: hsl(350, 80%, 55%);

  /* Interactive states */
  --btn-primary-gradient: linear-gradient(135deg, hsl(263, 85%, 65%), hsl(240, 80%, 60%));
  --btn-primary-hover: linear-gradient(135deg, hsl(263, 90%, 70%), hsl(240, 85%, 65%));
  --btn-success-gradient: linear-gradient(135deg, hsl(142, 72%, 45%), hsl(158, 64%, 40%));
  --glass-blur: blur(20px);
  --shadow-premium: 0 12px 40px -10px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   RESET & GLOBAL BASE STYLES
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding: 1.5rem;
}

/* Background glowing blobs */
.glass-bg-glow {
  position: absolute;
  top: -15%;
  right: -10%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, rgba(99, 102, 241, 0.05) 50%, rgba(0,0,0,0) 100%);
  z-index: -1;
  pointer-events: none;
  filter: blur(80px);
  animation: float-glow 10s ease-in-out infinite alternate;
}

@keyframes float-glow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-5%, 10%) scale(1.1); }
}

/* ==========================================================================
   REUSABLE UI COMPONENTS
   ========================================================================== */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  box-shadow: var(--shadow-premium);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Badges */
.badge-pro {
  background: var(--btn-primary-gradient);
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
  margin-left: 0.5rem;
  text-transform: uppercase;
}

.count-badge {
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 30px;
  color: var(--text-secondary);
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  color: white;
}

.btn-primary {
  background: var(--btn-primary-gradient);
  box-shadow: 0 4px 15px var(--accent-purple-glow);
}
.btn-primary:hover {
  background: var(--btn-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-success {
  background: var(--btn-success-gradient);
}
.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(34, 197, 94, 0.25);
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--accent-danger);
}
.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.2);
  color: white;
}

.btn-icon-only {
  padding: 0.65rem;
  border-radius: 10px;
}

.btn-sm {
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  transition: color 0.2s;
}
.btn-icon:hover {
  color: var(--accent-danger);
}

/* ==========================================================================
   APP CONTAINER & LAYOUT STRUCTURE
   ========================================================================== */
.app-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* HEADER STYLE */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.header-logo i {
  font-size: 1.8rem;
}

.header-logo-img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 12px;
  filter: drop-shadow(0 0 10px rgba(0, 212, 255, 0.4));
  transition: transform 0.3s ease, filter 0.3s ease;
}

.header-logo-img:hover {
  transform: scale(1.08) rotate(-3deg);
  filter: drop-shadow(0 0 18px rgba(0, 212, 255, 0.7));
}

.logo-text h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
}

.logo-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 30px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-connected {
  color: var(--accent-green);
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.2);
}
.status-connected .status-dot {
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.status-disconnected {
  color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
}
.status-disconnected .status-dot {
  background-color: var(--accent-danger);
  box-shadow: 0 0 8px var(--accent-danger);
  animation: pulse-red 1.5s infinite alternate;
}

@keyframes pulse-red {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* ==========================================================================
   METRICS GRID
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem;
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.metric-info h3 {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-info p {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  margin-top: 0.2rem;
}

/* Metric Colors */
.bg-blue-trans { background: rgba(59, 130, 246, 0.12); color: var(--accent-blue); }
.bg-cyan-trans { background: rgba(6, 182, 212, 0.12); color: var(--accent-cyan); }
.bg-orange-trans { background: rgba(249, 115, 22, 0.12); color: var(--accent-orange); }
.bg-purple-trans { background: rgba(139, 92, 246, 0.12); color: var(--accent-purple); }
.bg-green-trans { background: rgba(34, 197, 94, 0.12); color: var(--accent-green); }

/* ==========================================================================
   DASHBOARD GRID & SECTIONS
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.main-section {
  min-height: 500px;
}

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

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.panel-header h2 i {
  color: var(--accent-purple);
}

/* Forms */
.panel-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

.label-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

input[type="text"],
input[type="email"],
select,
textarea {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.2s ease;
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
  background: rgba(255, 255, 255, 0.07);
}

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  outline: none;
  margin: 10px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-purple);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-purple);
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* ==========================================================================
   RUNS LIST (APIFY ACTIVE/PAST JOBS)
   ========================================================================== */
.runs-list-wrapper {
  max-height: 250px;
  overflow-y: auto;
  padding: 0.75rem;
}

.runs-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.run-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.2s ease;
}

.run-item:hover {
  border-color: rgba(255, 255, 255, 0.08);
}

.run-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.run-term {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* Run status classes */
.run-status-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.run-status-running { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); animation: pulse-running 1.5s infinite alternate; }
.run-status-succeeded { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.run-status-failed { background: rgba(239, 68, 68, 0.15); color: var(--accent-danger); }
.run-status-ready { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }

@keyframes pulse-running {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

.run-item-details {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.run-item-details span {
  display: block;
}

.run-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 0.5rem;
}

.btn-run-action {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.btn-import-active {
  background: var(--accent-purple);
  color: white;
}
.btn-import-active:hover {
  background: hsl(263, 90%, 70%);
}

.btn-imported {
  background: rgba(34, 197, 94, 0.1);
  color: var(--accent-green);
  cursor: not-allowed;
}

/* ==========================================================================
   CRM LEADS CONTAINER & CONTROLS
   ========================================================================== */
.crm-header {
  flex-wrap: wrap;
  gap: 1rem;
}

.title-with-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.crm-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  width: 250px;
}

.search-box i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.search-box input {
  padding-left: 2.2rem;
  width: 100%;
}

.select-filter {
  padding: 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
}

/* CRM TABLE STYLES */
.table-container {
  overflow-x: auto;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

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

.crm-table th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  font-weight: 700;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-card);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.crm-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
  color: var(--text-primary);
  transition: background-color 0.2s;
}

.crm-table tbody tr:hover td {
  background-color: rgba(255, 255, 255, 0.02);
}

.lead-primary-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.lead-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
}

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

.lead-category {
  background: rgba(139, 92, 246, 0.1);
  color: var(--accent-purple);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
}

.lead-contact-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.contact-link {
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.1s ease;
}

.contact-link:hover {
  color: var(--accent-purple);
}

.contact-link i {
  font-size: 0.8rem;
  width: 14px;
}

.rating-stars {
  font-size: 0.75rem;
  color: hsl(45, 100%, 55%);
}

.rating-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* CRM Status Dropdown inside the table */
.select-crm-status {
  padding: 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  width: 130px;
}

.crm-status-Novo { background: rgba(59, 130, 246, 0.15) !important; color: var(--accent-blue) !important; border-color: rgba(59, 130, 246, 0.25) !important; }
.crm-status-Contato { background: rgba(249, 115, 22, 0.15) !important; color: var(--accent-orange) !important; border-color: rgba(249, 115, 22, 0.25) !important; }
.crm-status-Qualificado { background: rgba(139, 92, 246, 0.15) !important; color: var(--accent-purple) !important; border-color: rgba(139, 92, 246, 0.25) !important; }
.crm-status-SemInteresse { background: rgba(255, 255, 255, 0.08) !important; color: var(--text-muted) !important; border-color: rgba(255, 255, 255, 0.15) !important; }
.crm-status-Fechado { background: rgba(34, 197, 94, 0.15) !important; color: var(--accent-green) !important; border-color: rgba(34, 197, 94, 0.25) !important; }

/* Notes Input inside the table */
.lead-notes-input {
  width: 100%;
  min-width: 140px;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  border-radius: 6px;
  color: var(--text-secondary);
  resize: vertical;
}

.lead-notes-input:focus {
  border-style: solid;
  border-color: var(--accent-purple);
  background: rgba(0, 0, 0, 0.2);
}

.lead-actions {
  display: flex;
  justify-content: center;
}

/* Table empty state */
.table-no-data {
  text-align: center;
  padding: 4rem 2rem !important;
  color: var(--text-muted);
}

.table-no-data i {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.table-no-data p {
  max-width: 450px;
  margin: 0 auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ==========================================================================
   MODAL OVERLAY (MANUAL LEAD & EDITING)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(6, 9, 17, 0.85);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

.modal-content {
  width: 100%;
  max-width: 650px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

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

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover {
  color: white;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  padding: 1.5rem;
}

.form-full-width {
  grid-column: span 2;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border-card);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Utilities */
.text-center { text-align: center; }
.text-gradient-purple {
  background: linear-gradient(135deg, hsl(263, 85%, 65%), hsl(290, 85%, 65%));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Custom scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  
  .sidebar-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 768px) {
  body {
    padding: 1rem;
  }
  
  .sidebar-section {
    grid-template-columns: 1fr;
  }
  
  .main-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
  
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .form-full-width {
    grid-column: span 1;
  }
}
