/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #f0f2f5;
  --sidebar:   #1e3a5f;
  --sidebar2:  #162d4a;
  --accent:    #3b82f6;
  --accent2:   #2563eb;
  --white:     #ffffff;
  --bubble-me: #dcf8c6;
  --bubble:    #ffffff;
  --text:      #1a1a2e;
  --muted:     #6b7280;
  --border:    #e5e7eb;
  --red:       #ef4444;
  --radius:    12px;
  --shadow:    0 2px 8px rgba(0,0,0,.12);
}
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 15px; background: var(--bg); color: var(--text); }

/* ── Pages ── */
.page { display: none; height: 100vh; }
.page.active { display: flex; }

/* ── Login ── */
#page-login { justify-content: center; align-items: center; background: var(--sidebar); }
.login-box { background: var(--white); border-radius: var(--radius); padding: 40px 36px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-logo { font-size: 48px; text-align: center; }
.login-box h1 { text-align: center; font-size: 22px; color: var(--sidebar); }
.login-box input { padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; outline: none; }
.login-box input:focus { border-color: var(--accent); }
.login-box button { padding: 11px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-box button:hover { background: var(--accent2); }
.err { color: var(--red); font-size: 13px; text-align: center; min-height: 18px; }

/* ── Main Layout ── */
#page-main { flex-direction: row; overflow: hidden; }

/* ── Sidebar ── */
#sidebar { width: 280px; min-width: 220px; background: var(--sidebar); display: flex; flex-direction: column; }
#sidebar-header { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-bottom: 1px solid var(--sidebar2); }
#org-name-bar { font-size: 13px; font-weight: 700; background: rgba(20,184,166,.25); border: 1px solid rgba(20,184,166,.4); border-radius: 6px; padding: 5px 10px; color: #5eead4; }
#org-name-bar span { color: #ccfbf1; }
#my-info { display: flex; align-items: center; gap: 8px; }
.my-info-btn { background: transparent; border: 1px solid rgba(255,255,255,.15); color: #94a3b8; border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12px; flex-shrink: 0; }

/* AI 助理浮動面板 */
#ai-panel { position: fixed; bottom: 88px; right: 24px; width: 380px; max-width: calc(100vw - 16px); max-height: 70vh; z-index: 900; }
#ai-panel.ai-max { width: 880px; max-width: calc(100vw - 32px); max-height: 90vh; bottom: 24px; }
#ai-panel.ai-max #ai-messages { max-height: calc(90vh - 130px) !important; }
#ai-messages > * { flex-shrink: 0; }   /* 防止訊息/表格被 flex 壓扁 */
#my-avatar-wrap { flex-shrink: 0; cursor: pointer; position: relative; }
#my-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 16px; color: #fff; font-weight: 600; overflow: hidden; border: 2px solid rgba(255,255,255,.3); }
#my-avatar img { width: 100%; height: 100%; object-fit: cover; }
#my-avatar-wrap:hover #my-avatar::after { content: '📷'; position: absolute; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; font-size: 16px; border-radius: 50%; }
#my-name { color: #fff; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btn-logout { background: none; border: none; color: rgba(255,255,255,.45); cursor: pointer; padding: 4px 8px; display: flex; align-items: center; gap: 4px; font-size: 12px; border-radius: 6px; flex-shrink: 0; }
#btn-logout:hover { color: #fff; background: rgba(255,255,255,.1); }
/* sidebar-actions：Grid 佈局，左側 action-btns 自動填滿，右側 btn-new-room 固定 28px */
#sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 28px;   /* action-btns 填滿剩餘 | btn-new-room 固定 */
  align-items: start;
  gap: 6px;
  padding: 4px 0;
}
/* 按鈕群組：grid 寬度明確，內部 flex-wrap 換行可靠 */
#action-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
/* 小按鈕共用樣式 */
#action-btns button {
  background: rgba(255,255,255,.15); color: #fff; border: none;
  border-radius: 8px; width: 30px; height: 28px;
  font-size: 15px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
#action-btns button:hover { background: rgba(255,255,255,.28); }
/* 新增群組按鈕靠右固定 */
#btn-new-room {
  background: var(--accent); color: #fff; border: none;
  border-radius: 50%; width: 28px; height: 28px;
  font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#btn-new-room:hover { opacity: .85; }

/* JS Tooltip（貼 body，不被父層 overflow 裁切）*/
.js-tooltip {
  position: fixed;
  background: rgba(15,23,42,.92);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  padding: 4px 9px;
  border-radius: 5px;
  pointer-events: none;
  z-index: 99999;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  transition: opacity .1s;
}

#room-list { flex: 1; overflow-y: auto; }
.room-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.06); transition: background .15s; }
.room-item:hover, .room-item.active { background: rgba(255,255,255,.12); }
.room-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0; }
.room-info { flex: 1; min-width: 0; }
.room-name-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.room-name { color: #fff; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-badge { background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.room-preview { color: rgba(255,255,255,.55); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* ── Chat Area ── */
#chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
#chat-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 16px; }
#chat-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
#chat-panel.hidden { display: none; }

#chat-header { background: var(--white); padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
#chat-title { font-weight: 600; font-size: 16px; }
#chat-actions { display: flex; gap: 8px; }
#chat-actions button { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 18px; cursor: pointer; }
#chat-actions button:hover { background: var(--bg); }

#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg-row { display: flex; align-items: flex-end; gap: 8px; }
.msg-row.me { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 13px; color: #fff; flex-shrink: 0; }
.msg-body { max-width: 65%; }
.msg-sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg-bubble { background: var(--bubble); padding: 9px 13px; border-radius: 16px; border-bottom-left-radius: 4px; font-size: 14px; line-height: 1.5; box-shadow: 0 1px 2px rgba(0,0,0,.08); word-break: break-word; }
.msg-row.me .msg-bubble { background: var(--bubble-me); border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg-file a { color: var(--accent); text-decoration: none; display: flex; align-items: center; gap: 6px; }
.msg-file a:hover { text-decoration: underline; }
.msg-sticker img { max-width: 120px; max-height: 120px; object-fit: contain; border-radius: 8px; display: block; }

/* ── 已收回訊息 ── */
.msg-recalled { font-style: italic; color: var(--muted); font-size: 13px; padding: 7px 12px; background: rgba(0,0,0,.05); border-radius: 12px; border: 1px dashed var(--border); }
/* Bot (@AI 助理) 泡泡 — 淡藍色識別 */
.msg-row.bot .msg-bubble { background: #e8f4fd; border: 1px solid #bee3f8; }

/* ── 翻譯文字 ── */
.msg-translation { font-size: 12px; color: #6b7280; margin-top: 5px; padding: 4px 8px; background: rgba(59,130,246,.06); border-left: 2px solid #93c5fd; border-radius: 0 6px 6px 0; line-height: 1.5; word-break: break-word; display: flex; align-items: flex-start; gap: 6px; }
.msg-row.me .msg-translation { border-left: none; border-right: 2px solid #93c5fd; border-radius: 6px 0 0 6px; flex-direction: row-reverse; }
.msg-translation-text { flex: 1; }
.msg-tts-btn { flex-shrink: 0; background: none; border: none; cursor: pointer; font-size: 14px; padding: 0; opacity: .6; line-height: 1; margin-top: 1px; }
.msg-tts-btn:hover { opacity: 1; }
.msg-tts-btn.speaking { animation: tts-pulse .8s infinite alternate; }
@keyframes tts-pulse { from { opacity: .4 } to { opacity: 1 } }

/* ── 訊息右鍵選單 ── */
#msg-ctx-menu { position: fixed; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.18); z-index: 9999; overflow: hidden; min-width: 160px; }
#msg-ctx-menu.hidden { display: none; }
#msg-ctx-menu button { display: block; width: 100%; padding: 13px 18px; background: none; border: none; text-align: left; cursor: pointer; font-size: 14px; color: var(--text); }
#msg-ctx-menu button:hover:not(:disabled) { background: var(--bg); }
#msg-ctx-menu button:disabled { color: var(--muted); cursor: not-allowed; font-size: 12px; }

/* ── 語音訊息 ── */
.msg-voice { display: flex; align-items: center; gap: 8px; background: var(--bubble); padding: 8px 12px; border-radius: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.08); min-width: 160px; }
.msg-row.me .msg-voice { background: var(--bubble-me); }
.voice-play-btn { background: var(--accent); color: #fff; border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 14px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.voice-play-btn:hover { background: var(--accent2); }
.voice-progress { flex: 1; height: 4px; background: rgba(0,0,0,.12); border-radius: 2px; overflow: hidden; cursor: pointer; }
.voice-progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width .1s linear; border-radius: 2px; }
.voice-duration { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ── 錄音按鈕 ── */
#btn-voice { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 6px; flex-shrink: 0; border-radius: 6px; line-height: 1; user-select: none; -webkit-user-select: none; }
#btn-voice:hover { background: var(--bg); }
#btn-voice.recording { background: #fee2e2; animation: pulse-rec 1s infinite; }
#btn-voice.processing { background: #fef9c3; cursor: not-allowed; animation: pulse-proc 1.2s infinite; }
@keyframes pulse-rec  { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }
@keyframes pulse-proc { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ── 會議模式 ── */
#meeting-panel { display: flex; flex-direction: column; background: #0f172a; border-bottom: 2px solid #1e293b; flex-shrink: 0; max-height: 290px; min-height: 160px; }
#mtg-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: #1e293b; gap: 8px; flex-shrink: 0; }
#mtg-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mtg-live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; flex-shrink: 0; animation: pulse-rec 1s infinite; }
#mtg-speaker-label { font-size: 13px; font-weight: 600; color: #f1f5f9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mtg-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#mtg-host-info { font-size: 11px; color: #64748b; white-space: nowrap; }
#mtg-end-btn { padding: 3px 10px; background: #ef4444; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; }
#mtg-subtitles { flex: 1; overflow-y: auto; padding: 8px 14px; display: flex; flex-direction: column; gap: 5px; scroll-behavior: smooth; }
.mtg-sub { background: #1e293b; border-radius: 8px; padding: 6px 10px; animation: mtgFadeIn .25s ease; }
.mtg-sub-who { font-size: 11px; color: #64748b; margin-bottom: 2px; }
.mtg-sub-text { font-size: 15px; color: #f1f5f9; line-height: 1.5; }
.mtg-sub-orig { font-size: 11px; color: #475569; margin-top: 2px; font-style: italic; }
@keyframes mtgFadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
#mtg-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: #0a0f1a; border-top: 1px solid #1e293b; flex-shrink: 0; gap: 8px; flex-wrap: wrap; min-height: 42px; }
#mtg-hand-queue { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; align-items: center; }
.mtg-hand-item { display: flex; align-items: center; gap: 4px; background: #1e293b; border-radius: 20px; padding: 3px 8px; font-size: 12px; color: #f1f5f9; }
.mtg-hand-item button { border: none; border-radius: 4px; padding: 2px 7px; cursor: pointer; font-size: 11px; font-weight: 600; }
.mtg-hand-item .mtg-grant { background: #3b82f6; color: #fff; }
.mtg-hand-item .mtg-dismiss { background: #334155; color: #94a3b8; }
#mtg-btns { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#mtg-lang-wrap { display: flex; align-items: center; gap: 4px; }
#mtg-lang-sel, #mtg-grant-lang-sel { background: #1e293b; color: #f1f5f9; border: 1px solid #334155; border-radius: 6px; padding: 3px 6px; font-size: 12px; cursor: pointer; }
#mtg-hand-btn { background: #1e293b; color: #f1f5f9; }
#mtg-hand-btn.raised { background: #f59e0b; color: #1e293b; }
#mtg-stop-btn { background: #ef4444; color: #fff; }
#mtg-revoke-btn { background: #dc2626; color: #fff; }
#btn-meeting { background: none; border: none; font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 6px; line-height: 1; }
#btn-meeting:hover { background: var(--bg); }
#btn-meeting.active { filter: drop-shadow(0 0 4px #ef4444); }
/* Check-in badge + list */
#mtg-checkin-badge { font-size: 12px; color: #4ade80; cursor: pointer; padding: 2px 8px; background: rgba(74,222,128,.12); border-radius: 20px; white-space: nowrap; }
#mtg-checkin-badge:hover { background: rgba(74,222,128,.22); }
#mtg-checkin-list { background: #0f2744; border-bottom: 1px solid #1e3a5f; padding: 6px 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.mtg-checkin-item { display: flex; align-items: center; gap: 4px; background: rgba(74,222,128,.1); border-radius: 20px; padding: 2px 10px; font-size: 12px; color: #a7f3d0; }
.mtg-checkin-item span { color: #64748b; font-size: 11px; }
/* Check-in + save buttons */
#mtg-self-speak-btn { background: #1d4ed8; color: #bfdbfe; border: 1px solid #3b82f6; }
#mtg-self-speak-btn:hover { background: #2563eb; color: #fff; }
#mtg-checkin-btn { background: #065f46; color: #a7f3d0; }
#mtg-checkin-btn.done { background: #1e293b; color: #4ade80; cursor: default; }
#mtg-checkout-btn { background: #7c3aed; color: #ede9fe; }
#mtg-checkout-btn:disabled { background: #1e293b; color: #64748b; cursor: default; }
#mtg-save-btn { background: #1e3a5f; color: #93c5fd; border: 1px solid #3b82f6; }
#mtg-save-btn:hover { background: #1d4ed8; color: #fff; }
#mtg-hand-btn, #mtg-stop-btn, #mtg-revoke-btn, #mtg-checkin-btn, #mtg-checkout-btn, #mtg-self-speak-btn, #mtg-save-btn { padding: 5px 12px; border: none; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; }
/* Grant Popover */
#mtg-grant-pop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 999; }
.mtg-grant-inner { background: #1e293b; border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 10px; min-width: 240px; box-shadow: 0 8px 32px rgba(0,0,0,.5); }

/* ── 錄音提示 ── */
#record-toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.75); color: #fff; padding: 8px 20px; border-radius: 20px; font-size: 14px; pointer-events: none; z-index: 500; }
.msg-system { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }

#typing-indicator { padding: 6px 18px; font-size: 12px; color: var(--muted); font-style: italic; }

/* AI 思考中 */
.ai-thinking-dots { color: #94a3b8; font-style: italic; }

/* ── Emoji / Sticker 面板 ── */
#emoji-panel, #sticker-panel { background: var(--white); border-top: 1px solid var(--border); padding: 8px; max-height: 260px; display: flex; flex-direction: column; gap: 6px; }
#emoji-tabs, #sticker-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
#emoji-tabs button, #sticker-tabs button { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 13px; cursor: pointer; }
#emoji-tabs button.active, #sticker-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#emoji-grid { display: flex; flex-wrap: wrap; gap: 2px; overflow-y: auto; }
#emoji-grid span { font-size: 24px; cursor: pointer; padding: 3px; border-radius: 6px; line-height: 1; }
#emoji-grid span:hover { background: var(--bg); }
#sticker-grid { display: flex; flex-wrap: wrap; gap: 6px; overflow-y: auto; }
#sticker-grid img { width: 72px; height: 72px; object-fit: contain; cursor: pointer; border-radius: 8px; border: 2px solid transparent; }
#sticker-grid img:hover { border-color: var(--accent); background: var(--bg); }
#btn-emoji, #btn-sticker { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px; flex-shrink: 0; border-radius: 6px; line-height: 1; }
#btn-emoji:hover, #btn-sticker:hover { background: var(--bg); }
#btn-emoji.active, #btn-sticker.active { background: #eff6ff; }

/* ── 貼圖管理 Modal ── */
#sm-packs { display: flex; flex-direction: column; gap: 10px; max-height: 300px; overflow-y: auto; }
.sm-pack { border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.sm-pack-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.sm-sticker-list { display: flex; flex-wrap: wrap; gap: 6px; }
.sm-sticker-wrap { position: relative; }
.sm-sticker-wrap img { width: 60px; height: 60px; object-fit: contain; border-radius: 6px; border: 1px solid var(--border); }
.sm-sticker-del { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border: none; border-radius: 50%; width: 16px; height: 16px; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; }
.sm-upload-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg); border: 1px dashed var(--border); border-radius: 6px; font-size: 12px; cursor: pointer; }
#sm-create-pack { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 14px; white-space: nowrap; }
#sm-close { background: var(--bg); border: none; border-radius: 8px; padding: 9px 20px; cursor: pointer; font-size: 14px; }

#chat-footer { background: var(--white); padding: 10px 14px; display: flex; align-items: flex-end; gap: 10px; border-top: 1px solid var(--border); }
#attach-btn { font-size: 22px; cursor: pointer; padding: 4px; flex-shrink: 0; line-height: 1; }
#msg-input { flex: 1; border: 1px solid var(--border); border-radius: 20px; padding: 9px 14px; font-size: 14px; font-family: inherit; resize: none; outline: none; max-height: 120px; overflow-y: auto; }
#msg-input:focus { border-color: var(--accent); }
#send-btn { background: var(--accent); color: #fff; border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; cursor: pointer; flex-shrink: 0; }
#send-btn:hover { background: var(--accent2); }

/* ── @提及 Popup ── */
#mention-popup {
  position: absolute;
  bottom: 72px;   /* 浮在 footer 上方 */
  left: 14px;
  width: 240px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  overflow: hidden;
  z-index: 200;
  max-height: 240px;
  overflow-y: auto;
}
#mention-popup .mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .15s;
}
#mention-popup .mention-item:hover,
#mention-popup .mention-item.active {
  background: #e8f0fe;
}
#mention-popup .mention-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent);
  color: #fff; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
#mention-popup .mention-avatar.all-avatar { background: #6b7280; font-size: 15px; }
#mention-popup .mention-name { font-size: 14px; color: var(--text); font-weight: 500; }
#mention-popup .mention-username { font-size: 11px; color: var(--muted); }

/* ── Members Panel ── */
#members-panel { width: 240px; background: var(--white); border-left: 1px solid var(--border); overflow-y: auto; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.panel-header button { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.member-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.member-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; flex-shrink: 0; position: relative; }
.online-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid #fff; }
.member-name { font-size: 14px; }
.member-role { font-size: 11px; color: var(--muted); }

/* ── Video Overlay ── */
#video-overlay { position: fixed; inset: 0; background: #000; z-index: 1000; display: flex; flex-direction: column; }
#close-video { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,.2); color: #fff; border: none; border-radius: 8px; padding: 8px 16px; font-size: 14px; cursor: pointer; z-index: 10; }
#jitsi-frame { flex: 1; border: none; width: 100%; }

/* ── Modal ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 900; display: flex; align-items: center; justify-content: center; }
/* modal-overlay：search / audit / template 等以 .hidden 切換顯示的彈窗。
   有 inline display 的彈窗（skill-mgmt/safety/i18n）會被 inline 覆蓋，不受影響。 */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; box-sizing: border-box; }
/* 技能助理工具下拉選單項目 */
.ai-tool-item { display: block; width: 100%; text-align: left; background: transparent; border: none; color: #cbd5e1; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.ai-tool-item:hover { background: #1e293b; }
.modal-box { background: #fff; border-radius: var(--radius); padding: 28px; width: 380px; max-height: 80vh; overflow: auto; display: flex; flex-direction: column; gap: 14px; resize: both; min-width: 280px; min-height: 120px; box-sizing: border-box; }
/* 聯絡人管理 Modal */
#modal-users .modal-box {
  width: 460px;
  height: 520px;          /* 預設高度，使用者可往下拖拉 */
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  resize: both;           /* 可自由拖拉調整大小 */
}
.um-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); flex-shrink: 0; margin-bottom: 6px; }
.um-tab { flex: 1; padding: 8px 0; border: none; background: none; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.um-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.um-tab:hover:not(.active) { color: var(--text); }
.um-tab-pane { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
/* um-list 自動填滿剩餘空間，覆蓋全域的 max-height:240px */
#modal-users #um-list { flex: 1; min-height: 0; max-height: none; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.modal-box h3 { font-size: 17px; cursor: move; user-select: none; padding-bottom: 4px; border-bottom: 1px dashed #e5e7eb; margin-bottom: 2px; }
.modal-box h3::after { content: ' ⠿'; font-size: 12px; color: #cbd5e1; font-weight: 400; }
.modal-box input, .modal-box select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 100%; outline: none; }
#nr-user-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.nr-user-item { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.nr-user-item.selected { background: #eff6ff; border-color: var(--accent); }
.nr-user-item input[type=checkbox] { width: 16px; height: 16px; }
.nr-select-all { background: #f8fafc; border-color: #cbd5e1; margin-bottom: 4px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; }
.modal-footer button { padding: 9px 20px; border-radius: 8px; border: none; font-size: 14px; cursor: pointer; }
#nr-cancel { background: var(--bg); }
#nr-create { background: var(--accent); color: #fff; font-weight: 600; }
#um-cancel { background: var(--bg); }
#um-add { background: var(--accent); color: #fff; font-weight: 600; }
#um-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.um-user-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.um-user-info { display: flex; flex-direction: column; }
.um-user-name { font-weight: 500; }
.um-user-login { font-size: 12px; color: var(--muted); }
.um-del-btn { background: none; border: 1px solid var(--red); color: var(--red); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.um-del-btn:hover { background: var(--red); color: #fff; }
/* 上傳大小限制欄 */
.um-limit-wrap { display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-right: 6px; }
.um-limit-input::-webkit-inner-spin-button { opacity: 1; }
/* 我的檔案分頁 */
.mf-tab { background: none; border: none; border-bottom: 3px solid transparent; padding: 8px 14px; font-size: 14px; cursor: pointer; color: var(--text-muted); margin-bottom: -2px; }
.mf-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.mf-tab:hover { color: var(--accent); }
.um-del-wrap { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.um-del-confirm { display: inline-flex; align-items: center; gap: 6px; }
.um-del-yes { background: #ef4444; color: #fff; border: none; border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.um-del-no  { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.modal-box h4 { color: var(--muted); font-size: .9rem; font-weight: 600; }

/* ── WS 斷線提示條 ── */
#ws-status { background: #92400e; color: #fef3c7; padding: 6px 14px; font-size: 13px; text-align: center; }

/* ── 通知封鎖提示條 ── */
#notify-banner { background:#92400e; color:#fef3c7; padding:8px 14px; font-size:13px; display:flex; align-items:center; gap:6px; }
#notify-banner a { color:#fde68a; }

/* ── Utilities ── */
.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ── Back / hamburger buttons（桌面隱藏）── */
#btn-back, #btn-open-sidebar { display: none; }

/* ── Mobile ── */
@media (max-width: 640px) {
  #sidebar { width: 85%; max-width: 300px; position: absolute; z-index: 200; height: 100%; transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 16px rgba(0,0,0,.3); }
  #sidebar.open { transform: translateX(0); }
  #members-panel { position: absolute; right: 0; top: 0; height: 100%; z-index: 200; }

  /* 遮罩 */
  #sidebar-overlay { display: block; position: absolute; inset: 0; background: rgba(0,0,0,.4); z-index: 150; }

  /* 返回按鈕（聊天頁標題列）*/
  #btn-back { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text); font-size: 26px; font-weight: 300; cursor: pointer; padding: 0 8px 0 0; line-height: 1; }

  /* 歡迎頁改為大按鈕 */
  #btn-open-sidebar { display: inline-flex; align-items: center; gap: 8px; padding: 12px 24px; background: var(--accent); color: #fff; border: none; border-radius: 24px; font-size: 16px; cursor: pointer; box-shadow: var(--shadow); }

  /* ① 手機版 my-info：按鈕縮小 */
  .my-info-btn { font-size: 11px; padding: 3px 7px; }

  /* ② AI 面板手機版：貼齊左右邊，不超出螢幕 */
  #ai-panel { right: 8px; left: 8px; width: auto; max-width: none; bottom: 72px; }
}

/* ── 聊天訊息超連結：支援已瀏覽顏色 ── */
a.chat-link {
  color: #1d6fca;           /* 未點擊：亮藍色 */
  text-decoration: underline;
  word-break: break-all;
  font-weight: 500;
}
a.chat-link.clicked {
  color: #999 !important;           /* 已點擊：灰色 */
  text-decoration: line-through !important;
  font-weight: 400 !important;
}
a.chat-link.clicked::after {
  content: ' ✓';
  font-size: 0.85em;
  color: #888;
}
a.chat-link:hover:not(.clicked) {
  color: #1558a8;
}
/* AI 訊息中的 Markdown 連結 */
a.chat-link-md {
  color: #1d6fca;
  font-weight: 600;
  text-decoration: underline;
}
a.chat-link-md.clicked {
  color: #999 !important;
  text-decoration: line-through !important;
  font-weight: 400 !important;
}
a.chat-link-md.clicked::after {
  content: ' ✓';
  font-size: 0.85em;
  color: #888;
}
