/* ============================================================
   carpriceflow - 공통 반응형 스타일
   모든 페이지 공용. 모바일 우선 (375px~) + 태블릿/데스크탑 대응
   ============================================================ */

/* ── 0. 전역 가드 ──────────────────────────────────────────── */
html, body { max-width: 100vw; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
img, canvas, svg { max-width: 100%; height: auto; }

/* ── 1. 태블릿 이하 (≤1024px) ─────────────────────────────── */
@media (max-width: 1024px) {
  main { padding: 20px 16px !important; }
  header { padding: 16px 20px !important; flex-wrap: wrap; gap: 8px !important; }
  header h1 { font-size: 18px !important; }
  .header-sub { font-size: 11px !important; margin-left: 0 !important; }
  .page-header { padding: 12px 16px !important; flex-wrap: wrap; gap: 8px !important; }
  .page-header h1 { font-size: 16px !important; }
  .page-header .header-sub { font-size: 11px !important; margin-left: 0 !important; }

  .filter-card { padding: 16px !important; }
  .filter-bar { padding: 12px 16px !important; }
  .filter-row { gap: 8px !important; }
  .filter-group { flex: 1 1 calc(50% - 4px) !important; min-width: 0 !important; }
  .fg { flex: 1 1 calc(50% - 4px) !important; min-width: 0 !important; }
  .fg select, .filter-group select, .filter-group input { min-width: 0 !important; width: 100% !important; }
  select, input[type="text"], input[type="number"] { min-width: 0 !important; max-width: 100% !important; }
}

/* ── 2. 모바일 (≤768px) ───────────────────────────────────── */
@media (max-width: 768px) {
  body { font-size: 13px !important; }
  main { padding: 16px 12px !important; }

  /* 헤더 */
  header, .page-header { padding: 12px 14px !important; }
  header h1, .page-header h1 { font-size: 16px !important; }
  .header-sub, .page-header .header-sub { font-size: 10px !important; width: 100%; }

  /* 페이지 탭 (상단 네비) */
  .tabs, .page-tabs {
    padding: 0 12px !important;
    gap: 0 !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar, .page-tabs::-webkit-scrollbar { display: none; }
  .tab-btn, .page-tab { padding: 10px 14px !important; font-size: 12px !important; white-space: nowrap !important; flex-shrink: 0; }
  .inner-tabs { padding: 0 12px !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .inner-tabs::-webkit-scrollbar { display: none; }
  .inner-tab { padding: 8px 14px !important; font-size: 12px !important; white-space: nowrap !important; flex-shrink: 0; }

  /* 필터 */
  .filter-card { padding: 12px !important; margin-bottom: 16px !important; }
  .filter-bar { padding: 10px 12px !important; }
  .filter-row { flex-direction: column; align-items: stretch !important; }
  .filter-group, .fg {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  .filter-group label, .fg label { font-size: 11px !important; }
  select, input[type="text"], input[type="number"] {
    width: 100% !important;
    min-width: 0 !important;
    font-size: 16px !important; /* iOS 자동확대 방지 + 가독성 */
    padding: 12px 14px !important;
    min-height: 48px !important;
    line-height: 1.3 !important;
  }
  select option { font-size: 16px !important; }
  .filter-group label, .fg label { font-size: 12px !important; margin-bottom: 6px !important; }
  .btn, .btn-primary, .btn-ghost, .btn-search, .btn-sm, .btn-neutral, .btn-danger, .btn-success {
    width: 100% !important;
    padding: 12px 16px !important;
    font-size: 14px !important;
  }
  .filter-opts, .filter-options { flex-wrap: wrap; gap: 12px !important; font-size: 12px !important; }

  /* 카드 / 통계 */
  .stats-row { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .stat-card { padding: 12px 14px !important; }
  .stat-card .svalue { font-size: 18px !important; }
  .stat-card .slabel { font-size: 11px !important; }
  .cards { flex-direction: column; gap: 10px !important; }
  .card { padding: 12px 14px !important; min-width: 0 !important; }
  .card-value { font-size: 1.1rem !important; }
  .summary-bar { flex-direction: column; gap: 8px !important; }
  .summary-card { width: 100% !important; padding: 10px 16px !important; }
  .summary-card .sc-value { font-size: 1.05rem !important; }
  .action-bar { width: 100% !important; margin-left: 0 !important; }

  /* 섹션 / 제목 */
  .section-title, .section-head { font-size: 13px !important; padding: 10px 14px !important; }
  .result-title { font-size: 14px !important; }

  /* 차트 컨테이너 */
  .chart-card { padding: 14px !important; margin-bottom: 16px !important; }
  .chart-header { flex-direction: column; align-items: flex-start !important; gap: 8px !important; }
  .chart-header h2 { font-size: 14px !important; }
  .chart-container { height: 280px !important; }
  .chart-wrap { padding: 14px !important; height: 280px !important; }
  .legend-row { gap: 10px !important; }
  .legend-item { font-size: 11px !important; }

  /* 테이블 */
  .table-wrap, .trend-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }
  table { min-width: 520px; font-size: 11px !important; }
  table th { padding: 8px 6px !important; font-size: 10px !important; white-space: nowrap; }
  table td { padding: 7px 6px !important; font-size: 11px !important; }
  table.depr thead th, table.depr tbody td { padding: 7px 8px !important; font-size: 11px !important; }
  table.mile { min-width: 560px; }
  table.main-tbl { min-width: 520px; }
  .vehicle-table thead th, .vehicle-table tbody td { padding: 6px 8px !important; font-size: 11px !important; }

  /* two-charts (askprice) */
  .two-charts { grid-template-columns: 1fr !important; gap: 14px !important; }

  /* forecast / empty state */
  .forecast-banner { flex-direction: column; gap: 10px !important; padding: 14px 16px !important; }
  .empty-state { padding: 32px 16px !important; }
  .empty-state .icon { font-size: 36px !important; }
  .empty-state p { font-size: 13px !important; }
  .prompt { padding: 28px 16px !important; }
  .prompt-icon { font-size: 28px !important; }
  .prompt p { font-size: 13px !important; }

  /* 로직 설명 블록 */
  .logic-info, .logic-block { font-size: 11px !important; padding: 12px !important; }
  .logic-formula { font-size: 10px !important; overflow-x: auto; }
  .footnote { font-size: 10px !important; }

  /* yearstats 필터바 */
  .grade-filter-bar { flex-wrap: wrap; gap: 8px !important; padding: 12px !important; }
  .grade-filter-bar input { width: 80px !important; }

  /* rawdata 연도 블록 */
  .year-head { flex-wrap: wrap; padding: 10px 14px !important; }
  .year-label { font-size: 13px !important; }
  .year-stats { font-size: 11px !important; width: 100%; }
  .year-actions { margin-left: 0 !important; width: 100%; justify-content: flex-end; }

}

/* ── 3. 초소형 모바일 (≤400px) ────────────────────────────── */
@media (max-width: 400px) {
  main { padding: 12px 10px !important; }
  header h1, .page-header h1 { font-size: 15px !important; }
  .tab-btn, .page-tab, .inner-tab { padding: 8px 12px !important; font-size: 11px !important; }
  .stats-row { grid-template-columns: 1fr !important; }
  .stat-card .svalue { font-size: 16px !important; }
  .chart-container, .chart-wrap { height: 240px !important; }
  table { font-size: 10px !important; }
  .btn, .btn-primary, .btn-ghost, .btn-search { padding: 11px 14px !important; font-size: 13px !important; }
}

/* ── 3.5. 터치 타겟 + 타이포 수정 (Design Audit Quick Wins) ─ */
input[type="checkbox"] { width: 22px; height: 22px; min-width: 22px; }
.filter-opt, .filter-options label { padding: 6px 4px; cursor: pointer; }
select { min-height: 44px; }
h2 { font-size: 19px !important; }
footer { font-size: 12px !important; }
footer p { font-size: 12px !important; }
/* ============================================================
   모바일 커스텀 select 피커 (mobile-select.js)
   ============================================================ */
.cf-sel-modal {
  position: fixed; inset: 0; z-index: 10000;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.cf-sel-modal.open { opacity: 1; pointer-events: auto; }
.cf-sel-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.cf-sel-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface, var(--white, #1a1d27));
  border-top: 1px solid var(--border, #2e3247);
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -10px 30px rgba(0,0,0,.5);
}
.cf-sel-modal.open .cf-sel-sheet { transform: translateY(0); }
.cf-sel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, #2e3247);
  position: sticky; top: 0;
  background: inherit;
}
.cf-sel-title {
  font-size: 16px; font-weight: 700;
  color: var(--accent, #4f8ef7);
}
.cf-sel-close {
  background: transparent; border: none;
  color: var(--text2, #9aa0b8);
  font-size: 22px; line-height: 1;
  padding: 4px 10px; cursor: pointer;
  border-radius: 6px;
}
.cf-sel-close:active { background: rgba(255,255,255,.08); }
.cf-sel-list {
  list-style: none; margin: 0; padding: 4px 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.cf-sel-opt {
  padding: 14px 20px;
  font-size: 16px;
  color: var(--text, #e8eaf0);
  border-bottom: 1px solid rgba(46,50,71,.4);
  cursor: pointer;
  min-height: 52px;
  display: flex; align-items: center;
  transition: background .12s ease;
}
.cf-sel-opt:active { background: rgba(79,142,247,.15); }
.cf-sel-opt.selected {
  background: rgba(79,142,247,.12);
  color: var(--accent, #4f8ef7);
  font-weight: 600;
}
.cf-sel-opt.selected::before {
  content: "✓";
  margin-right: 10px;
  color: var(--accent, #4f8ef7);
  font-weight: 700;
}
.cf-sel-opt.disabled {
  opacity: .4; cursor: not-allowed;
}
/* 데스크탑에서는 모달 숨김 */
@media (min-width: 769px) {
  .cf-sel-modal { display: none !important; }
}

/* ── 4. 터치 친화 (호버 없는 기기) ────────────────────────── */
@media (hover: none) {
  .tab-btn:hover, .page-tab:hover, .inner-tab:hover,
  .btn:hover, .btn-primary:hover, .btn-search:hover { background-color: inherit; }
}

/* ============================================================
   5. 모바일 햄버거 네비게이션 (mobile-nav.js 동작용)
   ============================================================ */

/* 기본: 데스크탑에서는 cf-nav-header와 overlay 숨김 */
.cf-nav-header { display: none; }
.cf-nav-overlay { display: none; }
.cf-nav-toggle { display: none; }

/* 모바일 (≤768px): 햄버거 드로어 모드 */
@media (max-width: 768px) {
  /* 상단 헤더 바 (햄버거 + 현재 페이지 라벨) */
  .cf-nav-header {
    display: flex !important;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface, var(--white, #1a1d27));
    border-bottom: 1px solid var(--border, #2e3247);
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .cf-nav-current {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent, var(--blue, #4f8ef7));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }

  /* 햄버거 버튼 */
  .cf-nav-toggle {
    display: flex !important;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 22px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
  }
  .cf-nav-toggle span {
    display: block;
    width: 100%;
    height: 2.5px;
    background: var(--text, #e8eaf0);
    border-radius: 2px;
    transition: transform .25s ease, opacity .2s ease;
    transform-origin: center;
  }
  .cf-nav-toggle.cf-nav-open span:nth-child(1) {
    transform: translateY(9.5px) rotate(45deg);
  }
  .cf-nav-toggle.cf-nav-open span:nth-child(2) {
    opacity: 0;
  }
  .cf-nav-toggle.cf-nav-open span:nth-child(3) {
    transform: translateY(-9.5px) rotate(-45deg);
  }

  /* 드로어 오버레이 */
  .cf-nav-overlay {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    z-index: 998;
  }
  .cf-nav-overlay.cf-nav-open {
    opacity: 1;
    pointer-events: auto;
  }

  /* 탭 영역을 드로어로 전환 */
  .cf-nav {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 78vw !important;
    max-width: 320px !important;
    background: var(--surface, var(--white, #1a1d27)) !important;
    flex-direction: column !important;
    padding: 72px 0 24px !important;
    margin: 0 !important;
    border-right: 1px solid var(--border, #2e3247) !important;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    z-index: 999;
    gap: 0 !important;
  }
  .cf-nav.cf-nav-open {
    transform: translateX(0);
  }

  /* 드로어 내부 탭 (세로 스택) */
  .cf-nav .tab-btn,
  .cf-nav .page-tab {
    width: 100% !important;
    text-align: left !important;
    padding: 16px 24px !important;
    font-size: 15px !important;
    border-radius: 0 !important;
    border-bottom: 1px solid var(--border, #2e3247) !important;
    margin: 0 !important;
    background: transparent !important;
    white-space: normal !important;
    flex-shrink: 0 !important;
    justify-content: flex-start !important;
  }
  .cf-nav .tab-btn.active,
  .cf-nav .page-tab.active {
    background: var(--blue-light, rgba(79, 142, 247, 0.12)) !important;
    border-left: 3px solid var(--accent, var(--blue, #4f8ef7)) !important;
    color: var(--accent, var(--blue, #4f8ef7)) !important;
  }
}
