/* 휴대폰·폴더블 전용 화면 (모바일은 보조 용도 — PC 화면은 바꾸지 않는다)
 * 모든 규칙은 "손가락으로 쓰는 화면(pointer: coarse)" 조건 안에만 둔다. 마우스로 쓰는 PC 는 창을 아무리 좁혀도 해당되지 않는다.
 *   휴대폰(바형·접은 폴드)      : 터치 + 폭 599px 이하
 *   펼친 화면(폴드·태블릿·가로) : 터치 + 폭 600~1100px (세로로 긴 폴드도, 가로로 넓고 세로가 짧은 폴더블도)
 *   위 둘 공통(좁은 터치 화면)  : 터치 + 폭 1100px 이하
 * 바꿀 때: README "휴대폰·폴더블 화면" 의 PC 비교 방법으로 PC 화면이 그대로인지 확인한다.
 */

/* PC 에서는 보이지 않는 요소 (보드 아래 막대 · 원장 [← 계정 목록] · 원장 [▾ 작업 정보]) */
.bd-mbar, .bb-m-back, .bb-m-info { display:none; }

/* ───────── 좁은 터치 화면 공통 ───────── */
@media (pointer: coarse) and (max-width: 1100px) {
  /* 아이폰 사파리가 가로 화면에서 일부 글자(계정 목록 등)만 멋대로 키우지 않게 */
  html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
  /* 🤖 클로드 패널: 휴대폰에는 연결 도우미(PC 프로그램)를 깔 수 없으므로 숨긴다 */
  #dhcBtn, #dhcPanel { display:none !important; }
  /* 🪟 탭 새 창(↗): 휴대폰에는 창을 나눠 쓸 자리가 없다 */
  .bb-tab-popout { display:none; }
  /* 머리글: 한 줄로 줄이고(버전·이메일 숨김), 아래로 내리면 숨겼다가 위로 올리면 다시 (js/mobile.js) */
  .header { position:sticky; top:0; z-index:800; margin:0 -20px 12px; padding:8px 20px; transition:transform .2s ease; }
  .header.m-hide { transform:translateY(-100%); }
  .header-inner { flex-wrap:nowrap; gap:10px; }
  .header h1 { font-size:18px; white-space:nowrap; }
  .header .version, #userEmail { display:none; }
  .main-tabs { order:0; width:auto; flex:1 1 auto; min-width:0; margin-left:4px; flex-wrap:nowrap; }
  .main-tab { flex:0 0 auto; padding:8px 12px; }
  .nav-cur { display:inline-block; max-width:30vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; vertical-align:bottom; }
  .header-user { flex:0 0 auto; margin-left:auto; }
  .btn-logout { padding:7px 10px; }

  /* 원장은 표 안이 아니라 화면 전체가 넘어가게 (합계 줄은 화면 아래에 붙음) */
  .bb-workspace { height:auto !important; min-height:0; }
  .bb-ledger { height:auto; }
  .bb-workspace, .bb-layout, .bb-main { overflow:clip; }
  #bbTabContent:has(> .bb-ledger) { overflow:visible; }
  .bb-ledger-scroll { max-height:none !important; overflow:visible; }
  .bb-ledger-table tfoot { position:sticky; bottom:0; }
  .bb-account-item { min-height:44px; }

  /* 🧮 전체 요약(시산표 모양): 칸 너비를 내용에 맞춰 금액이 잘리지 않게, 옆으로 밀어도 코드·계정과목은 왼쪽에 고정 */
  .bb-tb-table { table-layout:auto; width:auto; min-width:100%; }
  .bb-tb-table th, .bb-tb-table td { width:auto !important; white-space:nowrap; overflow:visible; text-overflow:clip; padding:7px 10px; }
  .bb-tb-table thead th:nth-child(-n+2), .bb-tb-table tbody tr.bb-tb-row > td:nth-child(-n+2) { position:sticky; z-index:1; }
  .bb-tb-table :where(tbody tr.bb-tb-row > td:nth-child(-n+2)) { background:#fff; }
  .bb-tb-table thead th:nth-child(1), .bb-tb-table tbody tr.bb-tb-row > td:nth-child(1) { left:0; width:64px !important; min-width:64px; font-size:11px; padding:7px 6px; }
  .bb-tb-table thead th:nth-child(2), .bb-tb-table tbody tr.bb-tb-row > td:nth-child(2) {
    left:64px; min-width:6.5em; white-space:normal; word-break:keep-all; box-shadow:1px 0 0 #e2e8f0;
  }
  .bb-tb-table thead th:nth-child(-n+2) { z-index:3; }

  /* 보드 프로젝트 화면 아래 막대 */
  .bd-mbar {
    display:flex; position:fixed; left:0; right:0; bottom:0; z-index:850;
    background:#fff; border-top:1px solid #e2e8f0; box-shadow:0 -4px 16px rgba(15,23,42,.08);
    padding:4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .bd-mbar button {
    flex:1; display:flex; flex-direction:column; align-items:center; gap:1px; min-height:48px; padding:4px 2px;
    border:0; background:none; font-family:inherit; font-size:11.5px; font-weight:600; color:#64748b; border-radius:8px;
  }
  .bd-mbar button span { font-size:19px; line-height:1.2; }
  .bd-mbar button.on { color:#2563eb; background:#eff6ff; }
  #boardSection:has(.bd-mbar) { padding-bottom:72px; }
  body:has(#boardSection .bd-mbar) .bd-chat-fab { bottom:calc(72px + env(safe-area-inset-bottom)); }
  .bd-ptabs, .bd-card { scroll-margin-top:64px; }
  /* 카드 머리의 단추 줄(일정: 달력·기간 수정·프로젝트 완료 등)이 화면 밖으로 나가 화면 전체가 옆으로 늘어나지 않게 */
  .bd-ch { flex-wrap:wrap; }
  .bd-ch .r { flex-wrap:wrap; min-width:0; }
  /* 아이폰에서 파일을 길게 누를 때 글자 선택·미리보기 대신 메뉴가 뜨게 */
  .bd-frow { -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }

  /* 원장: 탭·월 단추를 한 줄로 두고 옆으로 넘긴다 */
  .bb-main-header { padding:6px 10px 0; }
  .bb-main-header .tabs { flex:1 1 100%; flex-wrap:nowrap; overflow-x:auto; scrollbar-width:none; }
  .bb-main-header .tabs::-webkit-scrollbar, .bb-month-chips::-webkit-scrollbar { display:none; }
  .bb-main-header .bb-tab { flex:0 0 auto; padding:10px 10px; }
  .bb-main-header #bbEntrySearch { margin:4px 0 8px; font-size:16px; }
  .bb-ledger-bar { gap:8px; }
  .bb-month-chips { flex-wrap:nowrap; overflow-x:auto; scrollbar-width:none; }
  .bb-month-chip { flex:0 0 auto; padding:7px 13px; font-size:13px; }

  /* 원장 한 거래 = 두 줄 카드: 1줄 날짜·거래처 … 차변/대변, 2줄 적요 … 잔액 */
  .bb-ledger-table { display:block; font-size:13px; }
  .bb-ledger-table colgroup, .bb-ledger-table thead { display:none; }
  .bb-ledger-table tbody, .bb-ledger-table tfoot { display:block; }
  .bb-ledger-table tr {
    display:grid; grid-template-columns:auto minmax(0,1fr) auto auto; column-gap:8px; row-gap:1px;
    padding:7px 12px; border-bottom:1px solid #eef2f7;
  }
  .bb-ledger-table td { display:block; padding:0 !important; border:0 !important; background:none !important; min-width:0; }
  .bb-ledger-table td:empty { display:none; }
  .bb-ledger-table tr.bb-ledger-open, .bb-ledger-table tr.bb-ledger-month, .bb-ledger-table tr.bb-ledger-cum,
  .bb-ledger-table tr.bb-ledger-adj-head, .bb-ledger-table tr.bb-ledger-adj { background:#f8fafc; }
  .bb-ledger-table tr.bb-ledger-open { background:#f0fdf4; }
  .bb-ledger-table tr.bb-ledger-month { background:#eff6ff; }
  .bb-ledger-table tr.bb-ledger-adj-head, .bb-ledger-table tr.bb-ledger-adj { background:#fffbeb; }
  .bb-ledger-table tr.is-selected { background:#fef9c3; }
  /* 거래 줄: 날짜 · 적요 · 코드 · 거래처 · 차변 · 대변 · 잔액 */
  .bb-ledger-table tr.bb-entry-row > td:nth-child(1) { grid-area:1 / 1; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(2) { grid-area:2 / 1 / 3 / 3; color:#64748b; font-size:12px; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(3) { display:none; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(4) { grid-area:1 / 2; font-weight:600; color:#1e293b; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(5) { grid-area:1 / 3; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(6) { grid-area:1 / 4; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(7) { grid-area:2 / 3 / 3 / 5; }
  /* 이월·월계·누계·수정분개 줄: (날짜) · 내용 · 차변 · 대변 · 잔액 */
  .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(1) { grid-area:1 / 1; }
  .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(2) { grid-area:1 / 2; white-space:normal; }
  .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(3) { grid-area:1 / 3; }
  .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(4) { grid-area:1 / 4; }
  .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(5) { grid-area:2 / 1 / 3 / 5; }
  .bb-ledger-table tbody td.bb-empty-cell { grid-column:1 / -1; text-align:center; }
  /* 합계 줄: 내용 · 차변 · 대변 · 잔액 */
  .bb-ledger-table tfoot tr { background:#e2e8f0; font-weight:700; }
  .bb-ledger-table tfoot td:nth-child(1) { grid-area:1 / 1 / 2 / 3; white-space:normal; }
  .bb-ledger-table tfoot td:nth-child(2) { grid-area:1 / 3; }
  .bb-ledger-table tfoot td:nth-child(3) { grid-area:1 / 4; }
  .bb-ledger-table tfoot td:nth-child(4) { grid-area:2 / 1 / 3 / 5; }
  /* 금액 앞에 차·대·잔액 표시 (머리줄을 숨겼으므로) */
  .bb-ledger-table td.num { text-align:right; font-variant-numeric:tabular-nums; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(5)::before, .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(3)::before, .bb-ledger-table tfoot td:nth-child(2)::before { content:'차 '; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(6)::before, .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(4)::before, .bb-ledger-table tfoot td:nth-child(3)::before { content:'대 '; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(7)::before, .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(5)::before, .bb-ledger-table tfoot td:nth-child(4)::before { content:'잔액 '; }
  .bb-ledger-table td.num::before { font-size:11px; font-weight:500; color:#94a3b8; }
  .bb-ledger-table tr.bb-entry-row > td:nth-child(7), .bb-ledger-table tbody tr:not(.bb-entry-row) > td:nth-child(5), .bb-ledger-table tfoot td:nth-child(4) { font-size:12px; color:#475569; }
  .bb-statusbar { justify-content:flex-start; gap:8px 14px; }
}

/* ───────── 휴대폰 (바형·접은 폴드) ───────── */
@media (pointer: coarse) and (max-width: 599px) {
  #app { padding:0 12px 32px; }
  /* 머리글: 회사 이름도 숨겨 메뉴·로그아웃만 한 줄로 */
  .header { margin:0 -12px 12px; padding:8px 12px; }
  .header-inner { gap:8px; position:relative; }
  .header h1 { display:none; }
  .main-tabs { margin-left:0; position:static; }
  .nav-cur { max-width:34vw; }
  .bb-main-header #bbEntrySearch { width:100% !important; }
  .bb-month-chips { flex:1 1 100%; }

  /* 원장: 계정·탭을 누르면 원장만 화면 가득 (#bbSection.bb-m-detail, js/mobile.js), [← 계정 목록]·뒤로가기로 돌아옴 */
  #bbSection.bb-m-detail .bb-session-bar,
  #bbSection.bb-m-detail #bbSummaryCards,
  #bbSection.bb-m-detail .bb-support-toolbar,
  #bbSection.bb-m-detail .bb-sidebar { display:none; }
  #bbSection.bb-m-detail .bb-m-back {
    display:flex; align-items:center; gap:10px; padding:8px 10px; border-bottom:1px solid #e2e8f0; background:#f8fafc;
  }
  .bb-m-back button {
    flex:0 0 auto; padding:8px 12px; border:1px solid #cbd5e1; border-radius:8px; background:#fff;
    font-family:inherit; font-size:13px; font-weight:600; color:#1e293b;
  }
  .bb-m-back span { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:700; color:#1e293b; }
}

/* ───────── 펼친 화면 (폴드·태블릿·가로로 넓은 폴더블) ─────────
 * 원장은 PC 처럼 왼쪽 계정 목록 · 오른쪽 원장. 계정·탭을 누르면 위의 작업 이름·요약·자료 추가 칸을
 * 한 줄 [▾ 작업 정보] 로 접어 원장이 화면 위부터 보이게 (#bbSection.bb-m-detail, js/mobile.js) */
@media (pointer: coarse) and (min-width: 600px) and (max-width: 1100px) {
  .bb-layout { grid-template-columns:230px minmax(0,1fr); gap:12px; }
  .bb-sidebar { max-height:none; position:sticky; top:8px; align-self:start; height:calc(100vh - 16px); }
  .bb-account-list { max-height:none; flex:1 1 auto; overflow:auto; }
  #bbSection.bb-m-detail .bb-session-bar,
  #bbSection.bb-m-detail #bbSummaryCards,
  #bbSection.bb-m-detail .bb-support-toolbar { display:none; }
  #bbSection.bb-m-detail .bb-m-info {
    display:flex; align-items:center; gap:10px; width:100%; padding:8px 14px; border:1px solid #e2e8f0; border-radius:10px;
    background:#fff; font-family:inherit; font-size:13px; color:#475569; text-align:left; cursor:pointer;
  }
  .bb-main-header .tabs { flex:1 1 0; min-width:0; }
  .bb-main-header #bbEntrySearch { width:160px !important; margin:4px 0; }
  .bb-month-chips { flex:1 1 0; min-width:0; }
  .bb-m-info b { flex:0 0 auto; color:#2563eb; }
  .bb-m-info span { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; color:#1e293b; }
}
