:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-2: #fbf7ef;
  --ink: #20242c;
  --muted: #6f756f;
  --line: #ddd5c8;
  --teal: #137a6b;
  --teal-dark: #0b5f55;
  --blue: #3f62a8;
  --gold: #a97818;
  --clay: #b44f2e;
  --red: #b7332d;
  --green: #317a45;
  --shadow: 0 18px 50px rgba(32, 36, 44, 0.12);
  --topbar-height: 96px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(244, 241, 234, 0.82)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", "PingFang SC", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(23px, 2.6vw, 34px);
  line-height: 1.12;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-link,
.ghost-button {
  min-height: 38px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.primary-link {
  padding: 0 16px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(19, 122, 107, 0.2);
}

.primary-link:hover {
  background: var(--teal-dark);
}

.primary-link[aria-disabled="true"] {
  pointer-events: none;
  background: #9aa19c;
  box-shadow: none;
}

.ghost-button {
  padding: 0 11px;
  background: #fffaf1;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(292px, 340px) minmax(480px, 1fr) minmax(330px, 390px);
  height: calc(100vh - var(--topbar-height));
  min-height: 0;
  overflow: hidden;
}

.control-panel,
.detail-panel {
  height: calc(100vh - var(--topbar-height));
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

.control-panel {
  border-right: 1px solid var(--line);
}

.detail-panel {
  border-left: 1px solid var(--line);
}

.filters {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(19, 122, 107, 0.12);
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 13px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.stat {
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.stat b {
  display: block;
  font-size: 22px;
  line-height: 1.05;
}

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

.list-header {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

.case-list {
  padding: 10px;
}

.case-item {
  width: 100%;
  text-align: left;
  display: block;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  padding: 11px 12px;
  cursor: pointer;
}

.case-item:hover,
.case-item.active {
  background: #fff8ec;
  border-color: #e5cfa9;
}

.case-item.active {
  box-shadow: inset 3px 0 0 var(--teal);
}

.case-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.case-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  background: #efe9dd;
  color: #5d625c;
}

.pill.risk-extreme {
  background: rgba(183, 51, 45, 0.12);
  color: var(--red);
}

.pill.risk-high {
  background: rgba(180, 79, 46, 0.12);
  color: var(--clay);
}

.pill.risk-mid {
  background: rgba(169, 120, 24, 0.14);
  color: var(--gold);
}

.pill.risk-low {
  background: rgba(49, 122, 69, 0.12);
  color: var(--green);
}

.pill.repaired {
  background: rgba(63, 98, 168, 0.13);
  color: var(--blue);
}

.map-stage {
  height: calc(100vh - var(--topbar-height));
  min-height: 0;
  position: relative;
  background:
    linear-gradient(135deg, rgba(19, 122, 107, 0.07), transparent 28%),
    linear-gradient(315deg, rgba(180, 79, 46, 0.08), transparent 34%),
    #f7f3eb;
  overflow: hidden;
}

.map-chart {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.map-toolbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 8px;
}

.map-side-zones {
  position: absolute;
  right: 16px;
  top: 64px;
  z-index: 6;
  width: min(230px, 34%);
  pointer-events: none;
  display: grid;
  gap: 10px;
}

.map-zone {
  pointer-events: auto;
  border: 1px solid #d9c6a8;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.93);
  box-shadow: 0 8px 22px rgba(32, 36, 44, 0.1);
  padding: 10px;
}

.map-zone[hidden] {
  display: none;
}

.map-zone-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
}

.zone-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.zone-button {
  border: 1px solid #d9c6a8;
  border-radius: 999px;
  background: #fffaf1;
  color: var(--ink);
  min-height: 34px;
  padding: 0 10px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-button:hover {
  border-color: var(--teal);
}

.detail-empty,
.detail-content {
  padding: 20px;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.detail-content h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.22;
}

.detail-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin: 16px 0 0;
  flex-wrap: wrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 11px;
  min-height: 70px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric b {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.35;
}

.section-block {
  margin-top: 20px;
}

.section-block h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.section-block p {
  margin: 0;
  line-height: 1.75;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
}

.plain-list li {
  margin: 7px 0;
  line-height: 1.55;
}

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

.quote {
  border-left: 3px solid var(--teal);
  background: #f6f0e5;
  padding: 9px 11px;
  line-height: 1.55;
}

details.full-section {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

details.full-section summary {
  cursor: pointer;
  padding: 12px 13px;
  font-weight: 800;
}

.full-section-body {
  border-top: 1px solid var(--line);
  padding: 12px 13px;
  color: #343942;
  font-size: 14px;
  line-height: 1.65;
}

.kv-grid {
  display: grid;
  gap: 9px;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(76px, 30%) 1fr;
  gap: 10px;
}

.kv-row dt {
  color: var(--muted);
  font-weight: 800;
}

.kv-row dd {
  margin: 0;
}

.empty-state {
  color: var(--muted);
  line-height: 1.65;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 320px) 1fr;
  }

  .detail-panel {
    grid-column: 1 / -1;
    min-height: auto;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .topbar-actions,
  .primary-link {
    width: 100%;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .map-stage {
    order: 1;
    height: 58vh;
    min-height: 58vh;
  }

  .map-chart {
    height: 58vh;
    min-height: 58vh;
  }

  .control-panel {
    order: 2;
    height: auto;
    min-height: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .detail-panel {
    order: 3;
    height: auto;
  }

  .filter-grid,
  .stat-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .case-list {
    max-height: 520px;
    overflow: auto;
  }

  .map-toolbar {
    top: 10px;
    left: 10px;
  }

  .map-side-zones {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
    display: grid;
    gap: 6px;
  }

  .map-zone {
    padding: 8px;
  }

  .map-zone-title {
    margin-bottom: 6px;
  }

  .zone-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .zone-button {
    flex: 0 0 auto;
  }

  .detail-title-row {
    display: block;
  }
}
