/* ========== GLOBAL LAYOUT / HEADER / SUMMARY / BUTTON / LOADING UI ========== */

* {
  box-sizing: border-box;
}

button, input, select, textarea {
  font-family: 'Pretendard', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Pretendard', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f3f4f8;
  color: #111827;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- HEADER ---------------- */
.page-header {
  padding: 16px 24px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  /* 카드 헤더(z-index:20)·예약 뱃지 등이 sticky 헤더 위로 뚫고 올라오지 않도록 충분히 높게 */
  z-index: 100;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;   /* 좁아져도 줄바꿈 금지 — 항상 한 줄 */
}

.page-subtitle {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;   /* 좁아져도 줄바꿈 금지 — 항상 한 줄 */
}

/* 헤더 내부 정렬 */
.page-header-row {
  display: contents; /* 넓은 화면에서 투명하게 — header-left/right가 page-header flex 항목으로 동작 */
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  order: 1;
}

.header-logo {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.header-text-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* 헤더 가운데 날씨 영역 */
.header-center {
  flex: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  order: 2;
}

/* 헤더 오른쪽 아이콘 */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
  order: 3;
}

/* ---- 날씨 위젯 (cc-weather) ---- */
.cc-weather {
  width: 100%;
  min-width: 0;
}

.cc-weather-card {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 14px;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
}

.cc-weather-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #F1F5F9;
  border-radius: 8px;
  padding: 5px 0;
  width: 96px;
  flex-shrink: 0;
}

.cc-weather-icon {
  font-size: 1.5rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.12));
  flex-shrink: 0;
}

.cc-weather-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  text-align: left;
  flex-shrink: 0;
}

.cc-weather-kicker {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
}

.cc-weather-desc {
  font-size: 12px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.25;
  max-width: 11em;
}

.cc-weather-divider {
  width: 1px;
  height: 30px;
  background: linear-gradient(180deg, transparent, #cbd5e1, transparent);
  flex-shrink: 0;
  margin: 0 10px;
}

.cc-weather-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 10px;
  min-width: 52px;
  gap: 2px;
}

.cc-weather-metric--dust {
  min-width: 58px;
}

.cc-weather-metric-head {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}

.cc-weather-metric-head .cc-weather-metric-label {
  margin-bottom: 0;
}

.cc-weather-metric-label {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 2px;
}

.cc-weather-grade {
  display: block;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.2;
  flex-shrink: 0;
}

.cc-weather-grade--good    { background: none; color: #2e7d32; }
.cc-weather-grade--moderate { background: none; color: #9a6700; }
.cc-weather-grade--bad     { background: none; color: #e65100; }
.cc-weather-grade--verybad { background: none; color: #b42318; }

.cc-weather-metric-val {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.cc-weather-metric-val .cc-weather-unit {
  font-size: 0.65rem;
  font-weight: 500;
  color: inherit;
  opacity: 0.75;
  margin-left: 1px;
}

.cc-weather-info,
.cc-weather-metric--temp,
.cc-weather-metric--hum,
.cc-weather-metric--pm25,
.cc-weather-metric--pm10 {
  height: 52px;
  border-radius: 8px;
  flex-shrink: 0;
  padding: 0;
}

.cc-weather-info {
  width: 120px;
}

.cc-weather-metric--temp,
.cc-weather-metric--hum,
.cc-weather-metric--pm25,
.cc-weather-metric--pm10 {
  width: 96px;
}

.cc-weather-metric--temp { background: #EFF6FF; }
.cc-weather-metric--temp .cc-weather-metric-val { color: #026EFF; }

.cc-weather-metric--hum  { background: #ECFEFF; }
.cc-weather-metric--hum  .cc-weather-metric-val { color: #0089B3; }

.cc-weather-metric--pm25 { background: #FFF7ED; }
.cc-weather-metric--pm25 .cc-weather-metric-val { color: #F54100; }

.cc-weather-metric--pm10 { background: #FEF2F2; }
.cc-weather-metric--pm10 .cc-weather-metric-val { color: #EA3033; }

.cc-weather-meta {
  margin: 0;
  padding-left: 12px;
  font-size: 10px;
  color: #94a3b8;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;       /* 좁아져도 세로(한 글자씩)로 무너지지 않게 */
  overflow: hidden;
  text-overflow: ellipsis;   /* 공간 부족 시 …로 잘림 */
  text-align: left;
  flex-shrink: 1;
  min-width: 0;
  max-width: 190px;
}

@media (max-width: 1400px) {
  /* 중간 너비: 헤더를 한 줄로 유지하되 타이틀/날씨 카드를 축소해 줄바꿈·잘림 방지 */
  .cc-weather-meta { display: none; }

  .page-title    { font-size: 16px; }
  .page-subtitle { font-size: 11px; }
  .header-logo   { height: 32px; }

  .cc-weather-card    { padding: 8px 10px; gap: 6px; }
  .cc-weather-divider { display: none; }            /* 구분선 제거로 폭 절약 */
  .cc-weather-info    { width: 100px; }
  .cc-weather-info,
  .cc-weather-metric--temp,
  .cc-weather-metric--hum,
  .cc-weather-metric--pm25,
  .cc-weather-metric--pm10 { height: 48px; }
  .cc-weather-metric--temp,
  .cc-weather-metric--hum,
  .cc-weather-metric--pm25,
  .cc-weather-metric--pm10 { width: 84px; flex-shrink: 1; min-width: 56px; }
  .cc-weather-metric-val { font-size: 1.05rem; }
}

@media (max-width: 900px) {
  /* 좁은 화면(모바일): 헤더를 column(스택)+날씨 그리드로 전환 */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px 0;
    gap: 0;
  }

  /* page-header-row: 로고+아이콘 행 — 명시적으로 전체 너비 */
  .page-header-row {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
  }

  .header-left  { flex: 1; min-width: 0; }
  .header-right { flex: 0; margin-left: auto; }

  /* 좁은 화면: 타이틀/로고 축소 */
  .page-title    { font-size: 14px; }
  .page-subtitle { font-size: 10px; }
  .header-logo   { height: 28px; }

  /* header-center: 날씨 위젯 — 전체 너비 행 */
  .header-center {
    width: 100%;
    display: block;
    padding-bottom: 12px;
    justify-content: flex-start;
    min-width: 0;
  }

  .cc-weather { width: 100%; }

  .cc-weather-card {
    display: flex !important;       /* 2열 그리드 → 한 줄 가로 (상단 높이 절약) */
    flex-wrap: nowrap;
    gap: 5px;
    padding: 0;
    width: 100%;
    overflow: hidden;             /* flex로 폭을 꽉 채우므로 스크롤 불필요 */
  }

  .cc-weather-divider { display: none !important; }
  .cc-weather-meta    { display: none !important; }

  .cc-weather-info {
    width: auto !important;
    max-width: none !important;
    flex: 1.7 1 0 !important;     /* 남는 공간 분배 — 한 줄 꽉 채움 (아이콘+텍스트라 조금 더 넓게) */
    min-width: 0 !important;
  }

  .cc-weather-metric,
  .cc-weather-metric--temp,
  .cc-weather-metric--hum,
  .cc-weather-metric--pm25,
  .cc-weather-metric--pm10 {
    width: auto !important;
    max-width: none !important;
    flex: 1 1 0 !important;       /* 4개 지표 균등 분배 */
    min-width: 0 !important;
  }
  .cc-weather-metric-val { font-size: 0.95rem; }
}

.header-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;

  color: #4b5563;
  font-size: 14px;

  transition: background 0.15s ease, color 0.15s ease,
              box-shadow 0.15s ease, transform 0.08s ease;
}

.header-btn:hover {
  background: #e5e7eb;
  color: #111827;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
  transform: translateY(-1px);
}

.header-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
}

.header-btn i {
  color: #374151 !important;
  pointer-events: none;
}

/* ---------------- BODY ---------------- */
.page-body {
  padding: 20px 24px 32px;
  flex: 1;
}

/* ---------------- SUMMARY GRID ---------------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  /* 모바일: 요약 2x2 + 여백·본문 패딩 축소 (상단 높이 절약) */
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
  .summary-card { padding: 12px 14px; }
  .page-body    { padding: 12px 14px 24px; }
}

.summary-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  gap: 14px;
}

/* 요약 카드 아이콘 원형 */
.summary-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #ffffff;
  flex-shrink: 0;
}

.summary-icon-wrap.play    { background: #1070dd; }
.summary-icon-wrap.stop    { background: #99a1af; }
.summary-icon-wrap.error   { background: #ed4545; }
.summary-icon-wrap.reserve { background: #ffc97b; }

/* 요약 카드 텍스트 영역 */
.summary-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-label {
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
}

.summary-count-line {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.summary-count-number {
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}

.summary-count-unit {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

/* ---------------- CONTROL PANELS ---------------- */
.control-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

/* 데모 계정: '다중 기기 제어'를 숨겨 2개만 남을 때 — 풀폭을 채우도록 2열 */
.control-panels.control-panels--two {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 900px) {
  /* 모바일: 전체 작동/LED 제어는 2열, 다중 기기 제어는 전체 너비 — 상단 높이 절약 */
  .control-panels { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .control-panels .control-panel:last-child { grid-column: 1 / -1; }
  .control-panel { padding: 10px 12px; gap: 8px; }
  .control-panel-title { font-size: 12px; }
}

.control-panel {
  background: #ffffff;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

.control-panel-btns {
  display: flex;
  gap: 8px;
}

/* 전체 산소 ON/OFF */
.ctrl-on {
  background: #1070dd;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ctrl-off {
  background: #99a1af;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* LED ON/OFF */
.ctrl-led-on {
  background: #7bbfff;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ctrl-led-off {
  background: #99a1af;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* 그룹 관리 버튼 (외곽선 스타일) */
.btn-group-reserve,
.btn-group-timer {
  background: #ffffff;
  color: #1070dd;
  border: 1.5px solid #1070dd !important;
  font-size: 13px;
  font-weight: 600;
}

.btn-group-reserve:hover,
.btn-group-timer:hover {
  background: #f0f5ff;
  filter: none;
}

/* ---------------- BUTTONS ---------------- */
.btn {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;

  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow: 0 4px 8px rgba(15, 23, 42, 0.22);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.30);
}

.btn-play-all {
  background: #1070dd;
  color: #ffffff;
}

.btn-stop-all {
  background: #d1d5dc;
  color: #666666;
}

.btn.is-pending {
  opacity: 0.6;
  cursor: wait;
  box-shadow: none;
  transform: none;
}

.btn.is-pending i {
  animation: spin 0.8s linear infinite;
}

/* ---------------- FOOTER ---------------- */
footer {
  padding: 16px 24px 20px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
}

footer span.brand {
  font-weight: 600;
  color: #111827;
}

/* ---------------- RESPONSIVE ---------------- */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---------------- LOADING OVERLAY ---------------- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-box {
  background: #ffffff;
  padding: 20px 28px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.loading-box p {
  margin: 0;
  font-size: 14px;
  color: #4b5563;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

:root {
  --device-card-width: 255px;
}

/* ---------------- 맨 위로 가기 버튼 (PC/모바일 공통) ---------------- */
.scroll-top-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: none;
  background: #2563eb;
  color: #ffffff;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
  /* 기본 숨김 — 스크롤 내리면 .is-visible 로 노출 */
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 90;          /* 카드(≤20) 위, 모달(≥2000) 아래 → 모달 열리면 가려짐 */
}

.scroll-top-btn.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn:hover { background: #1d4ed8; }
.scroll-top-btn:active { transform: translateY(0) scale(0.94); }

/* 카드 그리드 영역 — 컬럼 수는 JS가 --device-grid-cols 로 주입 */
.device-row-scroll {
  display: grid;
  grid-template-columns: repeat(var(--device-grid-cols, 4), minmax(var(--device-card-width, 255px), 1fr));
  gap: 16px;
  overflow-x: auto;
  /* 부모(.device-row, align-items:flex-start) 안에서 폭을 꽉 채우고 내용보다 좁아질 수 있게 →
     화면이 좁아지면 컬럼이 넘쳐서 이 줄에 가로 스크롤이 생김 (전체 페이지가 잘리지 않음) */
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-left: 0 !important;
  padding-left: 0 !important;
}

.device-row-scroll .device-card {
  min-width: var(--device-card-width, 255px);
}

.btn-led-play {
  background: #7bbfff;
  color: #ffffff;
}

.btn-led-stop {
  background: #d1d5dc;
  color: #666666;
}