* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: #f4f5f7;
  color: #1f2430;
}
a { color: inherit; }

/* ---------- Customer landing ---------- */
.landing-wrap {
  max-width: 480px;
  margin: 60px auto;
  padding: 0 16px;
}
.landing-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
}
.landing-card {
  background: #fff;
  border-radius: 10px;
  padding: 28px 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}
.landing-notice {
  font-size: 14px;
  color: #444;
  margin-bottom: 18px;
  line-height: 1.6;
}
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; }
.field label .req { color: #e0245e; margin-left: 2px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d7dae0;
  border-radius: 6px;
  font-size: 14px;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  background: #241f96;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: #322aae; }
.field-hint { font-size: 12px; color: #8a8d99; margin-top: 6px; line-height: 1.5; }
.error-text { color: #e0245e; font-size: 13px; margin-bottom: 12px; }

/* ---------- Chat room (shared customer/admin) ---------- */
.chat-shell {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.chat-header {
  position: relative;
  padding: 14px 18px;
  border-bottom: 1px solid #eceef1;
  text-align: center;
  font-weight: 700;
}
.chat-header .sub { font-size: 12px; color: #888; font-weight: 400; margin-top: 4px; }
.chat-back-btn {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #555;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.chat-back-btn:hover { background: #f0f1f4; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.system-note { text-align: center; font-size: 12px; color: #999; margin: 6px 0; }
.date-divider { display: flex; align-items: center; justify-content: center; }
.date-divider span {
  background: #eceef1; color: #888; font-size: 12px; padding: 4px 14px; border-radius: 999px;
}
.msg-row { display: flex; flex-direction: column; max-width: 78%; }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }
.msg-sender { font-size: 12px; color: #6c6f7a; margin-bottom: 4px; }
.msg-row.mine .msg-sender { color: #241f96; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f0f1f4;
}
.msg-row.mine .msg-bubble { background: #241f96; color: #fff; }
.msg-time { font-size: 11px; color: #b2b4bb; margin-top: 3px; }
.msg-media img, .msg-media video {
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  cursor: zoom-in;
  display: block;
}
.chat-locked-notice {
  display: none;
  padding: 10px 14px;
  border-top: 1px solid #eceef1;
  background: #fbf7ee;
  color: #8a6d3b;
  font-size: 13px;
  line-height: 1.5;
}
.chat-locked-notice.show { display: block; }

.pending-attachments {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px 0;
  border-top: 1px solid #eceef1;
}
.pending-attachments.show { display: flex; }
.pending-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  overflow: hidden;
  background: #f5f6f8;
}
.pending-thumb img,
.pending-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pending-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  line-height: 1;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.chat-input-area {
  border-top: 1px solid #eceef1;
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  min-height: 42px;
  max-height: 120px;
}
.icon-btn {
  border: 1px solid #d7dae0;
  background: #fff;
  border-radius: 8px;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: #f4f5f7; }
.send-btn {
  background: #241f96;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 18px;
  height: 42px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:hover { background: #322aae; }
.send-btn:disabled { background: #b7b6d6; cursor: not-allowed; }

.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: none; align-items: center; justify-content: center; z-index: 999; padding: 24px;
}
.lightbox-overlay.open { display: flex; }
.lightbox-overlay img, .lightbox-overlay video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.lightbox-close {
  position: absolute; top: 18px; right: 24px; color: #fff; font-size: 28px;
  cursor: pointer; background: none; border: none;
}

/* ---------- Admin shell ---------- */
.admin-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.admin-sidebar {
  width: 200px;
  background: #1c1f2b;
  color: #d5d7e0;
  padding: 20px 0;
  flex-shrink: 0;
}
.admin-sidebar .brand { padding: 0 20px 18px; font-weight: 700; font-size: 16px; color: #fff; border-bottom: 1px solid #33364a; margin-bottom: 12px; }
.admin-sidebar .who { padding: 0 20px 18px; font-size: 12px; color: #9698ab; }
.admin-sidebar nav a {
  display: block;
  padding: 11px 20px;
  text-decoration: none;
  font-size: 14px;
  color: #c6c8d6;
}
.admin-sidebar nav a.active { background: #241f96; color: #fff; }
.admin-sidebar nav a:hover { background: #2a2d3d; }
.admin-sidebar .logout-form { padding: 14px 20px 0; }
.admin-sidebar .logout-form button {
  width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #454864;
  background: transparent; color: #c6c8d6; cursor: pointer; font-size: 13px;
}
.admin-main { flex: 1; padding: 28px 32px; max-width: 1200px; }
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.last-updated { font-size: 12px; font-weight: 400; color: #9698ab; margin-left: 10px; }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px;
  background: #fff; padding: 14px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.filter-bar input, .filter-bar select {
  padding: 8px 10px; border: 1px solid #d7dae0; border-radius: 6px; font-size: 13px;
}
.filter-bar button {
  padding: 8px 16px; border: none; border-radius: 6px; background: #241f96; color: #fff; cursor: pointer; font-size: 13px;
}

table.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
table.data-table th { text-align: left; font-size: 12px; color: #888; padding: 12px 14px; border-bottom: 1px solid #eceef1; }
table.data-table td { padding: 12px 14px; border-bottom: 1px solid #f1f2f5; font-size: 14px; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr.needs-reply td { color: #d9622b; }
table.data-table tr.needs-reply td.acct-cell { font-weight: 700; }
table.data-table tr:hover td { background: #fafbfc; }
table.data-table a.row-link { text-decoration: none; color: inherit; display: block; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.badge.pending { background: #fdeee3; color: #d9622b; }
.badge.active { background: #e3f3e6; color: #2f9950; }
.badge.closed { background: #eceef1; color: #888; }

.empty-state { text-align: center; padding: 60px 0; color: #9698ab; font-size: 14px; }

.btn-outline {
  border: 1px solid #241f96; color: #241f96; background: #fff;
  border-radius: 6px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.btn-outline.btn-danger { border-color: #d9362b; color: #d9362b; }
.btn-outline.btn-danger:hover { background: #fdeeed; }
.btn-fab {
  border: 1px solid #d7dae0; background: #fff; border-radius: 999px;
  padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.section-toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center; z-index: 999;
}
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 10px; padding: 24px; width: 360px; position: relative; }
.modal-box h3 { margin-top: 0; }
.modal-box .field { margin-bottom: 14px; }
.modal-box .field label { display: block; font-size: 13px; margin-bottom: 5px; color: #555; }
.modal-box .field input { width: 100%; padding: 8px 10px; border: 1px solid #d7dae0; border-radius: 6px; font-size: 14px; }
.modal-box .field input:disabled { background: #f4f5f7; color: #999; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; padding: 9px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.modal-actions .confirm { background: #241f96; color: #fff; border: none; }
.modal-actions .cancel { background: #fff; border: 1px solid #d7dae0; }
.modal-msg { text-align: center; font-size: 14px; padding: 10px 0 4px; }
.modal-close { position: absolute; top: 14px; right: 16px; background: none; border: none; font-size: 18px; cursor: pointer; color: #999; }

.login-wrap { max-width: 360px; margin: 90px auto; }
.login-card { background: #fff; padding: 30px 26px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.06); }
.login-card h2 { text-align: center; margin-top: 0; }

.reply-identity { font-size: 13px; color: #555; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.reply-identity b { color: #241f96; }
.reply-identity select { padding: 5px 8px; border: 1px solid #d7dae0; border-radius: 6px; font-size: 13px; }

/* ---------- Inbox (對話紀錄：左列表／中聊天／右會員資訊) ---------- */
.admin-main.inbox-mode {
  max-width: none;
  padding: 0;
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.inbox-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.conv-list-pane {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid #eceef1;
  background: #fff;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.list-toolbar { padding: 12px 14px 0; }
.conv-list-pane .filter-bar.compact {
  flex-direction: column; gap: 6px; padding: 0 14px 12px; margin-bottom: 0;
  box-shadow: none; background: transparent;
}
.conv-list-pane .filter-bar.compact input,
.conv-list-pane .filter-bar.compact select { width: 100%; }
.conv-list-pane .filter-bar.compact button { width: 100%; padding: 8px; }

.conv-rows { flex: 1; overflow-y: auto; border-top: 1px solid #f1f2f5; }
.conv-row {
  padding: 12px 14px; border-bottom: 1px solid #f1f2f5; cursor: pointer;
}
.conv-row:hover { background: #fafbfc; }
.conv-row.active { background: #eeecfb; border-left: 3px solid #241f96; padding-left: 11px; }
.conv-row.needs-reply .conv-row-name { color: #d9622b; font-weight: 700; }
.conv-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
/* 帳號最長 15 碼，這裡一律完整顯示不截斷：放不下就換行，IP 另外一行 */
.conv-row-name {
  font-size: 14px; font-weight: 600; min-width: 0; flex: 1;
  overflow-wrap: anywhere; word-break: break-word; line-height: 1.35;
}
.conv-row-top .badge { flex-shrink: 0; }
.conv-row-sub {
  margin-top: 2px; font-size: 11px; color: #9698ab;
  display: flex; flex-wrap: wrap; gap: 8px; overflow-wrap: anywhere;
}
.conv-row-account { color: #6c6f7a; }
.conv-row-time { font-size: 11px; color: #9698ab; white-space: nowrap; }
.conv-row-preview {
  font-size: 13px; color: #666; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-row-meta { font-size: 11px; color: #aaa; margin-top: 4px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-row-tags { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-row-meta-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.conv-row-delete-btn {
  border: none; background: transparent; color: #b2b4bb; cursor: pointer;
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
}
.conv-row-delete-btn:hover { color: #d9362b; background: #fdeeed; }

.chat-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #eceef1;
  overflow: hidden;
}
.chat-empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #9698ab; font-size: 14px;
}
.chat-pane-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 18px; border-bottom: 1px solid #eceef1;
}
.chat-pane-header > div:first-child { min-width: 0; }
.chat-pane-header .acct { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.chat-pane-header .meta { font-size: 12px; color: #888; margin-top: 4px; overflow-wrap: anywhere; }
.chat-pane-header .badge { flex-shrink: 0; }

.member-pane {
  width: 300px;
  flex-shrink: 0;
  background: #fff;
  overflow-y: auto;
  padding: 18px;
}
.member-empty-state { color: #9698ab; font-size: 13px; }
.member-info .acct { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.member-info .meta { font-size: 12px; color: #888; margin-top: 4px; overflow-wrap: anywhere; }
.member-plain-value { font-size: 14px; }
.member-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid #f1f2f5; }
.member-section-title { font-size: 12px; color: #9698ab; margin-bottom: 8px; font-weight: 700; }

.notebook-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.notebook-empty { font-size: 13px; color: #9698ab; }
.notebook-entry { background: #f7f7fa; border-radius: 8px; padding: 8px 10px; }
.notebook-entry-meta {
  font-size: 11px; color: #9698ab; margin-bottom: 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.notebook-del-btn {
  border: 0; background: transparent; color: #b9bbc9; cursor: pointer;
  font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
}
.notebook-del-btn:hover { color: #d9362b; background: #fdeeed; }
.notebook-entry-content { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.notebook-compose textarea {
  width: 100%; min-height: 64px; resize: vertical; padding: 8px 10px;
  border: 1px solid #d7dae0; border-radius: 6px; font-size: 13px; font-family: inherit;
}
.notebook-compose-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.notebook-counter { font-size: 11px; color: #9698ab; }

.form-card {
  background: #fff; padding: 26px; border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06); max-width: 420px;
}
.success-text { color: #1f9d55; font-size: 13px; margin-bottom: 12px; }
.form-hint { color: #888; font-size: 12px; margin-top: 16px; line-height: 1.7; }

/* 快捷語 */
.quick-reply-wrap { position: relative; }
.quick-reply-panel {
  display: none; position: absolute; bottom: 46px; left: 0; z-index: 30;
  width: 340px; max-height: 320px; overflow-y: auto;
  background: #fff; border: 1px solid #d7dae0; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12); padding: 6px;
}
.quick-reply-panel.open { display: block; }
.quick-reply-head { font-size: 12px; color: #888; padding: 6px 8px 8px; }
.quick-reply-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 0; border-radius: 6px; padding: 8px;
}
.quick-reply-item:hover { background: #f2f1fc; }
.quick-reply-item .qr-title { display: block; font-size: 13px; font-weight: 700; color: #241f96; }
.quick-reply-item .qr-preview {
  display: block; font-size: 12px; color: #666; margin-top: 2px; line-height: 1.5;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.qr-content { white-space: pre-wrap; }

/* 提示音開關 */
.sound-toggle {
  border: 0; background: transparent; cursor: pointer; font-size: 15px;
  line-height: 1; padding: 2px 4px; opacity: 1;
}
.sound-toggle.muted { opacity: 0.35; filter: grayscale(1); }

/* 招呼語設定 */
.greeting-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.greeting-name { font-size: 15px; font-weight: 700; }
.greeting-staff { font-size: 12px; color: #9698ab; margin-top: 2px; }
.greeting-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #555; cursor: pointer; flex-shrink: 0; }
.greeting-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.greeting-status { font-size: 13px; }
.greeting-status.ok { color: #1f9d55; }
.greeting-status.error { color: #e0245e; }

/* 正在輸入中 */
.typing-indicator {
  height: 0; overflow: hidden; opacity: 0;
  padding: 0 18px; font-size: 12px; color: #9698ab;
  transition: height .12s ease, opacity .12s ease;
}
.typing-indicator.show { height: 20px; opacity: 1; }

/* ---------- 前台（會員端）配色 ----------
   後台沿用原本的深藍，所以這一段只掛在 body.theme-customer 底下，
   不要直接改上面共用的 .btn-primary / .send-btn / .msg-row 等樣式。 */
.theme-customer {
  --fg-bg: #FBF8EF;
  --fg-accent: #C1AE9F;
  --fg-accent-dark: #AD9887;
  --fg-accent-soft: #EFE7E0;
  background: var(--fg-bg);
}
.theme-customer .landing-card { background: var(--fg-bg); }
.theme-customer .btn-primary { background: var(--fg-accent); }
.theme-customer .btn-primary:hover { background: var(--fg-accent-dark); }

.theme-customer .chat-shell { background: var(--fg-bg); }
.theme-customer .chat-header { border-bottom-color: var(--fg-accent-soft); }
.theme-customer .chat-back-btn:hover { background: var(--fg-accent-soft); }
.theme-customer .date-divider span { background: var(--fg-accent-soft); color: #8b7d70; }
.theme-customer .msg-bubble { background: #FFFFFF; }
.theme-customer .msg-row.mine .msg-sender { color: var(--fg-accent-dark); }
.theme-customer .msg-row.mine .msg-bubble { background: var(--fg-accent); color: #fff; }

.theme-customer .chat-locked-notice,
.theme-customer .pending-attachments,
.theme-customer .chat-input-area { border-top-color: var(--fg-accent-soft); }
.theme-customer .chat-input-area textarea,
.theme-customer .icon-btn { background: #fff; border-color: #DCD2C8; }
.theme-customer .icon-btn:hover { background: var(--fg-accent-soft); }
.theme-customer .send-btn { background: var(--fg-accent); }
.theme-customer .send-btn:hover { background: var(--fg-accent-dark); }
.theme-customer .send-btn:disabled { background: #DCD2C8; }
.theme-customer .field input,
.theme-customer .field select,
.theme-customer .field textarea { border-color: #DCD2C8; background: #fff; }
