/* ── 앱 헤더 (고정, 로그인 후 표시) ─────────────────────── */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: none;          /* showPage()에서 flex로 전환 */
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.header-logo {
  font-size: 19px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0;
  cursor: pointer;
}
.header-nav { flex: 1; display: flex; gap: 6px; margin-left: 8px; }
.header-right { display: flex; gap: 4px; margin-left: auto; align-items: center; }
body.app-mode .header-nav {
  display: none !important;
}
.header-loc-btn {
  padding: 4px 12px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  background: var(--card);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-loc-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .header-loc-btn { background: var(--card); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .header-loc-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.header-nav-btn {
  padding: 4px 12px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  background: var(--card);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
}
.header-nav-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.hamburger-btn {
  width: 38px; height: 38px;
  border: none; background: none;
  font-size: 21px; cursor: pointer;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  transition: background .15s;
}
.hamburger-btn:hover { background: var(--bg); }

/* ── 슬라이드 메뉴 (우측) ────────────────────────────────── */
#menu-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.38);
  z-index: 200; display: none;
}
#slide-menu {
  position: fixed; top: 0; right: 0;
  width: 275px; height: 100%;
  max-height: 100dvh;
  background: var(--card);
  z-index: 201;
  transform: translateX(100%);
  transition: transform .24s ease;
  display: flex; flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,.1);
  overflow-y: auto;
  overscroll-behavior: contain;
  /* iOS safe-area (노치/홈바) 대응 */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#slide-menu.open { transform: translateX(0); }

.menu-user-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.menu-uavatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
  overflow: hidden;
}
.menu-uinfo { flex: 1; min-width: 0; }
.menu-uname { font-size: 14px; font-weight: 700; }
.menu-uemail { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-my-btn {
  padding: 3px 9px;
  border: 1.5px solid var(--primary);
  border-radius: 99px;
  background: none; color: var(--primary);
  font-size: 12px; font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
.menu-my-btn:hover { background: var(--primary); color: #fff; }

.my-info-panel {
  padding: 10px 16px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 13px; line-height: 1.9;
}
.admin-token-box {
  margin: 8px 12px;
  background: #0f172a;
  border-radius: 8px;
  padding: 10px 12px;
}
.admin-token-label { font-size: 10px; color: #64748b; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.admin-token-val { font-family: 'Consolas', monospace; font-size: 10px; color: #7dd3fc; word-break: break-all; line-height: 1.6; }

.menu-section { border-bottom: 1px solid var(--border); }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 20px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s;
  border: none; background: none; width: 100%;
  text-align: left; color: var(--text);
}
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--danger); }
.menu-theme-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 20px; cursor: pointer; transition: background .15s;
}
.menu-theme-row:hover { background: var(--bg); }
.menu-theme-row-label { font-size: 14px; font-weight: 500; color: var(--text); }
.theme-sw {
  width: 46px; height: 26px; border-radius: 13px;
  background: #ccc; position: relative;
  transition: background .25s; flex-shrink: 0;
}
.theme-sw.on { background: #22c55e; }
.theme-sw-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  position: absolute; top: 3px; left: 3px;
  transition: transform .25s; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.theme-sw.on .theme-sw-thumb { transform: translateX(20px); }

/* ── 위치 설정 모달 (강제) ──────────────────────────────── */
#location-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
}
#location-modal-overlay.active { display: flex; }

/* ── 알림 패널 ──────────────────────────────────────────── */
#notif-panel {
  position: fixed;
  top: 58px;
  right: 60px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 150;
  width: 280px;
  max-height: 360px;
  overflow-y: auto;
  display: none;
}
.notif-item {
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.notif-item:hover { background: #f8fafc; }
.notif-item.is-disabled {
  opacity: .55;
  cursor: not-allowed;
}
.notif-item.is-disabled:hover { background: transparent; }
.notif-item:last-child { border-bottom: none; }
.notif-badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 99px;
  display: none;
  min-width: 16px;
  text-align: center;
}

/* ── 앱 모드 (로그인 후 레이아웃) ───────────────────────── */
body.app-mode {
  display: block;
  padding-top: 54px;
}
body.app-mode .page.active {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
  min-height: calc(100vh - 54px);
}

/* ── 대시보드 스크롤 레이아웃 ─────────────────────────────── */
#page-dashboard.active {
  align-items: flex-start !important;
}

/* ══════════════════════════════════════════════════════════
   헤더 다크모드 토글 버튼
══════════════════════════════════════════════════════════ */
#header-theme-btn {
  width: 36px; height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  font-size: 17px;
  cursor: pointer;
  display: none;           /* showPage()에서 app-mode 시 flex */
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
#header-theme-btn:hover { background: var(--primary); border-color: var(--primary); }
[data-theme="dark"] #header-theme-btn { background: var(--card); }

/* ══════════════════════════════════════════════════════════
   하단 탭 네비게이션 (Android 앱 스타일)
══════════════════════════════════════════════════════════ */
#bottom-nav {
  display: none;            /* app-mode 시 flex */
  position: fixed;
  bottom: 0; left: 50%; right: auto;
  transform: translateX(-50%);
  width: min(100vw, 430px);
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 100;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -2px 12px rgba(0,0,0,.07);
  max-width: 100%;
}
.bnav-item {
  flex: 1 1 0;
  max-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.bnav-item .bnav-icon {
  width: 24px; height: 24px;
  font-size: 20px;
  line-height: 24px;
  text-align: center;
  flex-shrink: 0;
}
.bnav-icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bnav-chat-badge {
  position: absolute;
  top: -5px;
  right: -8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  font-weight: 700;
  text-align: center;
  display: none;
  box-shadow: 0 0 0 2px var(--card);
  z-index: 1;
}
.bnav-item.active     { color: var(--primary); }
.bnav-item.active .bnav-icon { transform: scale(1.1); }
/* 등록 버튼 강조 */
.bnav-item.bnav-add {
  display: none;
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  max-width: none;
  min-height: 56px;
  padding: 0;
  z-index: 520;
  color: #171A20;
  font-size: 0;
  flex: none;
}
.bnav-item.bnav-add.active {
  color: #171A20;
}
.bnav-item.bnav-add .bnav-icon-wrap {
  width: 56px; height: 56px;
  flex-shrink: 0;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #171A20; font-size: 22px;
  box-shadow: 0 4px 12px rgba(34,40,49,.18);
  margin-bottom: 0;
}
.bnav-item.bnav-add.active .bnav-icon-wrap {
  color: #FFFFFF;
}
[data-theme="dark"] #bottom-nav { background: var(--card); }
[data-theme="dark"] body.app-mode {
  border-left-color: var(--border);
  border-right-color: var(--border);
}

/* ══════════════════════════════════════════════════════════
   app-mode 시 bottom-nav 공간 확보
══════════════════════════════════════════════════════════ */
body.app-mode {
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
}
body.app-mode .page.active {
  min-height: calc(100vh - 54px - 60px - env(safe-area-inset-bottom, 0px)) !important;
}

/* ── 내 상품 관리 패널 ───────────────────────────────────── */
.my-items-panel {
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--border);
  display: none;
}
.my-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.my-item-row:last-child { border-bottom: none; }
.my-item-thumb {
  width: 44px; height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #e2e8f0;
  flex-shrink: 0;
}
.my-item-info { flex: 1; min-width: 0; }
.my-item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-item-price { font-size: 11px; color: var(--muted); }
.my-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-edit-sm, .btn-del-sm {
  padding: 3px 9px;
  border-radius: 6px;
  background: none;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-align: center;
}
.btn-edit-sm { border: 1.5px solid var(--primary); color: var(--primary); }
.btn-del-sm  { border: 1.5px solid var(--danger);  color: var(--danger); }

/* ── GPS 위치 배지 ───────────────────────────────────────── */
.gps-badge {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
}

/* ── 페이지 푸터 ──────────────────────────────────────── */
.page-footer {
  text-align: center;
  padding: 24px 0 12px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 32px;
  line-height: 1.8;
}
.page-footer a { color: var(--primary); text-decoration: none; }

/* ══════════════════════════════════════════════════════════
   반응형 (모바일 우선 — 최대 480px 기준)
══════════════════════════════════════════════════════════ */

/* 헤더 nav 버튼 → 모바일에서 숨김 (하단 탭으로 대체) */
@media (max-width: 600px) {
  .header-nav { display: none !important; }

  /* 카드 전체 폭 */
  .card { max-width: 100% !important; padding: 28px 20px; }

  /* 대시보드 카드 */
  #page-dashboard .card { max-width: 100% !important; }

  /* 상품 썸네일 */
  .item-thumb, .item-thumb-placeholder { width: 72px; height: 72px; }

  /* FAB: 헤더 아래 우측 */
  #fab-upload {
    top: calc(72px + env(safe-area-inset-top, 0px)) !important;
    bottom: auto !important;
    right: 16px !important;
  }

  /* Toast: 하단 탭 위 */
  #toast-container {
    bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    right: 12px !important;
    max-width: 100%;
  }
  .toast { max-width: 100%; }

  /* 어드민 테이블 → 가로 스크롤 */
  .admin-table-wrap, #admin-users-table, #admin-items-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .um-row {
    min-width: 700px;
  }
  .admin-item-row {
    min-width: 560px;
  }
  .mypage-wrap {
    padding: 0 16px 24px;
  }
  .mypage-actions {
    gap: 6px;
  }
  .mypage-action {
    min-height: 70px;
    font-size: 11px;
  }

  /* 채팅 버블 최대 폭 */
  .msg-wrap { max-width: 88%; }

  /* 대여기간 캘린더 폰트 */
  .cal-day { font-size: 12px; padding: 6px 1px; }

  /* info-grid 단일 컬럼 */
  .info-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 380px) {
  .card { padding: 24px 16px; }
  .info-grid { grid-template-columns: 1fr; }
}

/* ── App header WIZ refresh ─────────────────────────── */
#app-header {
  height: 60px;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%);
  width: min(100vw, 430px);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bar-bg) !important;
  border-bottom: 1px solid var(--bar-border);
  box-shadow: 0 6px 20px rgba(34,40,49,.07);
  backdrop-filter: blur(18px) saturate(160%);
}
.header-logo {
  font-size: 22px;
  font-weight: 900;
  color: var(--bar-text);
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
.header-loc-btn {
  background: #FAFAF7;
  border-color: #E3DED2;
  color: var(--bar-text);
}
.header-loc-btn:hover {
  background: #FFF7CC;
  border-color: rgba(242,183,5,.55);
  color: var(--bar-text);
}
.header-nav-btn,
.filter-btn,
.tag-pill {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-weight: 750;
}
.header-nav-btn:hover,
.filter-btn.active,
.tag-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #171A20;
  box-shadow: 0 6px 14px rgba(242,183,5,.20);
}
.hamburger-btn,
#header-theme-btn {
  border: 1px solid #E3DED2;
  background: #FAFAF7;
  color: var(--bar-text);
  border-radius: 12px;
}
.hamburger-btn:hover,
#header-theme-btn:hover {
  background: #FFF7CC;
  border-color: rgba(242,183,5,.55);
}

/* ── Bottom nav WIZ refresh ─────────────────────────── */
#bottom-nav {
  height: calc(66px + env(safe-area-inset-bottom, 0px));
  background: var(--bar-bg) !important;
  border-top: 1px solid var(--bar-border);
  box-shadow: 0 -6px 22px rgba(34,40,49,.08);
  backdrop-filter: blur(18px) saturate(160%);
}
.bnav-item {
  max-width: none;
  gap: 4px;
  color: #72756F;
  font-weight: 750;
}
.bnav-item.active { color: #171A20; }
.bnav-item.bnav-add .bnav-icon-wrap {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #FFE066, #F2B705);
  color: #171A20;
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
}
body.app-mode {
  padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)) !important;
}

/* ── Slide menu WIZ refresh ─────────────────────────── */
#slide-menu {
  width: min(340px, 88vw);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 44px rgba(34,40,49,.20);
}
.menu-user-bar {
  padding: 24px 18px 18px;
  background: linear-gradient(180deg, #FFF7CC, #FFFFFF);
}
.menu-uavatar,
.room-avatar,
.avatar,
#item-detail-avatar {
  background: linear-gradient(135deg, #FFE066, #F2B705) !important;
  color: #171A20 !important;
}
.menu-item {
  min-height: 48px;
  font-weight: 650;
}

/* ── Page footer WIZ refresh ────────────────────────── */
.page-footer {
  border-top: none;
  color: var(--muted);
}

/* ── FAB WIZ refresh ────────────────────────────────── */
#fab-upload {
  background: linear-gradient(135deg, #FFE066, #F2B705) !important;
  color: #171A20 !important;
  box-shadow: 0 12px 26px rgba(34,40,49,.22) !important;
}
