/* ==========================================================================
   LINE 多租戶客服系統 — 共用基礎樣式（web 版 / H5 版 共用）
   只放設計變數與與版面無關的元件（按鈕、標籤、氣泡、彈窗…）。
   版面容器的排版分別在 web.css / h5.css。
   ========================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e2e4e9;
  --text: #1f2329;
  --muted: #7a828e;
  --primary: #06c755;
  --primary-dark: #05a848;
  --danger: #d64545;
  --chat-bg: #ededed;        /* 微信聊天區底色 */
  --bar-bg: #f7f7f7;         /* 頂欄／輸入欄底色 */
  --bubble-in: #ffffff;
  --bubble-out: #95ec69;     /* 微信自己氣泡（淺綠＋深字） */
  --radius: 8px;
}

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 卡片 / 表單元件 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1.5px solid var(--primary); border-color: var(--primary); }
.stack label { margin-bottom: 10px; }

/* 按鈕 */
.btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { background: #f0f1f4; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.block { width: 100%; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 頭像 / 標籤 */
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #dfe3e8; object-fit: cover; flex-shrink: 0; }
.chip {
  display: inline-block; font-size: 11px; line-height: 1; padding: 3px 7px;
  border-radius: 9px; background: #eef1f5; color: var(--muted);
  vertical-align: middle; max-width: 140px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.chip-danger { background: #fdecec; color: var(--danger); font-weight: 600; }
.chip-todo { background: #fff4e0; color: #b26a00; font-weight: 600; }        /* 未指派 / 待接手 */
.chip-assignee { background: #eaf3ff; color: #1a6fd4; }                       /* 處理人 */
.chip-unread { background: #fdecec; color: var(--danger); font-weight: 600; }
.badge {
  background: var(--danger); color: #fff; font-size: 11px; border-radius: 10px;
  padding: 1px 6px; display: inline-block; min-width: 18px; text-align: center;
}

/* 訊息氣泡（版面寬度由各端 css 決定） */
.msg { display: flex; max-width: 72%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
/* 內層用直向 flex：氣泡與時間各自貼合內容，短訊息（例：1）不會被時間列撐寬 */
.msg > div { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.msg.out > div { align-items: flex-end; }
.bubble {
  padding: 9px 13px; border-radius: 6px; background: var(--bubble-in);
  word-break: break-word; white-space: pre-wrap; position: relative;
  max-width: 100%;
}
.msg.out .bubble { background: var(--bubble-out); color: var(--text); }
.bubble img.media { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; }
.bubble video.media { max-width: 320px; border-radius: 6px; display: block; }
.bubble audio { width: 240px; display: block; }
.bubble img.sticker { width: 120px; height: 120px; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; }

/* 已讀／未讀標記 */
.read-tag {
  font-size: 11px; color: var(--muted);
  background: #eef1f5; border-radius: 8px; padding: 1px 6px; margin-left: 4px;
}
.msg.out .msg-meta .read-tag { background: rgba(0,0,0,.07); color: #5a6470; }
.read-tag.unread { background: #fdecec; color: var(--danger); font-weight: 600; }

/* 按住說話（微信式語音） */
#voice-mode { padding: 4px 0; }
.hold-btn {
  width: 100%; padding: 14px; font-size: 16px; border-radius: 8px;
  border: 1px solid var(--border); background: #f7f8fa; color: var(--text);
  font-family: inherit; cursor: pointer;
  touch-action: none;                 /* 觸控時不觸發滾動，保證 pointermove 可用 */
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;        /* iOS 長按不彈選單 */
}
.hold-btn:active { background: #eafaf1; border-color: var(--primary); }
.rec-panel {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, .75); color: #fff; border-radius: 12px;
  padding: 20px 36px; text-align: center; z-index: 60;
  pointer-events: none;               /* 不擋住手指操作 */
  min-width: 200px;
}
.rec-panel .rec-state { font-size: 14px; }
.rec-panel .rec-time { font-size: 28px; font-weight: 700; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.rec-panel .rec-tip { font-size: 12px; opacity: .8; }
.rec-panel.cancel { background: rgba(214, 69, 69, .85); }

/* 彈窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { width: min(380px, calc(100vw - 32px)); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.sticker-grid img { width: 100%; cursor: pointer; border-radius: 6px; border: 2px solid transparent; }
.sticker-grid img:hover { border-color: var(--primary); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row.end { justify-content: flex-end; }
.check-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.check-item input { width: auto; margin: 0; }

/* 表格（後台） */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 500; }
.code { font-family: Consolas, monospace; font-size: 12px; background: #f0f1f4; padding: 2px 6px; border-radius: 4px; word-break: break-all; }

/* 首屏顯示哪一屏：由 <html data-auth="yes|no"> 決定。
   Worker 送出 HTML 時會依登入 cookie 注入這個屬性，所以重新整理不會先閃一下登入頁；
   JS 跑起來後由 core.js 更新同一個屬性（登入成功設 yes、判定未登入設 no）。
   注意：#app-view 不要加 .hidden，顯隱一律交給下面這兩條。 */
html:not([data-auth="yes"]) #app-view { display: none; }
html[data-auth="yes"] #login-view { display: none; }

/* 登入 */
.center-wrap {
  height: 100vh; height: 100dvh; overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card { width: min(340px, 100%); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
#login-sub { margin-bottom: 16px; }

/* 提示 */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2b2f36; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 99;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.error { background: var(--danger); }

#notify-btn.off { opacity: 0.55; }
