:root {
  --bg: #f4f1ea;
  --surface: #fffaf1;
  --panel: #ffffff;
  --ink: #1f2522;
  --muted: #677069;
  --line: #ded8cc;
  --green: #31755b;
  --red: #c94a35;
  --amber: #d79226;
  --violet: #5f5aa2;
  --blue: #1f6fb2;
  --shadow: 0 14px 36px rgba(45, 36, 25, 0.12);
  font-family: Inter, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  min-height: 88px;
  padding: 18px 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  background: #1f2522;
  color: #fffaf1;
  border-bottom: 4px solid var(--amber);
}

.app-header h1,
.section-heading h2,
.panel-section h2,
.detail-topline h3 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: clamp(1.6rem, 2.2vw, 2.25rem);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: #e8d6a9;
}

.header-main {
  display: grid;
  gap: 10px;
  min-width: 260px;
  padding-top: 4px;
}

.header-dashboard {
  display: grid;
  flex: 1;
  gap: 8px;
  justify-items: end;
  min-width: 0;
  max-width: none;
}

.app-nav {
  display: grid;
  grid-template-columns: repeat(4, max-content);
  justify-content: end;
  gap: 8px;
  width: 100%;
}

.nav-link {
  min-height: 34px;
  min-width: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid rgba(232, 214, 169, 0.72);
  border-radius: 7px;
  background: #fffaf1;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: inset 0 -2px 0 rgba(215, 146, 38, 0.22);
}

.nav-link strong,
.nav-link span {
  display: block;
}

.nav-link span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.nav-link.is-active {
  border-color: var(--amber);
  background: var(--amber);
  color: #1f2522;
  box-shadow: inset 0 -2px 0 rgba(31, 37, 34, 0.2);
}

.nav-link:hover,
.nav-link:focus-visible {
  border-color: var(--amber);
  background: #fff2d6;
  color: var(--ink);
}

.nav-link:hover span,
.nav-link:focus-visible span,
.nav-link.is-active span {
  color: var(--ink);
}

.header-metrics {
  display: grid;
  grid-template-columns: repeat(4, max-content);
  justify-content: end;
  gap: 8px;
  width: max-content;
  max-width: 100%;
  min-width: 0;
}

.header-metrics div {
  min-height: 38px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: max-content;
  min-width: 0;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid rgba(255, 250, 241, 0.22);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.06);
}

.header-metrics span,
.detail-stats span {
  display: block;
  font-size: 1.26rem;
  font-weight: 800;
}

.header-metrics small,
.detail-stats small {
  color: rgba(255, 250, 241, 0.72);
  font-size: 0.72rem;
}

.header-metrics span {
  display: inline;
  flex: 0 0 auto;
  font-size: 1.05rem;
}

.header-metrics small {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: max-content;
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  grid-template-rows: minmax(620px, calc(100vh - 88px)) auto auto;
  gap: 0;
}

.control-panel {
  grid-row: 1 / 2;
  padding: 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

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

.panel-section:first-child {
  padding-top: 0;
}

.panel-section h2 {
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span,
.check-row,
.status-text {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.field textarea {
  resize: vertical;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segment {
  min-height: 39px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment + .segment {
  border-left: 1px solid var(--line);
}

.segment.is-active {
  background: var(--green);
  color: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
}

.legend-dot,
.swatch {
  display: inline-block;
  flex: 0 0 auto;
  border-radius: 50%;
}

.legend-dot {
  width: 13px;
  height: 13px;
}

.legend-dot.temple {
  background: var(--green);
}

.legend-dot.heritage {
  background: var(--violet);
}

.legend-dot.house {
  background: var(--blue);
}

.legend-dot.conifer {
  background: #2f7d32;
}

.legend-dot.slope {
  background: #8b5a2b;
}

.action-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 9px;
}

.full-button {
  width: 100%;
  margin-top: 9px;
}

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

.icon-button,
.primary-button,
.secondary-button,
.risk-chip {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  font-weight: 850;
}

.icon-button {
  background: #e7dfd2;
  color: var(--ink);
}

.primary-button {
  background: var(--red);
  color: #fff;
}

.secondary-button,
.risk-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.status-text {
  min-height: 20px;
  margin: 10px 0 0;
  line-height: 1.45;
}

.environment-source {
  display: block;
  margin-top: 3px;
  color: #6f6658;
  font-size: 0.78rem;
  line-height: 1.35;
}

.vworld-source {
  display: block;
  margin-top: 3px;
  color: #9a3d27;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.35;
}

.map-workspace {
  position: relative;
  min-width: 0;
  background: #d7ddd8;
}

.map-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-overlay {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 450;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 36px);
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--shadow);
}

.basemap-switch {
  position: absolute;
  top: 18px;
  right: 70px;
  z-index: 460;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid rgba(31, 37, 34, 0.18);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
}

.basemap-button {
  min-width: 78px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 850;
}

.basemap-button + .basemap-button {
  border-left: 1px solid var(--line);
}

.basemap-button.is-active {
  background: var(--ink);
  color: #fffaf1;
}

.overlay-item {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.swatch {
  width: 12px;
  height: 12px;
}

.swatch.fire {
  background: var(--red);
}

.swatch.area {
  background: rgba(201, 74, 53, 0.45);
}

.swatch.radius {
  background: rgba(49, 117, 91, 0.28);
  border: 1px solid var(--green);
}

.swatch.steep-slope {
  background: #8b5a2b;
  border: 1px solid #5f4428;
}

.swatch.steep-slope-geocoded {
  background: #2f6fb3;
  border: 1px solid #173f72;
}

.swatch.vworld {
  background: #d79226;
  border: 1px solid #9a3d27;
}

.analytics-band,
.report-band,
.heritage-band {
  grid-column: 1 / -1;
  padding: 24px 28px;
  border-top: 1px solid var(--line);
}

.page-view {
  display: none;
}

.page-view.is-active {
  display: block;
}

.dashboard-page:not(.is-analysis-view) .page-view {
  display: none;
}

.dashboard-page.is-analysis-view .app-shell {
  grid-template-rows: minmax(620px, calc(100vh - 88px));
}

.dashboard-page:has(.page-view.is-active) .app-shell {
  grid-template-rows: minmax(620px, calc(100vh - 88px));
}

.dashboard-page.is-analysis-view .map-workspace {
  display: none;
}

.dashboard-page:has(.page-view.is-active) .map-workspace {
  display: none;
}

.route-page .app-shell {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  grid-template-rows: auto;
  min-height: calc(100vh - 88px);
}

.route-page .map-workspace {
  display: none;
}

.route-page .page-view.is-active,
.dashboard-page.is-analysis-view .page-view.is-active,
.dashboard-page:has(.page-view.is-active) .page-view.is-active {
  grid-column: 2;
  grid-row: 1;
  border-top: 0;
}

.analytics-band {
  background: #fffaf1;
}

.heritage-band {
  background: #f8f6f1;
}

.report-band {
  background: #f4f1ea;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 1.15rem;
}

.daily-chart {
  min-height: 260px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow-x: auto;
}

.analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
  gap: 18px;
}

.alerts-panel {
  min-height: 260px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title-row h3 {
  margin: 0;
  font-size: 0.98rem;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eee8dc;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 850;
}

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

.alert-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
  text-align: left;
}

.alert-item strong {
  font-size: 0.9rem;
}

.alert-item small,
.empty-alert {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.empty-alert {
  min-height: 190px;
  display: grid;
  place-items: center;
  text-align: center;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.report-summary div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-summary span {
  display: block;
  font-size: 1.25rem;
  font-weight: 900;
}

.report-summary small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 18px;
}

.report-table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.report-table th,
.report-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.report-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f6f1;
  color: var(--muted);
  font-size: 0.74rem;
}

.report-row {
  cursor: pointer;
}

.report-row.is-selected,
.report-row:hover {
  background: #fff6f1;
}

.report-table strong,
.report-table small {
  display: block;
}

.report-table small {
  color: var(--muted);
  margin-top: 3px;
}

.report-detail {
  min-height: 520px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.report-detail-head h3 {
  margin: 0;
  font-size: 1.08rem;
}

.report-kv {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.report-kv div {
  padding: 10px;
  border-radius: 8px;
  background: #f6f1e8;
}

.report-kv span,
.report-kv strong {
  display: block;
}

.report-kv span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.report-kv strong {
  margin-top: 3px;
  font-size: 0.88rem;
}

.priority-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 850;
}

.priority-badge.urgent {
  background: rgba(201, 74, 53, 0.16);
  color: #a63626;
}

.priority-badge.watch {
  background: rgba(215, 146, 38, 0.19);
  color: #86520b;
}

.priority-badge.normal {
  background: rgba(49, 117, 91, 0.14);
  color: #28634e;
}

.prevention-box {
  padding: 14px;
  border-radius: 8px;
  background: #fffaf1;
}

.prevention-box.emergency {
  border-left: 4px solid var(--red);
}

.prevention-box.watch {
  border-left: 4px solid var(--amber);
}

.prevention-box.normal {
  border-left: 4px solid var(--green);
}

.prevention-box h4 {
  margin: 0 0 8px;
}

.prevention-box ul {
  margin: 0;
  padding-left: 18px;
}

.prevention-box li {
  margin: 6px 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.chart-svg {
  display: block;
  min-width: 760px;
  width: 100%;
  height: 235px;
}

.risk-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.risk-chip {
  padding: 0 13px;
}

.risk-chip.is-active {
  background: var(--ink);
  color: #fff;
}

.management-grid {
  display: grid;
  grid-template-columns: minmax(310px, 0.95fr) minmax(320px, 1.05fr);
  gap: 18px;
}

.heritage-list {
  display: grid;
  gap: 10px;
  max-height: 630px;
  overflow-y: auto;
}

.list-notice {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.heritage-card,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(45, 36, 25, 0.06);
}

.heritage-card {
  width: 100%;
  padding: 13px;
  text-align: left;
}

.heritage-card.is-selected {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(201, 74, 53, 0.2);
}

.heritage-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.heritage-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.98rem;
}

.heritage-card small,
.timeline small {
  color: var(--muted);
}

.heritage-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.meta-pill,
.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 850;
}

.meta-pill {
  background: #eee8dc;
  color: var(--ink);
}

.risk-badge.high {
  background: rgba(201, 74, 53, 0.16);
  color: #a63626;
}

.risk-badge.medium {
  background: rgba(215, 146, 38, 0.19);
  color: #86520b;
}

.risk-badge.low {
  background: rgba(49, 117, 91, 0.14);
  color: #28634e;
}

.detail-panel {
  min-height: 520px;
  padding: 18px;
}

.empty-state {
  min-height: 470px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.detail-content {
  display: grid;
  gap: 16px;
}

.detail-content.is-hidden,
.empty-state.is-hidden {
  display: none;
}

.detail-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.detail-stats div {
  min-height: 72px;
  padding: 12px;
  border-radius: 8px;
  background: #f6f1e8;
}

.detail-stats small {
  color: var(--muted);
}

.detail-panel h4 {
  margin: 0 0 10px;
}

.timeline {
  display: grid;
  gap: 8px;
}

.timeline-item {
  padding: 11px 12px;
  border-left: 4px solid var(--red);
  border-radius: 0 7px 7px 0;
  background: #fff6f1;
}

.timeline-item strong {
  display: block;
  margin-bottom: 3px;
}

.heritage-marker {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}

.heritage-marker.temple {
  background: var(--green);
}

.heritage-marker.heritage {
  background: var(--violet);
}

.heritage-marker.house {
  background: var(--blue);
}

.heritage-marker.risk-high {
  box-shadow: 0 0 0 4px rgba(201, 74, 53, 0.3), 0 3px 10px rgba(0, 0, 0, 0.22);
}

.heritage-marker.risk-medium {
  box-shadow: 0 0 0 4px rgba(215, 146, 38, 0.26), 0 3px 10px rgba(0, 0, 0, 0.22);
}

.leaflet-popup-content {
  margin: 11px 13px;
  min-width: 190px;
}

.popup-title {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.popup-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 1040px) {
  .app-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .header-metrics {
    width: max-content;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: repeat(4, max-content);
    justify-content: start;
  }

  .header-main,
  .header-dashboard,
  .app-nav {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 70vh) auto auto;
  }

  .route-page .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .dashboard-page.is-analysis-view .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .dashboard-page:has(.page-view.is-active) .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .route-page .page-view.is-active,
  .dashboard-page.is-analysis-view .page-view.is-active,
  .dashboard-page:has(.page-view.is-active) .page-view.is-active {
    grid-column: 1;
    grid-row: auto;
  }

  .control-panel {
    grid-row: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

@media (max-width: 640px) {
  .app-header,
  .analytics-band,
  .report-band,
  .heritage-band {
    padding: 18px;
  }

  .header-dashboard {
    justify-items: start;
  }

  .header-metrics {
    width: 100%;
    grid-template-columns: repeat(2, max-content);
    justify-content: start;
    gap: 6px;
  }

  .header-metrics div {
    min-height: 34px;
    gap: 6px;
    padding: 6px 8px;
  }

  .header-metrics span {
    font-size: 0.95rem;
  }

  .header-metrics small {
    font-size: 0.68rem;
  }

  .detail-stats {
    grid-template-columns: 1fr;
  }

  .app-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
  }

  .nav-link {
    min-width: 58px;
    min-height: 32px;
    padding: 6px 9px;
    font-size: 0.78rem;
  }

  .threshold-grid,
  .analytics-grid,
  .report-grid,
  .report-summary {
    grid-template-columns: 1fr;
  }

  .map-workspace {
    min-height: 520px;
  }

  .map-overlay {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .basemap-switch {
    top: 12px;
    right: 58px;
  }

  .basemap-button {
    min-width: 68px;
    padding: 0 8px;
  }
}

@media (max-width: 760px) {
  .header-dashboard {
    justify-items: start;
    width: 100%;
  }

  .header-metrics {
    display: flex !important;
    flex-wrap: wrap !important;
    grid-template-columns: none !important;
    justify-content: flex-start !important;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    max-width: 100%;
  }

  .header-metrics div {
    flex: 0 1 auto;
    width: auto;
    max-width: calc(50% - 3px);
    min-height: 34px;
    padding: 6px 8px;
    gap: 6px;
  }

  .header-metrics span {
    font-size: clamp(0.88rem, 4.2vw, 0.98rem);
  }

  .header-metrics small {
    min-width: 0;
    font-size: clamp(0.62rem, 2.8vw, 0.68rem);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .app-nav {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start;
    gap: 5px;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .app-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-link {
    flex: 0 0 auto;
    min-width: 52px;
    min-height: 32px;
    padding: 6px 8px;
    font-size: clamp(0.68rem, 3.2vw, 0.78rem);
    white-space: nowrap;
  }
}
