:root {
  --bg: #f1f2ee;
  --surface: #ffffff;
  --soft: #f7f7f3;
  --text: #20242a;
  --muted: #6c747d;
  --line: #d9ddd5;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --work: #d97706;
  --wait: #7c3aed;
  --reject: #9ca3af;
  --primary: #047857;
  --blue: #2563eb;
  --shadow: 0 16px 40px rgba(28, 35, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  height: 100vh;
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.live-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 6px;
  background: #eef7f5;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.stat-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.stat-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  font-size: 19px;
  line-height: 1.1;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 12px;
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.filters .full {
  grid-column: 1 / -1;
}

.filters select,
.filters input[type="search"] {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.filters select:focus,
.filters input[type="search"]:focus {
  border-color: var(--accent);
}

.range-control {
  display: grid;
  grid-template-columns: 1fr 48px;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.range-control input {
  width: 100%;
}

.range-control output {
  text-align: right;
  color: var(--text);
  font-size: 13px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.work {
  background: var(--work);
}

.dot.wait {
  background: var(--wait);
}

.dot.reject {
  background: var(--reject);
}

.dot.primary {
  background: var(--primary);
}

.site-list {
  display: grid;
  gap: 8px;
}

.site-card {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.site-card:hover,
.site-card.is-selected {
  border-color: #111827;
}

.site-card-title {
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

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

.tep-card {
  display: grid;
  grid-template-columns: minmax(112px, max-content) 1fr;
  gap: 4px 8px;
  margin: 9px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 11px;
  line-height: 1.25;
}

.tep-card dt {
  color: var(--muted);
}

.tep-card dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.workspace {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(560px, 1fr) 292px;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}

.map-panel,
.analytics-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.map-topbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  pointer-events: none;
}

.map-topbar > div {
  max-width: 560px;
  padding: 12px 14px;
  border: 1px solid rgba(217, 221, 213, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(28, 35, 45, 0.11);
  pointer-events: auto;
}

.map-topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.map-topbar button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
}

.map {
  width: 100%;
  height: 100%;
  min-height: 560px;
}

.map-message {
  position: absolute;
  z-index: 10;
  right: 18px;
  bottom: 18px;
  max-width: 430px;
  padding: 12px 14px;
  border: 1px solid #f2c0a0;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 13px;
  line-height: 1.4;
}

.ymarker {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--marker-color);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  font-size: 10px;
  font-weight: 700;
  transform: translate(-50%, -50%);
  cursor: pointer;
}

.ymarker::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 7px);
  top: 50%;
  min-width: max-content;
  transform: translateY(-50%);
  color: #111827;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 2px #fff, 0 -1px 2px #fff, 1px 0 2px #fff, -1px 0 2px #fff;
}

.ymarker.is-selected {
  outline: 3px solid #111827;
  outline-offset: 2px;
}

.popup {
  width: min(360px, 82vw);
  max-height: 360px;
  overflow: auto;
  padding: 16px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

.popup h3 {
  margin: 0 28px 10px 0;
  font-size: 16px;
  line-height: 1.2;
}

.popup dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 5px 9px;
  margin: 0;
  font-size: 12px;
}

.popup dt {
  color: var(--muted);
}

.popup dd {
  margin: 0;
}

.popup .note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.popup .tep-card {
  grid-template-columns: 1fr max-content;
  margin-top: 10px;
  font-size: 12px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 10px;
  min-height: 0;
}

.analytics-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 13px;
  box-shadow: none;
}

.panel-heading {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.bar-chart {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  gap: 6px;
}

.bar-row {
  display: grid;
  grid-template-columns: 154px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.bar-label {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 13px;
  overflow: hidden;
  border-radius: 4px;
  background: #eef0ea;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
}

.bar-value {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

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

.district-table {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.district-table th,
.district-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.district-table th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.district-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .workspace {
    grid-template-rows: 640px auto;
  }

  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .filters,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .map-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .bar-row {
    grid-template-columns: 110px 1fr 42px;
  }
}
