:root {
  --ink: #1a2233;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f7f8fa;
  --accent: #2563eb;
  --good: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header .wordmark {
  font-weight: 700;
  font-size: 18px;
}

header .tagline {
  color: var(--muted);
  font-size: 13px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.controls {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

select, button {
  font: inherit;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

button.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}

#map {
  height: 420px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.status-line {
  font-size: 13px;
  color: var(--muted);
  margin: -8px 0 16px;
}

.gap-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 18px;
  overflow: hidden;
}

.gap-section h3 {
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gap-section h3 .count {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child, td:first-child {
  text-align: left;
}

thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: #fafafa;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f0f5ff;
}

.gap-pos { color: var(--good); font-weight: 600; }
.gap-neg { color: var(--bad); }
.flag { color: var(--warn); font-size: 11px; margin-left: 4px; }

.hidden { display: none !important; }

#detailPanel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-top: 8px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.detail-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.detail-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafbfc;
}

.card .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.card .value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

#detailMap {
  height: 320px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.dot-target { background: #7c3aed; }
.dot-used { background: var(--good); }
.dot-excluded { background: #9ca3af; }

.close-btn {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}