/* HAKSAN DOT 모바일 레이아웃 (폭 768px 이하) — 항상 다른 CSS 뒤에 로드한다.
   데스크톱 화면은 이 파일의 영향을 받지 않는다(전부 @media 안에 있다).
   1단계: 왼쪽 레일 → 하단 탭바, 상단바/서브탭 축소, 가로 넘침 방지, 홈 화면 설치(standalone) 안전영역 처리 */

/* 모바일에서만 보이는 요소 */
.m-only, .m-backbar { display: none; }

@media (max-width: 768px) {
  .m-only { display: block; }
  html, body { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }

  /* 입력칸 글자: 기본 14px. iOS만 16px 미만이면 포커스 때 화면을 확대해 버리므로 아래 @supports 에서 16px */
  input, select, textarea { font-size: 14px !important; }
  @supports (-webkit-touch-callout: none) { input, select, textarea { font-size: 16px !important; } }

  /* 전체 틀: 위(본문) + 아래(탭바) */
  .app-shell { flex-direction: column; height: 100vh; height: 100dvh; height: var(--app-h, 100dvh); }
  .app-shell { position: relative; top: var(--app-top, 0px); }   /* 키보드가 보이는 영역을 밀어도 앱 틀이 따라간다 */   /* --app-h: common.js가 잰 '실제로 보이는' 높이 */
  .main-col { order: 1; min-height: 0; flex: 1 1 auto; width: 100%; }
  /* 하단 탭바는 어떤 기기·브라우저에서도 화면 맨 아래에 고정(position: fixed). 문서가 스크롤되거나 주소창이 늘고 줄어도,
     폴더블처럼 화면 높이가 특이해도 항상 보인다. 본문은 탭바 높이만큼 아래 여백을 둔다. */
  html:has(.app-shell), body:has(.app-shell) { height: 100%; overflow: hidden; overscroll-behavior: none; }
  .main-col { padding-bottom: calc(58px + env(safe-area-inset-bottom)); box-sizing: border-box; }
  .rail, .rail.rail-expanded {
    position: fixed !important; left: 0; right: 0; bottom: 0; top: auto !important; z-index: 60;
    order: 2; width: 100%; height: calc(58px + env(safe-area-inset-bottom));
    flex-shrink: 0; transition: none; background: var(--surface, #fff);
  }
  .rail-inner {
    position: static; width: 100%; height: 100%;
    flex-direction: row; align-items: stretch; gap: 0;
    padding: 0 0 env(safe-area-inset-bottom);
    border-right: 0; border-top: 1px solid var(--border);
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .rail-inner::-webkit-scrollbar { display: none; }
  .rail-brand, .rail-toggle-btn { display: none !important; }
  /* 관리자 메뉴(계정/전사 LINE/공지 관리)는 PC에서만 — 탭바에 8칸이 한 줄에 다 들어가게 한다 */
  #nav-users, #nav-admin-projects, #nav-notice-admin { display: none !important; }
  .rail-inner a {
    flex: 1 0 44px; min-width: 0; max-width: 100px; height: auto; margin: 0; padding: 6px 0 4px;
    flex-direction: column; justify-content: center; align-items: center; gap: 3px;
    border-radius: 0; overflow: visible;
  }
  .rail-inner a:hover { background: none; }
  .rail-inner a.active { background: none; color: #1C1C1A; }
  .rail-inner a.active .rail-icon { background: rgba(28,28,26,.09); }
  .rail-icon { width: 40px; height: 26px; border-radius: 13px; }
  .rail-label, .rail.rail-expanded .rail-label {
    opacity: 1; font-size: 10px; font-weight: 600; max-width: 100%; letter-spacing: -.03em; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; line-height: 1.1;
  }
  .dm-unread-dot { top: 0; right: 8px; }

  /* 상단바 */
  .topbar { height: auto; min-height: 50px; padding: env(safe-area-inset-top) 12px 0; gap: 8px; }
  .topbar > * { min-width: 0; }
  .topbar > div:last-child { flex-shrink: 0; gap: 8px !important; }
  #me-name { max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .crumbs { overflow: hidden; white-space: nowrap; flex: 1 1 auto; min-width: 0; }
  .crumbs .current { overflow: hidden; text-overflow: ellipsis; }

  /* LINE 하위 탭(보드/리스트/…/파일) — 밀지 않아도 전부 보이게 한 줄에 4개씩 줄바꿈 */
  .project-subnav { flex-wrap: wrap; overflow: visible; white-space: normal; padding: 0 4px; gap: 0; }
  .project-subnav a { flex: 1 0 25%; max-width: 25%; text-align: center; padding: 10px 2px; font-size: 13px; box-sizing: border-box; }

  /* 본문 여백 축소 */
  .page-pad { padding-left: 12px; padding-right: 12px; }
  .board-header, .projects-toolbar { padding-left: 14px; padding-right: 14px; }
  .columns { padding-left: 14px; padding-right: 14px; padding-bottom: 76px; scroll-snap-type: x proximity; }
  .column { flex: 0 0 min(78vw, 300px); scroll-snap-align: start; }   /* 폭이 넓은 폰(폴드 등)에서도 컬럼이 너무 넓어지지 않게 상한 */
}

/* ---- 2단계: 화면별 최적화 ------------------------------------------------------------------ */
@media (max-width: 768px) {
  /* 공통 머리글(보드/리스트/타임라인/채팅/파일) */
  .board-header { flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 14px 6px; }
  .board-header h1 { font-size: 17px; }
  .board-header > div { min-width: 0; }
  /* 버튼줄은 잘리지 않게 줄바꿈 (+ 새 DOT 는 오른쪽 아래 둥근 버튼으로 따로 띄운다) */
  .board-header > div:last-child { flex-wrap: wrap; gap: 8px !important; overflow: visible; }
  .board-header > div:last-child > div { flex-wrap: wrap; gap: 6px !important; }
  .board-header .btn { white-space: nowrap; padding: 6px 10px; font-size: 12.5px; }
  /* 화면마다 있는 "+ 새 …" 주 버튼은 오른쪽 아래 둥근 버튼(FAB)으로 — 엄지로 누르기 쉽다 */
  #new-card-btn, #new-project-btn, #wb-new, #cal-new, #docs-new, #dm-new-group-btn {
    position: fixed !important; right: 16px; left: auto !important; bottom: calc(58px + 14px + env(safe-area-inset-bottom)); z-index: 45;
    width: auto !important; margin: 0 !important;
    border-radius: 999px; padding: 12px 20px !important; font-size: 14px !important; font-weight: 700;
    box-shadow: 0 4px 14px rgba(47, 93, 232, .38);
  }
  #dm-new-group-btn { background: var(--accent) !important; color: #fff !important; border: none !important; }
  /* 상세 화면(채팅방·문서 보기)이 열려 있으면 FAB는 숨김 */
  .dm-shell.m-detail-open #dm-new-group-btn, .docs-layout.m-detail-open #docs-new { display: none !important; }
  /* FAB가 마지막 항목을 가리지 않도록 아래 여백 */
  .project-grid, .wb-list-view, .docs-side, .dm-sidebar { padding-bottom: 84px; }
  /* 보조 버튼(멤버/컬럼/템플릿 관리, DOT 루틴, 엑셀, 휴지통)은 "⋯ 더보기"를 눌러야 보인다 → 머리글이 깔끔해진다 */
  body:not(.m-more-open) #member-manage-btn, body:not(.m-more-open) #manage-columns-btn, body:not(.m-more-open) #preset-manage-btn,
  body:not(.m-more-open) #recurring-btn, body:not(.m-more-open) #export-btn, body:not(.m-more-open) #trash-btn:not(.m-keep) { display: none !important; }
  .m-more-btn { display: inline-flex; }
  body.m-dragging .columns { scroll-snap-type: none; }
  body.m-dragging { touch-action: none; }
  .tl-toolbar { flex-wrap: wrap; gap: 8px; }
  /* "완료 항목 포함"은 모바일에서 토글 뒤(오른쪽 끝)에 둔다 — 토글이 항상 줄의 맨 앞에 오도록 */
  .tl-toolbar .tl-check { order: 1; margin-left: auto; }
  .tl-toolbar #tl-zoom-seg { order: 2; }
  /* 줄이 늘어나도 머리글이 눌려서 아래 날짜 헤더와 겹치지 않게 */
  .board-header { flex-shrink: 0; }
  /* 세로 배치 머리글에서 flex-basis 100%가 툴바를 머리글 높이만큼 늘려 줄 사이가 벌어지고 아래로 넘치던 문제 */
  .board-header .tl-toolbar:has(.tl-check) { flex: 0 0 auto; align-content: flex-start; }
  /* 표시 범위 밖 줄은 이름 칸이 좁아서 컬럼 칩은 숨기고 날짜 칩만 보여준다 */
  .tl-oor .tl-chip:not(.date):not(.pred) { display: none; }
  .projects-toolbar { padding: 12px 14px 8px; }

  /* 보드 도구줄(필터 등) */
  .board-tools { flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
  .board-tools .bt-left, .board-tools .bt-right { flex-wrap: wrap; gap: 6px; }
  .board-tools .btn { white-space: nowrap; padding: 6px 10px; font-size: 12.5px; }
  .bt-hint { display: none !important; }
  /* 줄 정리: 이슈별/담당자별 토글은 혼자 한 줄, 필터 줄은 왼쪽 정렬 + "더보기"가 맨 끝, 펼친 보조 버튼은 아래에서 한 줄로 이어진다 */
  .board-header .tl-toolbar { flex: 0 0 100%; }
  .board-tools { justify-content: flex-start; }
  .board-tools .bt-left { flex: 0 0 100%; }
  .board-tools .bt-left .m-more-btn { order: 9; margin-left: 0; }
  .board-tools .bt-left #trash-btn { order: 8; margin-left: auto; }
  .board-header #recurring-btn, .board-header #export-btn { border: 1px solid var(--border); }
  .board-tools .bt-left #bf-reset { order: 5; }
  .board-tools .bt-right { flex: 0 0 100%; }

  /* 목록/표 형태는 옆으로 밀어서 본다 */
  .line-list-wrap, .page-pad { -webkit-overflow-scrolling: touch; }
  .line-list-wrap { padding: 4px 14px 12px; }

  /* 리스트: 표 대신 카드형 줄(제목 위, 상태·라벨·우선순위·담당자·날짜 아래) */
  .list-head { display: none; }
  .list-scroll { padding: 0 14px 24px; }
  .list-row { flex-wrap: wrap; gap: 6px 8px; padding: 12px 2px; align-items: center; }
  .list-row > * { order: 3; }
  .list-row .list-title { order: 1; flex: 1 0 100%; width: 100%; font-size: 14.5px; font-weight: 600; }
  .list-row .list-status, .list-row .list-label, .list-row .list-priority { order: 2; width: auto; flex: 0 0 auto; }
  .list-row .list-start, .list-row .list-due { width: auto; flex: 0 0 auto; }
  .list-row .list-index, .list-row .list-content, .list-row .list-created { display: none; }

  /* 타임라인: 왼쪽 이름 칸을 좁혀 날짜 칸을 더 보이게 */
  .tl-labels { flex: 0 0 116px; width: 116px; }
  /* 좁은 이름 칸(116px)에서 칩이 제목을 다 가리지 않도록 작게 */
  .tl-chip { font-size: 9.5px; padding: 1px 4px; margin-right: 3px; border-radius: 7px; }
  .chat-input-row textarea { min-height: 44px; }

  /* 팝업(모달) → 아래에서 올라오는 시트, 화면 가득 */
  /* 팝업 배경은 '지금 실제로 보이는 영역'(키보드·주소창 제외)에 맞춘다 → 시트 맨 아래 버튼이 키보드/탭바 뒤로 숨지 않는다 */
  .modal-backdrop { align-items: flex-end; z-index: 70; inset: auto; left: 0; right: 0; top: var(--vv-top, 0px); height: 100vh; height: 100dvh; height: var(--app-h, 100dvh); }
  /* 각 팝업에 인라인으로 박힌 max-height(90vh 등)는 모바일 주소창·키보드 높이를 몰라서 아래가 잘린다 → 보이는 높이 기준으로 통일 */
  .modal-backdrop .modal { max-height: calc(100vh - 12px) !important; max-height: calc(100dvh - 12px) !important; max-height: calc(var(--app-h, 100dvh) - 12px) !important; }   /* 하단 탭바(z 60)보다 위: 시트 맨 아래 [저장]·[닫기]가 탭바에 가려지지 않게 */
  .modal {
    width: 100%; max-width: 100%; max-height: 94vh; max-height: 94dvh;
    border-radius: 16px 16px 0 0; flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-main { flex: 0 0 auto; border-right: 0; overflow: visible; }
  .modal-side { width: auto; flex: 0 0 auto; border-top: 1px solid var(--border); overflow: visible; }
  #comment-list, #checklist-list, #activity-list { max-height: none !important; overflow: visible !important; }
  .modal-close { top: 10px; right: 10px; width: 36px; height: 36px; font-size: 20px; }

  /* 알림창·검색창 → 화면 폭에 맞춰 상단바 아래에 고정 */
  .notif-dropdown, .gsearch-panel {
    position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto;
    max-height: calc(100dvh - 140px - env(safe-area-inset-top));
  }
  .gsearch-results { max-height: calc(100dvh - 240px); }
  .dot-dropdown { max-width: calc(100vw - 24px); }

  /* 목록 → 상세 전환형 화면(DM, Wiki) */
  .dm-shell, .docs-layout { position: relative; }
  .dm-sidebar, .docs-side { width: 100%; flex: 1 1 auto; border-right: 0; }
  .dm-thread, .docs-main { width: 100%; flex: 1 1 auto; }
  .dm-shell:not(.m-detail-open) .dm-thread { display: none; }
  .dm-shell.m-detail-open .dm-sidebar { display: none; }
  .docs-layout:not(.m-detail-open) .docs-main { display: none; }
  .docs-layout.m-detail-open .docs-side { display: none; }
  .docs-layout { flex-direction: column; }
  .m-backbar { display: none; flex-shrink: 0; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
  .m-back { border: 0; background: none; font: inherit; font-size: 14px; font-weight: 600; color: var(--accent); padding: 8px 10px; border-radius: 8px; }
  .dm-shell.m-detail-open .m-backbar, .docs-layout.m-detail-open .m-backbar { display: block; }
  .dm-thread { flex-direction: column; }
  .dm-directory-results { left: 12px; right: 12px; }

  /* Wiki 문서 화면 */
  .doc-wrap { padding: 14px 14px 70px; }
  .doc-head { flex-wrap: wrap; gap: 6px; }
  .doc-title-input { font-size: 22px; flex: 1 1 calc(100% - 60px); }
  .doc-actions { margin-left: 0; flex-wrap: wrap; }
  .doc-meta { margin-left: 0; }
  .docs-empty { margin-top: 40px; padding: 0 16px; }

  .cm-status-row { padding: 0 16px 8px !important; }
  #card-modal .modal-main > div[style*="padding:22px 26px 0"] { padding: 20px 16px 0 !important; }
  #card-modal .modal-main > div[style*="overflow-y:auto"] { padding-left: 16px !important; padding-right: 16px !important; }
  #card-modal .modal-main > div[style*="border-top"] { padding-left: 16px !important; padding-right: 16px !important; }
  .modal-side { padding: 16px; }

  /* 캘린더: 보기 선택은 접어 두고 달력을 먼저 보여준다 */
  .cal-side { max-height: none; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .cal-side .cal-new-btn { flex: 1 1 auto; margin: 0; }
  .cal-side .cal-side-toggle { flex: 0 0 auto; display: block; }
  .cal-side:not(.m-open) .cal-side-title, .cal-side:not(.m-open) #cal-sources { display: none; }
  .cal-side.m-open .cal-side-title, .cal-side.m-open #cal-sources { flex: 1 0 100%; }
  .cal-side.m-open #cal-sources { max-height: 38vh; overflow-y: auto; }
  .cal-main { padding: 10px 10px 20px; }
  .cal-toolbar { flex-wrap: wrap; gap: 8px; }
  .cal-title { font-size: 18px; }

  /* 대시보드: 위젯은 내용만큼만(고정 높이·안쪽 스크롤 없음), 여백 축소, KPI 2x2 */
  .page-pad { padding-top: 12px; padding-bottom: 16px; }
  .dash-kpi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
  .dash-kpi { padding: 10px 12px !important; min-width: 0; }
  .dash-kpi-value { font-size: 21px; }
  .dash-kpi-label { font-size: 12px; }
  .dash-kpi-hint { display: none; }
  /* 편집: 오른쪽 위 [편집] 버튼만 남기고, 편집 중에는 폭 선택(1~3칸) 대신 ▲▼ 순서 버튼 */
  .dash-toolbar { margin: 0 0 8px; min-height: 0; }
  .dash-toolbar[hidden] { display: none !important; }
  .dash-toolbar-hint { display: none; }
  .dash-edit-banner { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .dash-edit-banner-text { flex: 1 1 100%; }
  .dash-edit-banner .btn { flex: 1 1 auto; }
  .dash-save-state { min-width: 0; flex: 1 1 100%; text-align: left; }
  .dash-grid.editing .dw .dw-edit-bar { flex-wrap: wrap; gap: 6px 8px; }
  .dw-seg { display: none !important; }
  .dw-mv { display: inline-flex; }
  .dw-hide { padding: 5px 10px; }
  .dash-tray-chip { padding: 8px 14px; }
  .dash-grid { gap: 10px; }
  .dash-grid .dw { padding: 14px 14px 12px; margin-bottom: 0; }
  .dash-grid .dw .dw-body, .dash-grid .dw[data-id="projects"] .dw-body { height: auto; max-height: none; overflow: visible; margin-right: 0; padding-right: 0; }
  .panel h2 { font-size: 14.5px; }
  .panel .panel-sub { margin-bottom: 8px; }
  .dw-chips { position: static; }
  .dw-dist { grid-template-columns: 1fr; gap: 18px; }

  /* 캘린더: 칸을 작게 — 일정은 색 막대로만 보이고, 날짜를 누르면 그날 목록이 뜬다 */
  .cal-main { padding: 8px 6px 16px; }
  .cal-toolbar { gap: 6px; margin-bottom: 8px; }
  .cal-nav .btn { padding: 5px 10px; }
  .cal-legend { gap: 8px; font-size: 11px; flex: 1 0 100%; }
  .cal-weekdays div { padding: 5px 0; font-size: 11.5px; }
  .cal-week { height: 70px; }
  .cal-week-ev { grid-template-rows: 22px repeat(4, 7px) 14px !important; }
  .cal-daynum { margin-left: 3px; padding: 1px 5px; font-size: 12px; }
  .cal-bar {
    height: 5px; margin: 1px 2px; padding: 0; border-radius: 3px; line-height: 0; font-size: 0;
    overflow: hidden;
  }
  .cal-bar * { display: none !important; }
  .cal-bar.is-dot { border-width: 1px; height: 5px; line-height: 0; }
  .cal-more { font-size: 0; margin: 0 0 0 3px; }
  .cal-more::after { content: "+"; font-size: 11px; font-weight: 700; color: var(--text-2); }

  /* LINE 목록(리스트 보기): 표 → 카드 */
  .line-table { display: block; border: 0; background: none; border-radius: 0; overflow: visible; }
  .line-table thead { display: none; }
  .line-table tbody { display: block; }
  .line-table tbody tr.line-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px;
  }
  .line-table td { display: block; padding: 0; border: 0; overflow: visible; text-overflow: clip; font-size: 12.5px; }
  .line-table tbody tr.line-row:hover td { background: none; }
  .line-table td { order: 3; }
  .line-table td.lt-name { order: 1; flex: 1 1 calc(100% - 50px); width: auto; white-space: normal; }
  .line-table td.lt-name a { font-size: 15px; }
  .line-table td.lt-act { order: 2; flex: 0 0 36px; width: 36px; padding: 0; }
  .line-table td.lt-desc { flex: 1 0 100%; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .line-table td.lt-desc:empty { display: none; }
  .line-table td.lt-members, .line-table td.lt-date, .line-table td.lt-mgr { width: auto; flex: 0 0 auto; color: var(--text-3); }
  .line-table td.lt-date:nth-child(4)::before { content: "시작 "; }
  .line-table td.lt-date:nth-child(5)::before { content: "마감 "; }
  .line-table td.lt-mgr:nth-child(6)::before { content: "관리자 "; }
  .line-table td.lt-mgr:nth-child(7) { display: none; }
  .line-table td.lt-badge { width: auto; min-width: 0; flex: 1 0 100%; }
  .line-table tr:has(.lt-empty) { display: block; }
  .line-table .lt-empty { text-align: center; padding: 24px 8px; }

  /* LINE 목록(카드 보기): 한 줄 카드 */
  .project-grid { display: flex; flex-direction: column; gap: 12px; padding: 12px 14px; overflow-x: hidden; overflow-y: auto; flex: 1 1 auto; min-height: 0; align-content: flex-start; }
  .card, .project-card, .wb-card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .project-card.drop-target, .wb-card.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
  .project-grid .grid-slot { display: none; }
  .project-card { min-height: 150px; flex-shrink: 0; cursor: default; }

  /* WhiteBoard 목록: LINE처럼 한 줄에 카드 1장 */
  .wb-list-view { padding: 14px 14px 30px; }
  .wb-list-head { flex-direction: column; gap: 10px; }
  .wb-grid { display: flex; flex-direction: column; gap: 12px; min-height: 0 !important; }   /* PC용 '빈 줄 6개' 높이를 폰에서는 쓰지 않는다(스크롤이 끝없이 길어지는 문제) */
  .wb-grid .wb-slot { display: none; }
  .wb-card { flex: 0 0 auto; width: 100%; height: auto; min-width: 0; }
  .wb-card-thumb { height: 128px; }
  /* 폰에는 마우스를 올리는 동작이 없어서, 삭제 X를 끌어야만 보였다 — 항상 보이게 하고 손가락으로 누르기 쉽게 키운다 */
  .wb-card-del { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; font-size: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
  .wb-card-meta { white-space: normal; }
  .wb-list-head > div:last-child { flex-wrap: wrap; }


  /* 내 계정(비밀번호/알림 설정 두 패널): 세로로 쌓기 */
  .dash-two-col { flex-direction: column !important; gap: 12px; align-items: stretch !important; }
  .dash-two-col > .panel { flex: 0 0 auto !important; width: 100% !important; min-width: 0; box-sizing: border-box; }

  /* 폼 입력칸은 가로로 가득 */
  .field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea { width: 100%; }
  input[type=checkbox], input[type=radio] { width: auto; flex-shrink: 0; }

  /* WhiteBoard 편집 상단줄: 잘리지 않게 줄바꿈 */
  .wb-topbar { flex-wrap: wrap; overflow: visible; gap: 6px 8px; height: auto; padding-top: 8px; padding-bottom: 8px; }
  .wb-topbar .wb-divider, .wb-topbar .wb-spacer { display: none; }
  .wb-topbar .wb-title-input { flex: 1 1 140px; min-width: 120px; }
  .wb-topbar .btn { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }

  /* 채팅/DM 입력줄 */
  .chat-wrap { padding: 0 12px 10px; }
  .chat-messages { gap: 22px; padding: 16px 0 8px; }
  .dm-thread .chat-messages { padding: 16px 12px 10px; }
  .dm-thread .chat-search-row, .chat-tools-row { padding-left: 12px; padding-right: 12px; flex-wrap: wrap; }
  .dm-thread-header { padding-left: 12px; padding-right: 12px; }
  .chat-input-row { gap: 8px; }
  .chat-input-row textarea { min-width: 0; }
}

/* 홈 화면에 설치해서 연 경우(주소창 없음): 위쪽 안전영역(노치) 확보 */
@media (max-width: 768px) and (display-mode: standalone) {
  .topbar { padding-top: env(safe-area-inset-top); }
}


/* 키보드가 올라와 있는 동안은 탭바·FAB를 숨겨 입력창을 키보드 바로 위에 둔다 */
@media (max-width: 768px) {
  body.m-kb .rail { display: none !important; }
  body.m-kb .main-col { padding-bottom: 0; }
  body.m-kb #new-card-btn, body.m-kb #new-project-btn, body.m-kb #wb-new, body.m-kb #cal-new, body.m-kb #docs-new, body.m-kb #dm-new-group-btn { display: none !important; }
}

/* ---- 3단계: 글자 크기 · 리스트 · 파일 · 캘린더 정리 ------------------------------------------------
   글자 크기 기준표(모바일): 캡션/배지 11 · 보조(메타) 12 · 본문/버튼 13 · 목록 제목 15 · 화면 제목 18 */
@media (max-width: 768px) {
  /* 하단 탭바 라벨: 8.5px는 너무 작아 10px로, 아주 좁은 폰(≤420px)만 9px */
  .rail-label, .rail.rail-expanded .rail-label { font-size: 10px; letter-spacing: -.04em; }
  .btn, .board-header .btn, .board-tools .btn, .wb-topbar .btn { font-size: 13px; }
  .crumbs, .crumbs a, .crumbs .current { font-size: 14px; }
  .project-subnav a { font-size: 13px; }
  .panel-sub, .field label, .dm-empty-hint, .files-summary { font-size: 12px; }
  .dw-day, .dw-row-sub, .dw-time, .manager, .mc-count, .dash-kpi-label, .dw-count { font-size: 12px; }
  .panel h2, .panel h3, .project-card h3 { font-size: 15px; }
  .label, .priority-tag, .status-pill, .tl-month, .tl-day, .docs-order-hint { font-size: 11px; }
  .cal-weekdays div, .cal-legend { font-size: 12px; }
  .cal-legend { font-size: 11.5px; }

  .cal-daynum { white-space: nowrap; padding: 1px 3px; letter-spacing: -.04em; }
  /* 캘린더: 오른쪽 아래 [+ 일정 등록] 버튼이 마지막 주 날짜를 가리지 않도록 아래 여백 */
  .cal-main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  /* 리스트(DOT): 1줄 제목 / 2줄 상태·라벨·우선순위 … 담당자·마감 */
  .list-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; padding: 12px 4px; }
  .list-row .list-title { order: 1; flex: 1 0 100%; width: 100%; font-size: 15px; font-weight: 600; line-height: 1.35; white-space: normal; overflow: visible; padding-left: 0; }
  .list-row .list-status, .list-row .list-label, .list-row .list-priority { order: 2; width: auto; flex: 0 0 auto; }
  .list-row .list-label:not(:has(.label)) { display: none; }          /* 라벨이 없으면 '-' 자리를 비운다 */
  .list-row .list-assignees { order: 3; width: auto; flex: 0 0 auto; margin-left: auto; }
  .list-row .list-due { order: 4; width: auto; flex: 0 0 auto; min-width: 64px; text-align: right; font-size: 12px; }
  .list-row .list-due::before { content: "마감 "; color: var(--text-3); font-weight: 400; }
  .list-row .list-due:has(input)::before, .list-row .list-due:has(.date-placeholder)::before { content: none; }
  .list-row .list-start, .list-row .list-index, .list-row .list-content, .list-row .list-created { display: none; }

  /* LINE 목록(리스트 보기): 카드 — 이름 / 설명 / 멤버·날짜·관리자 한 줄 */
  .line-table tbody tr.line-row { gap: 6px 12px; padding: 12px 14px; }
  .line-table td { font-size: 12px; }
  .line-table td.lt-name a { font-size: 15px; }
  .line-table td.lt-desc { font-size: 12.5px; color: var(--text-2); }
  .line-table td.lt-date.is-empty { display: none; }
  .line-table td.lt-mgr:nth-child(6):empty { display: none; }
  .line-table td.lt-badge:not(:has(.line-tab-badge[style*="inline-flex"])) { display: none; }   /* 새 소식 배지가 하나도 없으면 줄 자체를 없앤다 */
  .line-table td.lt-badge { padding-top: 2px; }

  /* 파일: 표 → 카드 줄 (썸네일 / 이름 + 다운로드 / 위치 / 올린 사람·날짜·크기) */
  .files-toolbar { padding: 0 14px 10px; gap: 8px; }
  .files-toolbar input[type=text] { width: auto; flex: 1 1 100%; }
  .files-toolbar select { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 8px 10px; }
  .files-summary { margin-left: 0; flex: 1 0 100%; }
  .files-wrap { padding: 0 14px calc(24px + env(safe-area-inset-bottom)); }
  .files-table, .files-table tbody { display: block; width: 100%; }
  .files-table thead { display: none; }
  .files-table tbody tr {
    display: grid; grid-template-columns: 44px auto auto 1fr; column-gap: 10px; row-gap: 2px;
    padding: 10px 2px; border-bottom: 1px solid var(--border); align-items: center;
  }
  .files-table td { display: block; padding: 0; border: 0; min-width: 0; }
  .files-table .f-thumb { grid-column: 1; grid-row: 1 / span 3; align-self: start; width: auto; }
  .files-table .f-name { grid-column: 2 / 4; grid-row: 1; font-size: 14px; line-height: 1.35; }
  .files-table .f-actions { grid-column: 4; grid-row: 1; justify-self: end; }
  .files-table .f-actions a { margin-left: 0; font-size: 12px; font-weight: 600; padding: 4px 0 4px 8px; }
  .files-table .f-loc { grid-column: 2 / 5; grid-row: 2; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .files-table .f-sub { font-size: 12px; grid-row: 3; white-space: nowrap; }
  .files-table .f-sub:nth-child(4) { grid-column: 2; }
  .files-table .f-sub:nth-child(5) { grid-column: 3; }
  .files-table .f-sub:nth-child(6) { grid-column: 4; }
  .files-empty { font-size: 13px; padding: 40px 12px; }
}
@media (max-width: 420px) {
  #nav-account .rail-label { font-size: 0 !important; }
  #nav-account .rail-label::after { content: "Account"; font-size: 9px; font-weight: 600; letter-spacing: -.04em; }
  .rail-label, .rail.rail-expanded .rail-label { font-size: 9px; }
}

/* ---- WhiteBoard 편집 화면(폰): 도구는 아래 가로줄, 확대/축소는 오른쪽 위, 서식줄은 도구줄 바로 위 ------------------ */
@media (max-width: 768px) {
  .wb-tools {
    left: 8px; right: 8px; top: auto; bottom: 8px; transform: none; flex-direction: row; align-items: center;
    overflow-x: auto; overflow-y: hidden; padding: 4px 6px; gap: 2px; border-radius: 14px; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .wb-tools::-webkit-scrollbar { display: none; }
  .wb-tools button { flex: 0 0 auto; width: 44px; height: 44px; }
  .wb-tools-sep { flex: 0 0 auto; width: 1px; height: 24px; margin: 0 4px; }
  .wb-zoom { right: 8px; top: 8px; bottom: auto; }
  .wb-zoom button { height: 36px; min-width: 38px; }
  .wb-hint { left: 8px; top: 8px; bottom: auto; right: auto; max-width: calc(100% - 180px); font-size: 11px; line-height: 1.4; }
  /* 서식줄: 한 줄로 옆으로 밀어서 본다(화면을 덜 가린다). 색/크기 팝업은 줄 위로 열린다 */
  .wb-stylebar {
    left: 8px; right: 8px; top: auto; bottom: 64px; transform: none; width: auto; max-width: none;
    flex-wrap: nowrap; padding: 4px;
  }
  .wb-stylebar .sb-row {
    display: flex; align-items: center; gap: 6px; width: 100%; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .wb-stylebar .sb-row::-webkit-scrollbar { display: none; }
  .wb-stylebar .sb-row > * { flex: 0 0 auto; }
  .wb-stylebar .sb-btn { height: 36px; min-width: 36px; font-size: 13px; white-space: nowrap; }
  .wb-stylebar .sb-ic { width: 34px; }
  .wb-stylebar .sb-select { height: 36px; }
  .wb-stylebar .sb-pop { top: auto; bottom: calc(100% + 8px); left: 0; right: 0; width: auto; max-height: 50vh; overflow-y: auto; }
  /* 글을 고치는 중에는 도구줄을 숨기고 서식줄을 맨 아래(키보드 바로 위)로 내린다 */
  body.wb-editing .wb-tools { display: none; }
  body.wb-editing .wb-stylebar { bottom: 8px; }
  .wb-swatch { width: 28px; height: 28px; }
}
/* 손가락으로 잡기 쉽게: 크기 조절 모서리와 연결선 점을 키운다(확대/축소와 상관없이 화면에서 일정한 크기) */
@media (pointer: coarse) {
  .wb-handle { width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 5px; }
  .wb-cdot { width: 24px; height: 24px; margin: -12px 0 0 -12px; }
}

/* Dashboard 최근 활동: 모바일에서는 최신 3건만 고정 표시 */
@media (max-width: 768px) {
  .dw-activity:nth-child(n+4) { display: none; }
  .dw-activity:nth-child(3) { border-bottom: none; }
}

/* Wiki 휴지통: 아래 푸터 대신 위쪽 버튼 줄로 */
@media (max-width: 768px) {
  .docs-new-row .docs-trash-top { display: inline-flex; align-items: center; justify-content: center; }
  .docs-side-foot #docs-trash-btn { display: none; }
  .docs-side-foot { border-top: 0; padding-top: 0; }
}

/* 공지사항 팝업(모바일): 아래에서 올라오는 시트 한 장 — 위에 공지 내역(여러 건일 때만), 아래에 선택한 공지 상세 */
@media (max-width: 768px) {
  .notice-popup-backdrop { z-index: 200; }   /* 위의 .modal-backdrop(z 70)보다 우선: 상단바 드롭다운보다 위에 떠야 한다 */
  .notice-popup-modal { width: 100%; max-width: 100%; height: min(86dvh, calc(var(--app-h, 100dvh) - 12px)); overflow: hidden; }
  .notice-popup-list { width: 100%; flex: 0 0 auto; max-height: 38%; border-right: 0; border-bottom: 1px solid var(--border); }
  .notice-popup-list-header { height: 40px; }
  .notice-popup-list-items { max-height: 132px; flex: 0 1 auto; }
  .notice-popup-list-item { padding: 9px 16px; }
  .notice-popup-list-footer { padding: 6px 16px; }
  /* 공지가 1건이면 목록은 필요 없다 → 상세만 크게 */
  .notice-popup-list:has(.notice-popup-list-item:only-child) { display: none; }
  .notice-popup-main { flex: 1 1 auto; min-height: 0; width: 100%; }
  .notice-popup-header { flex: 0 0 auto; }
  .notice-popup-body { padding: 18px 18px 8px; -webkit-overflow-scrolling: touch; }
  .notice-popup-title { font-size: 16px; line-height: 1.4; }
  .notice-popup-footer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); gap: 12px; flex-wrap: nowrap; }
  .notice-popup-footer .text-link-btn { white-space: nowrap; font-size: 12px; }
  .notice-popup-footer .btn-primary { flex: 0 0 auto; min-width: 72px; }
}
