:root {
  --bg: #1a0a2e;
  --purple: #a855f7;
  --purple-light: #c084fc;
  --purple-dark: #7e22ce;
  --white: #ffffff;
  --muted: #f3f4f6;
  --card: rgba(168, 85, 247, 0.1);
  --border: rgba(168, 85, 247, 0.3);
  --glow-purple: 0 0 20px rgba(168, 85, 247, 0.5);
  --glow-white: 0 0 15px rgba(255, 255, 255, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #1a0a2e 0%, #2d1b4e 50%, #1a0a2e 100%);
  color: var(--muted);
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(168, 85, 247, 0.15);
  border-bottom: 2px solid var(--border);
  box-shadow: var(--glow-purple);
  backdrop-filter: blur(10px);
}

.topbar-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--white);
  cursor: pointer;
  text-shadow: var(--glow-white);
}

/* BUTTONS */
.btn-gold {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-light) 100%);
  color: var(--white);
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glow-purple);
}

.btn-gold:hover {
  background: linear-gradient(135deg, var(--purple-light) 0%, var(--purple) 100%);
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.7);
  transform: translateY(-2px);
}

.btn-gold:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.icon-btn-gold {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-light) 100%);
  color: var(--white);
  border: none;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--glow-purple);
}

.icon-btn-gold:hover {
  background: linear-gradient(135deg, var(--purple-light) 0%, var(--purple) 100%);
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.7);
  transform: scale(1.05);
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: none;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.call-btn {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  color: var(--white);
  box-shadow: var(--glow-purple);
}

.call-btn:hover {
  box-shadow: 0 0 25px rgba(168, 85, 247, 0.8);
}

.wa-btn {
  background: transparent;
  border: 2px solid var(--purple-light);
  color: var(--purple-light);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.3);
}

.wa-btn:hover {
  background: rgba(192, 132, 252, 0.1);
  box-shadow: 0 0 20px rgba(192, 132, 252, 0.5);
}

.view-btn {
  background: transparent;
  border: 2px solid var(--white);
  color: var(--white);
  box-shadow: var(--glow-white);
}

.view-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 25px rgba(255, 255, 255, 0.6);
}

/* CARDS & LAYOUT */
.page {
  padding: 16px;
}

.section-title {
  color: var(--white);
  font-weight: 700;
  margin: 16px 0 10px;
  font-size: 1.1rem;
  text-shadow: var(--glow-white);
}

.card-lead {
  background: var(--card);
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--border);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  box-shadow: var(--glow-purple);
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
}

.card-lead:hover {
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.6);
  transform: translateY(-2px);
}

.stat-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat-card {
  flex: 1 1 140px;
  background: var(--card);
  padding: 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  box-shadow: var(--glow-purple);
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
}

.stat-card:hover {
  box-shadow: 0 0 25px rgba(168, 85, 247, 0.6);
  transform: translateY(-2px);
}

.stat-card b {
  display: block;
  font-size: 1.3rem;
  margin-bottom: 4px;
  color: var(--white);
  text-shadow: var(--glow-white);
}

/* FORM ELEMENTS */
.label {
  color: var(--white);
  margin-top: 12px;
  margin-bottom: 4px;
  font-size: 0.9rem;
  text-shadow: var(--glow-white);
}

.input {
  width: 100%;
  padding: 10px;
  background: rgba(168, 85, 247, 0.08);
  border: 2px solid var(--border);
  color: var(--white);
  border-radius: 10px;
  margin-bottom: 10px;
  font-family: inherit;
  transition: all 0.3s ease;
}

.input:focus {
  outline: none;
  border-color: var(--purple-light);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
  background: rgba(168, 85, 247, 0.12);
}

textarea.input {
  min-height: 100px;
  resize: vertical;
}

select.input {
  cursor: pointer;
}

/* NAVIGATION */
.nav-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.nav-btn {
  flex: 1 1 140px;
  background: var(--card);
  padding: 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--glow-purple);
  backdrop-filter: blur(5px);
}

.nav-btn:hover {
  background: rgba(168, 85, 247, 0.2);
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.7);
  transform: translateY(-3px);
}

.nav-btn span {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--white);
  text-shadow: var(--glow-white);
}

/* UTILS */
.text-muted { opacity: 0.7; }
.text-small { font-size: 0.8rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-10 { gap: 10px; }
.ml-auto { margin-left: auto; }

/* GRID FORM */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 20px;
  background: rgba(168, 85, 247, 0.03);
}

.form-section-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--purple-light);
  text-transform: uppercase;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title i {
  font-size: 1.1rem;
}

.modal-content-wide {
  max-width: 800px !important;
  max-height: 90vh;
  overflow-y: auto;
}

/* TEAM TREE STYLES */
.team-tree-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-left: 10px;
  max-width: 900px;
}

.tree-item {
  position: relative;
  padding-left: 30px;
}

/* Vertical line for children */
.tree-item:before {
  content: "";
  position: absolute;
  left: 12px;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--border);
}

/* Hide line below the last child if needed (complex) - keeping it simple for now */
.tree-item:last-child:before {
  height: 25px; /* Stop the line at the last node card */
}

/* Horizontal line for node */
.tree-item:after {
  content: "";
  position: absolute;
  left: 14px;
  top: 25px;
  width: 15px;
  height: 2px;
  background: var(--border);
}

.tree-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
  margin-bottom: 10px;
}

.tree-card:hover {
  transform: translateX(5px);
  border-color: var(--purple-light);
  box-shadow: var(--glow-purple);
}

.tree-node-avatar {
  width: 45px;
  height: 45px;
  border-radius: 10px;
  background: #222;
  border: 1px solid var(--border);
}

.tree-node-info { flex: 1; }
.tree-node-info b { font-size: 0.95rem; color: white; display: block; }
.tree-node-info span { font-size: 0.7rem; color: var(--purple-light); font-weight: 800; text-transform: uppercase; }

.tree-node-stats {
  display: flex;
  gap: 15px;
  text-align: right;
}

.tree-stat div { font-size: 1rem; font-weight: 900; color: white; }
.tree-stat label { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; display: block; }

.tree-children {
  display: flex;
  flex-direction: column;
}

/* GLOBAL LOADER */
.loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(26, 10, 46, 0.8);
  backdrop-filter: blur(5px);
  display: none; /* Controlled by JS */
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  gap: 15px;
}

.loader-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(168, 85, 247, 0.2);
  border-top: 4px solid var(--purple-light);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  box-shadow: var(--glow-purple);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loader-text {
  color: var(--purple-light);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 0.8rem;
}
