/* v12 – Giao diện điện thoại thoáng, nút to (chỉ màn hình ≤ 760px) */
@media (max-width: 760px) {
  /* Khung app phủ đúng toàn màn hình (bỏ khoảng trống dưới thanh tab) */
  body.m12 { overflow: hidden; }
  body.m12 #app.app.v9 { position: fixed; inset: 0; height: auto; padding-top: 0; display: flex; flex-direction: column; }
  body.m12 #mHead { order: 0; }
  body.m12 .app-main { order: 1; flex: 1 1 auto; min-height: 0; }
  body.m12 .topbar { order: 2; }

  /* Header gọn */
  #mHead { flex: 0 0 auto; background: var(--bar, #2f6db5); color: #fff; padding-top: env(safe-area-inset-top); position: relative; z-index: 12; box-shadow: 0 1px 3px #0000002e; }
  #mHead .mh-row { height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; }
  #mHead .mh-logo { width: 32px; height: 32px; border-radius: 50%; background: #fff; object-fit: contain; flex: 0 0 32px; }
  #mHead .mh-page select { appearance: none; -webkit-appearance: none; background: #ffffff26 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 6px center / 18px; color: #fff; border: 0; border-radius: 18px; height: 36px; padding: 0 28px 0 12px; font-size: 15px !important; font-weight: 600; max-width: 52vw; width: auto; }
  #mHead .mh-page select option { color: #000; }
  #mHead .mh-ic { width: 44px; height: 44px; border: 0; background: transparent; color: #fff; display: grid; place-items: center; border-radius: 50%; padding: 0; }
  #mHead .mh-ic svg { width: 24px; height: 24px; fill: currentColor; }
  #mHead .mh-right { display: flex; align-items: center; gap: 4px; }
  #mHead #bellBtn { width: 44px !important; height: 44px !important; background: transparent !important; font-size: 21px !important; border-radius: 50%; }
  #mHead #meBtn { width: 34px; height: 34px; font-size: 13px; box-shadow: 0 0 0 2px #ffffff88; margin-left: 2px; }
  #mHead .notif-panel { position: fixed; left: 8px; right: 8px; top: calc(56px + env(safe-area-inset-top)); bottom: auto; max-height: 70vh; color: var(--text); }
  #mHead .mh-search { display: none; }
  #mHead.searching .mh-row { display: none; }
  #mHead.searching .mh-search { height: 52px; display: flex; align-items: center; gap: 6px; padding: 0 6px 0 10px; }
  #mHead .mh-sbox { flex: 1; }
  #mHead #search { width: 100%; height: 38px; border: 0; border-radius: 19px; padding: 0 14px; font-size: 16px !important; background: #fff; color: #050505; }
  body.m12:has(#view-inbox.hidden) #mHead .mh-page, body.m12:has(#view-inbox.hidden) #mhSearchBtn { visibility: hidden; }
  body.m12:has(#view-inbox.chatting) #mHead, body.m12:has(#view-inbox.chatting) .topbar { display: none !important; }

  /* Bộ lọc 1 hàng cuộn ngang */
  body.m12 .app.v9 .list-head { padding: 8px 0 6px; gap: 0; border-bottom: 1px solid var(--line); }
  body.m12 .list-head > .row, body.m12 #tagDots { display: none !important; }
  body.m12 #mChips { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  body.m12 #mChips::-webkit-scrollbar { display: none; }
  body.m12 .app.v9 #filterChips { display: flex !important; flex-wrap: nowrap; gap: 8px; padding: 0 12px; width: max-content; }
  body.m12 #filterChips .chip { height: 36px; padding: 0 14px; font-size: 15px; border-radius: 18px; white-space: nowrap; flex: 0 0 auto; }
  body.m12 #filterChips .chip.m-drop.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
  body.m12 #cfBar, body.m12 #postChip { margin: 6px 12px 0; }

  /* Danh sách hội thoại */
  body.m12 .app.v9 .conv { min-height: 72px; padding: 10px 12px 10px 11px; gap: 12px; align-items: center; }
  body.m12 .app.v9 .conv .avatar { width: 52px; height: 52px; flex-basis: 52px; font-size: 17px; }
  body.m12 .app.v9 .conv .name { font-size: 16px; font-weight: 600; }
  body.m12 .app.v9 .conv .snippet { font-size: 14px; color: var(--muted); opacity: 1; }
  body.m12 .app.v9 .conv.unread .snippet { color: var(--text); }
  body.m12 .app.v9 .conv .meta { font-size: 12px; align-self: stretch; }
  body.m12 .unread-dot { min-width: 22px; height: 22px; line-height: 22px; border-radius: 11px; text-align: center; font-size: 12px; padding: 0 7px; }

  /* Thanh tab dưới: 5 mục, biểu tượng nét đều */
  body.m12 .topbar { height: auto !important; flex: 0 0 auto; padding: 0 0 env(safe-area-inset-bottom) !important; background: var(--panel) !important; color: var(--muted); border-top: 1px solid var(--line) !important; box-shadow: none !important; }
  body.m12 .topbar .tb-right, body.m12 .topbar .tb-brand { display: none !important; }
  body.m12 .tb-tabs { display: flex; width: 100%; justify-content: space-around; }
  body.m12 .topbar .rail-btn[data-view="stats"], body.m12 .topbar .rail-btn[data-view="settings"] { display: none !important; }
  body.m12 .topbar .rail-btn { flex: 1 1 0; height: 56px !important; min-width: 0; display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0 !important; margin: 0 !important; border: 0 !important; border-radius: 0 !important; background: transparent !important; color: var(--muted) !important; font-size: 11.5px !important; font-weight: 500 !important; opacity: 1 !important; }
  body.m12 .topbar .rail-btn .ic { display: block !important; width: 24px; height: 24px; font-size: 0; }
  body.m12 .topbar .rail-btn .ic svg { width: 24px; height: 24px; fill: currentColor; }
  body.m12 .topbar .rail-btn.m-on { color: var(--accent) !important; font-weight: 700 !important; }
  body.m12 .topbar .rail-btn .tx { white-space: nowrap; }

  /* Khung chat toàn màn hình */
  body.m12 .chat-head { position: sticky; top: 0; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; min-height: 56px; }
  body.m12 #backBtn { width: 44px; height: 44px; font-size: 22px; }
  body.m12 .composer { padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); }
  body.m12 .composer-tools { margin-bottom: 4px; }
  body.m12 .composer textarea { font-size: 16px !important; min-height: 40px; }
  body.m12 #sendBtn { min-width: 44px; height: 44px; font-size: 16px; }
  body.m12 #attachBtn { width: 44px; height: 44px; font-size: 22px; }
  body.m12 .who-label { margin-top: 6px; }
  body.m12 .post-card.m-collapsed { cursor: pointer; padding: 10px 12px; }
  body.m12 .post-card.m-collapsed .pc-text { -webkit-line-clamp: 2 !important; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
  body.m12 .post-card.m-collapsed .pc-img, body.m12 .post-card.m-collapsed .pc-more, body.m12 .post-card.m-collapsed .pc-id { display: none; }
  body.m12 .post-card.m-collapsed::after { content: 'Chạm để xem bài viết đầy đủ'; display: block; font-size: 12px; color: var(--accent); margin-top: 6px; font-weight: 600; }

  /* Nút bật thông báo nằm trong mục "Thêm" thay vì nổi */
  body.m12 .push-btn { display: none !important; }

  /* Bảng trượt từ dưới lên */
  .m-sheet { position: fixed; inset: 0; z-index: 60; }
  .m-sheet.hidden { display: none; }
  .m-sheet-bg { position: absolute; inset: 0; background: #0006; }
  .m-sheet-card { position: absolute; left: 0; right: 0; bottom: 0; background: var(--panel); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto; box-shadow: 0 -10px 30px #0003; }
  .m-sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
  .m-sheet-body h3 { margin: 4px 0 12px; font-size: 17px; }
  .m-opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: 16px; text-align: left; padding: 0 4px; }
  .m-opt.on { color: var(--accent); font-weight: 700; }
  .m-opt i { font-style: normal; width: 26px; display: grid; place-items: center; color: var(--muted); }
  .m-opt i svg { width: 24px; height: 24px; fill: currentColor; }
  .m-opt.danger { color: var(--danger); } .m-opt.danger i { color: var(--danger); }
  .m-tags { display: flex; flex-wrap: wrap; gap: 8px; }
  .m-tag { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 10px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 15px; }
  .m-tag i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
  .m-tag.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); font-weight: 600; }
  .m-sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
  .m-sheet-actions .btn { flex: 1; height: 46px; font-size: 16px; }
}

/* v12.1 – Lấp kín chiều cao màn hình (iPhone app ngoài màn hình chính) + co giãn theo cỡ máy */
@media (max-width: 760px) {
  html, body { height: 100%; background: var(--panel, #fff) !important; }
  body.m12 #app.app.v9 { top: 0; bottom: auto; left: 0; right: 0; height: var(--app-h, 100dvh); height: max(100lvh, var(--app-h, 100dvh)); }
  body.m12 .topbar { margin-bottom: 0 !important; }
  /* cỡ chữ / nút co giãn: máy nhỏ (SE 375×667) đến máy lớn (Pro Max 440×956) */
  #mHead .mh-row { height: clamp(48px, 6.4vh, 56px); }
  #mHead .mh-page select { font-size: clamp(14px, 3.9vw, 16px) !important; max-width: 48vw; text-overflow: ellipsis; }
  body.m12 #filterChips .chip { height: clamp(34px, 4.6vh, 38px); font-size: clamp(14px, 3.9vw, 15.5px); padding: 0 clamp(11px, 3.4vw, 15px); }
  body.m12 .app.v9 .conv { min-height: clamp(64px, 9vh, 76px); }
  body.m12 .app.v9 .conv .avatar { width: clamp(46px, 13vw, 54px); height: clamp(46px, 13vw, 54px); flex-basis: clamp(46px, 13vw, 54px); }
  body.m12 .app.v9 .conv .grow { min-width: 0; }
  body.m12 .app.v9 .conv .name, body.m12 .app.v9 .conv .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.m12 .app.v9 .conv .name { font-size: clamp(15px, 4.1vw, 16.5px); }
}
/* Điện thoại nằm ngang (màn rộng nhưng thấp): giao diện máy tính thu gọn */
@media (min-width: 761px) and (max-height: 500px) and (orientation: landscape) {
  .topbar { height: 44px !important; flex-basis: 44px !important; }
  .topbar .rail-btn { height: 44px !important; padding: 0 12px !important; font-size: 13px !important; }
  .app.v9 .rail { width: 52px !important; padding: 6px 4px !important; }
  .app.v9 .rail .frail-btn { justify-content: center !important; padding: 0 !important; height: 40px !important; }
  .app.v9 .rail .frail-btn .fl { display: none; }
  .app.v9 .list-col { width: 300px !important; }
  .tb-brand .brand-name { display: none; }
}
/* Máy tính bảng dọc (761–1024px): danh sách hẹp lại để khung chat đủ rộng */
@media (min-width: 761px) and (max-width: 1024px) {
  .app.v9 .list-col { width: 300px !important; }
  .app.v9 .rail { width: 112px !important; }
  .app.v9 .rail .frail-btn .fl { font-size: 12.5px !important; }
  .topbar .rail-btn { padding: 0 12px !important; font-size: 14px !important; }
  .tb-brand { min-width: 0 !important; }
  .push-btn { padding: 6px 10px; font-size: 12px; }
}
@media (min-width: 761px) and (max-width: 1024px) {
  .topbar { gap: 8px !important; padding: 0 10px !important; }
  .topbar .rail-btn { padding: 0 9px !important; font-size: 13.5px !important; white-space: nowrap; }
  .topbar .rail-btn .tx { white-space: nowrap; }
  .tb-brand .brand-name, .tb-me .nm { display: none; }
  .tb-right { min-width: 0 !important; gap: 6px !important; }
}

/* v12.2 – Luôn hiện chữ dưới biểu tượng ở thanh tab điện thoại (sửa lỗi mất chữ trên iPhone) */
@media (max-width: 760px) {
  body.m12 .topbar .rail-btn { height: auto !important; min-height: 56px !important; padding: 6px 0 4px !important; justify-content: center !important; gap: 3px !important; overflow: visible !important; }
  body.m12 .topbar .rail-btn .ic { flex: 0 0 24px; }
  body.m12 .topbar .rail-btn .tx { display: block !important; visibility: visible !important; opacity: 1 !important; position: static !important; font-size: 11.5px !important; line-height: 14px !important; height: 14px; color: inherit !important; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 360px) { body.m12 .topbar .rail-btn .tx { font-size: 10.5px !important; } }

/* v12.3 – iPhone app ngoài màn hình chính: lớp position:fixed bị iOS cắt ở chiều cao "ảo" (innerHeight),
   trong khi trang thường vẫn vẽ tới đáy màn hình. → Không dùng fixed cho khung app; dùng luồng thường cao đúng bằng màn hình. */
@media (max-width: 760px) {
  html.m12h, html.m12h body { height: var(--app-h, 100dvh); min-height: var(--app-h, 100dvh); overflow: hidden; margin: 0; }
  body.m12 #app.app.v9 { position: relative !important; inset: auto !important; top: 0; width: 100%; height: var(--app-h, 100dvh) !important; min-height: 0; overflow: visible; }
  body.m12 .topbar, body.m12 .tb-tabs { overflow: visible !important; height: auto !important; max-height: none !important; }
  body.m12 .tb-tabs { align-items: stretch; }
  body.m12 .topbar .rail-btn { flex: 1 1 0 !important; min-height: 62px !important; padding: 7px 0 6px !important; gap: 4px !important; }
  body.m12 .topbar .rail-btn .ic { width: 28px !important; height: 28px !important; flex: 0 0 28px; }
  body.m12 .topbar .rail-btn .ic svg { width: 28px !important; height: 28px !important; }
  body.m12 .topbar .rail-btn .tx { font-size: 12px !important; line-height: 15px !important; height: 15px; }
}
