/* [DVIGO NVR 1.8.0] 모바일 레이아웃 — 폰 폭(≤ 640px)에서만. 같은 index.html·같은 데이터, 레이아웃만 바꾼다: 왼쪽 메뉴 → 하단 탭 4개(라이브·알림·재생·더보기), 사이드 패널 접기, 타일 세로 1열, 알림 상세는 아래에서 올라오는 시트 */
@media (max-width: 640px) {
  :root { --hh: 48px; }
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: contain; }
  header { padding: 0 10px; gap: 8px; }
  header h1 { font-size: 15px; }
  header .hb, #hclock, #huser, header .admin-only > button, #hstat_b { display: none !important; }
  #hchips, #run { display: none !important; }   /* 상태 칩은 더보기 시트에 */
  header h1 { flex: 1; }
  header .bell { font-size: 15px; }
  nav#menu, body.rail nav#menu, body.rail nav#menu:hover { display: none !important; }
  .layout { display: block; }
  main { padding: 8px 10px calc(78px + env(safe-area-inset-bottom, 0px)); }
  main section { padding: 8px !important; }
  .page > section, .page > .two { margin-bottom: 10px; }
  h2 { font-size: 15px; }

  /* 하단 탭 */
  #mtab { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); height: calc(60px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: #0e1826; border-top: 1px solid var(--line); box-sizing: border-box; }
  #mtab a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #8aa0b5; font-size: 11px; text-decoration: none; position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  #mtab a svg { width: 22px; height: 22px; }
  #mtab a.act { color: var(--acc); font-weight: 600; }
  #mtab a .n { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
  #mtab a .n:empty { display: none; }
  #lvgrid.full ~ #mtab, body.lvfull #mtab { display: none; }

  /* 더보기 시트 */
  #msheet { position: fixed; inset: 0; z-index: 46; background: rgba(3, 8, 16, .6); display: none; }
  #msheet.open { display: block; }
  #msheet .sh { position: absolute; left: 0; right: 0; bottom: 0; max-height: 82vh; overflow: auto; background: #0e1826; border-radius: 14px 14px 0 0; padding: 10px 12px calc(16px + env(safe-area-inset-bottom, 0px)); box-sizing: border-box; }
  #msheet .grip { width: 36px; height: 4px; border-radius: 2px; background: #33456a; margin: 0 auto 10px; }
  #msheet .me { display: flex; align-items: center; gap: 10px; padding: 6px 2px 10px; }
  #msheet .me .av { width: 40px; height: 40px; border-radius: 50%; background: #1b3b4a; color: var(--acc); display: flex; align-items: center; justify-content: center; font-weight: 700; }
  #msheet .st3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
  #msheet .st3 div { background: #111c2b; border: 1px solid var(--line); border-radius: 8px; padding: 7px 4px; text-align: center; font-size: 11px; color: #8aa0b5; }
  #msheet .st3 b { display: block; font-size: 14px; color: var(--txt); }
  #msheet .lk { font-size: 11px; color: #5f6f8a; padding: 8px 4px 4px; }
  #msheet .grp { border-radius: 10px; background: #111c2b; border: 1px solid var(--line); overflow: hidden; }
  #msheet .grp a { display: flex; align-items: center; gap: 10px; padding: 12px 12px; color: var(--txt); text-decoration: none; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
  #msheet .grp a:last-child { border-bottom: 0; }
  #msheet .grp a .ic { width: 20px; text-align: center; color: var(--acc); }
  #msheet .grp a .n { margin-left: auto; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 9px; min-width: 18px; text-align: center; }
  #msheet .grp a .n:empty { display: none; }
  #msheet .grp a .hint { margin-left: auto; }

  /* 라이브 */
  .lv, .lv.nosel { display: block; }
  .lv > aside { display: none !important; }
  .lvbar { gap: 4px; margin-bottom: 6px; }
  .lvbar #lv_lays button:nth-child(n+4), .lvbar #lv_tour_s, .lvbar label:has(#lv_tour), .lvbar button[onclick="lvZoomReset()"], .lvbar button[onclick="lvFull()"], .lvbar label:has(#lv_sub), .lt.empty { display: none !important; }
  .lvbar label.hint { font-size: 11px; }
  #lv_total { width: 100%; order: 99; font-size: 11px; }
  #lvgrid { grid-template-columns: 1fr !important; grid-auto-rows: auto; gap: 8px; padding: 0; background: transparent; border: 0; }
  .lt { border-radius: 10px; }
  .lt .tools { display: flex; }
  .lt .cnt { font-size: 11px; }
  #lvgrid.full { grid-template-columns: 1fr !important; }
  #lvgrid.full .lt { border-radius: 0; aspect-ratio: auto; height: 100vh; }

  /* 알림센터 */
  .ac2 { height: auto; display: flex; flex-direction: column; gap: 8px; }
  .acsum { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .acsum .k { padding: 6px 8px; border-left-width: 3px; }
  .acsum .k b { font-size: 18px; }
  .acsum .k small { font-size: 10px; }
  .acsum .acts { display: none; }
  .acflt { gap: 4px; }
  .acflt input { width: 100%; flex: 1 1 100%; }
  .acflt label.chip { display: none; }
  .acbody { display: block; }
  .acsum { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .acsum .k:nth-child(n+4) { display: none; }   /* 미확인·처리 중·오늘 발생만 */
  .arow2 { grid-template-columns: 0px 4px 84px minmax(0, 1fr) auto; gap: 0 8px; padding: 9px 8px; }
  .arow2 > input[type=checkbox] { visibility: hidden; width: 0; margin: 0; }
  .arow2 .memo-n { display: none; }
  .arow2 .tx b { font-size: 15px; flex-wrap: wrap; gap: 5px; }
  .arow2 .who { display: none; }
  .arow2 .tm { font-size: 12px; }
  .arow2 .tm small { font-size: 10px; }
  .arow2 > .chipx { display: none !important; }
  .arow2 img { width: 84px; height: 48px; }
  .aclist2 { max-height: none; }
  .acdet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 47; max-height: 78vh; border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform .22s ease; box-shadow: 0 -10px 30px #000a; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  body.acopen .acdet { transform: none; display: flex !important; }   /* 1100px 이하에서 숨기던 규칙보다 우선 */
  .acdet .mclose { position: sticky; top: 0; display: flex; justify-content: flex-end; margin: -4px -4px 4px 0; }
  #acdim { position: fixed; inset: 0; z-index: 46; background: rgba(3, 8, 16, .55); display: none; }
  body.acopen #acdim { display: block; }

  /* 재생 */
  .pb { display: block; }
  .pb > aside, .pb > div:last-child:not(:first-child) { margin-top: 10px; }
  #pbgrid { grid-template-columns: repeat(2, 1fr) !important; padding: 0; border: 0; background: transparent; gap: 6px; }
  #pbgrid.one { grid-template-columns: 1fr !important; }
  .pbctl button[onclick="pbSmart()"] { display: none; }
  .pbctl { gap: 4px; }
  .pbctl button { min-height: 38px; }
  .pbctl .big { width: 56px; height: 44px; font-size: 18px; border-radius: 22px; }
  .pbctl #pb_sel, .pbctl button[onclick="pbSelClear()"] { display: none; }
  #pbtl { width: 100%; height: 110px; touch-action: none; }

  /* 주차·표·대화상자 */
  .pklanes { grid-template-columns: 1fr; }
  .pklane { grid-template-columns: 110px 1fr; }
  .two { display: block; }
  table { font-size: 12px; }
  .tblwrap, section:has(> table) { overflow-x: auto; }
  .modal-box, .dlg .modal-box { width: 96vw !important; max-width: 96vw; max-height: 90vh; overflow: auto; }
  .ctxmenu, .ctx { max-width: 92vw; }
  #toasts { top: auto; left: 8px; right: 8px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); width: auto; pointer-events: none; }   /* 빈 컨테이너가 탭을 가로채지 않게 */
  #toasts > * { pointer-events: auto; }
  #loginp .row { flex-wrap: wrap; }
  #loginp input { width: 100% !important; font-size: 16px; }   /* iOS 자동 확대 방지 */
  #loginp button { min-height: 44px; width: 100%; }
}
@media (max-width: 640px) and (orientation: landscape) {
  #mtab { display: none; }
  main { padding-bottom: 8px; }
  #lvgrid { grid-template-columns: repeat(2, 1fr) !important; }
}
