:root {
  --bg: #cfd9e2;
  --card: #ffffff;
  --text: #1f2430;
  --text-dim: #6b7280;
  --text-faint: #9ca3af;
  --border: #d9d9d9;
  --border-dash: #eceef2;
  --accent: #4c63b6;
  --accent-2: #4c63b6;
  --sidebar-bg: #3e4c59;
  --sidebar-bg-2: #4a5a68;
  --sidebar-text: #cfd3dc;
  --sidebar-text-dim: #9aa7b0;
  --btn-gray: #616e7c;
  --btn-dark: #616e7c;
  --input-bg: #d4dbe1;
  --line: #b9c3cc;
  --shadow: 0 1px 3px rgba(20, 24, 38, .12);
}
/* 這份色票是直接從真實系統（pd.cschat6.com）用 getComputedStyle 量出來的，
   不是憑印象調的：側邊欄 #3E4C59、內容區底色 #CFD9E2、主色（開單按鈕/當前分頁）
   #4C63B6、灰色按鈕（重置/篩選）#616E7C、開單原因色塊 進貨 #F3914E／四方進貨 #AE76EB。 */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
}

/* ---- 通行碼閘門 ---- */
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); }
.gate-box { background: var(--card); border-radius: 14px; padding: 32px 28px; width: 300px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.gate-box h2 { margin: 0 0 4px; }
.gate-box p { color: var(--text-faint); font-size: 13px; margin: 0 0 16px; }
.gate-box input { width: 100%; padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.gate-box button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: linear-gradient(135deg,#6366f1,#3b82f6); color: #fff; font-weight: 600; cursor: pointer; }
.gate-err { color: #ef4444; font-size: 12px; margin-top: 8px; min-height: 16px; }

/* ---- 整體版面 ---- */
.app { display: flex; height: 100vh; }

/* ---- 左側側邊欄 ---- */
.sidebar { width: 136px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; }
.sidebar-top { padding: 16px 12px; display: flex; flex-direction: column; align-items: center; border-bottom: 1px solid #2f3648; }
.avatar { width: 40px; height: 40px; border-radius: 50%; margin-bottom: 6px; overflow: hidden; background: #d9d9d9; }
.avatar img { width: 100%; height: 100%; display: block; }
.icon { display: inline-block; vertical-align: -1px; }
.icon-svg { width: 1em; height: 1em; }
.me { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #fff; max-width: 100%; overflow: hidden; }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
.me button { background: none; border: 0; color: var(--sidebar-text-dim); cursor: pointer; font-size: 11px; }
.side-tabs { display: flex; padding: 8px; gap: 4px; }
.side-tab { flex: 1; background: none; border: 0; color: var(--sidebar-text-dim); padding: 8px 4px; border-radius: 8px; font-size: 13px; cursor: pointer; position: relative; }
.side-tab.active { background: linear-gradient(#4e6070, #37444f); color: #fff; }
.side-tab .dot { position: absolute; top: 4px; right: 10px; width: 6px; height: 6px; border-radius: 50%; background: #f59e0b; }
.side-list { padding: 8px; }
.side-item { padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.side-item.active { background: var(--sidebar-bg-2); color: #fff; }

/* ---- 中間主內容 ---- */
.main { flex: 1; padding: 20px; overflow-y: auto; min-width: 0; }
.main-header { font-size: 18px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 6px; }
.card { background: var(--card); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); }

.tabs-row { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-dash); padding-bottom: 10px; margin-bottom: 16px; }
.status-tabs { display: flex; gap: 22px; }
.status-tab { background: none; border: 0; font-size: 14px; color: var(--text-dim); cursor: pointer; padding: 4px 0; position: relative; }
.status-tab.active { color: var(--accent); font-weight: 600; }
.status-tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -11px; height: 2px; background: var(--accent); }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 13px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; align-items: end; }
.form-row-2 { grid-template-columns: 1fr auto auto auto; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; background: var(--input-bg); }
.checkbox-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); white-space: nowrap; padding-bottom: 8px; }
.btn-group { display: flex; gap: 8px; }
.filter-btn-group { align-items: center; }
.total-txt { font-size: 13px; color: var(--text-dim); margin-right: 8px; white-space: nowrap; align-self: center; font-variant-numeric: tabular-nums; }
.date-range { display: flex; align-items: center; gap: 6px; }
.date-range input { flex: 1; padding: 8px 6px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }

.btn { padding: 8px 18px; border-radius: 6px; border: 0; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn-gray { background: var(--btn-gray); color: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-dark { background: var(--btn-dark); color: #fff; }
.btn:hover { filter: brightness(1.08); }

.filter-row { border-top: 1px dashed var(--border-dash); padding-top: 14px; }
.note-banner { background: #f3f4f9; border: 1px dashed var(--border); border-radius: 8px; padding: 8px 12px; font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }

.ticket-list { margin-top: 6px; }
.empty { text-align: center; color: var(--text-faint); padding: 60px 0; font-size: 14px; }

.ticket-row { display: grid; grid-template-columns: 90px 1fr 150px; align-items: center; gap: 14px; padding: 12px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.ticket-row:hover { background: #f7f8fb; }
.ticket-row.selected { background: #eef1ff; border-color: #c7d2fe; }
.row-left { display: flex; flex-direction: column; gap: 4px; position: relative; }
.row-check { position: absolute; margin-left: -22px; margin-top: 2px; width: 15px; height: 15px; }
.badge { display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; white-space: nowrap; color: #fff; }
.opener-name { font-size: 11px; color: var(--text-faint); }
.row-mid { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-mid .name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.row-mid .line { flex: 1; height: 1px; background: var(--line); position: relative; min-width: 30px; }
.row-mid .line::after { content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--accent-2); }
.row-right { text-align: right; font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.row-right .customer { color: var(--text); font-size: 13px; font-weight: 600; margin-bottom: 3px; }

.badge.processing { background: #f59e0b; }
.badge.tracking { background: #8b5cf6; }
.badge.closed { background: #6b7280; }
.badge.deleted { background: #ef4444; }
.reason-会员主动要求转人工 { background: #f3914e; }
.reason-机器人连续判断不到 { background: #ae76eb; }
.reason-订单异常 { background: #4c63b6; }
.reason-投诉建议 { background: #e05c5c; }
.reason-系统问题 { background: #3fb1a3; }
.reason-其他 { background: #9ca3af; }

/* ---- 右側派單資訊 ---- */
.detail { width: 400px; flex-shrink: 0; background: #fff; margin: 20px 20px 20px 0; border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.detail-header { padding: 18px 20px; font-weight: 700; border-bottom: 1px solid var(--border-dash); flex-shrink: 0; }
.detail-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.detail-empty { text-align: center; color: var(--text-faint); padding: 60px 10px; margin: auto; }
.detail-empty .illust-img { width: 220px; margin-bottom: 16px; }

.d-section-title { font-size: 12px; color: var(--text-faint); margin: 4px 0 8px; display: flex; justify-content: space-between; }
.d-orderno { display: flex; align-items: center; gap: 8px; background: #f7f8fb; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 18px; font-variant-numeric: tabular-nums; }
.d-orderno button { margin-left: auto; background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; }

.d-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; font-size: 13px; }
.d-quick div label { display: block; font-size: 11px; color: var(--text-faint); margin-bottom: 2px; }
.d-open-tg { display: inline-block; margin-top: 4px; color: var(--accent); font-size: 12.5px; text-decoration: none; }

.d-attach-box { border: 1.5px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; margin-bottom: 18px; }
.d-attach-box .ico { font-size: 30px; margin-bottom: 6px; }
.d-attach-box p { margin: 0 0 8px; color: var(--text-faint); font-size: 12.5px; }
.attach-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 0; text-align: left; }

.d-thread { flex: 1; display: flex; flex-direction: column; min-height: 160px; }
.thread-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 2px; max-height: 220px; }
.msg { display: flex; gap: 8px; }
.msg-avatar { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 700; }
.msg-body { min-width: 0; }
.msg-head { font-size: 11.5px; color: var(--text-faint); margin-bottom: 2px; }
.msg-head b { color: var(--text); font-weight: 600; }
.msg-bubble { background: #f2f3f8; border-radius: 8px; padding: 6px 10px; font-size: 13px; display: inline-block; max-width: 100%; word-break: break-word; }
.msg.system .msg-bubble { background: #eef1ff; color: var(--accent); font-size: 12px; }
.thread-compose { display: flex; gap: 8px; margin-top: 12px; flex-shrink: 0; }
.thread-compose input { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }

.d-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 4px; }
.d-actions button { flex: 1; padding: 9px; border-radius: 8px; border: 0; font-size: 12.5px; cursor: pointer; min-width: 80px; }

/* ---- 批量轉接彈窗 ---- */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; width: 320px; }
.modal-box h3 { margin: 0 0 10px; font-size: 15px; }
.modal-box p { font-size: 12px; color: var(--text-dim); margin: 0 0 12px; }
.modal-box input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
