/* HAMI - giao diện web/PWA. Màu nhận diện: xanh ngọc đậm + hổ phách (không dùng xanh dương kiểu Zalo). */
:root {
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-ink: #ffffff;
  --accent: #f59e0b;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --line: #dfe5e3;
  --ink: #17201e;
  --ink-2: #55615e;
  --ink-3: #87918f;
  --bubble-me: #d7f3ee;
  --bubble-other: #ffffff;
  --danger: #c2410c;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1413; --surface: #151d1c; --surface-2: #1c2625; --line: #26322f;
    --ink: #e6efed; --ink-2: #a9b6b3; --ink-3: #7b8885;
    --bubble-me: #134e48; --bubble-other: #1c2625; --brand-2: #2dd4bf;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* Màn ứng dụng (sau đăng nhập): KHÔNG cuộn toàn trang. Chỉ danh sách tin / pane-body tự cuộn.
   iOS Safari: khi bàn phím mở, 100vh/100dvh KHÔNG co lại -> Safari cuộn cả trang để lộ ô nhập, header bị đẩy mất.
   Cách xử lý: khung .shell cố định, cao = visualViewport.height (--app-height), đặt tại visualViewport.offsetTop
   (--app-top); JS cập nhật 2 biến này khi resize/scroll/orientationchange (xem js/viewport.js). */
html.app-locked, html.app-locked body { overflow: hidden; overscroll-behavior: none; }
html.app-locked body { position: fixed; inset: 0; width: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
/* iOS Safari tự phóng to khi focus ô nhập có font < 16px -> giữ tối thiểu 16px cho mọi ô nhập */
input, textarea, select { font-size: 16px; }
button { cursor: pointer; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ------------------------------------------------ buttons / inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 16px; min-height: 42px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg, .btn svg, .nav-item svg { width: 22px; height: 22px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; outline: none;
}
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 25%, transparent); }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 4px 0 8px; }
.muted { color: var(--ink-3); font-size: 13px; }
.center { text-align: center; }

/* ------------------------------------------------ avatar */
.avatar {
  flex: none; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; background: var(--brand); position: relative; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.dot-online {
  position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--surface);
}

/* ------------------------------------------------ auth */
.auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--brand-2) 30%, transparent), transparent), var(--bg);
}
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.brand img { width: 52px; height: 52px; border-radius: 14px; }
.brand b { font-size: 28px; letter-spacing: 2px; color: var(--brand); }
.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--ink-2); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.avatar-pick { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
/* Avatar có icon bút chì ở góc dưới phải (Cá nhân, Đăng ký) */
.avatar-edit { position: relative; flex: none; margin: 0 auto; }
.avatar-edit-hit { border: 0; padding: 0; background: none; border-radius: 50%; display: block; cursor: pointer; }
.avatar-edit-img { display: block; line-height: 0; }
.avatar-pencil {
  position: absolute; right: -2px; bottom: -2px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--brand); color: #fff; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.avatar-pencil svg { width: 15px; height: 15px; }
.avatar-pencil:hover { filter: brightness(1.1); }
.avatar-field { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 0 0 14px; }
.field-label { font-size: 13px; color: var(--ink-2); }
.field .hint { display: block; font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.auth-note { text-align: center; font-size: 13px; color: var(--ink-3); margin: 14px 0 0; line-height: 1.5; }
.auth-note a { color: var(--ink-2); font-weight: 600; text-decoration: none; white-space: nowrap; }
.auth-note a:hover { text-decoration: underline; }
.pending-card { text-align: center; }
.pending-card .big { font-size: 48px; }

/* ------------------------------------------------ shell */
.shell {
  position: fixed; left: 0; right: 0; top: 0;
  height: 100vh;                                  /* trình duyệt rất cũ */
  height: 100dvh;                                 /* trước khi JS chạy */
  height: var(--app-height, 100dvh);              /* = visualViewport.height */
  transform: translateY(var(--app-top, 0px));     /* = visualViewport.offsetTop (iOS cuộn layout viewport khi focus) */
  display: flex; flex-direction: column; overflow: hidden;
}
.shell > div { min-height: 0; }
.rail { display: none; }
.panes { flex: 1; display: flex; min-height: 0; }
.list-pane, .main-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.list-pane { flex: 1; }
.main-pane { flex: 1; display: none; }
.shell.show-main .list-pane { display: none; }
.shell.show-main .main-pane { display: flex; }
.shell.show-main:not(.wide) .bottom-nav { display: none; }  /* chỉ ẩn khi đang mở 1 cuộc chat / 1 trang cá nhân */
.shell.wide .list-pane { display: none; }
.shell.wide .main-pane { display: flex; }

.pane-head {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px;
  border-bottom: 1px solid var(--line); min-height: 58px; background: var(--surface);
  flex: 0 0 auto;
}
.pane-head h1 { font-size: 20px; margin: 0; flex: 1; }
.pane-head .title { flex: 1; min-width: 0; }
.pane-head .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-head .title small { color: var(--ink-3); }
.pane-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.search { padding: 8px 12px; }
.search .input { background: var(--surface-2); border-color: transparent; min-height: 38px; }

.bottom-nav {
  display: flex; border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b)); flex: 0 0 auto;
}
/* bàn phím đang mở: ẩn thanh tab dưới (ô nhập ở Sân chơi/Danh bạ), không cộng safe-area */
html.kb-open .bottom-nav { display: none; }
.nav-item {
  flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--ink-3); position: relative; font-weight: 600;
}
.nav-item.active { color: var(--brand); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.nav-item .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); }
.empty svg { width: 56px; height: 56px; opacity: .5; }

/* ------------------------------------------------ list rows */
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; border: 0;
  background: transparent; width: 100%; text-align: left;
}
.row:hover { background: var(--surface-2); }
.row.active { background: color-mix(in srgb, var(--brand-2) 14%, transparent); }
.row .meta { flex: 1; min-width: 0; }
.row .line1 { display: flex; gap: 8px; align-items: baseline; }
.row .name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--ink-3); flex: none; }
.row .line2 { display: flex; gap: 8px; align-items: center; }
.row .preview { flex: 1; min-width: 0; color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .preview { color: var(--ink); font-weight: 600; }
.section-label { padding: 12px 14px 4px; font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .5px; }

/* ------------------------------------------------ chat */
/* .chat = HEADER (cố định) + MESSAGES (cuộn độc lập) + TYPING + COMPOSER (cố định, ngay trên bàn phím) */
.chat { display: flex; flex-direction: column; flex: 1 1 auto; height: 100%; min-height: 0; overflow: hidden; background: var(--bg); }
.messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 10px 6px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; overflow-anchor: none;
}
.typing { flex: 0 0 auto; }
.msg { display: flex; gap: 8px; margin: 2px 0; align-items: flex-end; }
.msg.me { justify-content: flex-end; }
.msg .avatar-slot { width: 30px; flex: none; }
.bubble {
  max-width: min(76%, 560px); padding: 8px 12px; border-radius: 18px; background: var(--bubble-other);
  box-shadow: 0 1px 1px rgba(0,0,0,.05); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.me .bubble { background: var(--bubble-me); }
.bubble.media { padding: 4px; background: transparent; box-shadow: none; }
.bubble .sender { font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.bubble .caption { padding: 4px 8px 2px; }
.msg-time { font-size: 11px; color: var(--ink-3); margin: 0 4px; flex: none; }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 1px solid var(--danger); }
.msg .retry { font-size: 12px; color: var(--danger); border: 0; background: none; }
.sys { text-align: center; font-size: 12px; color: var(--ink-3); margin: 10px 0; }
.day { text-align: center; margin: 14px 0 8px; }
.day span { background: var(--surface-2); color: var(--ink-2); font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.seen { text-align: right; font-size: 11px; color: var(--ink-3); margin: 2px 6px 6px; }
.deleted { font-style: italic; color: var(--ink-3); }

.grid { display: grid; gap: 3px; border-radius: 14px; overflow: hidden; }
.grid.n1 { grid-template-columns: 1fr; }
.grid.n2, .grid.n4 { grid-template-columns: 1fr 1fr; }
.grid.n3, .grid.nmany { grid-template-columns: 1fr 1fr 1fr; }
/* Ô ảnh luôn có kích thước trước khi ảnh tải xong (aspect-ratio) -> không có khung cao 0, chat không nhảy. */
.grid .cell {
  border: 0; padding: 0; margin: 0; background: var(--surface-2); aspect-ratio: 1; overflow: hidden;
  display: block; width: 100%; min-width: 0; position: relative; cursor: zoom-in;
}
.grid.n1 .cell { aspect-ratio: 4 / 3; }
.media-ph { position: absolute; inset: 0; display: block; background: var(--surface-2); }
.media-ph img { display: block; width: 100%; height: 100%; object-fit: cover; }
.media-ph.loading img, .media-ph.error img { opacity: 0; }
.media-ph.loading { background: linear-gradient(100deg, var(--surface-2) 30%, var(--line) 50%, var(--surface-2) 70%) 0 0 / 300% 100%; animation: hami-shimmer 1.2s linear infinite; }
.media-ph.error { display: flex; align-items: center; justify-content: center; }
.media-retry { position: absolute; inset: auto 6px 50% 6px; transform: translateY(50%); text-align: center; font-size: 12px; color: var(--ink-2); background: var(--surface); border-radius: 10px; padding: 6px 8px; }
@keyframes hami-shimmer { to { background-position: -300% 0; } }
@media (prefers-reduced-motion: reduce) { .media-ph.loading { animation: none; } }
.msg .grid { width: min(300px, 74vw); }

.file-card {
  display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink); min-width: 220px; max-width: min(320px, 74vw); margin: 2px 0;
  white-space: normal;
}
.file-card .fc-main {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 4px; border: 0; background: none;
  color: inherit; text-decoration: none; text-align: left; font: inherit; cursor: pointer; border-radius: 8px;
}
.file-card .fc-info { min-width: 0; flex: 1; }
.file-card .fc-acts { display: flex; flex-direction: column; gap: 4px; flex: none; }
.file-card .fc-act {
  display: flex; align-items: center; justify-content: center; gap: 4px; min-width: 56px; min-height: 30px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink-2);
  font: inherit; font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.file-card .fc-act svg { width: 16px; height: 16px; flex: none; }
.file-card.busy { opacity: .6; pointer-events: none; }
.file-card.busy .fsize::after { content: " · Đang mở…"; }

/* Thư mục (máy chủ đóng gói .zip) */
.file-card .ext.folder { background: #ca8a04; }
.file-card .ext.folder svg { width: 24px; height: 24px; }

/* Tiến độ gửi tệp lớn */
.upl { margin-top: 6px; min-width: 200px; }
.upl-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.upl-bar span { display: block; height: 100%; background: var(--brand); transition: width .2s; }
.upl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--ink-2); }
.upl-cancel { border: 1px solid var(--line); background: var(--surface); color: var(--danger); border-radius: 8px; padding: 3px 10px; font: inherit; font-size: 12px; font-weight: 600; }
.bubble.media .upl { padding: 0 4px 2px; }

/* Thu hồi: nút ⋯ cạnh tin của mình (máy tính, hiện khi rê chuột); điện thoại dùng nhấn giữ */
.msg-more {
  flex: none; align-self: center; width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent;
  color: var(--ink-3); display: flex; align-items: center; justify-content: center; opacity: 0; cursor: pointer; padding: 0;
}
.msg-more svg { width: 18px; height: 18px; }
.msg:hover .msg-more, .msg-more:focus-visible { opacity: 1; }
.msg-more:hover { background: var(--surface-2); }
/* Điện thoại (2.0.0): nút ⋯ LUÔN hiện trên mọi tin, vùng bấm 40×40, biểu tượng nhỏ để không rối bong bóng */
@media (hover: none) {
  .msg .grid { width: min(300px, 62vw); }   /* chừa chỗ cho giờ + nút ⋯ trong màn hình 375 px */
  .msg .file-card { min-width: 0; }
  .msg .bubble { min-width: 0; }
  .msg-more { opacity: .75; width: 40px; height: 40px; margin: 0 -6px; }
  .msg-more svg { width: 20px; height: 20px; }
  .msg .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .msg .grid img { -webkit-touch-callout: none; }
}
.fwd-label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-3); margin: 0 0 2px; font-style: italic; }
.bubble.media .fwd-label { padding: 2px 6px 0; }
.fwd-label svg { width: 14px; height: 14px; flex: none; }
.pop-back { position: fixed; inset: 0; z-index: 80; }
.pop-back.dim { background: rgba(0,0,0,.35); }
.pop-menu.sheet {
  left: 0; right: 0; bottom: 0; top: auto; border-radius: 16px 16px 0 0; min-width: 0;
  padding: 8px 8px calc(8px + var(--safe-b)); max-height: 80dvh; overflow-y: auto;
}
.pop-menu.sheet button { min-height: 52px; font-size: 16px; padding: 12px 16px; }
.pop-menu .pop-title { font-size: 13px; color: var(--ink-3); padding: 6px 12px; }
.pop-menu .pop-close { justify-content: center; margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0; color: var(--ink-2); font-weight: 600; }

/* Bảng "Chia sẻ với" (bottom-sheet trên điện thoại, hộp giữa màn hình trên máy tính) */
.share-back { position: fixed; inset: 0; z-index: 85; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.share-sheet {
  background: var(--surface); color: var(--ink); width: 100%; max-width: 520px; max-height: 85dvh; display: flex; flex-direction: column;
  border-radius: 16px 16px 0 0; padding: 12px 12px calc(12px + var(--safe-b)); gap: 10px;
}
@media (min-width: 700px) { .share-back { align-items: center; } .share-sheet { border-radius: 16px; } }
.share-head { display: flex; align-items: center; justify-content: space-between; font-size: 17px; }
.share-list { flex: 1 1 auto; min-height: 120px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; }
.share-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.share-row input { width: 22px; height: 22px; flex: none; accent-color: var(--brand); }
.share-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.share-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.share-btns { display: flex; gap: 8px; margin-left: auto; }
.share-btns .btn { min-height: 44px; }

/* Trình duyệt thư mục */
.fv {
  position: fixed; inset: 0; z-index: 66; display: flex; flex-direction: column; background: var(--bg, var(--surface));
  height: var(--app-height, 100dvh); top: var(--app-top, 0px); color: var(--ink);
}
.fv-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; background: var(--surface); padding: calc(6px + var(--safe-t)) 6px 6px; border-bottom: 1px solid var(--line); }
.fv-head { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.fv-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-sub { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-crumbs { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; padding: 6px 10px; overflow-x: auto; white-space: nowrap; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 14px; scrollbar-width: none; }
.fv-crumb { border: 0; background: none; color: var(--brand); font: inherit; padding: 8px 6px; min-height: 36px; border-radius: 8px; }
.fv-crumb.current { color: var(--ink); font-weight: 600; }
.fv-sep { color: var(--ink-3); }
.fv-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--surface); }
.fv-row { display: flex; align-items: center; width: 100%; min-height: 60px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; padding: 0 4px 0 12px; gap: 12px; }
.fv-row.dir { cursor: pointer; padding-right: 12px; }
.fv-row:active, .fv-open:active { background: var(--surface-2); }
.fv-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; border: 0; background: none; color: inherit; font: inherit; text-align: left; padding: 8px 0; min-height: 60px; cursor: pointer; }
.fv-ico { width: 40px; height: 40px; flex: none; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: #fff; background: #64748b; overflow: hidden; }
.fv-ico.folder { background: #ca8a04; } .fv-ico.folder svg { width: 24px; height: 24px; }
.fv-ico.pdf { background: #dc2626; } .fv-ico.doc { background: #2563eb; } .fv-ico.xls { background: #16a34a; }
.fv-ico.ppt { background: #ea580c; } .fv-ico.zip { background: #7c3aed; }
.fv-ico.thumb { background: var(--surface-2); } .fv-ico.thumb img { width: 100%; height: 100%; object-fit: cover; }
.fv-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fv-n { font-size: 15px; font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.fv-name small { font-size: 12px; color: var(--ink-3); }
.fv-go svg { width: 20px; height: 20px; color: var(--ink-3); }
.fv-dl { width: 44px; height: 44px; flex: none; color: var(--ink-2); }
.fv-foot { flex: 0 0 auto; padding: 10px 12px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); }
.fv-zip { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; text-decoration: none; }
.fv-zip svg { width: 20px; height: 20px; }
.fv-status { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 16px; color: var(--ink-2); text-align: center; }
.fv-status .pdfv-spin { border-color: var(--line); border-top-color: var(--brand); }
.fv-empty { padding: 24px 16px; }
@media (min-width: 900px) {
  .fv-list, .fv-crumbs { padding-left: calc((100% - 760px) / 2); padding-right: calc((100% - 760px) / 2); }
  .fv-foot .fv-zip { max-width: 760px; margin: 0 auto; }
}
/* Điện thoại hẹp: nút trên thẻ tệp chỉ còn biểu tượng (chữ vẫn có cho trình đọc màn hình) -> tên tệp không bị ngắt vụn */
@media (max-width: 480px) {
  .file-card .fc-act { min-width: 40px; min-height: 40px; padding: 4px; }
  .file-card .fc-act span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .file-card .fc-act svg { width: 20px; height: 20px; }
}
.bubble .file-card .fname { overflow-wrap: anywhere; word-break: normal; }
.file-card .fc-legacy { font-size: 12px; color: #b45309; margin-top: 2px; }
.pop-menu {
  position: fixed; z-index: 81; min-width: 170px; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px; display: flex; flex-direction: column;
}
.pop-menu button {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; color: inherit; font: inherit; font-size: 15px;
  padding: 10px 12px; border-radius: 8px; text-align: left; cursor: pointer; min-height: 44px;
}
.pop-menu button:hover, .pop-menu button:focus-visible { background: var(--surface-2); outline: none; }
.pop-menu button.danger { color: var(--danger); }
.pop-menu svg { width: 20px; height: 20px; flex: none; }

/* Trình xem PDF / bản xem trước tệp văn phòng (PDF.js tự host) */
.pdfv {
  position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: #525659;
  height: var(--app-height, 100dvh); top: var(--app-top, 0px);
}
.pdfv-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 4px; background: var(--surface); color: var(--ink);
  padding: calc(6px + var(--safe-t)) 6px 6px; border-bottom: 1px solid var(--line);
}
.pdfv-bar .icon-btn { flex: none; }
.pdfv-bar .icon-btn:disabled { opacity: .35; }
.pdfv-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; padding: 0 4px; }
.pdfv-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdfv-count { font-size: 12px; color: var(--ink-3); min-height: 14px; }
.pdfv-body {
  flex: 1 1 auto; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 8px 8px calc(8px + var(--safe-b)); position: relative;
}
.pdfv-pages { display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; min-width: 100%; }
.pdfv-page { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); position: relative; flex: none; }
.pdfv-canvas { display: block; width: 100%; height: 100%; }
.pdfv-status {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: #fff; text-align: center; padding: 24px;
}
.pdfv-status[hidden] { display: none; }
.pdfv-status p { margin: 0; font-size: 15px; max-width: 320px; }
.pdfv-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pdfv-spin { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: hami-spin .8s linear infinite; }
.file-card .ext {
  width: 40px; height: 46px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #fff; background: #64748b; flex: none;
}
.file-card .ext.pdf { background: #dc2626; } .file-card .ext.doc { background: #2563eb; }
.file-card .ext.xls { background: #16a34a; } .file-card .ext.ppt { background: #ea580c; }
.file-card .ext.zip { background: #7c3aed; }
.file-card .fname { font-weight: 600; font-size: 14px; word-break: break-word; }
.file-card .fsize { font-size: 12px; color: var(--ink-3); }

.composer {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 8px 8px calc(8px + var(--safe-b));
  flex: 0 0 auto;
}
/* bàn phím mở: mép dưới khung = mép trên bàn phím -> bỏ khoảng Home Indicator, tránh ô nhập bị đội lên */
html.kb-open .composer { padding-bottom: 8px; }
.composer .tray { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.composer .tray .chip { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 11px; text-align: center; padding: 2px; }
.composer .tray .chip img { width: 100%; height: 100%; object-fit: cover; }
.composer .tray .chip button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1; }
.composer .bar { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; resize: none; min-height: 42px; border-radius: 21px; padding: 9px 14px;
  font-size: 16px; line-height: 22px; max-height: calc(5 * 22px + 20px);   /* tối đa 5 dòng rồi cuộn nội bộ */
  border: 1px solid var(--line); background: var(--surface-2); outline: none; overflow-y: hidden;
}
.send-btn { background: var(--brand); color: #fff; }
.send-btn:hover { background: var(--brand); filter: brightness(1.08); }
.typing { font-size: 12px; color: var(--ink-3); padding: 0 14px 4px; min-height: 16px; }

/* ------------------------------------------------ feed */
.feed { max-width: 640px; margin: 0 auto; padding: 10px 0 24px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 8px 12px; }
.composer-card { padding: 12px; }
.composer-card textarea { width: 100%; border: 0; resize: vertical; min-height: 64px; background: transparent; outline: none; font-size: 16px; }
.composer-card .actions { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 6px; }
.post-head .who { flex: 1; min-width: 0; }
.post-head .who button { border: 0; background: none; padding: 0; font-weight: 700; text-align: left; }
.post-body { padding: 0 12px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; }
.post .grid { border-radius: 0; }
.post-stats { display: flex; justify-content: space-between; padding: 8px 12px; font-size: 13px; color: var(--ink-3); }
.post-actions { display: flex; border-top: 1px solid var(--line); }
.post-actions button { flex: 1; border: 0; background: transparent; padding: 10px; font-weight: 600; color: var(--ink-2); }
.post-actions button.on { color: var(--brand); }
.react-pick { display: flex; gap: 4px; padding: 6px 12px; }
.react-pick button { border: 0; background: var(--surface-2); border-radius: 18px; font-size: 22px; padding: 4px 10px; }
.comments { border-top: 1px solid var(--line); padding: 8px 12px 12px; }
.comment { display: flex; gap: 8px; margin-bottom: 8px; }
.comment .cbody { background: var(--surface-2); border-radius: 14px; padding: 6px 10px; overflow-wrap: anywhere; white-space: pre-wrap; }
.comment .cbody b { display: block; font-size: 13px; }
.comment-form { display: flex; gap: 6px; }
.new-posts { position: sticky; top: 8px; z-index: 2; display: flex; justify-content: center; }

/* ------------------------------------------------ profile */
.profile { max-width: 640px; margin: 0 auto; padding: 20px 12px 30px; }
.profile-top { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; margin-bottom: 16px; }
.profile-top h2 { margin: 6px 0 0; }
.profile-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.settings { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.settings h3 { margin: 0 0 10px; font-size: 16px; }
.session-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.session-row:last-child { border-bottom: 0; }
.session-row div { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------ modal / lightbox / toast */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 88dvh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b));
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.pick-row label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.role-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 75; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox .lb-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: calc(8px + var(--safe-t)) 8px 8px; }
.lightbox .icon-btn { color: #fff; background: rgba(255,255,255,.12); }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); }
.lightbox .prev { left: 8px; } .lightbox .next { right: 8px; }
.lightbox .count { color: #fff; align-self: center; font-size: 14px; }
.lightbox img { user-select: none; -webkit-user-select: none; }
.lightbox .lb-spin { display: none; position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: hami-spin .8s linear infinite; pointer-events: none; }
.lightbox.loading .lb-spin { display: block; }
.lightbox .lb-msg { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #fff; background: rgba(255,255,255,.15);
  border: 0; border-radius: 10px; padding: 10px 14px; font: inherit; font-size: 14px; }
@keyframes hami-spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); z-index: 70;
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
}
.conn-bar { background: var(--accent); color: #1f1300; text-align: center; font-size: 13px; padding: 4px; font-weight: 600; }

/* ------------------------------------------------ desktop */
@media (min-width: 900px) {
  .shell { flex-direction: row; }
  .bottom-nav { display: none !important; }
  .rail {
    display: flex; flex-direction: column; align-items: center; gap: 6px; width: 72px; flex: none;
    background: var(--brand); padding: 14px 0; color: #fff;
  }
  .rail .logo { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px; }
  .rail .nav-item { flex: none; width: 56px; height: 56px; border-radius: 14px; color: rgba(255,255,255,.75); font-size: 10px; }
  .rail .nav-item.active, .rail .nav-item:hover { background: rgba(255,255,255,.16); color: #fff; }
  .rail .spacer { flex: 1; }
  .rail .me-btn { border: 0; background: none; padding: 0; border-radius: 50%; }
  .list-pane { flex: none; width: 340px; border-right: 1px solid var(--line); display: flex !important; }
  .main-pane { display: flex !important; flex: 1; }
  .shell.wide .list-pane { display: none !important; }
  .main-pane .back-btn { display: none; }
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; }
  .msg .grid { width: 340px; }
}

/* ===== 2.1.0: danh bạ theo tổ chức + văn bản ===== */
.nav-item { min-width: 0; }
.nav-item span:not(.badge) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 4px; color: var(--brand); font-size: 14px; }
.org-head svg { width: 18px; height: 18px; flex: none; }
.org-head b { overflow-wrap: anywhere; }
.org-group > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 20px; font-size: 12px; font-weight: 700;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: .3px; cursor: pointer; }
.org-group > summary::-webkit-details-marker { display: none; }
.org-group > summary::before { content: "▸"; transition: transform .15s; }
.org-group[open] > summary::before { transform: rotate(90deg); }
.org-group > summary span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.org-group .cnt { font-weight: 600; }
.org-group .row { padding-left: 22px; }
.org-line { color: var(--brand); font-size: 14px; margin: 2px 0; text-align: center; overflow-wrap: anywhere; }
.seg { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 6px; border-radius: 8px; font-weight: 600; color: var(--ink-2); font-size: 13px; min-width: 0; }
.seg button.on { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pane-head .btn.small svg { width: 18px; height: 18px; }
.doc-row .doc-ic { width: 44px; height: 44px; border-radius: 12px; background: #e0f2fe; color: #0369a1; display: flex; align-items: center; justify-content: center; flex: none; }
.doc-row .doc-ic.off { background: var(--surface-2); color: var(--ink-3); }
.doc-row .doc-ic svg { width: 24px; height: 24px; }
.doc-row.unread .name { font-weight: 800; }
.doc-count { font-size: 12px; color: var(--ink-3); flex: none; }
.doc-view { padding: 14px; }
.doc-title { margin: 0 0 4px; font-size: 19px; overflow-wrap: anywhere; }
.doc-banner { background: #fee2e2; color: #991b1b; padding: 8px 10px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.doc-acts { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.doc-acts .btn svg { width: 18px; height: 18px; }
.doc-files { display: grid; gap: 8px; padding: 0 2px; }
.doc-files > * { min-width: 0; max-width: 100%; }
.doc-timeline { list-style: none; margin: 4px 0 20px; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.doc-timeline li { position: relative; padding: 6px 0 6px 12px; font-size: 14px; overflow-wrap: anywhere; }
.doc-timeline li::before { content: ""; position: absolute; left: -21px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.doc-timeline li.ev-recall::before { background: var(--danger); }
.doc-timeline li.ev-view::before, .doc-timeline li.ev-ack::before { background: #16a34a; }
.doc-timeline .ev-time { font-size: 12px; color: var(--ink-3); }
.doc-receipts .ok { color: #16a34a; font-size: 13px; }
.doc-receipts .muted { font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip-tag { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 14px; padding: 4px 6px 4px 10px; font-size: 13px; max-width: 100%; overflow-wrap: anywhere; }
.chip-tag button { border: 0; background: transparent; font-size: 16px; line-height: 1; color: var(--ink-3); padding: 0 4px; }
.recip-picker .seg { margin-bottom: 8px; }
.recip-picker .input[type=search] { margin-bottom: 6px; }
.pick-list { max-height: 42vh; overflow: auto; }
.pick-txt { display: flex; flex-direction: column; min-width: 0; }
.pick-txt b { font-weight: 600; overflow-wrap: anywhere; }
.pick-txt small { font-size: 12px; overflow-wrap: anywhere; }
.doc-compose .field > .btn { margin-top: 4px; align-self: flex-start; }
.doc-compose .btn svg { width: 18px; height: 18px; }
.muted.small, .small { font-size: 12px; }
