:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent2: #10b981;
  --google: #4285f4;
  --meta: #1877f2;
  --danger: #ef4444;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.5rem; }

label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }

input[type="password"],
input[type="date"],
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  width: 100%;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
}

button:hover { opacity: 0.9; }
button.secondary { background: var(--surface2); border: 1px solid var(--border); }
button.ghost { background: transparent; color: var(--muted); margin-top: 0; }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; }

#app { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header h1 { font-size: 1.75rem; }
.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.header-actions input[type="date"] { width: auto; }
.header-actions button { margin-top: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stats-grid-leads {
  grid-template-columns: repeat(6, 1fr);
}

.stat-card.stat-total { border-color: var(--accent); }
.stat-card.stat-pageviews { border-color: var(--muted); }
.stat-card.stat-phone { border-color: #34d399; }
.stat-card.stat-booking { border-color: #818cf8; }
.stat-card.stat-contact { border-color: #fbbf24; }
.stat-card.stat-sms { border-color: #22d3ee; }

.badge.lead-type,
.badge.conversion-type,
.badge.device-type { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge.ai { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }

@media (max-width: 1100px) {
  .stats-grid-leads { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .stats-grid-leads { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 100px 1fr 32px; }
}

.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 2rem; font-weight: 700; }

.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.panel h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--muted); }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.panel-header h2 { margin-bottom: 0; }
.panel-header select { width: auto; min-width: 180px; }

.bar-chart { display: flex; flex-direction: column; gap: 0.5rem; }

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 40px;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.bar-track {
  background: var(--surface2);
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.3s ease;
}

.bar-count { text-align: right; font-weight: 600; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }

td { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--surface2);
}

.badge.paid-google { background: rgba(66, 133, 244, 0.2); color: #7eb3ff; }
.badge.paid-search-google { background: rgba(249, 115, 22, 0.22); color: #fdba74; }
.badge.paid-meta { background: rgba(24, 119, 242, 0.2); color: #6eb0ff; }
.badge.organic { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.badge.direct { background: rgba(139, 156, 179, 0.2); color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 2rem; }
