:root {
  color-scheme: light;
  --ink: #172234;
  --muted: #64748b;
  --line: #dbe4ec;
  --surface: #ffffff;
  --surface-soft: #f6f9fc;
  --navy: #12365a;
  --blue: #1675d1;
  --blue-dark: #0e5ba7;
  --cyan: #00a8c8;
  --orange: #f07630;
  --green: #138a62;
  --red: #c33b3b;
  --shadow: 0 12px 30px rgb(25 50 75 / 10%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #eef3f7;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="checkbox"],
input[type="file"] {
  cursor: pointer;
}

.app-header {
  height: 68px;
  padding: 10px 22px;
  display: grid;
  grid-template-columns: max-content minmax(240px, 1fr) max-content;
  align-items: center;
  gap: 18px;
  color: white;
  background: linear-gradient(112deg, #102c4b 0%, #174d76 62%, #117a87 100%);
  box-shadow: 0 4px 18px rgb(4 28 50 / 24%);
  position: relative;
  z-index: 1001;
}

.header-brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: #aee7ef;
  font-size: 12px;
  letter-spacing: .18em;
  font-weight: 700;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: .02em;
}

#versionBadge {
  margin-left: 8px;
  padding: 3px 8px;
  border: 1px solid rgb(255 255 255 / 36%);
  border-radius: 999px;
  color: #d9f7fb;
  font-size: 13px;
  font-weight: 600;
  vertical-align: middle;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgb(255 255 255 / 10%);
  font-size: 14px;
}

.header-error {
  width: min(100%, 620px);
  max-height: 50px;
  justify-self: center;
  overflow-y: auto;
  padding: 8px 12px;
  border: 1px solid #ffb8b8;
  border-radius: 8px;
  color: #7d1e1e;
  background: #fff1f1;
  box-shadow: 0 4px 14px rgb(48 8 8 / 18%);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  white-space: pre-line;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f4bd55;
  box-shadow: 0 0 0 3px rgb(244 189 85 / 20%);
}

.header-status.is-ready .status-dot {
  background: #57dda9;
  box-shadow: 0 0 0 3px rgb(87 221 169 / 20%);
}

.workspace {
  height: calc(100% - 68px);
  display: grid;
  grid-template-columns: minmax(350px, 420px) 1fr;
}

.control-panel {
  overflow-y: auto;
  padding: 10px;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.panel-section {
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgb(25 50 75 / 5%);
}

.step-section {
  border-left: 4px solid #aebdca;
}

.step-section.is-active {
  border-left-color: var(--blue);
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.step-number {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: white;
  background: var(--navy);
  font-size: 15px;
  font-weight: 800;
}

.section-heading h2,
.result-title h2 {
  margin: 0;
  font-size: 17px;
}

.section-heading p,
.result-title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.file-drop {
  min-height: 58px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  grid-template-areas:
    "icon title"
    "icon help"
    "names names";
  align-items: center;
  column-gap: 8px;
  border: 1.5px dashed #9bb3c8;
  border-radius: 10px;
  background: #f7fbff;
  text-align: left;
  transition: border-color .15s, background .15s;
}

.file-drop:hover,
.file-drop.is-dragging {
  border-color: var(--blue);
  background: #edf7ff;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop-icon {
  grid-area: icon;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  background: var(--blue);
  font-size: 23px;
  line-height: 1;
}

.file-drop-title {
  grid-area: title;
  font-size: 15px;
  font-weight: 700;
}

.file-drop-help,
.field-note {
  color: var(--muted);
  font-size: 12.5px;
}

.file-drop-help {
  grid-area: help;
}

.file-names {
  grid-area: names;
  max-width: 100%;
  margin-top: 2px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.field-row {
  margin-top: 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.field-row label,
fieldset legend {
  color: #42556a;
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid #bdcad6;
  border-radius: 7px;
  color: var(--ink);
  background: white;
  outline: none;
}

select:focus,
input[type="text"]:focus,
.button:focus-visible,
.map-button:focus-visible,
summary:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(22 117 209 / 17%);
}

.inline-field {
  margin-top: 4px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
}

.field-note {
  margin: 3px 0 6px;
}

.two-columns {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 8px;
}

fieldset {
  min-width: 0;
  margin: 8px 0 0;
  padding: 0;
  border: 0;
}

fieldset legend {
  margin-bottom: 4px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px 6px;
}

.check-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.check-grid label,
.advanced-options label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  color: #33465a;
  font-size: 12.5px;
  line-height: 1.25;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--blue);
  flex: 0 0 auto;
}

.advanced-options {
  margin-top: 7px;
  padding: 6px 8px 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.advanced-options summary {
  margin-bottom: 5px;
  color: #3f556b;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.button {
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  transition: transform .1s, box-shadow .15s, background .15s;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.button.full {
  width: 100%;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.button.primary {
  color: white;
  background: var(--blue);
  box-shadow: 0 5px 12px rgb(22 117 209 / 20%);
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button.secondary {
  color: var(--blue-dark);
  border-color: #9cc3e8;
  background: #f3f9ff;
}

.button.accent {
  color: white;
  background: linear-gradient(100deg, #ea6d2b, #e94f3c);
  box-shadow: 0 5px 14px rgb(226 81 48 / 23%);
}

.button.download {
  color: white;
  background: var(--green);
}

.button.text {
  color: var(--blue-dark);
  border-color: var(--line);
  background: white;
}

.inspection-card {
  margin-top: 7px;
  padding: 8px;
  border: 1px solid #a9dac9;
  border-radius: 9px;
  background: #f1fbf7;
}

.inspection-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #116a4e;
  font-size: 14px;
}

.inspection-check,
.result-check {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-weight: 800;
}

.inspection-card dl {
  margin: 6px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
}

.inspection-card dl div {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 5px;
}

.inspection-card dl div:last-child {
  grid-column: 1 / -1;
}

.inspection-card dt {
  color: var(--muted);
  font-size: 12.5px;
}

.inspection-card dd {
  margin: 0;
  color: #304257;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.confirmation-help {
  margin: 5px 0 0;
  padding-top: 5px;
  border-top: 1px solid #cce8de;
  color: #315e50;
  font-size: 12.5px;
  line-height: 1.35;
}

.notice {
  margin-top: 10px;
  padding: 10px 11px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

.notice.warning {
  color: #80510b;
  border: 1px solid #efd08f;
  background: #fff8e8;
}

.notice.error {
  color: #8b2727;
  border: 1px solid #e8abab;
  background: #fff1f1;
}

.result-section {
  border-color: #9cd5bf;
  background: #f9fffc;
}

.result-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.grid-counts {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.count-chip {
  padding: 5px 8px;
  border-radius: 999px;
  color: #195b74;
  background: #e9f7fb;
  font-size: 12.5px;
  font-weight: 700;
}

.process-log {
  max-height: 240px;
  margin: 9px 0 0;
  padding: 10px;
  overflow: auto;
  border-radius: 7px;
  color: #dce9f4;
  background: #172534;
  font: 10.5px/1.55 Consolas, monospace;
  white-space: pre-wrap;
}

.map-shell {
  position: relative;
  min-width: 0;
  background: #d9e2e9;
}

#map {
  width: 100%;
  height: 100%;
  background: #d9e2e9;
}

.map-toolbar {
  position: absolute;
  z-index: 800;
  top: 12px;
  left: 50px;
  display: grid;
  grid-template-rows: 32px 32px;
  gap: 4px;
}

.map-button {
  width: 74px;
  height: 32px;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid #aebdca;
  border-radius: 6px;
  color: #314559;
  background: rgb(255 255 255 / 94%);
  box-shadow: 0 2px 8px rgb(21 46 68 / 15%);
  font-size: 13px;
  font-weight: 700;
}

.leaflet-control-zoom a,
.leaflet-touch .leaflet-control-zoom a {
  width: 32px;
  height: 32px;
  line-height: 32px;
}

.map-drop-guide {
  position: absolute;
  z-index: 790;
  inset: 10px;
  display: none;
  place-items: center;
  align-content: center;
  gap: 7px;
  border: 3px dashed #1675d1;
  border-radius: 14px;
  color: #0d4f88;
  background: rgb(231 245 255 / 88%);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 75%);
  pointer-events: none;
  text-align: center;
}

.map-drop-guide span {
  color: #49677f;
  font-size: 13px;
}

.map-drop-guide .map-drop-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: white;
  background: var(--blue);
  font-size: 32px;
  line-height: 1;
}

.map-shell.is-file-dragging .map-drop-guide {
  display: grid;
}

.map-legend {
  position: absolute;
  z-index: 800;
  left: 12px;
  bottom: 22px;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 12.5px;
  max-width: calc(100% - 24px);
}

.legend-item,
.legend-layer-toggle,
.scale-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-layer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-layer-toggle {
  min-height: 27px;
  padding: 4px 8px;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.legend-layer-toggle.is-off {
  opacity: 0.42;
}

.scale-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
}

.scale-legend-shell {
  padding: 4px 9px;
  border-radius: 999px;
  overflow: hidden;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 3px solid;
}

.legend-line.input {
  border-color: #e53935;
}

.legend-line.grid {
  border-color: #009fc5;
}

.legend-label-mark {
  min-width: 18px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border-radius: 3px;
  color: #ffffff;
  background: rgb(10 72 98 / 88%);
  font-size: 11px;
  font-style: normal;
  line-height: 1;
}

.map-empty {
  position: absolute;
  z-index: 700;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(390px, 76%);
  padding: 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 1px solid rgb(139 158 174 / 45%);
  border-radius: 14px;
  color: #42566b;
  background: rgb(255 255 255 / 90%);
  box-shadow: var(--shadow);
  text-align: center;
  pointer-events: none;
}

.map-empty-icon {
  color: var(--blue);
  font-size: 40px;
  line-height: 1;
}

.map-empty span {
  color: var(--muted);
  font-size: 13px;
}

.grid-name-tooltip {
  padding: 1px 4px;
  border: 0;
  border-radius: 3px;
  color: white;
  background: rgb(10 72 98 / 88%);
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.grid-name-tooltip.scale-50000 { color: #fff; background: rgb(61 61 61 / 92%); }
.grid-name-tooltip.scale-5000 { color: #fff; background: rgb(123 97 168 / 92%); }
.grid-name-tooltip.scale-2500 { color: #102c4b; background: rgb(86 180 233 / 92%); }
.grid-name-tooltip.scale-1250 { color: #fff; background: rgb(166 118 29 / 92%); }
.grid-name-tooltip.scale-1000 { color: #fff; background: rgb(0 114 178 / 92%); }
.grid-name-tooltip.scale-500 { color: #172234; background: rgb(230 159 0 / 94%); }
.grid-name-tooltip.scale-250-std { color: #fff; background: rgb(0 158 115 / 92%); }
.grid-name-tooltip.scale-250-custom { color: #fff; background: rgb(213 94 0 / 92%); }
.grid-name-tooltip.scale-125 { color: #172234; background: rgb(204 121 167 / 94%); }

.grid-name-tooltip::before {
  display: none;
}

.leaflet-control-layers {
  max-height: none;
  overflow: hidden;
  font-family: inherit;
  font-size: 13px;
}

.draggable-layer-control {
  position: absolute;
  z-index: 1000;
  top: 12px;
  right: auto;
  left: 204px;
  margin: 0 !important;
}

.draggable-layer-control:not(.leaflet-control-layers-expanded),
.draggable-layer-control:not(.leaflet-control-layers-expanded) .leaflet-control-layers-toggle {
  width: 32px;
  height: 32px;
}

.draggable-layer-control:not(.leaflet-control-layers-expanded) .leaflet-control-layers-toggle {
  background-size: 20px 20px;
}

.draggable-layer-control.leaflet-control-layers-expanded {
  min-width: 250px;
}

.leaflet-control-layers-expanded {
  padding: 0 11px 9px;
  border-radius: 8px;
}

.layer-control-drag-handle {
  margin: 0 -11px 8px;
  padding: 7px 8px 7px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: #274158;
  background: transparent;
  cursor: move;
  font-weight: 700;
  user-select: none;
  touch-action: none;
}

.layer-control-collapse {
  width: 25px;
  height: 25px;
  padding: 0;
  border: 1px solid #b8c7d4;
  border-radius: 5px;
  color: #314559;
  background: #fff;
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
}

.draggable-layer-control.is-dragging {
  box-shadow: 0 10px 28px rgb(20 46 68 / 28%);
}

.draggable-layer-control.is-dragging .leaflet-control-layers-list {
  display: block;
}

.busy-overlay {
  position: fixed;
  z-index: 3000;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(12 28 43 / 42%);
  backdrop-filter: blur(2px);
}

.busy-card {
  min-width: 260px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  border-radius: 13px;
  background: white;
  box-shadow: 0 20px 55px rgb(0 0 0 / 25%);
}

.busy-card span {
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin-bottom: 4px;
  border: 4px solid #dfe9f1;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.is-hidden {
  display: none !important;
}

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

@media (max-width: 850px) {
  html,
  body {
    overflow: auto;
  }

  .app-header {
    height: auto;
    min-height: 64px;
    padding: 9px 14px;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .header-status {
    display: none;
  }

  .header-error {
    width: 100%;
    max-height: none;
    justify-self: stretch;
  }

  .workspace {
    height: auto;
    display: flex;
    flex-direction: column;
  }

  .control-panel {
    overflow: visible;
    border-right: 0;
  }

  .map-shell {
    height: 70vh;
    min-height: 480px;
  }
}

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