/**
 * ============================================
 * 모바일 모드 시스템 CSS (완전 재설계)
 * ============================================
 */

/* ============================================
 * 0. PWA Safe Area 지원 (홈 화면 추가 시 Notch/Navigation Bar 대응)
 * ============================================ */

:root {
  /* Safe area inset 변수 정의 */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);

  /* 기본 패딩 + safe area */
  --padding-horizontal: max(12px, env(safe-area-inset-left, 12px), env(safe-area-inset-right, 12px));
  --padding-top: max(0px, env(safe-area-inset-top, 0px));
  --padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
}

/* 모바일 전역 - 가로 스크롤 방지 및 safe-area 적용 */
@media (max-width: 767px) {
  body, html {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
  }

  /* 모든 컨테이너가 safe-area를 넘지 않도록 */
  * {
    box-sizing: border-box;
  }
}

/* ============================================
 * 1. 모바일 전용 요소 표시
 * ============================================ */

@media (max-width: 767px) {
  .mobile-only {
    display: block;
  }
}


/* ============================================
 * 1. 모드 화면 공통
 * ============================================ */

@media (max-width: 767px) {
  /* 모드 화면 컨테이너 - 초기 상태는 무조건 숨김 (로그인 후 표시) */
  .mode-screen.mobile-only {
    display: none !important;
    visibility: hidden !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    background: #FFFFFF;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
  }

  /* 모드 활성화 시 표시 */
  .mode-screen.mobile-only.mode-active {
    display: flex !important;
    visibility: visible !important;
    z-index: 100;
    pointer-events: auto;
    animation: fadeIn 0.2s ease-out forwards;
  }

  /* 매장검색 모드는 흰색 배경 유지 (기본) */
  #mobileStoreSearchMode.mode-screen.mobile-only.mode-active {
    background: #FFFFFF;
  }

  /* 매장검색 모드에서 지도 뷰 활성화 시 투명 배경 + 터치 이벤트 통과 */
  #mobileStoreSearchMode.mode-screen.mobile-only.mode-active.map-view {
    background: transparent !important;
    pointer-events: none !important; /* 지도 터치가 통과되도록 */
  }

  /* 지도 뷰일 때도 헤더, 카드, 컨트롤은 클릭 가능하도록 */
  #mobileStoreSearchMode.map-view .mode-header,
  #mobileStoreSearchMode.map-view .selected-store-info,
  #mobileStoreSearchMode.map-view .mode-map-controls {
    pointer-events: auto !important;
  }

  .mode-screen[style*="display: none"] {
    display: none !important;
  }

  .mode-screen[style*="display: flex"] {
    display: flex !important;
  }

  @keyframes fadeIn {
    to {
      opacity: 1;
    }
  }

  /* 모드 헤더 */
  .mode-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #FFFFFF;
    border-bottom: 1px solid #F3F4F6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--padding-top) var(--padding-horizontal) 0 var(--padding-horizontal);
    padding-top: max(var(--safe-area-inset-top), 0px);
    z-index: 100;
  }

  .mode-header-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin: 0;
  }

  .mode-header-btn {
    min-width: 60px;
    min-height: 48px;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #4B5563;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mode-header-btn:active {
    background: #F3F4F6;
    transform: scale(0.96);
  }

  .mode-header-btn[data-mode] {
    color: #6366F1;
  }

  .mode-header-btn[data-mode]:active {
    background: #EEF2FF;
  }

  /* 모드 메인 컨텐츠 */
  .mode-main {
    position: absolute;
    top: calc(64px + var(--safe-area-inset-top));
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: #F8F9FA;
  }

  /* 매장검색 모드의 mode-main은 지도 표시를 위해 배경 제거 */
  #mobileStoreSearchMode .mode-main {
    background: transparent;
  }

  /* ============================================
   * 2. 모드 선택 화면
   * ============================================ */

  .mode-selection-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px var(--padding-horizontal);
    padding-bottom: max(20px, var(--safe-area-inset-bottom));
  }

  .mode-selection-header {
    text-align: center;
    margin-bottom: 80px;
  }

  .mode-selection-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px 0;
  }

  .mode-selection-header p {
    font-size: 14px;
    color: #6B7280;
    margin: 0;
  }

  .mode-selection-buttons {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .mode-select-btn {
    width: 100%;
    min-height: 72px;
    padding: 24px;
    background: #FFFFFF;
    border: 2px solid #E5E7EB;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .mode-select-btn:active {
    transform: scale(0.98);
    background: #F9FAFB;
    border-color: #6366F1;
  }

  .mode-btn-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
  }

  .mode-btn-desc {
    font-size: 14px;
    color: #6B7280;
  }

  /* ============================================
   * 3. 매장검색 모드 - 목록/지도 뷰
   * ============================================ */

  /* 목록 뷰 (기본) */
  .store-list-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: #F8F9FA;
    z-index: 10; /* 지도 위에 */
  }

  /* 검색바 */
  .mode-search-bar {
    flex-shrink: 0;
    margin: 12px var(--padding-horizontal) 0 var(--padding-horizontal);
    display: flex;
    align-items: center;
    gap: 8px;
    background: #FFFFFF;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    padding: 0 12px;
    height: 52px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .mode-search-input {
    flex: 1;
    height: 100%;
    border: none;
    outline: none;
    font-size: 16px;
    color: #111827;
    background: transparent;
  }

  .mode-search-input::placeholder {
    color: #9CA3AF;
  }

  .mode-search-clear {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #6B7280;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mode-search-clear:active {
    background: #F3F4F6;
  }

  /* 필터 */
  .store-filters {
    flex-shrink: 0;
    margin: 12px var(--padding-horizontal) 0 var(--padding-horizontal);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  /* 정렬 */
  .store-sort {
    flex-shrink: 0;
    margin: 8px var(--padding-horizontal) 0 var(--padding-horizontal);
    display: flex;
    gap: 8px;
  }

  .filter-select {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    background: #FFFFFF;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
  }

  /* 결과 카운트 */
  .store-result-count {
    flex-shrink: 0;
    margin: 0 12px 12px 12px;
    padding: 12px;
    background: #FFFFFF;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #111827;
  }

  /* 매장 목록 스크롤 영역 */
  .store-list-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .store-list {
    padding: 0 12px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  /* 선택된 매장 정보 카드 (지도 위) - 컴팩트 디자인 */
  #mobileStoreSearchMode .selected-store-info {
    position: fixed;
    top: 76px; /* 헤더(64px) + 여백(12px) */
    left: 12px;
    right: 12px;
    z-index: 50;
    background: #FFFFFF;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto; /* 카드 자체는 클릭 가능 */
    max-width: calc(100% - 24px); /* 좌우 여백 고려 */
  }

  .btn-back-to-list {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: none;
    border-radius: 8px;
    background: #6366F1;
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  .btn-back-to-list:active {
    background: #4F46E5;
    transform: scale(0.98);
  }

  .selected-store-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  /* 매장검색 모드가 아닐 때는 지도 숨김 */
  .mode-screen.mobile-only {
    pointer-events: none;
  }

  .mode-screen.mobile-only.mode-active {
    pointer-events: auto;
  }

  /* 기본 상태: 모바일에서 지도 숨김 */
  #map {
    display: none !important;
  }

  /* 매장검색 모드 활성화 시 지도 표시 */
  body.mobile-store-mode #map {
    position: fixed !important;
    top: 64px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: calc(100% - 64px) !important;
    z-index: 3 !important; /* 목록 뷰 아래, 지도 뷰와 같은 레벨 */
    display: block !important;
    visibility: visible !important;
  }

  /* 지도 컨트롤과 바텀시트가 지도 위에 표시되도록 z-index 조정 */
  body.mobile-store-mode .mode-map-controls,
  body.mobile-store-mode .mode-show-list-btn,
  body.mobile-store-mode .mode-bottom-sheet {
    z-index: 10 !important;
  }

  /* 지도 컨트롤 */
  #mobileStoreSearchMode .mode-map-controls {
    position: fixed;
    bottom: max(20px, var(--safe-area-inset-bottom));
    right: max(16px, var(--safe-area-inset-right));
    z-index: 40;
    pointer-events: auto; /* 컨트롤 버튼은 클릭 가능 */
  }

  .map-control-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 12px;
    background: #FFFFFF;
    color: #4B5563;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
  }

  .map-control-btn:active {
    transform: scale(0.94);
    background: #F9FAFB;
  }

  /* 목록보기 버튼 */
  .mode-show-list-btn {
    position: absolute;
    bottom: max(16px, var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 11;
    height: 48px;
    padding: 0 24px;
    background: #6366F1;
    color: #FFFFFF;
    border: none;
    border-radius: 24px;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mode-show-list-btn:active {
    transform: translateX(-50%) scale(0.96);
  }

  /* 바텀시트 */
  .mode-bottom-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #FFFFFF;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85%;
    display: flex;
    flex-direction: column;
  }

  .sheet-handle {
    width: 40px;
    height: 4px;
    background: #E5E7EB;
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
  }

  .sheet-handle:active {
    cursor: grabbing;
  }

  .sheet-header {
    padding: 12px var(--padding-horizontal);
    border-bottom: 1px solid #F3F4F6;
  }

  .sheet-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 12px;
  }

  .sheet-filters::-webkit-scrollbar {
    display: none;
  }

  .filter-select {
    flex-shrink: 0;
    height: 40px;
    padding: 0 32px 0 12px;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    background: #FFFFFF url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E") no-repeat right 12px center;
    font-size: 14px;
    font-weight: 600;
    color: #4B5563;
    cursor: pointer;
    appearance: none;
  }

  .sheet-count {
    font-size: 14px;
    font-weight: 600;
    color: #6B7280;
  }

  .sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px var(--padding-horizontal);
    padding-bottom: max(16px, var(--safe-area-inset-bottom));
  }

  .store-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  /* ============================================
   * 4. 재고검색 모드
   * ============================================ */

  .inventory-main {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 24px var(--padding-horizontal);
    padding-bottom: max(24px, var(--safe-area-inset-bottom));
    background: #FAFBFC;
  }

  .inventory-section {
    margin-bottom: 20px;
    background: #FFFFFF;
    padding: 20px;
    border-radius: 16px;
    border: 1px solid #E5E7EB;
  }

  .inventory-label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: #4B5563;
    margin-bottom: 10px;
  }

  .inventory-search-row {
    display: flex;
    gap: 10px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .inventory-input {
    flex: 1;
    min-width: 0; /* CRITICAL: flex item이 부모 너비를 초과하지 않도록 */
    height: 52px;
    padding: 0 16px;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    background: #FFFFFF;
    font-size: 16px;
    color: #111827;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
  }

  .inventory-input:focus {
    border-color: #6366F1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  }

  .inventory-input::placeholder {
    color: #9CA3AF;
  }

  .inventory-search-btn {
    flex-shrink: 0;
    min-width: fit-content; /* 내용에 맞춰 축소 가능 */
    max-width: 30%; /* 화면의 30%를 넘지 않도록 */
    height: 52px;
    padding: 0 20px;
    background: #6366F1;
    border: none;
    border-radius: 12px;
    color: #FFFFFF;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap; /* 텍스트 줄바꿈 방지 */
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
  }

  .inventory-search-btn:active {
    transform: scale(0.98);
    background: #4F46E5;
  }

  .inventory-select {
    width: 100%;
    height: 52px;
    padding: 0 40px 0 16px;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    background: #FFFFFF url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E") no-repeat right 16px center;
    font-size: 16px;
    color: #111827;
    cursor: pointer;
    appearance: none;
    outline: none;
    transition: all 0.2s ease;
  }

  .inventory-select:focus {
    border-color: #6366F1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  }

  .inventory-count {
    padding: 12px 24px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #6B7280;
  }

  .inventory-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
  }

  .inventory-reset-btn {
    width: 100%;
    height: 52px;
    margin-top: 20px;
    padding: 0 16px;
    background: #FFFFFF;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    color: #6B7280;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .inventory-reset-btn:active {
    transform: scale(0.98);
    background: #F9FAFB;
  }

  /* ============================================
   * 5. 매장 카드 (store-card)
   * ============================================ */

  .store-card {
    padding: 20px;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
  }

  .store-card:active {
    transform: scale(0.98);
    background: #F9FAFB;
    border-color: #6366F1;
  }

  .store-card-top {
    display: flex;
    gap: 12px;
  }

  .store-card-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 40px;
  }

  .store-card-name {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
  }

  .store-card-address {
    font-size: 14px;
    color: #6B7280;
    line-height: 1.4;
  }

  .store-card-contact {
    font-size: 13px;
    color: #9CA3AF;
  }

  .store-fav-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
  }

  .store-fav-btn:active {
    background: #F3F4F6;
    transform: scale(0.94);
  }

  .store-distance {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #F3F4F6;
    font-size: 13px;
    color: #6366F1;
    font-weight: 600;
  }

  /* ============================================
   * 6. 재고 카드 (inventory-card)
   * ============================================ */

  .inventory-card {
    padding: 20px;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 16px;
    transition: all 0.15s ease;
  }

  .inventory-card:active {
    transform: scale(0.98);
    background: #F9FAFB;
  }

  .inventory-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .inventory-card-model {
    font-size: 17px;
    font-weight: 700;
    color: #111827;
  }

  .inventory-card-color {
    padding: 6px 12px;
    background: #F3F4F6;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #4B5563;
  }

  .inventory-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .inventory-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .inventory-card-label {
    font-size: 13px;
    font-weight: 600;
    color: #6B7280;
  }

  .inventory-card-value {
    font-size: 14px;
    color: #4B5563;
  }

  /* ============================================
   * 7. 바텀시트 상태
   * ============================================ */

  .mode-bottom-sheet.closed {
    transform: translateY(calc(100vh - 80px));
  }

  .mode-bottom-sheet.half {
    transform: translateY(30vh);
  }

  .mode-bottom-sheet.full {
    transform: translateY(10vh);
  }

  /* ============================================
   * 8. 거리측정 모달 (전체 화면)
   * ============================================ */

  #mobileDistanceSheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #FFFFFF;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  #mobileDistanceSheet:not(.closed) {
    transform: translateY(0);
  }

  .distance-header {
    position: relative;
    padding: max(20px, var(--safe-area-inset-top)) var(--padding-horizontal) 20px var(--padding-horizontal);
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: #FFFFFF;
  }

  .distance-header .sheet-title {
    font-size: 20px;
    font-weight: 700;
    color: #111827;
    margin: 0;
  }

  .distance-header .sheet-close-btn {
    position: absolute;
    right: max(16px, var(--safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #F3F4F6;
    color: #4B5563;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 11;
  }

  .distance-header .sheet-close-btn:active {
    background: #E5E7EB;
    transform: translateY(-50%) scale(0.95);
  }

  .distance-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px var(--padding-horizontal);
    padding-bottom: max(20px, var(--safe-area-inset-bottom));
  }

  .bottom-sheet-handle {
    display: none; /* 바텀시트 핸들 숨김 */
  }

  /* Step 인디케이터 */
  .mobile-distance-step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 16px;
    background: #F9FAFB;
    border-radius: 12px;
  }

  .mobile-distance-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .mobile-distance-step .step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #E5E7EB;
    color: #6B7280;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
  }

  .mobile-distance-step.active .step-number {
    background: #6366F1;
    color: #FFFFFF;
  }

  .mobile-distance-step .step-label {
    font-size: 12px;
    color: #6B7280;
    font-weight: 600;
  }

  .mobile-distance-step.active .step-label {
    color: #6366F1;
  }

  .step-divider {
    color: #D1D5DB;
    font-size: 20px;
  }

  /* 거리측정 섹션 */
  .mobile-distance-section {
    margin-bottom: 20px;
  }

  .mobile-distance-section .section-label {
    font-size: 14px;
    font-weight: 600;
    color: #4B5563;
    margin-bottom: 10px;
  }

  /* 매장 선택 박스 */
  .mobile-store-select-box {
    position: relative;
    margin-bottom: 12px;
  }

  .mobile-store-search-input {
    width: 100%;
    height: 48px;
    padding: 0 40px 0 16px;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    font-size: 15px;
    color: #111827;
    background: #FFFFFF;
    outline: none;
    transition: all 0.2s ease;
  }

  .mobile-store-search-input:focus {
    border-color: #6366F1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  }

  .mobile-store-search-input::placeholder {
    color: #9CA3AF;
  }

  .mobile-store-search-input:disabled {
    background: #F3F4F6;
    color: #9CA3AF;
  }

  /* 선택된 매장 카드 */
  .mobile-selected-store-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #FFFFFF;
    border: 2px solid #6366F1;
    border-radius: 12px;
    margin-top: 12px;
  }

  .mobile-selected-store-card .store-icon {
    font-size: 24px;
    flex-shrink: 0;
  }

  .mobile-selected-store-card .store-info {
    flex: 1;
    min-width: 0;
  }

  .mobile-selected-store-card .store-name {
    font-size: 15px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 4px;
  }

  .mobile-selected-store-card .store-address {
    font-size: 13px;
    color: #6B7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-selected-store-card .btn-clear-store {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: #F3F4F6;
    color: #6B7280;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
  }

  .mobile-selected-store-card .btn-clear-store:active {
    background: #E5E7EB;
    transform: scale(0.95);
  }

  /* 거리 계산 버튼 */
  .mobile-distance-calculate-section {
    margin: 24px 0;
  }

  /* 거리 결과 */
  .mobile-distance-result-section {
    margin-top: 24px;
  }

  .mobile-distance-display-box {
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    color: #FFFFFF;
    margin-bottom: 16px;
  }

  .mobile-distance-display-box .distance-icon {
    font-size: 32px;
    margin-bottom: 8px;
  }

  .mobile-distance-display-box .distance-label {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
  }

  .mobile-distance-display-box .distance-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .mobile-distance-display-box .distance-method {
    font-size: 12px;
    opacity: 0.8;
  }

  .mobile-road-distance-box {
    background: #F9FAFB;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
  }

  .mobile-road-distance-box .road-icon {
    font-size: 24px;
    flex-shrink: 0;
  }

  .mobile-road-distance-box .road-info {
    flex: 1;
  }

  .mobile-road-distance-box .road-label {
    font-size: 13px;
    color: #6B7280;
    margin-bottom: 4px;
  }

  .mobile-road-distance-box .road-value {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
  }

  /* 액션 버튼 */
  .mobile-distance-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-distance-actions .btn {
    width: 100%;
    height: 48px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mobile-distance-actions .btn-secondary {
    background: #F3F4F6;
    color: #4B5563;
  }

  .mobile-distance-actions .btn-secondary:active {
    background: #E5E7EB;
    transform: scale(0.98);
  }

  .mobile-distance-actions .btn-primary {
    background: #6366F1;
    color: #FFFFFF;
  }

  .mobile-distance-actions .btn-primary:active {
    background: #4F46E5;
    transform: scale(0.98);
  }

  /* ============================================
   * 거리측정 모드 (새로운 독립 모드)
   * ============================================ */

  /* 거리측정 모드 활성화 시 지도 표시 */
  body.mobile-distance-mode #map {
    position: fixed !important;
    top: 64px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 64px) !important;
    display: block !important;
    z-index: 5 !important;
  }

  /* 거리측정 모드에서 모드 화면이 지도 위에 표시되도록 z-index 조정 */
  body.mobile-distance-mode #mobileDistanceMode {
    z-index: 10 !important;
  }

  /* PC용 지도 컨트롤 버튼 숨김 (모바일에서는 mode-map-controls 사용) */
  .map-controls {
    display: none !important;
  }

  /* ============================================
   * 모바일 버튼 오버플로우 방지 (전체 적용)
   * ============================================ */

  /* 모든 버튼이 safe-area를 벗어나지 않도록 */
  .btn,
  button,
  .btn-primary,
  .btn-secondary,
  .btn-reset-filters,
  .inventory-search-btn,
  .mode-header-btn {
    max-width: 100%;
    word-break: keep-all;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 필터 컨트롤 영역 - safe-area 준수 */
  .filter-controls {
    padding-left: var(--padding-horizontal);
    padding-right: var(--padding-horizontal);
    max-width: 100vw;
    box-sizing: border-box;
  }

  .filter-row {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* 초기화 버튼 - 전체 너비에서 safe-area 고려 */
  .btn-reset-filters {
    width: calc(100% - var(--padding-horizontal) * 2);
    margin-left: var(--padding-horizontal);
    margin-right: var(--padding-horizontal);
    box-sizing: border-box;
    flex-shrink: 0;
  }

  /* 재고 검색 입력 그룹 - 오버플로우 방지 */
  .inventory-input-group {
    display: flex;
    gap: 8px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .inventory-input-flex {
    flex: 1;
    min-width: 0; /* flex item이 부모 너비를 초과하지 않도록 */
  }

  #inventorySearchBtn {
    flex-shrink: 0;
    white-space: nowrap;
    min-width: fit-content;
    max-width: 30%; /* 검색 버튼이 너무 크지 않도록 */
  }

  /* 재고 검색 섹션 전체 - safe-area 준수 */
  .inventory-search-section {
    padding-left: var(--padding-horizontal);
    padding-right: var(--padding-horizontal);
    max-width: 100vw;
    box-sizing: border-box;
  }

  .inventory-form-group {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* 재고 초기화 버튼 */
  #inventoryResetBtn {
    width: 100%;
    max-width: calc(100vw - var(--padding-horizontal) * 2);
    box-sizing: border-box;
  }

  /* 모바일 재고 검색 모드의 컴팩트 초기화 버튼 */
  .inventory-reset-btn-compact {
    flex-shrink: 0;
    white-space: nowrap;
    min-width: fit-content;
    max-width: 100px; /* 최대 너비 제한 */
  }

  /* 모든 섹션이 safe-area를 넘지 않도록 */
  .sidebar-content {
    max-width: 100vw;
    overflow-x: hidden;
  }

  #inventoryTab,
  #listTab,
  #detailTab,
  #distanceTab {
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* 거리측정 탭 버튼들 */
  .btn-calculate-distance,
  .btn-block {
    width: 100%;
    max-width: calc(100vw - var(--padding-horizontal) * 2);
    box-sizing: border-box;
  }

  /* 결과 카운트 박스 */
  .result-count-box {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* 검색 박스 */
  .search-box {
    max-width: 100%;
    box-sizing: border-box;
  }

  .search-input {
    width: 100%;
    box-sizing: border-box;
  }

  /* 모든 select 요소 */
  select,
  .select,
  .filter-select,
  .inventory-dropdown {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* 모든 input 요소 */
  input,
  .input {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* flex 컨테이너 일반 규칙 */
  .flex,
  .flex-gap {
    max-width: 100%;
    flex-wrap: wrap; /* 필요시 줄바꿈 */
    box-sizing: border-box;
  }
}
