/* Tesla 인카 디스플레이 (15.4인치 1920×1200) 기준 가로형 레이아웃 */

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

:root {
  --tab-height: 56px;
  --color-bg: #ffffff;
  --color-surface: #f2f2f7;
  --color-text: #1c1c1e;
  --color-tab-bg: #ffffff;
  --color-tab-active: #e31937;
  --color-tab-active-text: #ffffff;
  --color-tab-text: #3a3a3c;
  --color-toast-bg: rgba(44, 44, 46, 0.92);
  --color-toast-text: #ffffff;
  --color-spinner: #e31937;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #000000;
    --color-surface: #1c1c1e;
    --color-text: #f2f2f7;
    --color-tab-bg: #1c1c1e;
    --color-tab-active: #ff453a;
    --color-tab-active-text: #ffffff;
    --color-tab-text: #ebebf5;
    --color-toast-bg: rgba(28, 28, 30, 0.95);
    --color-toast-text: #f2f2f7;
    --color-spinner: #ff453a;
  }
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  font-size: 16px;
}

/* 탭 바 — 화면 상단 고정, 터치 타겟 56px */
#tab-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--tab-height);
  display: flex;
  align-items: stretch;
  background: var(--color-tab-bg);
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  z-index: 100;
}

.tab-btn {
  min-width: 120px;
  min-height: var(--tab-height); /* 터치 타겟 최소 48px 충족 */
  padding: 0 24px;
  border: none;
  background: transparent;
  color: var(--color-tab-text);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tab-btn.active {
  background: var(--color-tab-active);
  color: var(--color-tab-active-text);
  font-weight: 700;
}

.tab-btn:not(.active):hover {
  background: rgba(128, 128, 128, 0.12);
}

/* 메인 컨테이너 — 탭 바 아래 나머지 전체 */
#app-container {
  position: fixed;
  top: var(--tab-height);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

/* 지도 컨테이너 — 전체 채움 */
#map-container {
  width: 100%;
  height: 100%;
}

/* 로딩 스피너 */
.spinner {
  position: fixed;
  top: calc(var(--tab-height) + 16px);
  right: 20px;
  width: 40px;
  height: 40px;
  border: 4px solid rgba(128, 128, 128, 0.25);
  border-top-color: var(--color-spinner);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  z-index: 200;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 에러 토스트 */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-toast-bg);
  color: var(--color-toast-text);
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  z-index: 300;
  pointer-events: none;
  transition: opacity 0.3s;
}

.hidden {
  display: none !important;
}

/* ── 말풍선 (기능 B, C) ── */
:root {
  --color-bubble-bg: rgba(0, 0, 0, 0.82);
  --color-bubble-text: #ffffff;
  --color-popup-bg: #ffffff;
  --color-popup-text: #1c1c1e;
  --color-popup-border: rgba(0, 0, 0, 0.08);
  --color-popup-extra-bg: rgba(0, 0, 0, 0.02);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bubble-bg: rgba(255, 255, 255, 0.9);
    --color-bubble-text: #000000;
    --color-popup-bg: #1c1c1e;
    --color-popup-text: #f2f2f7;
    --color-popup-border: rgba(255, 255, 255, 0.1);
    --color-popup-extra-bg: rgba(255, 255, 255, 0.03);
  }
}

.bubble {
  background: var(--color-bubble-bg);
  color: var(--color-bubble-text);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.bubble:active {
  opacity: 0.75;
}

/* ── 슬라이드업 팝업 (기능 D) ── */
.apt-popup {
  position: fixed;
  left: 0;
  right: 0;
  bottom: -100%;
  max-height: 60vh;
  background: var(--color-popup-bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.2);
  z-index: 500;
  display: flex;
  flex-direction: column;
  transition: bottom 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.apt-popup--open {
  bottom: 0;
}

.apt-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-popup-border);
  flex-shrink: 0;
}

.apt-popup__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-popup-text);
}

.apt-popup__close {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border: none;
  background: rgba(128, 128, 128, 0.15);
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-popup-text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* 기능 D: 팝업 내부 스크롤 — Tesla 터치 스크롤 필수 속성 */
.apt-popup__body {
  flex: 1;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 env(safe-area-inset-bottom, 0);
}

.apt-popup__trade {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--color-popup-border);
  color: var(--color-popup-text);
  font-size: 15px;
}

.apt-popup__trade--extra {
  background: var(--color-popup-extra-bg);
}

.apt-popup__trade-area {
  min-width: 48px;
  font-weight: 600;
}

.apt-popup__trade-floor {
  color: var(--color-popup-text);
  opacity: 0.6;
  min-width: 36px;
}

.apt-popup__trade-price {
  font-weight: 700;
  font-size: 16px;
  margin-left: auto;
}

.apt-popup__trade-date {
  opacity: 0.55;
  font-size: 13px;
  min-width: 52px;
  text-align: right;
}

.apt-popup__empty {
  padding: 32px 24px;
  color: var(--color-popup-text);
  opacity: 0.5;
  font-size: 15px;
  text-align: center;
}

/* ── 현재 위치 마커 ── */
.location-marker {
  width: 22px;
  height: 22px;
  position: relative;
}

.location-marker::before {
  content: '';
  position: absolute;
  inset: 3px;
  background: #007aff;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 1;
}

.location-marker::after {
  content: '';
  position: absolute;
  inset: -4px;
  background: rgba(0, 122, 255, 0.22);
  border-radius: 50%;
  animation: location-pulse 2s ease-out infinite;
}

@keyframes location-pulse {
  0%   { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}
