:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-alt: #eef3ef;
  --ink: #17201b;
  --muted: #667269;
  --line: #d8ded9;
  --line-strong: #b8c2bb;
  --accent: #116b5b;
  --accent-2: #b6512e;
  --focus: #1f77b4;
  --shadow: 0 10px 26px rgba(30, 40, 35, 0.08);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
}

button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

select,
input {
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid color-mix(in srgb, var(--focus) 30%, transparent);
  outline-offset: 1px;
}

.app-shell {
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
  height: 100vh;
  min-height: 620px;
}

.sidebar {
  min-width: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.meta-line {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.notice {
  margin: 14px 0;
  padding: 10px;
  border: 1px solid #d7ad6b;
  border-radius: 6px;
  background: #fff7e8;
  font-size: 13px;
}

.notice span {
  display: block;
  margin-top: 4px;
}

.panel,
.viz-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  margin-top: 16px;
  padding: 14px;
}

.panel-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: #39433d;
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 8px 0 12px;
  color: #344039;
  font-size: 13px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-grid input {
  width: auto;
  min-height: auto;
}

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

.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.kpi {
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}

.kpi-value {
  font-size: 22px;
  line-height: 1.05;
  font-weight: 760;
}

.kpi-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.visual-grid {
  display: grid;
  grid-template-columns: minmax(460px, 1.4fr) minmax(320px, 0.8fr);
  grid-template-rows: minmax(300px, 1.15fr) minmax(260px, 0.85fr);
  gap: 14px;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.viz-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.map-panel {
  grid-row: span 2;
}

.viz-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.viz-head h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.map-wrap {
  position: relative;
  min-height: 0;
  flex: 1;
  background: #f8f9f8;
}

#leafletMap,
#scatterCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#leafletMap {
  background: #f8f9f8;
}

.leaflet-container {
  font: inherit;
}

.leaflet-control-layers,
.leaflet-control-zoom a {
  border-color: var(--line-strong);
}

.point-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#scatterCanvas {
  min-height: 260px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 10px;
  max-width: 420px;
  font-size: 12px;
  color: #3c4640;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  max-width: 280px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.tooltip strong {
  display: block;
  margin-bottom: 2px;
}

.hidden {
  display: none !important;
}

.matrix {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.matrix-table th,
.matrix-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px 6px;
  text-align: right;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
}

.matrix-table th {
  color: var(--muted);
  font-weight: 650;
}

.quality-content {
  overflow: auto;
  padding: 12px 14px 16px;
  font-size: 13px;
  line-height: 1.45;
}

.quality-content h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.quality-content ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.empty-state {
  padding: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.selection-panel {
  display: grid;
  gap: 12px;
}

.selection-title {
  font-size: 16px;
  font-weight: 760;
}

.selection-subtitle {
  color: var(--muted);
  font-size: 12px;
}

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

.measure {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--panel-alt);
}

.measure span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.measure strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
}

.sparkline {
  width: 100%;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

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

  .workspace {
    overflow: visible;
  }

  .visual-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: visible;
  }

  .map-panel {
    grid-row: auto;
    height: 62vh;
    min-height: 420px;
  }

  .kpi-row {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 620px) {
  .sidebar,
  .visual-grid,
  .kpi-row {
    padding: 10px;
  }

  .split-fields,
  .actions,
  .measure-grid,
  .kpi-row {
    grid-template-columns: 1fr;
  }

  .map-panel {
    min-height: 360px;
  }
}
