:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #6b7280;
  --line: #d9e2ec;
  --blue: #2166f3;
  --green: #119c67;
  --amber: #d97706;
  --red: #dc2626;
  --violet: #6d28d9;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
}

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

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px 1fr;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 4px 14px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #f97316;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-title h2 {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.25;
}

.brand p {
  color: #aeb7c7;
  font-size: 12px;
  margin-top: 4px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar .panel {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.compact {
  padding: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

.sidebar input,
.sidebar select {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.94);
}

textarea {
  resize: vertical;
}

textarea[readonly] {
  min-height: 360px;
  color: #0f172a;
  background: #f8fafc;
  line-height: 1.55;
}

.scenario-meta {
  margin-top: 10px;
  color: #c4ccda;
  font-size: 12px;
  line-height: 1.5;
}

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

.nav-button {
  border: 0;
  border-radius: 8px;
  color: #d7deea;
  background: transparent;
  text-align: left;
  padding: 12px 13px;
  font-weight: 800;
}

.nav-button.active {
  background: #ffffff;
  color: #111827;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 28px;
  line-height: 1.2;
}

.top-actions,
.toolbar,
menu,
.address-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary,
.ghost,
.status-button,
.icon-button,
.mini-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
}

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

.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

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

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue);
  border-radius: 8px;
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 27px;
  margin-top: 7px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.single-view {
  display: grid;
  gap: 14px;
}

.hidden {
  display: none;
}

.map-shell {
  position: relative;
  min-height: 650px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dde7ef;
  box-shadow: var(--shadow);
}

.map,
.fallback-map {
  position: absolute;
  inset: 0;
}

/* 지도 타일 깨짐(간격 벌어짐) 방지 */
.map *,
.fallback-map * {
  box-sizing: content-box;
}

.map img,
.fallback-map img {
  max-width: none;
  margin: 0;
  padding: 0;
}

.fallback-map {
  background:
    linear-gradient(90deg, rgba(255,255,255,.48) 1px, transparent 1px) 0 0 / 64px 64px,
    linear-gradient(rgba(255,255,255,.48) 1px, transparent 1px) 0 0 / 64px 64px,
    radial-gradient(circle at 30% 30%, #d7eafc, #e7edf3 48%, #d8e2ea);
}

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

.fake-marker {
  position: absolute;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  border-radius: 50% 50% 50% 0;
  rotate: -45deg;
  border: 3px solid white;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.25);
}

.fake-marker::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  inset: 4px;
  border-radius: 50%;
  background: white;
}

.map-message {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 18px;
  z-index: 500;
  border: 1px solid #bfd3ea;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2937;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
  white-space: pre-line;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.leaflet-pin {
  display: block;
  width: 22px;
  height: 22px;
  transform: rotate(-45deg);
  border-radius: 50% 50% 50% 0;
  border: 3px solid white;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.28);
}

.leaflet-pin::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  inset: 4px;
  border-radius: 50%;
  background: white;
}

.pin-normal {
  background: var(--blue);
}

.pin-warning {
  background: var(--amber);
}

.pin-danger {
  background: var(--red);
}

.pin-done {
  background: var(--green);
}

.map-link {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.stack {
  display: grid;
  gap: 16px;
  align-content: start;
}

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

.section-title h2 {
  font-size: 16px;
}

.section-title span,
.pill {
  border-radius: 999px;
  background: #eef2ff;
  color: #3949ab;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 900;
}

.list {
  display: grid;
  gap: 9px;
}

.timeline {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  border-left: 2px solid var(--line);
  padding-left: 10px;
}

.timeline-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.timeline-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.timeline-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.list-item,
.incident-card,
.org-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.list-item strong,
.incident-card strong,
.org-card strong {
  display: block;
  margin-bottom: 4px;
}

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

.status {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.status.REPORTED,
.status.미보고,
.status.신규 {
  color: #b42318;
  background: #fee4e2;
}

.status.ASSIGNED,
.status.예찰중,
.status.조치중 {
  color: #92400e;
  background: #fef3c7;
}

.status.RESOLVED,
.status.이상없음,
.status.완료 {
  color: #027a48;
  background: #d1fadf;
}

.status.이상있음,
.status.긴급,
.status.위험 {
  color: #8429b8;
  background: #f3e8ff;
}

.toolbar {
  justify-content: space-between;
}

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

.segmented button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 0 12px;
  font-weight: 800;
}

.segmented button.active {
  color: white;
  background: #111827;
  border-color: #111827;
}

.table-wrap {
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

.incident-grid,
.org-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.incident-card {
  display: grid;
  gap: 10px;
}

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

.status-button {
  min-height: 34px;
  background: #f8fafc;
  border-color: var(--line);
  font-size: 12px;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-form {
  padding: 18px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: #f1f5f9;
  font-size: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

menu {
  justify-content: flex-end;
  padding: 0;
  margin: 18px 0 0;
}

@media (max-width: 1080px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
/* Custom Map Popup Styles */
.custom-map-popup, .leaflet-custom-popup .leaflet-popup-content-wrapper {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  width: 320px;
  overflow: hidden;
  font-family: inherit;
}
.leaflet-custom-popup .leaflet-popup-content {
  margin: 0;
  width: 100% !important;
}
.leaflet-custom-popup .leaflet-popup-tip {
  background: white;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 2px solid #f1f5f9;
}
.popup-title {
  font-weight: 800;
  color: #0f172a;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}
.popup-close-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  color: #94a3b8;
  cursor: pointer;
  padding: 0;
  margin-left: 8px;
}
.popup-close-btn:hover { color: #334155; }
.popup-body {
  max-height: 250px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.timeline-item {
  position: relative;
  padding-left: 14px;
  border-left: 3px solid var(--item-color);
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 4px;
  width: 11px;
  height: 11px;
  background: white;
  border: 3px solid var(--item-color);
  border-radius: 50%;
}
.timeline-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.timeline-badge {
  color: white;
  padding: 2px 6px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 11px;
}
.timeline-status {
  font-weight: 700;
  color: #475569;
}
.timeline-time {
  color: #94a3b8;
  font-weight: 600;
  margin-left: auto;
}
.timeline-content {
  background: #f8fafc;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  color: #334155;
  line-height: 1.5;
}
.timeline-content strong {
  color: #0f172a;
  font-size: 14px;
}
.popup-footer {
  padding: 12px 16px;
  border-top: 1px solid #f1f5f9;
  background: white;
}
.popup-action-btn {
  width: 100%;
  background: #ef4444;
  color: white;
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}
.popup-action-btn:hover { background: #dc2626; }
.popup-action-btn:active { transform: scale(0.98); }

/* Location Picker UI */
.map-center-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -100%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}
.map-center-pin svg {
  color: #ef4444; /* red-500 */
  fill: white;
}
.map-floating-action {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  gap: 8px;
}
.shadow-lg {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.bg-white {
  background-color: white !important;
}
.pointer-events-none {
  pointer-events: none;
}

