:root {
  --md-primary: #1677ff;
  --md-primary-hover: #4096ff;
  --md-primary-soft: #e6f4ff;
  --md-text: #1f2329;
  --md-muted: #8c8c8c;
  --md-border: #e0e0e0;
  --md-surface: #fff;
  --md-radius: 8px;
  --md-radius-sm: 6px;
  --md-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --md-gap: 20px;
  --md-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--md-font);
  color: var(--md-text);
}

.md-map {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.md-overlay {
  position: absolute;
  z-index: 10000;
}

.md-overlay--top-left {
  left: var(--md-gap);
  top: var(--md-gap);
}

.md-toolbar {
  left: var(--md-gap);
  top: var(--md-gap);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.md-top-right {
  right: var(--md-gap);
  top: var(--md-gap);
}

.md-card {
  box-sizing: border-box;
  padding: 16px 18px;
  border-radius: var(--md-radius);
  background: var(--md-surface);
  box-shadow: var(--md-shadow);
}

.md-card h1,
.md-card h2,
.md-card h3,
.md-card h4 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.md-card p {
  margin: 6px 0 0;
  font-size: 14px;
}

.md-card p:first-child {
  margin-top: 0;
}

.md-info {
  margin-top: 10px;
}

.md-panel {
  left: var(--md-gap);
  top: 64px;
  width: 320px;
}

.md-hint {
  margin-top: 6px;
  color: #999;
  font-size: 12px;
}

.md-data-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.md-data-list label {
  display: block;
  margin-bottom: 4px;
  color: var(--md-muted);
  font-size: 12px;
}

.md-value {
  color: var(--md-text);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-all;
}

.md-value--coord {
  color: var(--md-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
}

.md-control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.md-btn {
  box-sizing: border-box;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--md-radius-sm);
  background: #fff;
  color: #333;
  font: inherit;
  font-size: 14px;
  line-height: 34px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: all 0.2s;
}

.md-btn:hover {
  background: #f0f6ff;
  color: var(--md-primary);
}

.md-btn:focus {
  outline: none;
}

.md-btn--primary {
  background: var(--md-primary);
  color: #fff;
}

.md-btn--primary:hover {
  background: var(--md-primary-hover);
  color: #fff;
}

.md-field {
  box-sizing: border-box;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius-sm);
  background: #fff;
  color: var(--md-text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
}

.md-field:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}

.md-field::placeholder {
  color: #bbb;
}

.md-search .md-field {
  width: 200px;
}

.md-map-type {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  padding: 4px;
  border-radius: var(--md-radius);
  background: #fff;
  box-shadow: var(--md-shadow);
}

.md-map-type-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.md-layers-panel {
  background: #fff;
  border-radius: var(--md-radius);
  box-shadow: var(--md-shadow);
  padding: 10px;
  width: 316px;
  max-height: min(70vh, 640px);
  overflow-y: auto;
}

.md-layers-title {
  margin: 4px 2px 8px;
  font-size: 12px;
  color: #999;
}

.md-layers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.md-layer-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 0 6px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.15s;
}

.md-layer-item:hover {
  border-color: var(--md-primary);
}

.md-layer-item.is-active {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 1px var(--md-primary);
}

.md-layer-item.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.md-layer-thumb {
  display: block;
  width: 100%;
  height: 56px;
  object-fit: cover;
}

.md-layer-thumb--vector {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0fe, #d3e3fd);
  color: var(--md-primary);
  font-size: 12px;
}

.md-layer-name {
  font-size: 12px;
  line-height: 1.4;
  color: #333;
  text-align: center;
  padding: 0 4px;
}

.md-overlay-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 6px;
  padding: 8px 10px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  transition: all 0.15s;
}

.md-overlay-item:hover {
  border-color: var(--md-primary);
  color: var(--md-primary);
}

.md-overlay-item.is-on {
  border-color: var(--md-primary);
  background: var(--md-primary-soft);
  color: var(--md-primary);
}

.md-overlay-state {
  font-size: 12px;
  color: #999;
}

.md-overlay-item.is-on .md-overlay-state {
  color: var(--md-primary);
}

.md-map-type .md-btn.is-disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.md-map-type .md-btn {
  height: 28px;
  line-height: 26px;
  background: transparent;
  color: #595959;
  box-shadow: none;
}

.md-map-type .md-btn:hover {
  background: #f0f6ff;
  color: var(--md-primary);
}

.md-map-type .md-btn.is-active {
  background: var(--md-primary-soft);
  color: var(--md-primary);
}

.md-toast {
  position: absolute;
  left: 50%;
  top: 24px;
  z-index: 10001;
  padding: 8px 16px;
  border-radius: var(--md-radius-sm);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: all 0.2s;
}

.md-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.md-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.md-layout__side {
  width: 380px;
  min-width: 380px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.md-layout__map {
  position: relative;
  flex: 1;
  height: 100%;
}

@media (max-width: 768px) {

  .md-toolbar {
    left: 12px;
    top: 12px;
    right: 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .md-toolbar::-webkit-scrollbar {
    display: none;
  }

  .md-top-right {
    right: 12px;
    top: 60px;
  }

  .md-map-type {
    max-width: calc(100vw - 24px);
  }

  .md-layers-panel {
    width: calc(100vw - 24px);
    max-width: 316px;
  }

  .md-layout {
    flex-direction: column;
  }

  .md-layout__side {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 55%;
  }
}

.leaflet-bottom.leaflet-left {
  display: flex;
  flex-direction: column;
}

.leaflet-control-scale {
  order: 1;
}

.leaflet-control-attribution {
  order: 2;
}

.md-legend-dialog {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 30, 50, 0.4);
}

.md-legend-dialog[hidden] {
  display: none;
}

.md-legend-dialog-card {
  display: flex;
  flex-direction: column;
  width: min(680px, 100%);
  height: min(78vh, 680px);
  padding: 14px 16px;
}

.md-legend-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.md-legend-tab {
  flex: 1;
  padding: 6px 0;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  background: #fff;
  color: var(--md-muted);
  font-size: 13px;
  cursor: pointer;
}

.md-legend-tab.is-active {
  border-color: var(--md-primary);
  background: #f0f6ff;
  color: var(--md-primary);
  font-weight: 600;
}

.md-legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.md-legend-close {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--md-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.md-legend-close:hover {
  background: #f0f6ff;
  color: var(--md-primary);
}

.md-legend-body {
  flex: 1;
  display: grid;
  gap: 8px;
  align-content: start;
  overflow-y: auto;
  padding-right: 4px;
}

.md-legend-section {
  margin-top: 2px;
  color: var(--md-muted);
  font-size: 12px;
}

.md-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.md-legend-item--empty {
  color: var(--md-muted);
  font-size: 12px;
}

.md-legend-swatch {
  flex: 0 0 24px;
  height: 12px;
}

.md-legend-swatch--base {
  background: linear-gradient(135deg, #d9e6c8 0 45%, #a9c8ec 45% 55%, #d9e6c8 55%);
  border: 1px solid var(--md-border);
  border-radius: 2px;
}

.md-legend-swatch--railway {
  height: 0;
  border-top: 3px dashed #4a4a4a;
}

.md-legend-swatch--trails {
  height: 0;
  border-top: 3px solid #e2332c;
}

.md-legend-swatch--seamark {
  background: #2f6fd6;
  border-radius: 3px;
}

.md-legend-swatch--hillshade {
  background: linear-gradient(90deg, #f5f5f5, #6b6b6b);
  border: 1px solid var(--md-border);
  border-radius: 2px;
}

.md-legend-swatch--marker {
  position: relative;
  height: 14px;
}

.md-legend-swatch--marker::after {
  content: "";
  position: absolute;
  top: 0;
  left: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50% 50% 50% 0;
  background: #e74c3c;
  transform: rotate(-45deg);
}

.md-legend-note {
  margin-bottom: 6px;
  color: var(--md-muted);
  font-size: 11px;
}

.md-legend-cat {
  margin-bottom: 4px;
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius-sm);
}

.md-legend-cat summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.md-legend-cat summary::-webkit-details-marker {
  display: none;
}

.md-legend-cat summary::after {
  content: "›";
  margin-left: auto;
  color: var(--md-muted);
  font-size: 14px;
  transform: rotate(90deg);
  transition: transform 0.15s;
}

.md-legend-cat[open] summary::after {
  transform: rotate(-90deg);
}

.md-legend-cat summary:hover {
  color: var(--md-primary);
}

.md-legend-cat-count {
  color: var(--md-muted);
  font-size: 11px;
  font-weight: normal;
}

.md-legend-cat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  padding: 4px 10px 10px;
}

.md-legend-cat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--md-text);
  font-size: 12px;
  line-height: 1.3;
}

.md-legend-cat-item > img {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;

}

.md-legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px 10px;
  padding: 2px 0 4px;
}

.md-legend-swatch-line {
  display: inline-block;
  flex: 0 0 24px;
  width: 24px;
  height: 0;
}

.md-legend-swatch-area {
  display: inline-block;
  flex: 0 0 24px;
  width: 24px;
  height: 12px;
  border: 1px solid var(--md-border);
  border-radius: 2px;
}

.md-legend-swatch-area--pattern {
  background-size: 12px 12px;
  background-repeat: repeat;
}

.md-legend-swatch-area--sample {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  overflow: hidden;
}

.md-legend-sample-img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.md-control-panel {
  left: var(--md-gap);
  top: 64px;
  width: auto;
  min-width: 0;
  padding: 12px 14px;
}

.md-control-panel h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.md-control-panel .md-control-group {
  gap: 6px;
  margin-bottom: 6px;
}

.md-control-panel .md-control-group:last-of-type {
  margin-bottom: 0;
}

.md-control-panel .md-btn {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  line-height: 28px;
}
