/* ==========================================================
   CCTV Statistics Dashboard — isolated styles
   ========================================================== */

.cstat-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100500;
  font-family: inherit;
  color: #172033;
}

.cstat-modal.is-open {
  display: block;
}

body.cstat-modal-open {
  overflow: hidden;
}

.cstat-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 18, 35, .62);
  backdrop-filter: blur(7px);
}

.cstat-window {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #f3f6fb;
  overflow: hidden;
}

/* ==========================================================
   Header
   ========================================================== */

.cstat-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 45px;
  padding: 5px clamp(18px, 4vw, 54px);
  color: #f8fbff;
  background: linear-gradient(115deg, #10243d 0%, #183c63 58%, #1c5276 100%);
  box-shadow: 0 8px 24px rgba(10, 30, 55, .16);
}

.cstat-title-area {
  display: flex;
  align-items: center;
  min-width: 0;
}

.cstat-title-area h2 {
  margin: 0;
  padding: 0;
  color: #f8fbff;
  font-size: 22px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -.035em;
  white-space: nowrap;
}

/* 기준 데이터 + 닫기 버튼 */
.cstat-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-shrink: 0;
}

/* 기준 데이터 */
.cstat-updated {
  color: #d4e2f0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

/* 닫기 버튼 */
.cstat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: transparent;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.cstat-close:hover {
  background: rgba(255, 255, 255, .13);
}

.cstat-header p {
  margin: 0;
  color: #c2d4e7;
  font-size: 12px;
}

/* ==========================================================
   Main content
   ========================================================== */

.cstat-content {
  flex: 1;
  overflow: auto;
  padding: 22px clamp(14px, 4vw, 54px) 30px;
}

/* ==========================================================
   KPI
   ========================================================== */

.cstat-kpis {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 13px;
  margin: 0 auto 16px;
  max-width: 1440px;
}

.cstat-kpi {
  min-width: 0;
  padding: 19px 20px;
  border: 1px solid #e3eaf2;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(21, 45, 75, .035);
}

.cstat-kpi-primary {
  color: #fff;
  border-color: #1d4770;
  background: linear-gradient(135deg, #163657, #245c86);
}

.cstat-kpi span {
  display: block;
  color: #6c7d91;
  font-size: 12px;
  font-weight: 700;
}

.cstat-kpi-primary span {
  color: #c5d9ed;
}

.cstat-kpi strong {
  display: block;
  margin-top: 7px;
  color: #172b43;
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 850;
  letter-spacing: -.045em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.cstat-kpi-primary strong {
  color: #fff;
}

.cstat-kpi strong small {
  margin-left: 5px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.cstat-kpi em {
  display: block;
  margin-top: 8px;
  color: #8997a8;
  font-size: 10px;
  font-style: normal;
}

.cstat-kpi-primary em {
  color: #b9d0e5;
}

/* ==========================================================
   Statistics grid and cards
   ========================================================== */

.cstat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 1440px;
  margin: 0 auto;
}

.cstat-card {
  min-width: 0;
  padding: 19px 20px;
  border: 1px solid #e3eaf2;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(21, 45, 75, .035);
}

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

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

.cstat-card-head span {
  color: #7890a9;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .08em;
}

.cstat-card-head h2 {
  margin: 5px 0 4px;
  color: #1b2d43;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: 1.4;
}

.cstat-card-head p {
  margin: 0;
  color: #8290a1;
  font-size: 11px;
  line-height: 1.5;
}

/* ==========================================================
   Bar charts
   ========================================================== */

.cstat-bars {
  display: grid;
  gap: 13px;
}

.cstat-bar-item {
  min-width: 0;
}

.cstat-bar-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 12px;
}

.cstat-bar-meta>span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #526276;
}

.cstat-bar-meta>b {
  flex: none;
  color: #1e344c;
  font-size: 12px;
}

.cstat-bar-meta small {
  margin-left: 3px;
  color: #7b8b9d;
  font-size: 10px;
}

.cstat-bar-meta em {
  margin-left: 8px;
  color: #91a0af;
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.cstat-bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 20px;
  background: #edf1f6;
}

.cstat-bar-track i {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: 20px;
  background: linear-gradient(90deg, #2874c7, #22a6bd);
}

/* ==========================================================
   Donut chart
   ========================================================== */

.cstat-donut-layout {
  display: grid;
  grid-template-columns: minmax(145px, .8fr) minmax(180px, 1.2fr);
  align-items: center;
  gap: 24px;
  padding: 4px 0 15px;
}

.cstat-donut {
  width: min(190px, 100%);
  aspect-ratio: 1;
  margin: auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  position: relative;
}

.cstat-donut:before {
  content: "";
  position: absolute;
  inset: 19%;
  border-radius: 50%;
  background: #fff;
}

.cstat-donut>div {
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cstat-donut>div b {
  color: #1b3048;
  font-size: 25px;
  letter-spacing: -.05em;
}

.cstat-donut>div small {
  color: #8392a3;
  font-size: 10px;
}

.cstat-legend {
  display: grid;
  gap: 9px;
}

.cstat-legend>div {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.cstat-legend i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cstat-legend span {
  min-width: 0;
  overflow: hidden;
  color: #5d6d80;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cstat-legend b {
  color: #243b55;
}

/* ==========================================================
   Tables
   ========================================================== */

.cstat-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 7px;
}

.cstat-table-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  background: #f6f8fb;
  font-size: 11px;
}

.cstat-table-name {
  overflow: hidden;
  color: #5c6d80;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cstat-table-row strong {
  color: #253d57;
  white-space: nowrap;
}

.cstat-table-row small {
  margin-left: 2px;
  color: #8190a1;
  font-size: 9px;
}

.cstat-table-pct {
  color: #8a98a8;
  font-size: 10px;
}

/* ==========================================================
   Empty state and notes
   ========================================================== */

.cstat-empty {
  padding: 22px 14px;
  border: 1px dashed #d6e0ea;
  border-radius: 11px;
  color: #8493a4;
  background: #f8fafc;
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
}

.cstat-notes {
  max-width: 1440px;
  margin: 15px auto 0;
  padding: 12px 15px;
  border: 1px solid #e8e2d1;
  border-radius: 12px;
  background: #fffdf7;
}

.cstat-notes p {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 5px 0;
  color: #7a6a46;
  font-size: 11px;
  line-height: 1.55;
}

.cstat-notes p span {
  flex: none;
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  color: #fff;
  background: #b9954b;
  font-size: 10px;
  font-weight: 800;
}

.cstat-footnote {
  margin-top: 12px;
  color: #9a7b3d;
  font-size: 10px;
}

.cstat-footer {
  max-width: 1440px;
  margin: 14px auto 0;
  color: #9aa7b5;
  text-align: center;
  font-size: 10px;
}

/* ==========================================================
   Statistics trigger buttons
   ========================================================== */

.cstat-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 24px;
  padding: 0 5px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 5px;
  color: #fff;
  background: #245b89;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  box-shadow: 0 3px 10px rgba(20, 55, 85, .12);
}

.cstat-trigger-icon {
  font-size: 16px;
  line-height: 1;
}

.cstat-trigger:hover {
  background: #17466f;
}

.cstat-trigger-mobile {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 4px 2px;
  flex-direction: column;
  gap: 2px;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: transparent;
  box-shadow: none;
  font-size: 10px;
}

.cstat-trigger-mobile .cstat-trigger-icon {
  font-size: 20px;
}

.cstat-trigger-floating {
  position: fixed;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  z-index: 1000;
  min-height: 42px;
  box-shadow: 0 5px 18px rgba(15, 45, 75, .25);
}

/* ==========================================================
   Installation year / month list
   ========================================================== */

.cstat-install-years {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cstat-year-item {
  border-bottom: 1px solid #e5e7eb;
}

.cstat-year-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 8px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.cstat-year-label {
  width: 55px;
  flex-shrink: 0;
  font-weight: 600;
}

.cstat-year-bar {
  flex: 1;
  height: 7px;
  overflow: hidden;
  border-radius: 10px;
  background: #e5e7eb;
}

.cstat-year-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #2563eb;
}

.cstat-year-button>strong {
  min-width: 55px;
  text-align: right;
}

.cstat-year-button small,
.cstat-month-row small {
  margin-left: 3px;
  font-size: 11px;
  font-weight: 400;
}

.cstat-year-arrow {
  color: #94a3b8;
  transition: transform 0.2s;
}

.cstat-year-button.is-expanded {
  color: #2563eb;
}

.cstat-year-button.is-expanded .cstat-year-arrow {
  transform: rotate(180deg);
}

.cstat-year-months {
  padding: 4px 12px 12px 75px;
}

.cstat-year-months[hidden] {
  display: none;
}

.cstat-month-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.cstat-month-row {
  display: grid;
  grid-template-columns: 1fr 65px 50px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 6px;
  background: #f8fafc;
  font-size: 13px;
}

.cstat-month-row strong {
  text-align: right;
}

.cstat-month-row>span:last-child {
  color: #64748b;
  text-align: right;
  font-size: 12px;
}

.cstat-month-empty {
  padding: 10px;
  color: #94a3b8;
  font-size: 12px;
}

/* ==========================================================
   Mobile
   ========================================================== */

@media (max-width: 760px) {

  .cstat-header {
    min-height: 40px;
    gap: 8px;
    padding: 5px 13px;
  }

  .cstat-title-area h2 {
    font-size: 18px;
    line-height: 1.2;
  }

  .cstat-header-actions {
    gap: 7px;
  }

  .cstat-updated {
    font-size: 12px;
    font-weight: 400;
    line-height: 1.2;
  }

  .cstat-close {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    font-size: 22px;
  }

  .cstat-content {
    padding: 12px 11px 22px;
  }

  .cstat-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .cstat-kpi {
    padding: 13px 12px;
    border-radius: 12px;
  }

  .cstat-kpi-primary {
    grid-column: 1/-1;
  }

  .cstat-kpi strong {
    font-size: 24px;
  }

  .cstat-kpi em {
    font-size: 9px;
  }

  .cstat-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .cstat-card {
    padding: 15px 13px;
    border-radius: 12px;
  }

  .cstat-card-wide {
    grid-column: auto;
  }

  .cstat-card-head h2 {
    font-size: 14px;
  }

  .cstat-donut-layout {
    grid-template-columns: 115px minmax(0, 1fr);
    gap: 12px;
  }

  .cstat-donut>div b {
    font-size: 19px;
  }

  .cstat-legend {
    gap: 7px;
  }

  .cstat-legend>div {
    font-size: 10px;
  }

  .cstat-table {
    grid-template-columns: 1fr;
  }

  .cstat-trigger-mobile {
    display: inline-flex;
  }
}

@media (max-width: 360px) {

  .cstat-header {
    gap: 5px;
    padding-right: 9px;
    padding-left: 9px;
  }

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

  .cstat-updated {
    font-size: 10px;
  }

  .cstat-header-actions {
    gap: 4px;
  }

  .cstat-close {
    flex-basis: 27px;
    width: 27px;
    height: 27px;
    font-size: 20px;
  }

  .cstat-donut-layout {
    grid-template-columns: 1fr;
  }

  .cstat-donut {
    width: 145px;
  }
}

/* 지도 화면 확대 전용 */
#mapScaleViewport {
  position: relative;
  overflow: hidden;
}

#mapScaleLayer {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}

#mapScaleLayer #map {
  width: 100%;
  height: 100%;
}