/* DESIGN.md(Meta 커머스 시스템) 기반 토큰 */
:root {
  --canvas: #ffffff;
  --surface-soft: #f1f4f7;
  --hairline: #dee3e9;
  --hairline-soft: #eaedf1;
  --ink-deep: #0a1317;
  --ink: #1c2b33;
  --charcoal: #344854;
  --slate: #465967;
  --steel: #64778b;
  --stone: #8a9aa9;
  --primary: #0064e0;

  /* status 팔레트 — 아이콘+라벨과 함께만 사용 */
  --status-good: #0ca30c;
  --status-good-bg: #e4f5e4;
  --status-good-text: #0a6e0a;
  --status-busy: #fab219;
  --status-busy-bg: #fdf2d9;
  --status-busy-text: #7d5700;
  --status-bad: #d03b3b;
  --status-bad-bg: #fbe7e7;
  --status-bad-text: #a12525;
  --status-neutral: #8a9aa9;
  --status-neutral-bg: #eef1f4;
  --status-neutral-text: #57646f;

  --rounded-lg: 8px;
  --rounded-xl: 16px;
  --rounded-xxxl: 32px;
  --rounded-full: 100px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
    'Apple SD Gothic Neo', 'Noto Sans KR', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.16px;
}

/* ── 상단 내비게이션 ───────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 1100;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline-soft);
}

.topnav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-deep);
  line-height: 1.25;
}

.brand .address {
  font-size: 14px;
  letter-spacing: -0.14px;
  color: var(--steel);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0; /* 제목이 길어도 새로고침 버튼은 찌그러지지 않는다 */
}

.updated-caption {
  font-size: 12px;
  color: var(--stone);
  text-align: right;
}

.btn-primary {
  background: var(--ink-deep);
  color: var(--canvas);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.14px;
  font-family: inherit;
  border: 0;
  border-radius: var(--rounded-full);
  padding: 12px 26px;
  cursor: pointer;
}

.btn-primary:active { background: var(--charcoal); }
.btn-primary:disabled { background: var(--stone); cursor: default; }

/* ── 레이아웃 ─────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.error-banner {
  background: var(--status-bad-bg);
  color: var(--status-bad-text);
  border-radius: var(--rounded-xl);
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 700;
}

/* ── 위치 카드: 평면도/지도 (상단) ─────────────── */
.map-card {
  border-radius: var(--rounded-xxxl);
  overflow: hidden;
  border: 1px solid var(--hairline-soft);
  background: var(--canvas);
}

.map-card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--hairline-soft);
}

.edit-toggle.editing {
  background: var(--primary);
  color: var(--canvas);
  border-color: var(--primary);
}

#map {
  height: 42vh;
  min-height: 300px;
  width: 100%;
}

.floorplan-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  background: var(--surface-soft);
}

/* 좌측 하단 핀 색상 범례 — 처음 방문자도 색만 보고 상태를 알 수 있게 */
.floorplan-legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--rounded-lg);
  padding: 10px 14px;
  box-shadow: rgba(20, 22, 26, 0.12) 0px 1px 4px 0px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.33;
  color: var(--slate);
  white-space: nowrap;
}

.legend-item .dot { width: 8px; height: 8px; }

.floorplan-wrap[hidden],
.edit-tray[hidden] { display: none; }

/* 스테이지가 이미지와 항상 같은 박스를 갖도록 aspect-ratio로 크기를 잡고
   이미지는 스테이지를 100% 채운다 — 핀(% 좌표)이 어떤 크기에서도 어긋나지 않는다. */
.floorplan-stage {
  position: relative;
  max-width: 100%;
  max-height: 58vh;
  aspect-ratio: 1180 / 944; /* 로드 후 JS가 실제 이미지 비율로 갱신 */
}

.floorplan-stage img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  /* 도면을 연하게 빼서 상태 핀이 가장 도드라지게 한다 */
  filter: contrast(0.35) brightness(1.12);
}

/* 편집 모드에서는 기둥 번호 등 도면 디테일이 필요하므로 원본 대비로 복원 */
.editing-mode .floorplan-stage img { filter: none; }

.floorplan-stage.placing { cursor: crosshair; }

/* 핀은 이미지 폭에 비례해 축소·확대하되 18~28px로 클램프 —
   고정 픽셀이면 이미지 축소 시 핀이 평면도를 과도하게 덮어 위치가 밀려 보인다 */
.charger-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(18px, 3.6%, 28px); /* %는 스테이지(=이미지) 폭 기준 */
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--canvas);
  --pin-color: var(--status-neutral);
  background: var(--pin-color);
  /* 상태색 후광 링 + 드롭 섀도로 옅은 도면 위에서 핀을 띄운다 */
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--pin-color) 30%, transparent),
    0 2px 6px rgba(20, 22, 26, 0.35);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.charger-pin.pin-good { --pin-color: var(--status-good); }
.charger-pin.pin-busy { --pin-color: var(--status-busy); color: #4a3400; }
.charger-pin.pin-bad { --pin-color: var(--status-bad); }
.charger-pin.pin-neutral { --pin-color: var(--status-neutral); }

/* 충전 가능 핀: 이중 레이더 링 + 숨쉬기 스케일로 빈 충전기를 한눈에 찾게 한다.
   링은 transform/opacity만 애니메이션 — box-shadow와 달리 컴포지터에서 처리되어
   상시 리페인트(CPU·배터리 소모)가 없다. */
.charger-pin.pin-good {
  animation: pin-breathe 2s ease-in-out infinite;
}

.charger-pin.pin-good::before,
.charger-pin.pin-good::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 3px solid var(--status-good);
  opacity: 0;
  animation: pin-pulse 2s ease-out infinite;
  pointer-events: none;
}

.charger-pin.pin-good::after { animation-delay: 1s; }

@keyframes pin-pulse {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes pin-breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.12); }
}

/* 편집 중이거나 모션 최소화 설정이면 애니메이션 정지 */
.editing-mode .charger-pin.pin-good,
.editing-mode .charger-pin.pin-good::before,
.editing-mode .charger-pin.pin-good::after { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .charger-pin.pin-good,
  .charger-pin.pin-good::before,
  .charger-pin.pin-good::after { animation: none; }
}

.editing-mode .charger-pin { cursor: grab; }
.editing-mode .charger-pin.dragging { cursor: grabbing; z-index: 10; }

/* ── 편집 트레이 ──────────────────────────────── */
.edit-tray {
  padding: 16px 24px;
  border-top: 1px solid var(--hairline-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.edit-hint {
  font-size: 12px;
  color: var(--steel);
}

.tray-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tray-chip {
  background: var(--surface-soft);
  color: var(--slate);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  border: 1px dashed var(--stone);
  border-radius: var(--rounded-full);
  padding: 8px 16px;
  cursor: pointer;
}

.tray-chip.selected {
  background: var(--primary);
  color: var(--canvas);
  border: 1px solid var(--primary);
}

.tray-empty {
  font-size: 12px;
  color: var(--stone);
}

/* ── 요약 스탯 타일 ───────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
}

.stat-tile {
  background: var(--canvas);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--rounded-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.14px;
  color: var(--slate);
}

.stat-value {
  font-size: 36px;
  font-weight: 500;
  line-height: 1.28;
  color: var(--ink-deep);
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot-good { background: var(--status-good); }
.dot-busy { background: var(--status-busy); }
.dot-bad { background: var(--status-bad); }
.dot-neutral { background: var(--status-neutral); }

/* ── 목록 헤더 + pill 탭 ──────────────────────── */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.list-header h2 {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink-deep);
}

.pill-tabs { display: flex; gap: 8px; }

.pill-tab {
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.14px;
  font-family: inherit;
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-full);
  padding: 8px 16px;
  cursor: pointer;
}

.pill-tab.active {
  background: var(--ink-deep);
  color: var(--canvas);
  border-color: var(--ink-deep);
}

/* ── 충전기 카드 그리드 (하단) ─────────────────── */
.charger-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.charger-card {
  background: var(--canvas);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--rounded-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.charger-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.charger-no {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.16px;
  color: var(--ink-deep);
}

/* 라벨 옆 차지비 단말기 번호 태그 — 현장 단말기와 대조용 */
.charger-terminal {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 8px;
  vertical-align: 2px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  color: var(--slate);
  background: var(--surface-soft);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--rounded-full);
}

.charger-terminal .terminal-label {
  font-weight: 400;
  color: var(--stone);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.33;
  border-radius: var(--rounded-full);
  padding: 4px 10px;
  white-space: nowrap;
}

/* 배지 내부 점 색상은 공용 .dot-{kind} 클래스가 담당 (app.js가 부여) */
.badge .dot { width: 8px; height: 8px; }

.badge-good { background: var(--status-good-bg); color: var(--status-good-text); }
.badge-busy { background: var(--status-busy-bg); color: var(--status-busy-text); }
.badge-bad { background: var(--status-bad-bg); color: var(--status-bad-text); }
.badge-neutral { background: var(--status-neutral-bg); color: var(--status-neutral-text); }

.charger-location {
  font-size: 14px;
  letter-spacing: -0.14px;
  color: var(--charcoal);
  min-height: 40px;
}

.charger-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  background: var(--surface-soft);
  color: var(--slate);
  font-size: 12px;
  font-weight: 700;
  border-radius: var(--rounded-full);
  padding: 4px 10px;
}

.charger-time {
  font-size: 12px;
  color: var(--stone);
  border-top: 1px solid var(--hairline-soft);
  padding-top: 12px;
}

/* ── 체류 시간 게이지 (충전 중 카드, 14시간 기준) ── */
.stay-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stay-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--slate);
}

.stay-progress-head .stay-over { color: var(--status-bad-text); }

.stay-bar {
  height: 6px;
  border-radius: var(--rounded-full);
  background: var(--surface-soft);
  overflow: hidden;
}

.stay-fill {
  height: 100%;
  border-radius: var(--rounded-full);
  background: var(--status-busy);
  min-width: 3px;
}

.stay-fill-over { background: var(--status-bad); }

.stay-deadline {
  font-size: 12px;
  color: var(--steel);
}

.stay-deadline.stay-over { color: var(--status-bad-text); }

.empty-state {
  grid-column: 1 / -1;
  background: var(--surface-soft);
  border-radius: var(--rounded-xl);
  padding: 40px;
  text-align: center;
  color: var(--steel);
  font-size: 14px;
}

/* ── 푸터 ─────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--hairline-soft);
  padding: 24px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--stone);
}

/* ── 반응형 ───────────────────────────────────── */
@media (max-width: 1023px) {
  .charger-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

@media (max-width: 767px) {
  .topnav-inner { padding: 10px 16px; gap: 10px; }
  .container { padding: 12px 12px 56px; gap: 12px; }
  .charger-grid { grid-template-columns: 1fr; gap: 12px; }
  /* 좁은 화면: 긴 충전소명은 한 줄 말줄임 — 두 줄로 감기며 버튼을 밀어내지 않게 */
  .brand { min-width: 0; }
  .brand h1 {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand .address {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .updated-caption { display: none; }
  .btn-primary { padding: 10px 18px; }
  #map { height: 36vh; min-height: 240px; }
  .map-card { border-radius: var(--rounded-xl); }
  .map-card-toolbar { padding: 12px 14px; gap: 8px; }
  .stat-row { gap: 12px; }
  .stat-tile { padding: 14px 16px; gap: 4px; }
  .stat-value { font-size: 26px; }
  /* 터치 타겟 확보 (pill 탭 ≥ 40px) */
  .pill-tab { padding: 10px 14px; }
  /* 카드 여백 압축 */
  .charger-card { padding: 16px; gap: 10px; }
  .charger-location { min-height: auto; }
  /* 좁은 화면에서는 범례를 오버레이 대신 도면 아래 일반 흐름으로 내려
     도면을 가리지 않게 한다 */
  .floorplan-wrap { flex-direction: column; align-items: center; }
  .floorplan-legend {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 12px;
    margin: 8px 12px 10px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }
  .legend-item { font-size: 11px; }
}
