:root {
  --bg: #f1f6fc;
  --surface: #ffffff;
  --text: #17375e;
  --text-muted: #62748a;
  --border: #cad9ec;
  --accent: #003e91;
  --accent-dark: #002e70;
  --accent-mid: #2a63b2;
  --accent-light: #6794d7;
  --shadow: 0 10px 28px rgba(0, 62, 145, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;

  display: grid;
  grid-template-columns: clamp(390px, 31vw, 420px) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.site-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 16px;
  color: #fff;
  background: linear-gradient(115deg, var(--accent) 0%, var(--accent-mid) 66%, var(--accent-light) 100%);
  border-bottom: 2px solid #b9cdea;
}

.brand h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.25;
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand h1 a {
  color: inherit;
  text-decoration: none;
}

.brand h1::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: #fff;
  flex: 0 0 auto;
}

.header-tagline {
  margin: 1px 0 0 22px;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.85);
}

.dataset-info {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.88);
  text-align: right;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dataset-info time,
.dataset-info span {
  color: #fff;
  font-weight: 600;
}

#data-quality-summary {
  position: relative;
}

#data-quality-summary summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  color: #fff;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  user-select: none;
}

#data-quality-summary summary::-webkit-details-marker {
  display: none;
}

#data-quality-summary summary::after {
  content: " ▾";
  font-size: 0.72em;
}

.dq-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1200;
  margin: 0;
  min-width: min(280px, 86vw);
  padding: 12px 14px;
  display: grid;
  gap: 4px;
  list-style: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
}

.dq-list li {
  color: var(--text-muted);
}

.dq-list li time {
  color: var(--text);
  font-weight: 600;
}

.mobile-toolbar {
  display: none;
}

#sidebar {
  grid-area: sidebar;
  width: auto;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}

.search-section,
.starter-contacts,
.sector-section,
.results-section,
#filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px;
  min-width: 0;
}

h2 {
  margin: 0 0 4px;
  font-size: 0.86rem;
  line-height: 1.3;
}

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

input[type="search"],
input[type="text"],
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
}

input::placeholder {
  color: var(--text-muted);
}

input[type="search"]:focus-visible,
select:focus-visible {
  outline-offset: 0;
  border-color: var(--accent);
}

button {
  font: inherit;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.search-controls {
  display: flex;
  gap: 6px;
}

.search-controls input[type="search"] {
  min-width: 0;
  flex: 1;
}

.search-controls button {
  margin: 0;
  padding: 6px 10px;
  font-size: 0.8rem;
}

#clear-search,
#reset-filters {
  color: var(--accent);
  background: var(--surface);
}

#clear-search:hover,
#reset-filters:hover {
  color: #fff;
}

.starter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

#sector-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

[data-sector],
[data-preset-contact] {
  font-size: 0.69rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
}

[data-sector]:hover,
[data-preset-contact]:hover {
  color: var(--text);
  background: var(--bg);
  border-color: var(--accent);
}

[data-sector][aria-pressed="true"],
[data-preset-contact][aria-pressed="true"] {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

[data-sector][aria-pressed="true"]:hover,
[data-preset-contact][aria-pressed="true"]:hover {
  color: #fff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.result-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 5px;
}

.result-bar label {
  margin: 0;
}

.result-bar select {
  width: auto;
  padding: 5px 9px;
  font-size: 0.85rem;
}

#results-count {
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

#results {
  display: grid;
  gap: 4px;
}

.result-card {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.result-card:hover {
  border-color: var(--accent);
  box-shadow: 0 3px 10px rgba(0, 62, 145, 0.14);
}

.result-card.selected {
  border-color: var(--accent);
  background: #eef4fc;
  box-shadow: inset 3px 0 0 var(--accent), 0 3px 10px rgba(0, 62, 145, 0.16);
}

.result-card h3 {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.3;
}

.result-card p {
  margin: 1px 0 0;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 2px 3px 0 0;
  padding: 1px 6px;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.5;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}

.badge-accent {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.badge-warn {
  color: #7a4a08;
  background: #fdf3e3;
  border-color: #e0b26a;
}

.empty-state {
  padding: 22px 14px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

#pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

#pagination:empty {
  display: none;
}

#pagination button {
  min-width: 34px;
  padding: 4px 9px;
  font-size: 0.82rem;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

#pagination button:hover {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#pagination button[aria-current="page"] {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#advanced-filters {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

#advanced-filters > summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  border-radius: 10px;
  user-select: none;
}

#advanced-filters > summary:hover {
  color: var(--accent-dark);
}

#advanced-filters[open] > summary {
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.filter-logic {
  margin: 10px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

#filters fieldset {
  margin: 0 12px 10px;
  padding: 7px 9px 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#filters legend {
  flex-basis: 100%;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

#filters input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

#filters fieldset label {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

#filters fieldset label:hover {
  border-color: var(--accent);
}

#filters fieldset label:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

#filters fieldset label:has(input:checked) {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#filters .location-note,
#filters #reset-filters {
  margin: 0 12px 12px;
}

.location-note {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.logo-pin {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.logo-pin.japan {
  border-color: var(--accent);
}

.logo-pin.approximate {
  border-style: dashed;
}

.logo-pin.presence-unverified {
  filter: grayscale(0.8);
  opacity: 0.58;
}

.logo-pin.selected {
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 3px rgba(42, 99, 178, 0.4);
}

.logo-pin img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-fallback {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  user-select: none;
}

.company-cluster {
  display: grid;
  place-items: center;
  color: #fff;
  background: radial-gradient(circle at 32% 28%, var(--accent-light), var(--accent-mid) 58%, var(--accent));
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(27, 31, 36, 0.32);
  font-weight: 800;
}

.company-cluster span {
  line-height: 1;
}

.company-cluster.selected {
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 4px rgba(42, 99, 178, 0.35), 0 2px 8px rgba(27, 31, 36, 0.32);
}

.overlap-leg {
  stroke: var(--accent-mid);
}

main {
  grid-area: main;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.map-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.map-overlay > * {
  pointer-events: auto;
}

#search-area,
#show-all-area {
  display: block;
  width: auto;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

dialog#detail {
  position: fixed;
  top: 0;
  right: 0;
  bottom: auto;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  width: min(400px, 92vw);
  max-width: min(400px, 92vw);
  margin: 0;
  padding: 46px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
  background: var(--surface);
  color: var(--text);
  border: none;
  border-left: 4px solid var(--accent);
  border-radius: 0;
  box-shadow: var(--shadow);
}

dialog#detail::backdrop {
  background: rgba(23, 55, 94, 0.45);
}

#close-detail {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 4px 11px;
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--border);
}

#close-detail:hover {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.detail-actions button {
  width: 100%;
}

@media (max-width: 700px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "header"
      "toolbar"
      "content";
  }

  .site-header {
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 10px 14px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .header-tagline {
    display: none;
  }

  .dataset-info {
    text-align: left;
    font-size: 0.78rem;
  }

  .mobile-toolbar {
    grid-area: toolbar;
    position: sticky;
    top: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 62, 145, 0.08);
  }

  .mobile-tabs {
    display: flex;
    flex: 1;
    gap: 6px;
    min-width: 0;
  }

  .mobile-toolbar button {
    flex: 1;
    padding: 7px 10px;
    font-size: 0.88rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
  }

  .mobile-toolbar button[aria-selected="true"] {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
  }

  #mobile-filter-button {
    flex: 0 0 auto;
  }

  #mobile-filter-button[aria-expanded="true"] {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
  }

  #sidebar,
  main {
    grid-area: content;
    min-height: 0;
  }

  #sidebar {
    padding: 10px;
    gap: 8px;
    border-right: none;
  }

  .search-section,
  .starter-contacts,
  .sector-section,
  .results-section,
  #filters {
    padding: 10px;
    border-radius: 12px;
  }

  [data-sector],
  [data-preset-contact] {
    min-height: 36px;
    padding: 8px 13px;
    font-size: 0.8rem;
  }

  .result-card {
    gap: 9px;
    padding: 9px;
  }

  .result-card h3 {
    font-size: 0.92rem;
  }

  .result-card p {
    margin: 2px 0 0;
    font-size: 0.78rem;
  }

  .badge {
    margin: 3px 4px 0 0;
    padding: 1px 8px;
    font-size: 0.7rem;
  }

  .logo-pin {
    width: 40px;
    height: 40px;
  }

  body.mobile-view-map #sidebar {
    display: none;
  }

  body.mobile-view-list main {
    display: none;
  }

  dialog#detail {
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    padding: 52px 14px 14px;
    border-left: none;
    border-top: 4px solid var(--accent);
  }

  .map-overlay {
    top: 8px;
    right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
