:root {
  --bg: #e8efe6;
  --panel: #f7faf6;
  --ink: #1c2a1f;
  --muted: #5a6b5e;
  --line: #c5d2c4;
  --accent: #2f6b3a;
  --accent-soft: #d7ead9;
  --warn: #8a4b12;
  --danger: #8b2e2e;
  --field: #3d7a4a;
  --field-sel: #1f5a2c;
  --merged: #2a5f8a;
  --merged-sel: #174066;
  --dim: #9aab9c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(120deg, #d9e8d4 0%, #eef4ec 55%, #dce8e2 100%);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-text p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.session-info {
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.login-page {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: min(360px, calc(100vw - 2rem));
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(28, 42, 31, 0.08);
}

.login-card .brand {
  margin-bottom: 1.25rem;
}

.login-card label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-card label input {
  margin-top: 0.3rem;
}

.login-card button {
  width: 100%;
  margin-top: 0.25rem;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.sidebar {
  overflow: auto;
  padding: 1rem;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#map {
  min-height: 420px;
  background: #cfd9cc;
}

.map-shell {
  position: relative;
  min-height: 420px;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.map-shell #map {
  flex: 1;
  min-height: 420px;
  height: 100%;
}

.vertex-info {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1000;
  min-width: 11.5rem;
  max-width: min(18rem, calc(100% - 24px));
  padding: 0.55rem 0.7rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(28, 36, 30, 0.12);
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink);
  pointer-events: none;
}

.vertex-info-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.vertex-info-coords {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: pre-line;
}

section h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hint {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.mode-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 0.5rem;
  border: 1px solid var(--line);
  background: #fff;
}

.mode-btn {
  flex: 1;
  border: none;
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  padding: 0.5rem 0.65rem;
}

.mode-btn + .mode-btn {
  border-left: 1px solid var(--line);
}

.mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.mode-btn:disabled {
  opacity: 0.45;
}

.map-mode-actions {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.4rem;
  margin: 0 -1rem 0.65rem;
  padding: 0.55rem 1rem;
  background: color-mix(in srgb, var(--panel) 92%, #fff);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 12px -10px rgba(28, 42, 31, 0.45);
}

.map-mode-actions button {
  flex: 1 1 calc(50% - 0.4rem);
  min-width: 0;
  white-space: normal;
  line-height: 1.2;
  padding: 0.4rem 0.5rem;
  text-align: center;
}

button.ghost.active-tool {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.point-list {
  max-height: 160px;
  overflow: auto;
  margin-top: 0.35rem;
}

.point-list li {
  cursor: default;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
}

.point-list li.selected {
  border-color: var(--danger);
  background: #f8e8e8;
}

.geometry-editor {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.geometry-editor .geometry-title {
  margin: 0;
  flex: 1;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.geometry-json {
  width: 100%;
  min-height: 220px;
  max-height: 360px;
  resize: vertical;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  background: #1c2a1f;
  color: #e8efe6;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  tab-size: 2;
}

.geometry-json:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.geometry-json.point-flash {
  outline: 2px solid #e85d5d;
  outline-offset: 1px;
}

.vertex-handle-wrap {
  background: transparent !important;
  border: none !important;
}

.vertex-handle {
  width: var(--vh-size, 10px);
  height: var(--vh-size, 10px);
  box-sizing: border-box;
  border: 2px solid var(--vh-border, #8a4b12);
  background: var(--vh-fill, #fff);
  pointer-events: none;
}

.vertex-handle.vertex-circle {
  border-radius: 50%;
}

.vertex-handle.vertex-diamond {
  border-radius: 1px;
  transform: rotate(45deg);
}

.vertex-marker {
  background: #fff;
  border: 2px solid #8a4b12;
  border-radius: 50%;
}

.vertex-marker.selected {
  background: #e85d5d;
  border-color: #8b2e2e;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.item-list li {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.item-list li:hover {
  border-color: #9bb59a;
}

.item-list li.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.item-list li.dimmed {
  opacity: 0.55;
  cursor: default;
}

.item-list .meta {
  flex: 1;
  min-width: 0;
}

.item-list .title {
  font-weight: 600;
  font-size: 0.92rem;
}

.item-list .badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6b3a12;
  background: #f0e2cc;
  border: 1px solid #c4a574;
  padding: 0.05rem 0.28rem;
  margin-right: 0.2rem;
  vertical-align: 0.1em;
}

.item-list .sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.item-list label.export-check {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  width: 100%;
  cursor: pointer;
}

.row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  align-items: center;
}

.row.compact {
  flex-direction: column;
  align-items: stretch;
}

.row.compact label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

button,
.file-btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

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

button.ghost,
.file-btn {
  background: #fff;
  color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: #fff;
}

.check {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.status {
  min-height: 1.2em;
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--accent);
}

.leaflet-container {
  font: inherit;
}

.leaflet-container .leaflet-interactive:focus {
  outline: none;
}

.leaflet-container path.leaflet-interactive:focus {
  outline: none;
}

.leaflet-control-layers {
  border: 1px solid var(--line) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: var(--panel) !important;
}

.leaflet-control-layers-expanded {
  padding: 0.45rem 0.65rem 0.5rem !important;
  font: inherit !important;
  color: var(--ink);
}

.leaflet-control-layers-base label,
.leaflet-control-layers-overlays label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.15rem 0;
  font-size: 0.85rem;
  cursor: pointer;
}

.import-picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  max-width: min(520px, calc(100vw - 2rem));
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(28, 42, 31, 0.18);
}

.import-picker::backdrop {
  background: rgba(28, 42, 31, 0.35);
}

.import-picker-panel {
  display: flex;
  flex-direction: column;
  max-height: min(80vh, 640px);
  margin: 0;
}

.import-picker-head,
.import-picker-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

.import-picker-foot {
  align-items: center;
  border-bottom: none;
  border-top: 1px solid var(--line);
}

.import-picker-foot-left {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.import-picker-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.import-picker-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
}

.import-picker-toolbar input[type='search'] {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.import-picker-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 0.35rem 0.5rem;
  max-height: none;
}

.import-picker-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem 0.4rem;
  cursor: pointer;
}

.import-picker-list li:hover {
  background: var(--accent-soft);
}

.import-picker-list li.hidden {
  display: none;
}

.import-picker-list input[type='checkbox'] {
  margin-top: 0.2rem;
}

.name-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  max-width: min(400px, calc(100vw - 2rem));
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(28, 42, 31, 0.18);
}

.name-dialog::backdrop {
  background: rgba(28, 42, 31, 0.35);
}

.name-dialog-panel {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.name-dialog-head,
.name-dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
}

.name-dialog-head {
  border-bottom: 1px solid var(--line);
}

.name-dialog-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.name-dialog-body {
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.name-dialog-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.name-dialog-label input {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.name-dialog-foot {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 48vh auto;
  }

  .map-shell {
    order: -1;
    min-height: 48vh;
  }

  .map-shell #map {
    min-height: 48vh;
  }

  .sidebar {
    border-right: none;
    border-top: 1px solid var(--line);
  }
}
