:root {
  --primary: #5865f2;         /* Discord blurple */
  --primary-dark: #4752c4;
  --primary-light: #eaecfd;
  --accent: #eb459e;          /* Discord fuchsia */
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2d3d;
  --muted: #6b7a8c;
  --border: #dfe6ec;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --ok: #1e8e3e;
  --ok-bg: #e6f4ea;
  --warn: #b7791f;
  --warn-bg: #fdf3e0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 36, 54, 0.08);
  --sidebar: #2b2d42;
  --sidebar-deep: #23243a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ---- 版面 ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--sidebar); color: #cdd0e0; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  padding: 18px 16px 14px; color: #fff; font-size: 17px; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #9aa0c9; margin-top: 2px; }
.sidebar .brand .dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; background:#f04747; vertical-align:middle; }
.sidebar .brand .dot.on { background:#3ba55d; }
.nav { flex: 1; padding: 8px 0; }
.nav a {
  display: block; padding: 10px 18px; color: #cdd0e0; font-size: 14px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,0.06); }
.nav a.active { background: rgba(255,255,255,0.1); color: #fff; border-left-color: var(--primary); }
.nav .nav-group { padding: 12px 18px 4px; font-size: 11px; color: #7d82ad; letter-spacing: 1px; }
.sidebar .user-box { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 13px; }
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box button {
  margin-top: 8px; width: 100%; padding: 6px; background: transparent; color: #cdd0e0;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.sidebar .user-box button:hover { background: rgba(255,255,255,0.08); }

.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.page-title { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* 手機版頂欄 */
.topbar { display: none; }
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { position: fixed; left: -240px; z-index: 60; transition: left 0.2s; height: 100vh; }
  .sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
  .topbar {
    display: flex; align-items: center; gap: 12px; background: var(--sidebar); color: #fff;
    padding: 12px 16px; position: sticky; top: 0; z-index: 50;
  }
  .topbar .menu-btn { background: none; border: 1px solid rgba(255,255,255,0.4); color: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
  .main { padding: 16px 14px 60px; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 55; }
  .backdrop.show { display: block; }
}

/* ---- 卡片、統計 ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--primary-dark); }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); border-radius: var(--radius); }
table.list th, table.list td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.list td.wrap { white-space: normal; min-width: 160px; }
table.list th { background: #f0f4f6; color: var(--muted); font-weight: 600; font-size: 12.5px; }
table.list tr:hover td { background: #f8f9ff; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---- 按鈕、標籤 ---- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 7px; border: 1px solid transparent;
  background: var(--primary); color: #fff; cursor: pointer; font-size: 14px; line-height: 1.4;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f0f4f6; }
.btn.danger { background: var(--danger); }
.btn.warn { background: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; background: #eef2f5; color: var(--muted); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.primary { background: var(--primary-light); color: var(--primary-dark); }

/* ---- 工具列 ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

/* ---- 表單 ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: #fff;
}
.field textarea { min-height: 84px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---- 彈窗 ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-start; justify-content: center; z-index: 80; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- 登入頁 ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #5865f2, #23243a); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); width: 100%; max-width: 360px; padding: 30px 28px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 10px; }
.login-card .err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---- Toast ---- */
#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #2b2d42; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.25); animation: toastin 0.2s; }
.toast.ok { background: #1e8e3e; }
.toast.err { background: #c0392b; }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }

/* ---- 表情選擇器（Discord 風格彈出面板）---- */
.emoji-pop {
  position: fixed; z-index: 300; width: 320px; max-width: calc(100vw - 20px);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.22); display: flex; flex-direction: column; overflow: hidden;
}
.emoji-pop-head { padding: 8px; border-bottom: 1px solid var(--border); }
.emoji-pop-head input { width: 100%; box-sizing: border-box; font-size: 14px; }
.emoji-pop-body { overflow-y: auto; max-height: 300px; padding: 6px 8px 10px; }
.emoji-pop-title {
  font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .5px;
  margin: 8px 2px 4px; position: sticky; top: -6px; background: var(--card); padding: 4px 0;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid > * {
  display: flex; align-items: center; justify-content: center; height: 34px;
  cursor: pointer; border-radius: 6px; font-size: 22px; line-height: 1; background: none; border: 0; padding: 0;
}
.emoji-grid > *:hover { background: rgba(127,127,127,.18); }
.emoji-grid img { width: 26px; height: 26px; object-fit: contain; }
.emoji-pop-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 9px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.emoji-pop-empty { padding: 18px 4px; text-align: center; color: var(--muted); font-size: 13px; }
/* 已選表情的欄位：把自訂表情圖直接顯示在輸入框裡 */
input.emoji-input {
  background-repeat: no-repeat; background-position: center; background-size: 22px 22px;
}
input.emoji-input.has-img { color: transparent; text-shadow: none; }

/* 所見即所得訊息編輯器：自訂表情直接顯示成圖，送出的仍是 Discord 原始碼 */
.rich-editor {
  min-height: 92px; max-height: 320px; overflow-y: auto;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: inherit; font: inherit; font-size: 14px; line-height: 1.75;
  white-space: pre-wrap; word-break: break-word; outline: none;
}
.rich-editor.single { min-height: 0; max-height: none; white-space: nowrap; overflow-x: auto; }
.rich-editor:focus { border-color: #5865f2; box-shadow: 0 0 0 2px rgba(88, 101, 242, .18); }
.rich-editor:empty::before { content: attr(data-ph); color: var(--muted); }
.rich-editor img.dc-em {
  width: 1.45em; height: 1.45em; object-fit: contain; vertical-align: -0.3em; margin: 0 1px;
}
/* 行內自動完成浮層：打 # / @ / : 時跳出來的候選清單 */
.dc-ac {
  position: absolute; z-index: 4000; width: 250px; max-height: 260px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18); padding: 4px;
}
.dc-ac [data-ac-item] {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px;
  font-size: 14px; cursor: pointer; white-space: nowrap; overflow: hidden;
}
.dc-ac [data-ac-item] span { overflow: hidden; text-overflow: ellipsis; }
.dc-ac [data-ac-item] img { width: 22px; height: 22px; object-fit: contain; flex: none; }
.dc-ac [data-ac-item].on { background: #5865f2; color: #fff; }

/* 訊息欄位下方的表情符號面板（展開式，點一下插到游標處） */
.emoji-panel {
  max-height: 260px; overflow-y: auto; padding: 8px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card);
}
.emoji-panel-title { font-size: 12px; color: var(--muted); margin: 4px 2px 6px; }
.emoji-panel-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; margin-bottom: 8px;
}
.emoji-panel-grid [data-em] {
  display: flex; align-items: center; justify-content: center;
  height: 38px; font-size: 22px; line-height: 1; border-radius: 6px; cursor: pointer;
}
.emoji-panel-grid [data-em]:hover { background: rgba(88, 101, 242, .12); }
.emoji-panel-grid [data-em] img { width: 26px; height: 26px; object-fit: contain; }
.emoji-panel-empty { padding: 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* 伺服器貼圖選擇器 */
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px;
  max-height: 300px; overflow-y: auto; padding: 6px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card);
}
.sticker-grid [data-sk-item] {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 4px;
  border: 2px solid transparent; border-radius: 8px; cursor: pointer; text-align: center;
}
.sticker-grid [data-sk-item]:hover { background: rgba(88, 101, 242, .08); }
.sticker-grid [data-sk-item].on { border-color: #5865f2; background: rgba(88, 101, 242, .12); }
.sticker-grid [data-sk-item] img { width: 56px; height: 56px; object-fit: contain; }
.sticker-grid [data-sk-item] span {
  font-size: 11px; line-height: 1.2; color: var(--muted);
  width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dc-chip {
  background: rgba(88, 101, 242, .16); color: #5865f2; padding: 0 4px; border-radius: 3px;
  white-space: nowrap;
}

/* ---- 表格工具列（table-tools.js 自動掛上）---- */
.tbl-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 0 0 10px; padding: 8px 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.tbl-bar input.tbl-q {
  flex: 1 1 200px; min-width: 160px; max-width: 320px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; background: #fff;
}
.tbl-bar select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; max-width: 190px; }
.tbl-bar .tbl-count { font-size: 12.5px; color: var(--muted); }
.tbl-bar .tbl-count.on { color: var(--primary-dark); font-weight: 600; }
.tbl-bar .tbl-spacer { flex: 1 1 0; }
.tbl-bar .tbl-pager { display: inline-flex; align-items: center; gap: 6px; }
.tbl-bar .tbl-page { font-size: 12.5px; color: var(--muted); min-width: 48px; text-align: center; }
/* 卡片裡的表格：工具列不要再畫一層框，改用淡底色跟表格區隔就好 */
.card .tbl-bar, .modal-body .tbl-bar { background: #f7f9fb; border-color: transparent; padding: 8px; }

table.list th.sortable { cursor: pointer; user-select: none; }
table.list th.sortable:hover { color: var(--primary-dark); }
table.list th.sortable::after { content: '⇅'; opacity: 0.35; margin-left: 5px; font-size: 11px; }
table.list th.sort-asc::after { content: '▲'; opacity: 1; color: var(--primary); }
table.list th.sort-desc::after { content: '▼'; opacity: 1; color: var(--primary); }

@media (max-width: 640px) {
  .tbl-bar { padding: 8px; }
  .tbl-bar input.tbl-q { max-width: none; }
  .tbl-bar select { flex: 1 1 130px; }
}


/* 後台清單裡的 Discord ID 上面補的伺服器暱稱（白白 vs sweet_0722）。
   暱稱常常又長又帶裝飾字，截成一行以免整列被撐高；滑鼠移上去（title）看全名。 */
b.nick {
  display: block; font-weight: 600; font-size: 13px;
  max-width: 22ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
