:root {
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.9);
  --border-color: rgba(255, 255, 255, 0.1);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-purple: #a855f7;
  --accent-orange: #f97316;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.app-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(6, 182, 212, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 50% 80%, rgba(168, 85, 247, 0.12) 0%, transparent 50%);
  z-index: -1;
  pointer-events: none;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Navbar */
.navbar {
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  background: rgba(15, 23, 42, 0.8);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 16px 0;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}

.logo i {
  color: var(--accent-cyan);
  font-size: 1.5rem;
}

.logo-badge {
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-indicator {
  font-size: 0.85rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-indicator i {
  font-size: 0.5rem;
  animation: pulse 1.8s infinite;
}

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

/* Card General */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card-header h2, .card-header h3, .card-header h4 {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-top: 6px;
  line-height: 1.5;
}

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

.flex-wrap {
  flex-wrap: wrap;
}

.gap-2 {
  gap: 12px;
}

/* Generator Form */
.generator-card {
  margin-top: 28px;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.generator-form {
  margin-top: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.span-2 {
  grid-column: span 2;
}

@media (max-width: 900px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}

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

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

.form-group input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.btn {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);

}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4338ca);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -4px rgba(99, 102, 241, 0.5);
}

.btn-copy {
  background: var(--accent-cyan);
  color: #000;
}

.btn-copy:hover {
  background: #22d3ee;
}

.btn-test {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  text-decoration: none;
}

.btn-test:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.4);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}

/* Result Box */
.result-box {
  margin-top: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
  animation: fadeIn 0.4s ease;
}

.result-header {
  color: var(--accent-green);
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-input-group {
  display: flex;
  gap: 10px;
}

.result-input-group input {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--accent-green);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.hidden {
  display: none !important;
}

/* Dashboard Section */
.dashboard-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  margin-top: 24px;
}

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

/* Links List */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
  max-height: 700px;
  overflow-y: auto;
  padding-right: 4px;
}

.link-item {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.link-item:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.link-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

.link-item-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.link-code-badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  color: var(--accent-cyan);
}

/* Analytics Wrapper */
.analytics-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0; /* Prevents CSS Grid track overflow */
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: monospace;
}

.active-title {
  font-size: 1.3rem;
  margin-top: 6px;
}

.active-target-url {
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
}

/* Metrics Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

@media (max-width: 900px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.metric-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.metric-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.icon-blue { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.icon-green { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.icon-purple { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.icon-orange { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); }

.metric-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

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

.chart-card h4 {
  font-size: 0.95rem;
  margin-bottom: 16px;
  color: var(--text-muted);
}

.chart-container {
  position: relative;
  height: 230px;
}

/* Table */
.logs-card {
  overflow: hidden;
}

.logs-count-badge {
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
  color: var(--text-muted);
}

.table-responsive {
  overflow-x: auto;
  margin-top: 16px;
}

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

.table th {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-muted);
  padding: 14px 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 16px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.tag-referrer {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.tag-wa { background: rgba(37, 211, 102, 0.2); color: #25d366; }
.tag-ig { background: rgba(225, 48, 108, 0.2); color: #e1306c; }
.tag-fb { background: rgba(24, 119, 242, 0.2); color: #1877f2; }
.tag-direct { background: rgba(148, 163, 184, 0.2); color: #94a3b8; }
.tag-other { background: rgba(168, 85, 247, 0.2); color: #c084fc; }

/* Map Component */
.map-card {
  padding: 24px;
}

.map-container {
  width: 100%;
  height: 320px;
  border-radius: var(--radius-md);
  margin-top: 14px;
  border: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.9);
  z-index: 1;
  overflow: hidden;
  box-sizing: border-box;
}

.leaflet-popup-content-wrapper {
  background: #ffffff !important;
  color: #0f172a !important;
  border-radius: 10px !important;
  border: 1px solid rgba(0, 0, 0, 0.15);
  font-family: 'Plus Jakarta Sans', sans-serif !important;
}

.leaflet-popup-tip {
  background: #ffffff !important;
}

/* Login Modal Overlay */
.login-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.login-modal-card {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-icon {
  font-size: 2.8rem;
  color: var(--accent-cyan);
  margin-bottom: 12px;
}

.login-header h2 {
  font-size: 1.5rem;
  color: #fff;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 6px;
  line-height: 1.4;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 10px;
  text-align: center;
}

.footer {
  margin-top: 60px;
  padding: 30px 0;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

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