/* ==========================================================================
   web 端（電腦版）版面 — 桌面優先，向下自適應到小筆電，向上撐滿寬螢幕
   容器 id 與 core.js 共用；H5 版請改 h5.css，兩邊互不影響。
   ========================================================================== */

html, body { height: 100%; overflow: hidden; }   /* 整頁不滾動，滾動只發生在訊息區 */

/* 主界面：左側圖標導航欄 + 右側工作區（微信/釘釘桌面式） */
#app-view {
  height: 100vh; height: 100dvh;
  display: flex; overflow: hidden;
}

/* 圖標導航欄 */
.rail {
  width: 68px; flex-shrink: 0;
  background: #2b2f36; color: #cfd4da;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0 12px; gap: 4px;
}
.rail-logo {
  width: 40px; height: 40px; border-radius: 10px; margin-bottom: 10px;
  background: var(--primary); color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.rail-item {
  position: relative; width: 60px; padding: 7px 0 5px;
  border: none; background: none; border-radius: 8px; cursor: pointer;
  color: #cfd4da; font-family: inherit; font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.rail-item:hover { background: rgba(255,255,255,.08); }
.rail-item.active { color: #fff; background: rgba(255,255,255,.12); }
.rail-item.active .rail-icon { transform: scale(1.1); }
.rail-icon { font-size: 20px; line-height: 1.1; transition: transform .15s; }
.rail-item .badge { position: absolute; top: 2px; right: 10px; }
.rail-spacer { flex: 1; }

/* 工作區（導航欄右側的全部內容） */
.view-area { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* 聯絡人 / 我的：置中窄欄 */
.page-section { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; }
.page-narrow { max-width: 680px; margin: 0 auto; }
.page-title { font-size: 17px; margin-bottom: 4px; }
.page-narrow > .muted { margin-bottom: 14px; }
.contacts-list { padding: 4px 0; }
.contact-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.contact-item:last-child { border-bottom: none; }
.contact-item:hover { background: #f7f8fa; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; }

/* 我的：資料卡與設定列 */
.me-card { margin-bottom: 14px; padding: 16px 18px; }
.me-profile-row { display: flex; align-items: center; gap: 14px; }
.me-profile-row .avatar { width: 56px; height: 56px; }
.me-profile-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.me-profile-info b { font-size: 16px; }
.me-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.me-row:last-child { border-bottom: none; }

/* 聊天版面：左列表 + 右聊天，佔滿剩餘高度 */
.chat-layout { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.sidebar {
  width: clamp(260px, 20vw, 380px);
  border-right: 1px solid var(--border); background: var(--card);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item {
  display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; align-items: center;
}
.conv-item:hover { background: #f7f8fa; }
.conv-item.active { background: #eafaf1; }
.pin-mark { font-size: 12px; }
/* 滑到會話上才出現的快捷鈕：置頂 / 隱藏 / 刪除 */
.conv-quick { display: none; gap: 2px; flex-shrink: 0; }
.conv-item:hover .conv-quick { display: flex; }
.conv-item:hover .conv-meta { display: none; }
.qk {
  border: none; background: none; cursor: pointer; font-size: 15px;
  padding: 5px 4px; border-radius: 6px; line-height: 1;
}
.qk:hover { background: #e8eaee; }
.qk-del:hover { background: #fdecec; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
/* 聊天面板：標頭固定、訊息區滾動、輸入區永遠貼在底部 */
#chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--bar-bg); border-bottom: 1px solid var(--border);
  flex-shrink: 0;                      /* 客戶資料固定頂部，不隨訊息滾動 */
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chat-name-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chat-sub-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.chat-name { font-weight: 600; }
.assign-select {
  width: auto; margin: 0; padding: 6px 8px; font-size: 12px; border-radius: 6px;
  background: #fff; max-width: 130px;
}
/* 訊息區：佔滿中間剩餘空間，只有這裡滾動 */
.msg-list {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
  background: var(--chat-bg);
}
.msg { max-width: min(72%, 680px); }   /* 超寬螢幕不讓氣泡無限拉長 */

/* 輸入區：固定貼底 */
.composer {
  border-top: 1px solid var(--border); background: var(--bar-bg);
  padding: 8px 12px 10px; flex-shrink: 0;
}
.composer-btns { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea { flex: 1; resize: none; max-height: 140px; }

/* 後台 */
.admin-layout { flex: 1; min-height: 0; padding: 20px; overflow-y: auto; }
.admin-col { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.admin-col h2 { font-size: 16px; margin-bottom: 12px; }
.admin-col h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); }

/* ---------- 自適應 ---------- */

/* 小筆電 / 視窗縮到 1180px 以下：頂欄與聊天頭部精簡 */
@media (max-width: 1180px) {
  .topbar-left { gap: 12px; }
  .chat-header { padding: 8px 12px; }
  .chat-actions .btn { padding: 6px 9px; font-size: 12px; }
  .assign-select { max-width: 108px; }
}

/* 窄窗（≈平板橫放 / 分割視窗）：列表縮窄 */
@media (max-width: 980px) {
  .sidebar { width: 240px; }
  .msg { max-width: 82%; }
  .contact-item { flex-wrap: wrap; }
}

/* 大螢幕：列表加寬、氣泡上限放寬、後台兩欄 */
@media (min-width: 1440px) {
  .msg { max-width: min(68%, 760px); }
  .admin-col { max-width: 1320px; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (min-width: 1920px) {
  .sidebar { width: 400px; }
  .msg-list { padding: 22px 28px; }
  .admin-col { max-width: 1560px; }
}

/* 極窄（<=820px，例如把視窗拉很窄）：電腦版不做單列佈局，直接提示切到手機版 */
.narrow-tip { display: none; }
@media (max-width: 820px) {
  .narrow-tip {
    display: flex; position: fixed; inset: 0; z-index: 80;
    align-items: center; justify-content: center; padding: 24px;
    background: var(--bg);
  }
  .narrow-tip .card { max-width: 380px; text-align: center; }
  .narrow-tip h2 { font-size: 16px; margin-bottom: 8px; }
  .narrow-tip p { color: var(--muted); font-size: 13px; line-height: 1.7; }
  .narrow-tip .btn { margin-top: 14px; display: inline-block; text-decoration: none; }
}
