:root {
  color-scheme: light;
  --ink: #172025;
  --muted: #647078;
  --paper: #fffef9;
  --canvas: #e8eee9;
  --line: #ccd5cf;
  --green: #0d6958;
  --green-soft: #dff2eb;
  --orange: #e46f3f;
  --orange-soft: #fff0e8;
  --blue: #1976a3;
  --red: #b43b3b;
  --yellow: #a66c00;
  --shadow: 0 12px 32px rgba(21, 49, 42, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(228, 111, 63, 0.12), transparent 32rem),
    linear-gradient(145deg, #edf3ee, #f8f1e9);
  font-family:
    Inter, "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", sans-serif;
}

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

button,
.button {
  min-height: 34px;
  padding: 7px 13px;
  color: white;
  background: var(--green);
  border: 1px solid var(--green);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: 120ms ease;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button.secondary,
.button.secondary {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
}

button.danger {
  background: transparent;
  border-color: #dfaaaa;
  color: var(--red);
}

button.small {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.app-shell {
  min-height: 100vh;
  padding: 12px;
}

.app-header,
.mode-bar,
.view-panel,
.card {
  background: rgba(255, 254, 249, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 14px 18px;
  border-radius: 14px 14px 0 0;
}

.brand h1,
.card h2,
.view-panel h2 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.25rem, 2.3vw, 1.8rem);
  letter-spacing: -0.03em;
}

.brand__eyebrow,
.panel-kicker {
  display: block;
  color: var(--orange);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control {
  display: grid;
  gap: 4px;
}

.control span,
form label > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
}

textarea {
  resize: vertical;
}

.transform-pill {
  min-height: 34px;
  padding: 7px 11px;
  background: var(--green-soft);
  border: 1px solid #a7d5c6;
  border-radius: 999px;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 800;
}

.mode-bar {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 0;
  border-radius: 0 0 14px 14px;
}

.mode-bar button[data-mode] {
  color: var(--ink);
  background: transparent;
  border-color: transparent;
}

.mode-bar button[data-mode].is-active {
  color: var(--green);
  background: var(--green-soft);
  border-color: #9ccfbd;
}

.mode-bar__label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.mode-bar__spacer {
  flex: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  margin-top: 12px;
}

.safety-banner {
  margin-top: 12px;
  padding: 14px 18px;
  color: #721f1f;
  background: #ffe7e7;
  border: 2px solid var(--red);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-weight: 800;
  line-height: 1.55;
}

.views {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-self: start;
  height: max(680px, calc(100vh - 194px));
  min-height: 680px;
  position: sticky;
  top: 12px;
}

.view-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
  border-radius: 14px;
}

.view-panel > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.view-panel h2,
.card h2 {
  font-size: 1rem;
}

.view-panel > header > span,
.view-panel > footer {
  color: var(--muted);
  font-size: 0.72rem;
}

.view-panel > footer {
  min-height: 32px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}

.canvas-stage,
#map {
  min-height: 600px;
}

.canvas-stage {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #dfe6e0 25%, transparent 25%),
    linear-gradient(-45deg, #dfe6e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe6e0 75%),
    linear-gradient(-45deg, transparent 75%, #dfe6e0 75%);
  background-color: var(--canvas);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

#imageCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  outline: none;
}

#imageCanvas.is-panning {
  cursor: grabbing;
}

#imageCanvas:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(13, 105, 88, 0.7);
}

.view-help {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.68rem;
  pointer-events: none;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  padding: 13px;
  border-radius: 12px;
}

.card-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  margin-bottom: 10px;
}

.status-dot {
  width: 11px;
  height: 11px;
  margin-top: 5px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--green-soft);
}

.status-dot.is-warning {
  background: var(--yellow);
  box-shadow: 0 0 0 4px #fff0c9;
}

.status-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

.candidate-box {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  padding: 9px;
  background: var(--orange-soft);
  border: 1px solid #f0c5b0;
  border-radius: 8px;
  font-size: 0.78rem;
}

.coordinate-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.coordinate-pair div {
  min-width: 0;
  padding: 8px;
  background: #f1f5f2;
  border-radius: 8px;
}

.coordinate-pair dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.coordinate-pair dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
}

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

form label {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.button-row {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
}

.validation-list {
  display: grid;
  gap: 6px;
}

.validation-item {
  padding: 7px 8px;
  border-left: 3px solid var(--green);
  background: #f0f6f3;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1.45;
}

.validation-item.warning {
  border-color: var(--yellow);
  background: #fff7df;
}

.validation-item.error {
  border-color: var(--red);
  background: #fff0f0;
}

.result-box {
  min-height: 54px;
  padding: 9px;
  color: var(--muted);
  background: #f1f5f2;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-line;
}

.consistency-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.anchor-list-card {
  min-height: 220px;
}

.table-wrap {
  max-height: 330px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.71rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px;
  text-align: left;
  background: #edf3ef;
}

td {
  padding: 7px;
  border-top: 1px solid #e5ebe7;
  vertical-align: top;
}

tr[data-anchor-id] {
  cursor: pointer;
}

tr[data-anchor-id]:hover,
tr[data-anchor-id].is-selected {
  background: var(--green-soft);
}

.confidence {
  display: inline-block;
  padding: 2px 5px;
  border-radius: 999px;
  font-weight: 800;
}

.confidence.high {
  color: #0a604f;
  background: #d6f2e7;
}

.confidence.medium {
  color: #8a5700;
  background: #fff0c9;
}

.confidence.low {
  color: #933636;
  background: #ffe0e0;
}

.muted {
  color: var(--muted);
  font-size: 0.75rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 13px;
  color: white;
  background: rgba(13, 105, 88, 0.96);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: rgba(180, 59, 59, 0.96);
}

.leaflet-tooltip.anchor-tooltip {
  padding: 2px 5px;
  font-size: 0.67rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 4px;
  font-weight: 750;
}

.check-row input {
  width: auto;
}

.validation-ok,
.validation-warn,
.validation-error {
  padding: 7px 8px;
  border-left: 3px solid var(--green);
  background: #f0f6f3;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1.45;
}

.validation-warn {
  border-color: var(--yellow);
  background: #fff7df;
}

.validation-error {
  border-color: var(--red);
  background: #fff0f0;
}

.warning-text {
  color: #9a4d00;
  font-weight: 700;
}

.frame-marker-wrap {
  background: transparent;
  border: 0;
}

.frame-marker {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  box-sizing: border-box;
  color: white;
  background: var(--frame-color);
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  font: 800 11px/1 system-ui, sans-serif;
}

.frame-marker.is-selected {
  outline: 4px solid rgba(17, 24, 39, 0.38);
}

.frame-center {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #0d6958;
  background: white;
  border: 2px solid #0d6958;
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  font-weight: 900;
  cursor: move;
}

#frameValidation {
  margin: 9px 0;
}

.usage-mode-switch {
  display: flex;
  gap: 5px;
  align-items: center;
  margin: 0 8px 0 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.usage-mode-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.usage-mode-switch label {
  position: relative;
  cursor: pointer;
}

.usage-mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.usage-mode-switch span {
  display: block;
  padding: 6px 9px;
  color: var(--muted);
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 800;
}

.usage-mode-switch input:checked + span {
  color: var(--green);
  background: var(--green-soft);
  box-shadow: inset 0 0 0 1px #9ccfbd;
}

.usage-mode-switch input:focus-visible + span {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.navigation-step {
  margin: -2px 0 10px;
  color: var(--orange);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.navigation-goal {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.navigation-goal > span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.navigation-details {
  display: grid;
  gap: 6px;
  margin: 8px 0 10px;
}

.navigation-details > div {
  padding: 7px 8px;
  color: #3f4c51;
  background: #f1f5f2;
  border-radius: 7px;
  font-size: 0.75rem;
  line-height: 1.5;
}

.navigation-details .navigation-alert {
  color: #855500;
  background: #fff5d6;
  border-left: 3px solid #d79a13;
}

.navigation-details .navigation-complete {
  color: #0a604f;
  background: var(--green-soft);
  border-left: 3px solid var(--green);
}

.quadrant-grid {
  display: grid;
  grid-template-areas: "top-left top-right" "bottom-left bottom-right";
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 10px 0;
}

.quadrant-top-right { grid-area: top-right; }
.quadrant-bottom-right { grid-area: bottom-right; }
.quadrant-bottom-left { grid-area: bottom-left; }
.quadrant-top-left { grid-area: top-left; }

.quadrant-item {
  display: grid;
  gap: 2px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.7rem;
}

.quadrant-item span {
  color: var(--muted);
}

.quadrant-item.is-covered {
  color: var(--green);
  background: var(--green-soft);
  border-color: #9ccfbd;
}

.quadrant-item.is-covered strong::before {
  content: "✓ ";
}

.quadrant-item.is-missing {
  color: #8a5700;
  background: #fff7df;
  border-color: #e8ca73;
}

.quadrant-item.is-unavailable {
  color: var(--muted);
  background: #eef1ef;
  border-color: #c7ceca;
}

.quadrant-item small {
  line-height: 1.35;
}

.quadrant-availability {
  min-height: 0;
  margin-top: 4px;
  padding: 4px 6px;
  color: #4f5d62;
  background: white;
  border-color: #bdc7c1;
  font-size: 0.64rem;
  line-height: 1.3;
}

.coverage-legend {
  display: grid;
  gap: 4px;
  margin: 10px 0;
  padding: 8px;
  color: var(--muted);
  background: #f7f7f3;
  border-radius: 7px;
  font-size: 0.7rem;
}

.coverage-legend span {
  display: flex;
  gap: 6px;
  align-items: center;
}

.legend-swatch {
  width: 20px;
  height: 8px;
  border-radius: 2px;
}

.legend-swatch.correction { background: rgba(53, 173, 114, 0.55); border: 1px solid #178a57; }
.legend-swatch.base { background: rgba(227, 173, 36, 0.5); border: 1px solid #c99100; }
.legend-swatch.extrapolation { background: rgba(180, 35, 24, 0.18); border: 1px dashed #b42318; }

.navigation-actions {
  margin-top: 10px;
}

.navigation-overrides {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e5ebe7;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .inspector {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .views {
    height: max(680px, calc(100vh - 194px));
    position: static;
  }

  .anchor-list-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .views,
  .inspector {
    grid-template-columns: 1fr;
  }

  .views {
    min-height: auto;
  }

  .canvas-stage,
  #map {
    min-height: 480px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 6px;
  }

  .toolbar,
  .field-grid,
  .coordinate-pair {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .mode-bar__spacer {
    display: none;
  }

  .canvas-stage,
  #map {
    min-height: 400px;
  }
}

.survey-import-preview { overflow-x: auto; margin: 0.7rem 0; }
.survey-import-preview table { min-width: 760px; }
.survey-import-preview select { min-width: 8rem; }
.survey-import-preview .is-conflict { background: #fff0f0; }
.survey-import-preview .is-warning { background: #fff8dc; }
