:root {
  --navy: #10416c;
  --brand: #e2231a;
  --blue: #2f6bff;
  --page: #f5f6fa;
  --green: #16a34a;
  --line: #e6e8ee;
  --text: #1f2430;
  --muted: #8a90a0;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(16, 65, 108, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============ 登錄頁 ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #10416c, #2f6bff);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 36px 30px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

.login-card .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.login-card .logo b {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.login-card h1 {
  font-size: 20px;
  margin: 14px 0 4px;
}

.login-card p.sub {
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 13px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--blue);
}

.filter-select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.filter-select:focus {
  border-color: var(--blue);
}

.btn {
  width: 100%;
  height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn:hover {
  opacity: 0.92;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  width: auto;
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-ghost {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--line);
}

.btn-danger {
  background: var(--brand);
}

.btn-blue {
  background: var(--blue);
}

/* ============ 後台佈局 ============ */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--navy);
  color: #dfe7f1;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar .brand b {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px;
  color: #c5d2e4;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.nav a .i {
  width: 18px;
  text-align: center;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav a.active {
  background: rgba(47, 107, 255, 0.18);
  border-left-color: var(--blue);
  color: #fff;
  font-weight: 600;
}

.sidebar .foot {
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
  color: #9fb0c7;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 58px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .title {
  font-size: 17px;
  font-weight: 700;
}

.topbar .who {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.content {
  padding: 22px;
  flex: 1;
}

/* ============ 卡片 / 統計 ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.stat .label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat .num {
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.card-head h2 {
  font-size: 16px;
  margin: 0;
}

.card-body {
  padding: 4px 0;
}

/* ============ 表格 ============ */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfd;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:hover {
  background: #fafbfd;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  background: #eef2f8;
  color: var(--navy);
}

.pill-yes {
  color: var(--green);
  font-weight: 600;
}

.pill-no {
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.link-btn {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 13px;
  padding: 0;
}

.link-btn.danger {
  color: var(--brand);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

/* ============ 彈窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-mask.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 18px 22px;
}

.modal-foot {
  padding: 14px 22px 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal .field input,
.modal .field textarea,
.modal .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.modal .field textarea {
  min-height: 84px;
  resize: vertical;
}

.modal .field input:focus,
.modal .field textarea:focus {
  border-color: var(--blue);
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch-line input {
  width: 18px;
  height: 18px;
}

/* ============ Toast ============ */
.toast-box {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  background: rgba(31, 36, 48, 0.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.2s ease;
}

.toast.ok {
  background: var(--green);
}

.toast.err {
  background: var(--brand);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============ 響應式 ============ */
@media (max-width: 820px) {
  .sidebar {
    width: 60px;
  }
  .sidebar .brand span,
  .nav a span,
  .sidebar .foot {
    display: none;
  }
  .nav a {
    justify-content: center;
    padding: 12px 0;
  }
}

/* ============ 在線客服工作台 ============ */
.cs {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  height: calc(100vh - 130px);
  min-height: 480px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cs__side {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cs__side-head {
  padding: 14px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cs__conn {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.cs__conn.is-ok {
  color: var(--green);
}

.cs__threads {
  flex: 1;
  overflow-y: auto;
}

.cs__empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

.cs__thread {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  transition: background 0.15s;
}

.cs__thread:hover {
  background: #f5f7fb;
}

.cs__thread.is-active {
  background: #eaf0f8;
}

.cs__avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10416c, #2f6bff);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.cs__thread-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cs__thread-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs__thread-last {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs__thread-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.cs__thread-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.cs__badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cs__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cs__head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 61px;
}

.cs__head-name {
  font-weight: 700;
}

.cs__head-sub,
.cs__head-tip {
  font-size: 13px;
  color: var(--muted);
}

.cs__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.cs__msg {
  display: flex;
}

.cs__msg--me {
  justify-content: flex-end;
}

.cs__bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 66%;
}

.cs__msg--me .cs__bubble-wrap {
  align-items: flex-end;
}

.cs__bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  background: #fff;
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}

.cs__msg--me .cs__bubble {
  background: var(--blue);
  color: #fff;
  border: 0;
  border-radius: 14px;
  border-top-right-radius: 4px;
}

.cs__msg-time {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
}

.cs__input {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  align-items: flex-end;
}

.cs__input input,
.cs__input textarea {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

.cs__input textarea {
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  max-height: 110px;
  min-height: 40px;
}

.cs__input input:focus,
.cs__input textarea:focus {
  border-color: var(--blue);
}

.cs__input .btn {
  width: auto;
  padding: 0 22px;
  height: 40px;
}

.cs__attach {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.cs__attach:hover:not(:disabled) {
  color: var(--blue);
  border-color: var(--blue);
}

.cs__attach:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cs__bubble--media {
  padding: 4px;
  background: #fff;
}

.cs__msg--me .cs__bubble--media {
  background: #fff;
  border: 1px solid var(--line);
}

.cs__media {
  display: block;
  max-width: 260px;
  max-height: 300px;
  border-radius: 8px;
  cursor: pointer;
}

video.cs__media {
  cursor: default;
  width: 300px;
}

.cs-lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(10, 14, 24, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.cs-lightbox[hidden] {
  display: none;
}

.cs-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

@media (max-width: 820px) {
  .cs {
    grid-template-columns: 200px 1fr;
  }
}
