/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f6f7f9;
  color: #1f2937;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- login ---------- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}
.login-card {
  background: #ffffff;
  padding: 32px 28px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  width: min(380px, 92vw);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card .login-sub { margin: 0 0 20px; color: #6b7280; font-size: 13px; }
.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  margin-bottom: 6px;
}
.login-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  margin-bottom: 16px;
  outline: none;
}
.login-card input[type="password"]:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.login-card button[type="submit"] {
  width: 100%;
  background: #2563eb;
  color: white;
  border: 0;
  padding: 11px;
  border-radius: 8px;
  font-weight: 600;
}
.login-card button[type="submit"]:hover { background: #1d4ed8; }
.login-error { color: #b91c1c; font-size: 13px; margin-top: 12px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.topbar-status { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
#status-text { font-size: 12px; color: #6b7280; }
.pin-counts { display: flex; gap: 8px; }
.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill-studio { background: #dbeafe; color: #1e40af; }
.pill-anchor { background: #ede9fe; color: #5b21b6; }
.logout-form { margin: 0; }
.btn-link {
  background: none;
  border: 0;
  color: #2563eb;
  text-decoration: underline;
  padding: 0;
}

/* ---------- app layout ---------- */
.app {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  height: calc(100vh - 50px);
  min-height: 0;
}

.panel {
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  padding: 14px 14px 24px;
}
.panel-right { border-right: 0; border-left: 1px solid #e5e7eb; }

.panel-header { margin-bottom: 12px; }
.panel-header h2 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: #374151; }
.panel-header input[type="search"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
}
.panel-header input[type="search"]:focus { border-color: #2563eb; }

.panel section { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.panel section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7280; }
.panel section input[type="text"],
.panel section select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  margin-bottom: 6px;
  background: white;
}
.panel section button {
  width: 100%;
  background: #1f2937;
  color: white;
  border: 0;
  padding: 8px;
  border-radius: 6px;
  font-weight: 600;
}
.panel section button.btn-secondary {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #d1d5db;
}
.panel section .row { display: flex; gap: 6px; }
.panel section .row > button { flex: 1; }
.panel section .hint { font-size: 11px; color: #6b7280; margin: 8px 0 0; }

.panel-actions { margin-bottom: 12px; }
.panel-actions button {
  width: 100%;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px;
  color: #374151;
}

/* ---------- categories & brand rows ---------- */
.categories { display: flex; flex-direction: column; gap: 8px; }
.category {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  overflow: hidden;
}
.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #f3f4f6;
  cursor: pointer;
  user-select: none;
}
.category-header .cat-name { font-size: 13px; font-weight: 600; color: #1f2937; flex: 1; }
.category-header .cat-count { font-size: 11px; color: #6b7280; }
.category-header .cat-toggle { font-size: 11px; color: #2563eb; background: none; border: 0; padding: 0; }
.category-body { padding: 4px 6px 8px; display: none; }
.category.open .category-body { display: block; }

/* synergy category gets a colored ribbon */
.category.synergy .category-header { background: linear-gradient(90deg, #fef3c7, #fde68a); }
.category.synergy .cat-name::before { content: "★ "; color: #b45309; }

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
}
.brand-row:hover { background: #f9fafb; }
.brand-row label { flex: 1; cursor: pointer; font-size: 13px; }
.brand-row input[type="checkbox"] { cursor: pointer; }
.brand-row .brand-delete,
.brand-row .brand-refresh {
  background: none;
  border: 0;
  color: #9ca3af;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.brand-row .brand-delete:hover { color: #b91c1c; background: #fee2e2; }
.brand-row .brand-refresh:hover { color: #2563eb; background: #dbeafe; }
.brand-row.loading label::after { content: " …"; color: #9ca3af; }

/* ---------- map ---------- */
.map-wrap {
  position: relative;
  height: 100%;
  min-height: 400px;
  background: #e5e7eb;
}
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Leaflet safety net (in case CDN CSS doesn't load) */
.leaflet-container { background: #ddd; outline: none; }
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer { position: absolute; left: 0; top: 0; }
.leaflet-container { overflow: hidden; }
.leaflet-tile { width: 256px; height: 256px; }

/* ---------- bulk select buttons ---------- */
.panel-actions-bulk {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 12px;
}
.panel-actions-bulk .btn-secondary { width: 100%; }

/* ---------- demographics card ---------- */
.demographics {
  padding: 10px 12px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fafbfc;
}
.demographics h3 {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #374151;
}
.demo-status {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 6px;
}
.demo-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.demo-radius {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px 10px;
}
.demo-radius-label {
  font-weight: 600;
  font-size: 12px;
  color: #f59e0b;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.demo-radius:nth-child(2) .demo-radius-label { color: #fb923c; }
.demo-radius:nth-child(3) .demo-radius-label { color: #ef4444; }
.demo-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 12px;
}
.demo-metrics > div {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.demo-key { color: #6b7280; }
.demo-val { font-variant-numeric: tabular-nums; font-weight: 600; color: #111827; }
.demo-bgs { grid-column: 1 / -1; color: #9ca3af; font-size: 11px; }
.demo-bgs .demo-val { color: #9ca3af; font-weight: 500; }
.demo-loading { font-size: 12px; color: #6b7280; font-style: italic; }
.demo-error {
  background: #fff4e6;
  border: 1px solid #fbbf24;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #92400e;
}
.demo-error a { color: #b45309; }
#demo-note { margin-top: 6px; font-size: 11px; color: #6b7280; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto;
    height: auto;
  }
  .panel { max-height: 50vh; border: 0; border-top: 1px solid #e5e7eb; }
  .panel-right { order: 3; }
  .map-wrap { order: 2; height: 60vh; }
  .panel-left { order: 1; }
}
