/* =====================================================================
   점마Pro 모바일 배치 (jeomma-google 전용)
   - 화면 폭 1023px 이하에서만 적용돼요. PC 화면과 인쇄물(@media print)은 그대로예요.
   - 결과지 인쇄용 쪽을 만드는 동안에는 mobile.js가 이 파일을 잠깐 꺼요.
     (인쇄 쪽 나누기가 화면 배치를 재서 만들어지기 때문에, 인쇄물이 PC와 똑같이 나오도록)
   - 기존 규칙 중 !important + ID가 붙은 것이 많아서, 덮어쓸 때는 #아이디를 두 번 써서 우선순위를 올려요.
   ===================================================================== */

:root {
  --m-bar-h: 56px;
  --m-safe-t: env(safe-area-inset-top, 0px);
  --m-safe-b: env(safe-area-inset-bottom, 0px);
  --m-top: calc(var(--m-bar-h) + var(--m-safe-t));
  --m-gutter: 16px;
  --m-drawer-w: min(86vw, 390px);
}

#jm-m-topbar,
#jm-m-backdrop {
  display: none;
}

@media screen and (max-width: 1023px) {

  /* ---------------------------------------------------------------
     0. 기본: PC 최소 폭(1400px) 해제, 화면 높이는 주소창을 뺀 높이(dvh)
     --------------------------------------------------------------- */
  html,
  body {
    min-width: 0 !important;
    width: 100% !important;
    overflow: hidden !important;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
  }

  .jm-screen {
    min-width: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    padding-top: var(--m-top) !important;
    box-sizing: border-box !important;
    flex-direction: column !important;
  }

  /* PC 왼쪽 아이콘 레일은 숨기고 모바일 상단 바를 써요 */
  .jm-icon-rail,
  .jm-p1-rail-pane {
    display: none !important;
  }

  /* ---------------------------------------------------------------
     1. 모바일 상단 바 (mobile.js가 만들어요)
     --------------------------------------------------------------- */
  #jm-m-topbar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 900;
    height: var(--m-top);
    padding: var(--m-safe-t) 6px 0;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-between;
    background-color: var(--jm-sidebar, #121212);
    border-bottom: 1px solid #1c1c1c;
  }
  .jm-m-bar-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b5b5b5;
    background: transparent;
    flex-shrink: 0;
  }
  .jm-m-bar-btn svg {
    display: block;
  }
  .jm-m-bar-btn:active,
  .jm-m-bar-logo:active {
    background-color: #1f1f1f;
  }
  .jm-m-bar-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 44px;
    padding: 0 10px;
    border-radius: 10px;
    background: transparent;
  }
  .jm-m-bar-logo img {
    height: 17px;
    width: auto;
    display: block;
  }
  .jm-m-bar-logo span {
    font-size: 12px;
    font-weight: 600;
    color: #8a8a8a;
    letter-spacing: -0.01em;
  }

  /* 서랍이 열렸을 때 뒤를 덮는 막 */
  #jm-m-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 950;
    background-color: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  html.jm-m-drawer-open #jm-m-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------------------------------------------------------------
     2. 고객 명단 서랍 (1화면: 사이드바 열림 칸 / 3화면: 명단 오버레이)
     --------------------------------------------------------------- */
  #jm-screen-1#jm-screen-1 .jm-p1-sidebar {
    position: static !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    height: 0 !important;
    border: 0 !important;
    overflow: visible !important;
    flex: 0 0 0 !important;
  }
  #jm-screen-1#jm-screen-1 .jm-p1-open-pane,
  #jm-screen-3#jm-screen-3 .jm-p3-client-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: var(--m-drawer-w) !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    padding: var(--m-safe-t) 0 var(--m-safe-b) !important;
    box-sizing: border-box !important;
    z-index: 1000 !important;
    background-color: var(--jm-sidebar, #121212) !important;
    border-right: 1px solid #1f1f1f !important;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.6) !important;
    opacity: 1 !important;
    transform: translateX(-104%) !important;
    pointer-events: none !important;
    transition: transform 0.28s cubic-bezier(0.2, 0, 0, 1) !important;
  }
  html.jm-m-drawer-1 #jm-screen-1#jm-screen-1 .jm-p1-open-pane,
  #jm-screen-3#jm-screen-3 .jm-p3-client-overlay.active {
    transform: none !important;
    pointer-events: auto !important;
  }
  .jm-p1-open-pane .jm-p1-side-top,
  .jm-p3-client-overlay .jm-p1-side-top,
  .jm-p1-open-pane .jm-brand-header,
  .jm-p3-client-overlay .jm-brand-header,
  .jm-p1-open-pane .jm-btn-new-intake,
  .jm-p3-client-overlay .jm-btn-new-intake,
  .jm-p1-open-pane .jm-p1-side-scroll,
  .jm-p3-client-overlay .jm-p1-side-scroll,
  .jm-p1-open-pane .jm-p1-side-bottom,
  .jm-p3-client-overlay .jm-p1-side-bottom {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .jm-p1-open-pane .jm-btn-new-intake,
  .jm-p3-client-overlay .jm-btn-new-intake {
    height: 44px !important;
  }
  .jm-p1-open-pane .jm-icon-btn,
  .jm-p3-client-overlay .jm-icon-btn {
    width: 40px !important;
    height: 40px !important;
  }
  .jm-crm-dropdown {
    min-width: 0 !important;
  }
  /* 고객 카드 점 3개 버튼: 손가락으로 누르기 쉽게 */
  .jm-p1-open-pane .jm-card-menu-btn,
  .jm-p3-client-overlay .jm-card-menu-btn {
    width: 36px !important;
    height: 36px !important;
  }

  /* ---------------------------------------------------------------
     3. 1화면: 만세력 입력
     --------------------------------------------------------------- */
  #jm-screen-1#jm-screen-1 .jm-p1-main {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    padding: 24px var(--m-gutter) calc(32px + var(--m-safe-b)) !important;
    align-items: flex-start !important;
  }
  #jm-screen-1 .jm-p1-form-wrapper {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 460px !important;
    margin: auto !important;
  }
  #jm-screen-1 .jm-p1-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  #jm-screen-1 .jm-p1-form-grid > .jm-col-3,
  #jm-screen-1 .jm-p1-form-grid > .jm-col-2:last-child {
    grid-column: span 2 !important;
  }
  #jm-screen-1 .jm-p1-form-grid > .jm-col-2 {
    grid-column: span 1 !important;
  }

  /* ---------------------------------------------------------------
     4. 2화면: 분석 로딩
     --------------------------------------------------------------- */
  #jm-screen-2#jm-screen-2 .jm-p2-checklist-pane {
    order: 2 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    border-right: 0 !important;
    border-top: 1px solid #161616 !important;
    padding: 10px var(--m-gutter) calc(10px + var(--m-safe-b)) !important;
    flex: 0 0 auto !important;
  }
  #jm-screen-2 .jm-p2-checklist-pane .jm-p2-title,
  #jm-screen-2 .jm-p2-checklist-pane .jm-p2-steps-wrap {
    display: none !important;
  }
  #jm-screen-2#jm-screen-2 .jm-p2-canvas-area {
    order: 1 !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    width: 100% !important;
  }
  #jm-screen-2 .jm-p2-stage-wrapper {
    padding: 12px !important;
  }
  #jm-screen-2#jm-screen-2 #jm-morph-stage-window {
    width: 100% !important;
    max-width: 100% !important;
    padding: 16px !important;
  }

  /* ---------------------------------------------------------------
     5. 3화면: 결과
     --------------------------------------------------------------- */
  #jm-screen-3#jm-screen-3 .jm-p3-dashboard-main {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    padding: 0 0 calc(24px + var(--m-safe-b)) !important;
    align-items: stretch !important;
  }

  /* 프로필 · 점수 카드: mobile.js가 결과창 맨 위로 옮겨요 */
  #jm-screen-3#jm-screen-3 .jm-p3-sidebar {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    position: static !important;
    overflow: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    border-right: 0 !important;
    padding: 20px var(--m-gutter) 8px !important;
    background-color: transparent !important;
    flex-shrink: 0 !important;
    will-change: auto !important;
  }

  /* 결과지 + 섹션 메뉴: 세로로 쌓고, 메뉴는 위에 붙는 가로 칩으로 */
  #jm-screen-3#jm-screen-3 .jm-p3-report-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
  }
  #jm-screen-3#jm-screen-3 .jm-p3-content-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
    margin: 8px 0 40px !important;
    padding: 0 var(--m-gutter) !important;
    box-sizing: border-box !important;
  }
  #jm-screen-3#jm-screen-3 #jm-p3-scroll-nav {
    order: -1 !important;
    position: sticky !important;
    top: 0 !important;
    align-self: stretch !important;
    margin: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    flex-direction: row !important;
    gap: 6px !important;
    padding: 8px var(--m-gutter) !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border: 0 !important;
    border-bottom: 1px solid #1c1c1c !important;
    border-radius: 0 !important;
    background-color: var(--jm-canvas, #0b0b0b) !important;
    scrollbar-width: none !important;
    z-index: 150 !important;
  }
  #jm-screen-3 #jm-p3-scroll-nav::-webkit-scrollbar {
    display: none !important;
  }
  #jm-screen-3#jm-screen-3 #jm-p3-scroll-nav {
    touch-action: pan-x pan-y !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    user-select: none;
  }
  #jm-screen-3#jm-screen-3 #jm-p3-scroll-nav.is-dragging {
    cursor: grabbing;
  }
  #jm-screen-3#jm-screen-3 #jm-p3-scroll-nav .jm-scroll-nav-btn {
    width: auto !important;
    flex: 0 0 auto !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 14px !important;
    border-radius: 17px !important;
    font-size: 14px !important;
  }

  /* ---------------------------------------------------------------
     6. 결과지 안쪽 부품 (좁은 화면에 맞게 줄 수 · 칸 수 조정)
     --------------------------------------------------------------- */
  /* 섹션 제목 · 설명 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .section-title {
    font-size: 22px !important;
    line-height: 1.4 !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .section-sub {
    font-size: 16px !important;
    line-height: 1.6 !important;
  }

  /* 소제목 배지 줄: 배지 위, 제목 아래 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .card-tag-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .card-tag {
    max-width: 100% !important;
    width: auto !important;
    white-space: normal !important;
    flex: 0 0 auto !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .report-lead {
    padding-left: 0 !important;
  }

  /* 아이콘 + 글 상자: 아이콘은 제목 옆, 본문은 상자 전체 폭 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .clean-feature-box {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    column-gap: 10px !important;
    row-gap: 8px !important;
    align-items: start !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .clean-feature-box > .cfb-body {
    display: contents !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .clean-feature-box > .cfb-body > * {
    grid-column: 1 / -1 !important;
    margin-left: 0 !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .clean-feature-box > .cfb-body > :first-child {
    grid-column: 2 !important;
  }

  /* 칸 나눔: 4칸 → 2칸, 6칸 → 3칸, 2칸 → 1칸 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .meta-cards-grid,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .masterkey-4-grid,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .yr-pill-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .month-grid-12 {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .gongmang-2col-boxes,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .cheoneul-2col-boxes {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .card-title-inline {
    white-space: normal !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* 원국 4기둥: 글자 길이 때문에 칸이 넓어지지 않게 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .wonguk-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    column-gap: 6px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-pillar-col {
    min-width: 0 !important;
  }
  /* 천간 · 지지 카드: 비율(aspect-ratio)과 최소 높이가 맞물려 사파리(아이폰)에서 칸보다 넓어지던 문제 →
     비율을 끄고 높이를 직접 지정해서 칸 폭에 딱 맞춰요 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-slot-row-3,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-slot-row-4 {
    aspect-ratio: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 120px !important;
    min-height: 120px !important;
    box-sizing: border-box !important;
  }
  /* 12신살 줄(2개)은 두 줄로, 기타 신살 줄은 개수만큼 늘어나게 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-slot-row-8 {
    height: 64px !important;
    min-height: 64px !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 3px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-slot-row-9 {
    height: auto !important;
    min-height: 145px !important;
    flex: 1 0 auto !important;
  }
  /* 지장간 막대: 칸이 좁아 한 줄에 다 안 들어가서 세로로 쌓아요 (기둥끼리 줄 높이는 같게) */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-slot-row-5 {
    height: 66px !important;
    min-height: 66px !important;
    align-items: flex-start !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-jjg-stacked-bar {
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    gap: 2px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-jjg-bar-seg {
    width: 100% !important;
    height: 20px !important;
    min-height: 20px !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 0 4px !important;
    border-radius: 4px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .jm-jjg-bar-seg span {
    font-size: 11px !important;
    line-height: 1 !important;
  }

  /* 오행 · 음양 · 오성 · 십성 분포도: 2칸 × 2줄, 그림 비율 유지 */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .charts-4-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .charts-4-grid canvas {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
  }

  /* 큰 섹션 사이 여백 96px → 56px */
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper #panel-personality,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper #panel-masterkey,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper #panel-love,
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper #panel-biz {
    margin-bottom: 56px !important;
  }
  #jm-screen-3#jm-screen-3#jm-screen-3 .jm-p3-content-wrapper .yr-pill {
    min-width: 0 !important;
    white-space: nowrap !important;
  }

  /* 대운 · 세운: 10칸 그래프와 표를 최소 640px로 그리고, 화면보다 넓으면 옆으로 밀어서 봐요 (칸이 너무 좁아지지 않게) */
  #jm-screen-3#jm-screen-3 #wave-sec-daeun .wave-card-box,
  #jm-screen-3#jm-screen-3 #wave-sec-seun .wave-card-box {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-x: contain;
    scrollbar-width: none !important;
  }
  #jm-screen-3#jm-screen-3 #wave-sec-daeun .wave-card-box,
  #jm-screen-3#jm-screen-3 #wave-sec-seun .wave-card-box {
    touch-action: pan-x pan-y !important;
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
  }
  /* 표 칸(.interactive-col)이 손가락(pointer) 커서를 덮어쓰지 않게, 안쪽 전부 펼친 손(grab)으로 */
  #jm-screen-3#jm-screen-3 #wave-sec-daeun .wave-card-box *,
  #jm-screen-3#jm-screen-3 #wave-sec-seun .wave-card-box * {
    cursor: grab !important;
  }
  #jm-screen-3#jm-screen-3 #wave-sec-daeun .wave-card-box.is-dragging,
  #jm-screen-3#jm-screen-3 #wave-sec-seun .wave-card-box.is-dragging,
  #jm-screen-3#jm-screen-3 #wave-sec-daeun .wave-card-box.is-dragging *,
  #jm-screen-3#jm-screen-3 #wave-sec-seun .wave-card-box.is-dragging * {
    cursor: grabbing !important;
  }
  #jm-screen-3 #wave-sec-daeun .wave-card-box::-webkit-scrollbar,
  #jm-screen-3 #wave-sec-seun .wave-card-box::-webkit-scrollbar {
    display: none !important;
  }
  #jm-screen-3#jm-screen-3 #viewport-daeun,
  #jm-screen-3#jm-screen-3 #viewport-seun,
  #jm-screen-3#jm-screen-3 #sub-charts-daeun,
  #jm-screen-3#jm-screen-3 #sub-charts-seun {
    width: 100% !important;
    min-width: 640px !important;
    max-width: none !important;
  }

  /* ---------------------------------------------------------------
     7. 로딩 화면 세부
     --------------------------------------------------------------- */
  #jm-screen-2 .jm-stage-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  #jm-screen-2 .jm-stage-status-pulse {
    max-width: 100% !important;
    white-space: normal !important;
    text-align: left !important;
  }
  #jm-screen-2 .jm-scan-readout {
    flex-wrap: wrap !important;
    gap: 2px 14px !important;
    font-size: 10px !important;
  }
  #jm-screen-2 .jm-sangseng-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* ---------------------------------------------------------------
     8. 터치 화면: 눌렀다 뗀 뒤 회색 hover가 남지 않게, 서랍 닫기 아이콘은 X
     --------------------------------------------------------------- */
  #jm-m-topbar button:hover {
    background-color: transparent;
  }
  #jm-m-topbar button:active {
    background-color: #1f1f1f;
  }
  #btn-toggle-p1-sidebar > svg:not(.jm-m-x),
  #btn-toggle-p3-client-sidebar > svg:not(.jm-m-x) {
    display: none !important;
  }
  #btn-toggle-p1-sidebar > .jm-m-x,
  #btn-toggle-p3-client-sidebar > .jm-m-x {
    display: block !important;
  }
}

.jm-m-x {
  display: none;
}
