:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --text: #18212b;
  --muted: #65717e;
  --border: #d8dee5;
  --border-strong: #bcc6d0;
  --blue: #1769e0;
  --blue-dark: #0d50b5;
  --normal: #168a67;
  --warning: #d89513;
  --abnormal: #d64545;
  --shadow: 0 8px 24px rgba(24, 33, 43, 0.14);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(23, 105, 224, 0.45);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 20;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 86px;
  padding: 18px 18px 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 750;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 21px;
  line-height: 1.25;
}

h2 {
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.3;
}

.sidebar-section {
  padding: 15px 18px;
  border-top: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-meta {
  color: var(--muted);
  font-size: 12px;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.connection-state::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca7b2;
  content: "";
}

.connection-state[data-state="loading"]::before {
  background: var(--warning);
}

.connection-state[data-state="ready"]::before {
  background: var(--normal);
}

.connection-state[data-state="error"]::before {
  background: var(--abnormal);
}

.field-label,
.compact-field > span,
.toolbar-field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.field-label:not(:first-of-type) {
  margin-top: 11px;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
}

input,
select {
  height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 188px;
  padding: 10px 11px;
  resize: vertical;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  tab-size: 2;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #96a4b2;
}

.input-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 7px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.threshold-settings {
  margin-top: 12px;
  padding: 10px 11px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.threshold-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.threshold-unit,
.threshold-help,
.threshold-field > span {
  color: var(--muted);
  font-size: 10px;
}

.threshold-help {
  margin: 10px 0 8px;
  line-height: 1.5;
}

.threshold-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.threshold-field > span {
  display: block;
  min-height: 28px;
  margin-bottom: 4px;
  line-height: 1.35;
}

.threshold-field input {
  height: 32px;
}

.threshold-reset {
  margin-top: 9px;
}

.text-button,
.icon-button,
.button,
.segmented-control button,
.segment-row {
  border: 0;
}

.text-button {
  padding: 2px 0;
  color: var(--blue);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}

.text-button:hover {
  color: var(--blue-dark);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  color: #344150;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
}

.icon-button:hover {
  color: var(--blue);
  background: #f0f5fc;
  border-color: #9ebce6;
}

.icon-button.subtle {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
  background: transparent;
  border-color: transparent;
}

.icon-button svg,
.button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.primary-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
  margin-top: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--blue);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  color: #344150;
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.secondary-button:hover {
  background: var(--surface-muted);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.operation-status {
  min-height: 18px;
  margin: 9px 0 -2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.operation-status.error {
  color: var(--abnormal);
}

.operation-status.success {
  color: var(--normal);
}

.stats-section {
  padding-top: 0;
  padding-bottom: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}

.stats-grid > div {
  min-width: 0;
  padding: 13px 6px 12px;
  text-align: center;
}

.stats-grid > div:not(:nth-child(3n + 1)) {
  border-left: 1px solid var(--border);
}

.stats-grid > div:nth-child(n + 4) {
  border-top: 1px solid var(--border);
}

.stats-grid dt {
  color: var(--muted);
  font-size: 10px;
}

.stats-grid dd {
  margin: 4px 0 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.status-filters label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 7px 5px;
  color: #3f4b58;
  background: var(--surface-muted);
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 11px;
}

.status-filters label:has(input:checked) {
  border-color: var(--border);
}

.status-filters input {
  width: 13px;
  height: 13px;
  margin: 0;
}

.status-filters strong {
  margin-left: auto;
  font-size: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
}

.status-dot.normal {
  background: var(--normal);
}

.status-dot.warning {
  background: var(--warning);
}

.status-dot.abnormal {
  background: var(--abnormal);
}

.segment-list {
  display: grid;
  gap: 3px;
}

.segment-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 38px;
  padding: 6px 7px;
  color: var(--text);
  background: transparent;
  border-radius: 5px;
  text-align: left;
}

.segment-row:hover,
.segment-row.active {
  background: #eef3f8;
}

.segment-swatch {
  width: 8px;
  height: 22px;
  border-radius: 2px;
}

.segment-name {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-summary {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.pace-segment-list {
  display: grid;
  gap: 8px;
}

.pace-empty {
  margin: 0;
}

.pace-segment-card {
  padding: 11px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.pace-segment-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 9px;
}

.pace-segment-card header strong,
.pace-segment-card header span {
  display: block;
}

.pace-segment-card header strong {
  font-size: 12px;
}

.pace-segment-card header div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
}

.pace-mode-badge {
  flex: 0 0 auto;
  padding: 4px 7px;
  color: var(--mode-color);
  background: color-mix(in srgb, var(--mode-color) 11%, white);
  border: 1px solid color-mix(in srgb, var(--mode-color) 28%, white);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
}

.pace-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 11px 0;
}

.pace-metrics-grid > div {
  min-width: 0;
}

.pace-metrics-grid dt {
  color: var(--muted);
  font-size: 9px;
}

.pace-metrics-grid dd {
  margin: 3px 0 0;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.confidence-row {
  display: grid;
  grid-template-columns: auto minmax(50px, 1fr);
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 9px;
}

.confidence-track {
  height: 5px;
  overflow: hidden;
  background: #dfe4e9;
  border-radius: 999px;
}

.confidence-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.map-stage {
  position: relative;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  background: #e6eaee;
}

.map-container {
  position: absolute;
  z-index: 0;
  inset: 0;
}

.map-toolbar {
  position: absolute;
  z-index: 10;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(188, 198, 208, 0.9);
  border-radius: 6px;
  box-shadow: 0 3px 14px rgba(24, 33, 43, 0.13);
}

.toolbar-field {
  width: 150px;
}

.toolbar-field > span {
  margin: 0 0 4px 2px;
}

.toolbar-field select {
  height: 34px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(54px, auto));
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
}

.segmented-control button {
  padding: 0 10px;
  color: #4a5664;
  background: var(--surface);
  border-right: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  color: #fff;
  background: #27394c;
}

.map-state {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 30px;
  color: #596675;
  background: #e9edf1;
  text-align: center;
}

.map-state[hidden] {
  display: none;
}

.map-state svg {
  width: 34px;
  height: 34px;
  color: var(--blue);
}

.map-state strong {
  font-size: 15px;
}

.map-state span {
  font-size: 12px;
}

.map-legend {
  position: absolute;
  z-index: 9;
  left: 12px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  max-width: calc(100% - 24px);
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(188, 198, 208, 0.9);
  border-radius: 5px;
  box-shadow: 0 3px 14px rgba(24, 33, 43, 0.12);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #43505e;
  font-size: 11px;
  white-space: nowrap;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.point-inspector {
  position: absolute;
  z-index: 12;
  right: 14px;
  bottom: 14px;
  width: min(330px, calc(100% - 28px));
  padding: 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.point-inspector header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.point-inspector header span,
.point-inspector header strong {
  display: block;
}

.point-inspector header span {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
}

.point-inspector header strong {
  font-size: 15px;
}

.point-inspector dl {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 7px 10px;
  margin: 12px 0;
  font-size: 11px;
}

.point-inspector dt {
  color: var(--muted);
}

.point-inspector dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.reason-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.reason-tag {
  padding: 4px 6px;
  color: #394554;
  background: #eef1f4;
  border-radius: 4px;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.toast {
  position: fixed;
  z-index: 50;
  top: 14px;
  left: 50%;
  max-width: min(440px, calc(100% - 28px));
  padding: 10px 14px;
  color: #fff;
  background: #27394c;
  border-radius: 5px;
  box-shadow: var(--shadow);
  font-size: 12px;
  transform: translateX(-50%);
}

.toast.error {
  background: #9e3030;
}

.mobile-only {
  display: none;
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(390px, 92vw);
    border-right: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
  }

  .map-toolbar {
    align-items: center;
    overflow-x: auto;
  }

  .toolbar-field {
    width: 130px;
    flex: 0 0 130px;
  }

  .toolbar-field > span {
    display: none;
  }

  .segmented-control {
    flex: 0 0 auto;
  }

  .segmented-control button {
    padding: 0 8px;
  }

  .point-inspector {
    right: 10px;
    bottom: 64px;
    width: calc(100% - 20px);
  }

  .map-legend {
    right: 10px;
    bottom: 10px;
    left: 10px;
  }
}

@media (max-width: 430px) {
  .sidebar-header,
  .sidebar-section {
    padding-right: 14px;
    padding-left: 14px;
  }

  .primary-actions {
    grid-template-columns: 1fr 1.25fr;
  }

  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  .field-row > :last-child {
    grid-column: 1 / -1;
  }

  .status-filters label {
    justify-content: center;
  }

  .status-filters input,
  .status-filters strong {
    display: none;
  }

  .map-toolbar {
    right: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
  }
}
