:root {
  --panel: #ffffff;
  --ink: #16201c;
  --muted: #66736d;
  --line: #dbe2dc;
  --accent: #26745d;
  --accent-soft: #e7f1ed;
  --danger: #a84242;
  --danger-soft: #fff1f1;
  --warning: #b7791f;
  --shadow: 0 14px 38px rgba(22, 32, 28, .14);
  --shadow-soft: 0 8px 24px rgba(22, 32, 28, .1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.primary-link,
.small-link {
  min-height: 36px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 0 14px;
  font-weight: 760;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button.secondary,
.small-link,
.filter-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.map-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #eef1ed;
}

.map-canvas,
.map-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-fallback {
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  background: #f6f7f4;
}

.floating-header {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 20;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.floating-header > div {
  pointer-events: auto;
}

.floating-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  text-shadow: 0 1px 0 #fff;
}

.floating-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-panel {
  position: absolute;
  top: 76px;
  left: 16px;
  z-index: 20;
  width: min(900px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: 76px minmax(140px, 180px) 82px 112px 132px auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.search-panel.expanded {
  width: min(1120px, calc(100vw - 32px));
  grid-template-columns: 76px minmax(0, 1fr) 150px minmax(220px, 1fr) 86px auto auto;
  box-shadow: var(--shadow);
}

.panel-toggle {
  align-self: end;
}

.search-panel:not(.expanded) .prefecture-picker,
.search-panel:not(.expanded) .industry-picker,
.search-panel:not(.expanded) label.wide {
  display: none;
}

.search-panel:not(.expanded) #randomIndustryButton {
  padding-inline: 11px;
}

.search-panel:not(.expanded) #searchButton {
  padding-inline: 14px;
}

.wide {
  grid-column: span 2;
}

.search-panel.expanded .wide {
  grid-column: span 3;
}

.prefecture-picker,
.industry-picker {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.prefecture-picker > span,
.industry-picker > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chip-rail {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip[data-score]::after {
  content: attr(data-score);
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: 7px;
  border-radius: 999px;
  background: #edf2f0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.chip[data-score="A"]::after {
  background: #fff1f1;
  color: var(--danger);
}

.chip[data-score="B"]::after {
  background: #fff8e7;
  color: var(--warning);
}

.chip[data-score="C"]::after {
  background: #eef1ed;
  color: var(--muted);
}

.checkline {
  grid-template-columns: auto 1fr;
  align-items: center;
  align-self: center;
  color: var(--ink);
}

.checkline input {
  width: 18px;
  height: 18px;
}

.lead-drawer {
  position: absolute;
  left: 16px;
  top: 124px;
  bottom: 86px;
  z-index: 25;
  width: min(430px, calc(100vw - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
  padding: 18px;
  transform: translateX(calc(-100% - 24px));
  transition: transform .22s ease;
  backdrop-filter: blur(14px);
}

.lead-drawer.open {
  transform: translateX(0);
}

.icon-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.detail {
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.detail h2 {
  margin: 0;
  padding-right: 28px;
  font-size: 24px;
  line-height: 1.25;
}

.detail p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.address {
  line-height: 1.45;
}

.status-row,
.link-row,
.filters,
.secondary-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.hot {
  border-color: rgba(168, 66, 66, .28);
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.warm {
  border-color: rgba(183, 121, 31, .3);
  background: #fff8e7;
  color: var(--warning);
}

.badge.priority {
  border-color: rgba(38, 116, 93, .25);
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.priority-a {
  border-color: rgba(168, 66, 66, .28);
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.priority-b {
  border-color: rgba(183, 121, 31, .3);
  background: #fff8e7;
  color: var(--warning);
}

.badge.priority-c {
  border-color: var(--line);
  background: #f5f6f4;
  color: var(--muted);
}

.research-card {
  display: grid;
  gap: 9px;
  border: 1px solid rgba(38, 116, 93, .22);
  border-radius: 8px;
  background: #f7faf8;
  padding: 12px;
}

.research-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.research-head strong {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
}

.research-head strong.score-a {
  background: var(--danger-soft);
  color: var(--danger);
}

.research-head strong.score-b {
  background: #fff8e7;
  color: var(--warning);
}

.research-head strong.score-c {
  background: #eef1ed;
  color: var(--muted);
}

.research-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.research-card p {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.link-row a,
.site-actions a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.site-list {
  display: grid;
  gap: 10px;
}

.site-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.site-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.site-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty {
  min-height: 140px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.result-tray {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: grid;
  grid-template-columns: 140px auto auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  max-height: 230px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  transition: width .18s ease, max-height .18s ease, background .18s ease;
}

.result-tray.collapsed {
  right: auto;
  width: min(360px, calc(100vw - 32px));
  grid-template-columns: minmax(0, 1fr) auto;
  max-height: 76px;
}

.result-tray.collapsed .filters,
.result-tray.collapsed .lead-list {
  display: none;
}

.tray-toggle {
  min-height: 34px;
  padding: 0 12px;
  justify-self: end;
}

.tray-head {
  display: grid;
  gap: 2px;
}

.tray-head strong {
  font-size: 18px;
}

.tray-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-button {
  min-height: 32px;
  font-size: 13px;
  padding: 0 10px;
}

.filter-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.lead-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.lead-item {
  flex: 0 0 228px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 6px;
  cursor: pointer;
  max-height: 172px;
  overflow: hidden;
}

.lead-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(38, 116, 93, .13);
}

.lead-title {
  display: grid;
  gap: 6px;
}

.lead-title strong {
  font-size: 14px;
  line-height: 1.25;
}

.badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.lead-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.manual-panel {
  position: absolute;
  right: 16px;
  bottom: 110px;
  z-index: 30;
  width: 320px;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 108px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .map-app {
    min-height: 100vh;
  }

  .floating-header {
    position: fixed;
  }

  .search-panel {
    top: 86px;
    width: min(560px, calc(100vw - 32px));
    grid-template-columns: 72px 1fr 86px;
  }

  .search-panel:not(.expanded) .checkline,
  .search-panel:not(.expanded) #randomIndustryButton {
    display: none;
  }

  .search-panel.expanded {
    grid-template-columns: 1fr 1fr;
  }

  .lead-drawer {
    position: fixed;
    top: 144px;
    bottom: 92px;
  }

  .result-tray {
    position: fixed;
    grid-template-columns: 1fr auto;
  }

  .result-tray:not(.collapsed) {
    grid-template-columns: 1fr auto;
  }

  .result-tray:not(.collapsed) .filters,
  .result-tray:not(.collapsed) .lead-list {
    grid-column: 1 / -1;
  }

  .quick-actions,
  .secondary-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .floating-header {
    flex-direction: column;
  }

  .search-panel {
    top: 118px;
    grid-template-columns: 72px 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .search-panel.expanded .wide {
    grid-column: 1 / -1;
  }

  .search-panel:not(.expanded) label:has(select) {
    display: none;
  }

  .lead-drawer {
    top: 184px;
    bottom: 92px;
  }
}
