/* 電腦版網頁的唯一一份樣式。桌面優先（後台給管理員在電腦上看），窄視窗仍要能用。 */
:root {
  --bg: #f6f6f4; --surface: #ffffff; --surface-2: #f1f0ec;
  --text: #1c1c1a; --text-2: #5f5e5a; --text-3: #8b8a84;
  --border: rgba(0,0,0,.09); --border-strong: rgba(0,0,0,.16);
  --accent: #2f6fd0; --accent-bg: #e6f0fb; --accent-text: #174f9e;
  --danger: #b3261e; --danger-bg: #fcebeb; --ok: #2e7d32; --warn: #a15c00;
  --line-b: #8b8a84;
  --radius: 8px; --radius-lg: 12px;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 17px; --fs-xl: 24px;
  --side-w: 220px; --side-w-collapsed: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --surface: #1f1f1d; --surface-2: #2a2a27;
    --text: #ecebe6; --text-2: #b4b2a9; --text-3: #85847d;
    --border: rgba(255,255,255,.09); --border-strong: rgba(255,255,255,.18);
    --accent: #6ea8f0; --accent-bg: #1d3352; --accent-text: #b5d4f4;
    --danger: #f09595; --danger-bg: #4a1b1b; --ok: #97c459; --warn: #efb04f;
    --line-b: #b4b2a9;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 400 var(--fs-md)/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
[x-cloak] { display: none !important; }
button { font: inherit; color: inherit; }
input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 9px 12px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.root, .shell { height: 100%; }
.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; }
.narrow { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login { text-align: center; }
.brand-mark { font-weight: 700; letter-spacing: .14em; font-size: var(--fs-lg); }
.brand-mark.sm { font-size: var(--fs-md); }
.h-page { font-size: var(--fs-lg); font-weight: 600; margin: 0; }
.hint { color: var(--text-2); font-size: var(--fs-sm); margin: 0; display: flex; gap: 6px; align-items: center; }
.hint.err { color: var(--danger); }
.hint.ok { color: var(--ok); }
.muted { color: var(--text-3); font-size: var(--fs-sm); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: var(--fs-xs); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* 按鈕：一種外框款、一個主色款、一個安靜款；非同步一律掛 is-loading */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
a.btn { text-decoration: none; color: inherit; }
a.btn--primary { color: #fff; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.btn--block { width: 100%; }
.btn.is-loading { opacity: .6; pointer-events: none; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; border-radius: var(--radius); color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* 左側欄：唯一的導覽；收起來只剩圖示 */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.shell.is-collapsed { grid-template-columns: var(--side-w-collapsed) minmax(0, 1fr); }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; height: 100vh; position: sticky; top: 0; overflow-y: auto; overflow-x: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 12px 8px; min-height: 44px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.nav-label { color: var(--text-3); font-size: var(--fs-xs); padding: 4px 10px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 10px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text-2); cursor: pointer; text-align: left; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-bg); color: var(--accent-text); }
.nav-item span:not(.badge):not(.avatar) { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--danger-bg); color: var(--danger); border-radius: 999px; font-size: var(--fs-xs); padding: 0 7px; line-height: 18px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 600; flex: none; }
.me { min-height: 44px; }
.me-mail { font-size: var(--fs-sm); }
.is-collapsed .side-head { justify-content: center; padding-left: 0; padding-right: 0; }
.is-collapsed .nav-item { justify-content: center; padding: 0; }
.is-collapsed .nav-item > span:not(.avatar), .is-collapsed .nav-label { display: none; }
.is-collapsed .nav-item .badge { display: none; }

/* 內容區 */
.main { min-width: 0; }
.page { max-width: 1280px; margin: 0 auto; padding: 22px 28px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; min-height: 38px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-weight: 600; font-size: var(--fs-md); margin-bottom: 10px; }
.panel-head .muted { font-weight: 400; }
.todo { color: var(--text-2); }

/* 總覽：左邊主內容、右邊「等你處理」 */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
.dash-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.dash-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; position: sticky; top: 22px; }
.side-title { font-weight: 600; margin-bottom: 6px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 14px; }
.kpi-label { color: var(--text-2); font-size: var(--fs-xs); }
.kpi-value { font-size: var(--fs-xl); font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi-sub { color: var(--text-3); font-size: var(--fs-xs); }
.kpi-sub.warn { color: var(--warn); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.chart { width: 100%; height: 120px; display: block; overflow: visible; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart .line-a { stroke: var(--accent); }
.chart .line-b { stroke: var(--line-b); }
.chart-foot { display: flex; justify-content: space-between; color: var(--text-3); font-size: var(--fs-xs); margin-top: 6px; }
.plan-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.plan-n { font-size: var(--fs-lg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 清單：一排同類用髮絲線分隔，不是每列一張卡 */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 2px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row--btn { width: 100%; background: transparent; border-left: 0; border-right: 0; border-bottom: 0; cursor: pointer; text-align: left; }
.row--btn:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-variant-numeric: tabular-nums; }
.row-meta.hot { color: var(--danger); font-weight: 600; }
.chev { width: 14px; height: 14px; color: var(--text-3); }

.skeleton-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.skeleton-grid div { height: 84px; border-radius: var(--radius-lg); background: var(--surface-2); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .55; } }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger); filter: brightness(1.06); }
.btn--sm { min-height: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 7px 10px; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 10px 12px; width: 100%; resize: none; }

/* 分段切換（同一頁裡的幾種清單），不是第二排分頁 */
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 6px; padding: 5px 12px; cursor: pointer; color: var(--text-2); display: inline-flex; gap: 6px; align-items: center; }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.seg .badge { line-height: 16px; }

/* 表格：全寬、可排序的欄頭、點一列開右側詳情 */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1; max-width: 360px; }
.search .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; }
.search input { padding-left: 32px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; overflow-y: hidden; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th { text-align: left; font-weight: 500; color: var(--text-2); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 9px 12px; border-top: 1px solid var(--border); white-space: nowrap; }
.tbl tbody tr:first-child td { border-top: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--surface-2); }
.tbl tbody tr.is-selected { background: var(--accent-bg); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .ell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 4px 0 2px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.chip { display: inline-block; font-size: var(--fs-xs); padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.chip.pro { background: var(--accent-bg); color: var(--accent-text); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.empty { padding: 28px 16px; text-align: center; color: var(--text-3); }

/* 右側滑出詳情：不換頁，關掉還在原本位置 */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--surface); border-left: 1px solid var(--border); z-index: 21; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 12px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.sec-title { font-weight: 600; font-size: var(--fs-sm); margin-bottom: 6px; }
pre.code { margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); font-size: var(--fs-xs); overflow-x: auto; overflow-y: hidden; white-space: pre-wrap; word-break: break-word; }

/* 待辦：左清單、右內容（像收信匣） */
.inbox { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; }
.inbox-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); max-height: calc(100vh - 150px); overflow-y: auto; overflow-x: hidden; }
.inbox-item { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--border); background: transparent; padding: 10px 14px; cursor: pointer; }
.inbox-item:first-child { border-top: 0; }
.inbox-item:hover { background: var(--surface-2); }
.inbox-item.is-selected { background: var(--accent-bg); }
.inbox-item .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item .m { display: block; color: var(--text-3); font-size: var(--fs-xs); margin-top: 2px; }
.inbox-item.unread .t { font-weight: 600; }

/* 我：左邊分區、右邊內容（一般網站的帳號設定頁） */
.settings { display: grid; grid-template-columns: 200px minmax(0, 720px); gap: 24px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 22px; min-height: 220px; }
.settings-body { min-width: 0; }
.avatar-lg { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; font-size: var(--fs-lg); }
.plans { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.plan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.plan-card.is-current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-card .hint { flex: 1; align-items: flex-start; }
.danger-zone { border-color: var(--danger-bg); }

/* 聊天：左對話列表、中間對話；整頁不捲，對話區自己捲 */
.chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: 100vh; }
.chat-list { border-right: 1px solid var(--border); padding: 14px 10px; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 10px; }
.chat-group { display: flex; flex-direction: column; gap: 1px; }
.chat-item { display: flex; align-items: center; border-radius: var(--radius); }
.chat-item:hover { background: var(--surface-2); }
.chat-item.is-active { background: var(--accent-bg); }
.chat-item-main { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 8px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.chat-item.is-active .chat-item-main { color: var(--accent-text); }
.chat-item-del { width: 28px; height: 28px; opacity: 0; }
.chat-item:hover .chat-item-del, .chat-item-del:focus-visible { opacity: 1; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
.chat-thread { max-width: 760px; margin: 0 auto; padding: 28px 24px 12px; display: flex; flex-direction: column; gap: 18px; }
.chat-empty { text-align: center; padding-top: 18vh; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.msg--user { align-self: flex-end; max-width: 80%; }
.bubble { background: var(--surface-2); border-radius: 14px; padding: 9px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer { line-height: 1.7; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; overflow-y: hidden; }
.md code { font-size: .92em; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.md a { color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: pulse .9s ease-in-out infinite alternate; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
.composer { max-width: 760px; width: calc(100% - 48px); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); padding: 8px 8px 8px 14px; }
.composer textarea { border: 0; padding: 6px 0; background: transparent; min-height: 34px; max-height: 200px; outline: none; overflow-y: auto; overflow-x: hidden; }
.send-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn:disabled { background: var(--surface-2); color: var(--text-3); cursor: default; }
.chat-foot { text-align: center; color: var(--text-3); font-size: var(--fs-xs); margin: 8px 0 12px; }

/* 確認框與提示 */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.32); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dialog { background: var(--surface); border-radius: var(--radius-lg); padding: 20px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); z-index: 50; font-size: var(--fs-sm); max-width: min(560px, calc(100vw - 32px)); }
.toast.err { background: var(--danger); color: #fff; }

/* 窄視窗：右欄掉到下面、側欄自動收成圖示 */
@media (max-width: 1100px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
  .dash-side { position: static; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox-list { max-height: 320px; }
  .settings { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; min-height: 0; }
  .settings-nav .nav-item { width: auto; }
  .plans { grid-template-columns: minmax(0, 1fr); }
  .chat { grid-template-columns: minmax(0, 1fr); }
  .chat-list { display: none; }
}
@media (max-width: 760px) {
  .shell, .shell.is-collapsed { grid-template-columns: var(--side-w-collapsed) minmax(0, 1fr); }
  .side-head .brand-mark, .nav-item > span:not(.avatar), .nav-label, .nav-item .badge { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .page { padding: 16px; }
  .plan-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .skeleton-grid { grid-template-columns: repeat(2, 1fr); }
}
