/* ============================================================
   轉數快FPS 後台管理 — admin.css
   純手寫樣式，無任何外部資源（CDN / 字體 / JS 庫）
   ============================================================ */

:root {
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-active: #2563eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --success-hover: #15803d;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }

.text-muted { color: var(--muted); }
.link-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.link { color: var(--primary); }
.link:hover { text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.ml-auto { margin-left: auto; }

/* ============ 全局布局 ============ */
.admin-shell { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand-mark {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { color: #fff; font-size: 14.5px; }
.brand-text small { color: #9ca3af; font-size: 11.5px; }

.menu { flex: 1; overflow-y: auto; padding: 12px 10px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 13.5px;
  transition: background .12s ease, color .12s ease;
}

.menu-item svg { flex-shrink: 0; opacity: .85; }
.menu-item:hover { background: var(--sidebar-hover); color: #fff; }

.menu-item.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.menu-item.active svg { opacity: 1; }

.menu-badge {
  margin-left: auto;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.admin-mini { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #374151;
  color: #e5e7eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.admin-mini-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.admin-mini-text strong { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-mini-text small { color: #9ca3af; font-size: 11.5px; }

.logout-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #9ca3af;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, .12);
  transition: all .12s ease;
}

.logout-link:hover { color: #fca5a5; border-color: #ef4444; background: rgba(239, 68, 68, .12); }

/* ---------- 主区域 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-date { color: var(--muted); font-size: 12.5px; }

.topbar-notice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #b91c1c;
  background: #fee2e2;
  padding: 4px 10px;
  border-radius: 999px;
}

.topbar-notice .dot {
  background: #ef4444;
  color: #fff;
  min-width: 17px; height: 17px;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

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

/* ---------- 提示 ---------- */
.alert {
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  border: 1px solid transparent;
}

.alert-success { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* ============ 卡片 ============ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.card-head h2 { font-size: 14.5px; font-weight: 700; }
.card-more { font-size: 12.5px; color: var(--primary); }

/* ============ 統計 ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  position: relative;
  transition: transform .12s ease, box-shadow .12s ease;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, .09); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-blue { background: #dbeafe; color: #1d4ed8; }
.icon-amber { background: #fef3c7; color: #b45309; }
.icon-teal { background: #ccfbf1; color: #0f766e; }
.icon-violet { background: #ede9fe; color: #6d28d9; }
.icon-red { background: #fee2e2; color: #b91c1c; }

.stat-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.stat-info strong { font-size: 21px; font-weight: 800; }
.stat-info span { font-size: 12px; color: var(--muted); }

.stat-trend {
  position: absolute;
  top: 10px; right: 12px;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 999px;
}

.stat-strip { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.mini-stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.mini-num { font-size: 19px; font-weight: 800; }
.mini-num.amber { color: var(--amber); }
.mini-num.green { color: var(--success); }
.mini-num.red { color: var(--danger); }
.mini-label { font-size: 12px; color: var(--muted); }

/* ============ 工具列 / 表單 ============ */
.toolbar { margin-bottom: 16px; }

.search-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-form .form-control { width: 220px; }
.search-form select.form-control { width: 150px; }

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}

.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
textarea.form-control { resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid > .form-group-wide { grid-column: 1 / -1; }

.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 5px;
}

.form-group-actions { display: flex; align-items: flex-end; gap: 8px; }

.check-label {
  display: flex !important;
  align-items: center;
  gap: 7px;
  font-weight: 500 !important;
  padding-top: 9px;
  cursor: pointer;
}

.create-panel { margin-bottom: 16px; padding: 0 18px; }
.create-panel summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--primary);
  list-style: none;
  user-select: none;
}
.create-panel summary::-webkit-details-marker { display: none; }
.create-panel[open] summary { border-bottom: 1px dashed var(--border); margin-bottom: 14px; }

/* ============ 表格 ============ */
.table-card { overflow: hidden; }

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

.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td { padding: 10px 14px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }

.table tbody tr:nth-child(even) { background: #fafbfc; }
.table tbody tr:hover { background: #eff6ff; }

.table tbody tr:last-child td { border-bottom: none; }

.table-compact td, .table-compact th { padding: 7px 12px; font-size: 12.8px; }

.th-actions { text-align: right !important; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 6px; }

.inline-form { display: inline-block; }

.log-detail {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #374151;
}

/* ============ 按鈕 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  background: #fff;
  color: #374151;
  border-color: #d1d5db;
  transition: all .12s ease;
  white-space: nowrap;
}

.btn:hover { background: #f3f4f6; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover { background: #f3f4f6; }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ============ 徽章 ============ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
}

.badge-pending { background: var(--amber-bg); color: #92400e; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
.badge-default { background: #e5e7eb; color: #374151; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ============ 分頁 ============ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12.5px;
}

.page-links { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

.page-link {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: #374151;
  transition: all .12s ease;
}

.page-link:hover { border-color: var(--primary); color: var(--primary); }

.page-link.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

.page-ellipsis { color: var(--muted); padding: 0 2px; }

/* ============ 詳情頁 ============ */
.detail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.detail-title { font-size: 16px; font-weight: 700; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.detail-card { padding-bottom: 6px; }

.detail-list { padding: 6px 18px 14px; }

.detail-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 9px 0;
  border-bottom: 1px dashed #f0f0f0;
}

.detail-row:last-child { border-bottom: none; }

.detail-row dt { color: var(--muted); font-size: 12.8px; flex-shrink: 0; white-space: nowrap; }
.detail-row dd { text-align: right; font-size: 13.2px; word-break: break-all; min-width: 0; }

.approve-form, .reject-form { padding: 12px 18px; }
.reject-form { border-top: 1px dashed var(--border); margin-top: 4px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.form-card .form-grid { padding: 18px; }

.photo-preview { display: block; padding: 14px 18px 0; }
.photo-preview img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f9fafb;
  transition: opacity .12s ease;
}
.photo-preview img:hover { opacity: .85; }
.photo-hint { padding: 8px 18px 4px; font-size: 12px; }

.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); display: block; }
.thumb-link:hover .thumb { border-color: var(--primary); }
.file-ico { font-size: 22px; display: inline-block; }

/* ============ 儀表板 ============ */
.dashboard-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

.dash-block-chat { grid-column: 1 / -1; }

/* ============ 聊天 ============ */
.chat-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 142px);
  min-height: 480px;
}

.chat-sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.chat-session-list { flex: 1; overflow-y: auto; }

.chat-session {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text);
  transition: background .1s ease;
}

.chat-session:hover { background: #f5f7fa; }

.chat-session.active { background: #eff6ff; box-shadow: inset 3px 0 0 var(--primary); }

.chat-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-session-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }

.chat-session-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-session-id { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-session-time { font-size: 11px; flex-shrink: 0; }

.chat-session-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-unread {
  min-width: 17px; height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-session-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.chat-order { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; display: inline-block; }
.online-text { color: #16a34a; font-weight: 600; }

/* 聊天窗 */
.chat-window {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-window-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 15px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.chat-window-head > div { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.chat-window-head small { font-size: 11.5px; }
.chat-window-total { margin-left: auto; font-size: 12px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #f7f8fa;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.msg-bubble {
  max-width: 72%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

.msg-row.theirs .msg-bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-row.mine .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }

.msg-text { white-space: pre-wrap; word-break: break-word; }

.msg-time { font-size: 10.5px; opacity: .65; align-self: flex-end; }

.msg-img {
  display: block;
  max-width: 240px;
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 2px;
}

.msg-img img { display: block; width: 100%; max-height: 200px; object-fit: cover; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #374151;
  font-size: 15px;
}

.chat-composer {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.chat-input { flex: 1; }
.chat-send { align-self: flex-end; padding: 9px 22px; }

/* ============ 分頁籤 ============ */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--border); }

.tab {
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--muted);
  cursor: pointer;
  transition: color .12s ease;
}

.tab:hover { color: var(--primary); }

.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tab-panel .card { margin-bottom: 16px; }

/* ============ 登入頁 ============ */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f172a 0%, #111827 45%, #1e293b 100%);
  padding: 20px;
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  padding: 34px 32px 26px;
}

.login-brand { text-align: center; margin-bottom: 22px; }

.brand-mark-lg { width: 52px; height: 52px; font-size: 16px; border-radius: 13px; margin-bottom: 12px; }

.login-brand h1 { font-size: 19px; font-weight: 800; letter-spacing: .5px; }
.login-brand p { color: var(--muted); font-size: 13px; margin-top: 2px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn { padding: 11px; font-size: 14px; margin-top: 4px; }

.login-tip { text-align: center; color: #9ca3af; font-size: 11.5px; margin-top: 20px; }

/* ============ 響應式 ============ */
@media (max-width: 900px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .menu { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; }
  .menu-item { flex: 1 1 40%; margin-bottom: 0; }
  .sidebar-footer { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .chat-shell { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .chat-sidebar { max-height: 320px; }
  .dash-block-chat { grid-column: auto; }
}

@media (max-width: 560px) {
  .content { padding: 14px 12px 32px; }
  .search-form .form-control { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .table { font-size: 12.5px; }
  .table td, .table th { padding: 8px 9px; }
}