:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent2: #06b6d4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

header {
  background: linear-gradient(135deg, #1a2332 0%, #0f1419 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header .badge {
  font-size: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 57px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

.main {
  display: flex;
  flex-direction: column;
}

#map {
  height: 45vh;
  min-height: 280px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.dashboard {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(55vh - 57px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.place-search-wrap {
  position: relative;
  margin-bottom: 0.5rem;
}

.place-search-wrap input {
  margin-bottom: 0;
}

.place-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 1000;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
}

.place-search-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  color: var(--text);
  cursor: pointer;
}

.place-search-item:last-child {
  border-bottom: none;
}

.place-search-item:hover {
  background: rgba(59, 130, 246, 0.12);
}

.place-search-main {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
}

.place-search-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.place-search-empty {
  padding: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: white;
  width: 100%;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
}

.competitor-list {
  margin-bottom: 0.75rem;
}

.competitor-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  margin: 0.2rem;
}

.competitor-tag button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.competitor-tag button:hover { color: var(--danger); }

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

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

.status-dot.running { background: var(--warning); animation: pulse 1s infinite; }
.status-dot.completed { background: var(--success); }
.status-dot.failed { background: var(--danger); }

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

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

.fpi-breakdown {
  display: grid;
  gap: 0.5rem;
}

.fpi-row {
  display: grid;
  grid-template-columns: 140px 1fr 40px;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.fpi-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}

.fpi-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-radius: 8px 8px 0 0;
}

.tab.active {
  color: var(--text);
  background: var(--surface2);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

tr:hover td { background: var(--surface2); }

.competitor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.competitor-card h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.metric {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.5rem;
  text-align: center;
}

.metric .num {
  font-size: 1.1rem;
  font-weight: 700;
}

.metric .lbl {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
}

.sentiment-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.sentiment-pos { background: var(--success); }
.sentiment-neu { background: var(--muted); }
.sentiment-neg { background: var(--danger); }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.tag.pos { border-color: var(--success); color: #86efac; }
.tag.neg { border-color: var(--danger); color: #fca5a5; }

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--muted);
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.scanning-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--muted);
}

.scanning-state h3 {
  font-size: 1.1rem;
  margin: 1rem 0 0.35rem;
  color: var(--text);
}

.scanning-state p {
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}

.scan-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: scan-spin 0.85s linear infinite;
}

@keyframes scan-spin {
  to { transform: rotate(360deg); }
}

.scanning-steps {
  list-style: none;
  padding: 0;
  margin: 0 auto;
  max-width: 280px;
  text-align: left;
}

.scanning-steps li {
  position: relative;
  padding: 0.45rem 0 0.45rem 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  transition: color 0.2s;
}

.scanning-steps li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(139, 156, 179, 0.35);
}

.scanning-steps li.active {
  color: var(--text);
}

.scanning-steps li.active::before {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.scanning-steps li.done {
  color: #86efac;
}

.scanning-steps li.done::before {
  background: var(--success);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: -0.5rem;
  margin-bottom: 0.75rem;
}

.not-found-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px;
  padding: 0.85rem;
}

.not-found-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  font-weight: 700;
  flex-shrink: 0;
}

.not-found-banner p {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.competitor-card.not-found h3 {
  color: var(--muted);
}

.found-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--success);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.trend-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.6rem;
}

.trend-card h4 {
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.history-item:hover {
  background: var(--surface2);
}

.history-item.active {
  background: var(--surface2);
  border: 1px solid var(--accent);
}

.history-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.source-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.source-osm {
  background: rgba(6, 182, 212, 0.15);
  color: #67e8f9;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.source-google {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.source-parse {
  background: rgba(249, 115, 22, 0.15);
  color: #fdba74;
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.source-serp {
  background: rgba(234, 179, 8, 0.15);
  color: #fde047;
  border: 1px solid rgba(234, 179, 8, 0.3);
}

.source-mappls {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.mappls-card .mappls-stats {
  margin-bottom: 1rem;
}

.mappls-address {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.mappls-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.mappls-chip {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
}

.mappls-subhead {
  font-size: 0.85rem;
  margin: 1rem 0 0.5rem;
  color: var(--text);
}

.mappls-brands {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.mappls-brand {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mappls-brand.found {
  border-color: rgba(34, 197, 94, 0.4);
}

.mappls-brand.missing {
  opacity: 0.65;
}

.mappls-brand-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.mappls-brand-role {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: capitalize;
}

.mappls-brand-dist {
  font-size: 0.75rem;
  color: var(--accent);
}

.intel-section {
  margin-bottom: 1rem;
}

.intel-section h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.intel-badge {
  font-size: 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
}

.intel-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.intel-item {
  padding: 0.65rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.intel-item-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.intel-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
}

.intel-link:hover {
  text-decoration: underline;
}

.intel-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.intel-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.chart-wrap {
  position: relative;
  height: 260px;
  margin-top: 0.75rem;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  margin: 0;
}

.chart-wrap-tall {
  height: 320px;
}

.chart-hint {
  margin-top: 0.25rem;
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: none; }
  .grid-3, .metric-grid { grid-template-columns: 1fr 1fr; }
}
