/* ============================================================
   an途 · 顧問端 / 專家端共用門戶樣式
   - 手機優先；≥900px 切側邊欄
   - 所有可點區域 ≥44px；iOS 安全區適配
   ============================================================ */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --ink: #23201c;
  --ink-2: #4b443c;
  --muted: #7c7264;
  --muted-2: #9a9082;
  --line: #e7ded2;
  --line-soft: #f0e9df;
  --card: #ffffff;
  --bg: #f6f3ed;
  --bg-2: #fbf9f5;
  --brand: #1e4d40;
  --brand-deep: #163b32;
  --brand-soft: #e6efeb;
  --brand-ink: #ffffff;
  --accent: #9a6238;
  --ok: #27795a;
  --ok-soft: #e9f5ef;
  --warn: #9a6a17;
  --warn-soft: #fff6e2;
  --danger: #a33f35;
  --danger-soft: #fdeeea;
  --info: #2f5f8a;
  --info-soft: #e8f0f8;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --shadow-sm: 0 2px 10px rgba(35, 32, 28, .05);
  --shadow-md: 0 12px 34px rgba(35, 32, 28, .10);
  --shadow-lg: 0 24px 60px rgba(35, 32, 28, .16);
  --bar-h: 56px;
  --tab-h: 62px;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "PingFang TC",
          "Hiragino Sans GB", "Microsoft JhengHei", "Microsoft YaHei", "Noto Sans TC", sans-serif;
}

body[data-portal="advisor"] {
  --brand: #1e4d40;
  --brand-deep: #163b32;
  --brand-soft: #e4efea;
  --bg: #f5f2ea;
  --bg-2: #fbf8f2;
  --accent: #9a6238;
}

body[data-portal="expert"] {
  --brand: #16324f;
  --brand-deep: #10263d;
  --brand-soft: #e4ecf5;
  --bg: #f2f5f9;
  --bg-2: #f9fbfd;
  --accent: #2f5f8a;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

img { max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }
[hidden], .hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── 加載遮罩 ───────────────────────────── */
.boot {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--muted); font-size: 14px; gap: 10px;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}

/* ── 登錄 / 身份提示 ─────────────────────── */
.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(18px + var(--sat)) 18px calc(24px + var(--sab));
  background:
    radial-gradient(900px 420px at 100% -10%, var(--brand-soft), transparent 60%),
    var(--bg);
}
.auth-top { display: flex; align-items: center; gap: 10px; padding: 4px 2px 18px; }
.auth-logo {
  width: 44px; height: 44px; border-radius: 13px; object-fit: cover;
  box-shadow: var(--shadow-sm); background: #fff;
}
.auth-brand { line-height: 1.25; }
.auth-brand strong { display: block; font-size: 16px; letter-spacing: .5px; }
.auth-brand span { font-size: 11px; color: var(--muted); letter-spacing: 1.2px; }
.auth-card {
  width: 100%; max-width: 430px; margin: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-md);
  padding: 24px 20px 20px;
}
.auth-title { margin: 0; font-size: 21px; line-height: 1.35; letter-spacing: .3px; }
.auth-sub { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }
.auth-tabs {
  display: flex; gap: 4px; padding: 4px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 999px; margin-bottom: 18px;
  overflow-x: auto; scrollbar-width: none;
}
.auth-tabs::-webkit-scrollbar { display: none; }
.auth-tab {
  flex: 1 0 auto; min-width: 76px; min-height: 44px; padding: 7px 12px;
  border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.auth-tab.active { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(0,0,0,.14); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > label { font-size: 12.5px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  outline: none; transition: border-color .15s, background .15s;
  -webkit-appearance: none; appearance: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); background: #fff; }
.textarea { min-height: 96px; resize: vertical; font-size: 15px; line-height: 1.55; }
.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%237c7264' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px;
}
.phone-row { display: flex; gap: 8px; }
.phone-row .select { width: 96px; flex: 0 0 96px; padding-left: 10px; }
.phone-row .input { flex: 1 1 auto; min-width: 0; }
.code-row { display: flex; gap: 8px; align-items: stretch; }
.code-row .input { flex: 1 1 auto; min-width: 0; letter-spacing: 2px; }
.code-row .btn { flex: 0 0 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font-size: 14.5px; font-weight: 600; letter-spacing: .2px; cursor: pointer; white-space: nowrap;
  transition: transform .12s, opacity .12s, background .12s;
  -webkit-appearance: none; appearance: none; text-align: center;
}
.btn:hover { background: var(--brand-deep); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn-ghost:hover { background: var(--bg-2); }
.btn-soft { background: var(--brand-soft); color: var(--brand-deep); border-color: transparent; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #f3d3cd; }
.btn-ok { background: var(--ok-soft); color: var(--ok); border-color: #cfe8dd; }
.btn-sm { min-height: 40px; padding: 7px 13px; font-size: 13px; border-radius: 9px; }
.btn-xs { min-height: 32px; padding: 5px 10px; font-size: 12px; border-radius: 8px; }

.auth-hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.auth-status { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.auth-status.err { color: var(--danger); }
.auth-status.ok { color: var(--ok); }
.qr-panel { text-align: center; padding: 4px 0 2px; }
.qr-img {
  width: 208px; height: 208px; max-width: 70vw; max-height: 70vw;
  margin: 6px auto; display: block; border-radius: 16px; background: #fff;
  border: 1px solid var(--line); object-fit: contain;
}
.qr-placeholder {
  width: 208px; height: 208px; max-width: 70vw; max-height: 70vw; margin: 6px auto;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); font-size: 13px;
}
.auth-legal { margin: 16px 0 0; font-size: 11.5px; color: var(--muted-2); text-align: center; line-height: 1.6; }

/* ── 應用外殼 ───────────────────────────── */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--bar-h);
  padding: calc(8px + var(--sat)) calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l));
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.appbar-logo { width: 32px; height: 32px; border-radius: 9px; object-fit: cover; flex: 0 0 auto; }
.appbar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.appbar-title strong { font-size: 15px; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title span { font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.appbar .spacer { flex: 1 1 auto; }
.appbar-user {
  display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 4px 8px 4px 4px;
  border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); max-width: 44vw;
}
.appbar-user img, .avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--brand-soft);
  display: inline-flex; align-items: center; justify-content: center; color: var(--brand-deep);
  font-size: 12px; font-weight: 700; flex: 0 0 auto;
}
.appbar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  flex: 1 1 auto; width: 100%; max-width: 1080px; margin: 0 auto;
  padding: 14px calc(14px + var(--safe-r)) calc(var(--tab-h) + 24px + var(--sab)) calc(14px + var(--safe-l));
}
.page-head { margin: 2px 0 14px; }
.page-head h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 20px 2px 10px; font-size: 14px; font-weight: 700; letter-spacing: .2px;
}
.section-title small { font-weight: 400; color: var(--muted); font-size: 11.5px; }
/* 「查看全部」是真實可點連結，13px 高在手機上點不中 */
.section-title small a,
.section-title > a {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 2px;
  color: var(--brand); text-decoration: none; font-weight: 600;
}

/* ── 卡片與列表 ─────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); padding: 16px; margin-bottom: 12px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; line-height: 1.4; }
.card-h .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.card-h .grow { flex: 1 1 auto; min-width: 0; }

.hero-card {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: #fff; border: 0; border-radius: var(--r-lg); padding: 20px 18px 18px;
  box-shadow: 0 16px 40px rgba(20, 40, 34, .22); margin-bottom: 14px;
}
.hero-card::after {
  content: ""; position: absolute; right: -60px; top: -80px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(255,255,255,.09);
}
.hero-card .hello { font-size: 12px; opacity: .82; letter-spacing: .6px; }
.hero-card h1 { position: relative; margin: 4px 0 2px; font-size: 23px; letter-spacing: .4px; }
.hero-card .meta { position: relative; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hero-chip {
  display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 4px 10px;
  border-radius: 999px; background: rgba(255,255,255,.16); color: #fff; font-size: 12px;
  border: 1px solid rgba(255,255,255,.18);
}
.hero-nums { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.hero-num { background: rgba(255,255,255,.12); border-radius: 12px; padding: 10px 8px; text-align: center; }
.hero-num b { display: block; font-size: 19px; line-height: 1.2; }
.hero-num span { font-size: 10.5px; opacity: .8; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px 14px 12px; box-shadow: var(--shadow-sm); min-width: 0;
}
.stat b { display: block; font-size: 24px; line-height: 1.15; letter-spacing: .3px; }
.stat span { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.stat .hint { margin-top: 6px; font-size: 11px; color: var(--muted-2); }

.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.quick a, .quick button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  min-height: 76px; padding: 10px 4px; border-radius: var(--r-md);
  background: var(--card); border: 1px solid var(--line); color: var(--ink-2);
  font-size: 11.5px; text-align: center; cursor: pointer;
}
.quick .ico {
  width: 34px; height: 34px; border-radius: 11px; background: var(--brand-soft); color: var(--brand-deep);
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700;
}
.quick a:active, .quick button:active { background: var(--bg-2); }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: flex-start; gap: 10px; padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft); background: var(--card); min-width: 0;
}
.item:last-child { border-bottom: 0; }
.item.clickable { cursor: pointer; }
.item.clickable:active { background: var(--bg-2); }
.item .grow { flex: 1 1 auto; min-width: 0; }
.item .title { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 14px; font-weight: 600; }
.item .desc { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.55; word-break: break-word; }
.item .side { flex: 0 0 auto; text-align: right; font-size: 11.5px; color: var(--muted-2); }
.item .arrow { color: var(--muted-2); font-size: 16px; align-self: center; }

.empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .ico { font-size: 28px; opacity: .5; display: block; margin-bottom: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; min-height: 22px; padding: 2px 8px;
  border-radius: 999px; background: #f2ece2; color: #6b5a4a; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand-deep); }

.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 13px 14px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--bg-2); font-size: 13px; line-height: 1.6; margin-bottom: 12px;
}
.banner .ico { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.banner.warn { background: var(--warn-soft); border-color: #f0dfb8; color: #6f4c0f; }
.banner.warn .ico { background: #f3d69a; color: #6f4c0f; }
.banner.danger { background: var(--danger-soft); border-color: #f3d3cd; color: #7d2c25; }
.banner.danger .ico { background: #f2c7c0; color: #7d2c25; }
.banner.info { background: var(--info-soft); border-color: #cfe0f0; color: #24496c; }
.banner.info .ico { background: #c9dcef; color: #24496c; }
.banner.ok { background: var(--ok-soft); border-color: #cfe8dd; color: #1d6047; }
.banner.ok .ico { background: #bde0cf; color: #1d6047; }
.banner .grow { flex: 1 1 auto; min-width: 0; }
.banner strong { font-weight: 700; }

.kv { display: grid; grid-template-columns: 1fr; gap: 0; }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px dashed var(--line-soft); font-size: 13px; }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { color: var(--muted); flex: 0 0 auto; }
.kv-row .v { text-align: right; word-break: break-word; min-width: 0; }

.divider { height: 1px; background: var(--line-soft); margin: 14px 0; }

/* ── 分段控制 ───────────────────────────── */
.segmented {
  display: flex; gap: 4px; padding: 4px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 999px; margin-bottom: 12px;
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto; min-height: 44px; padding: 6px 14px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.segmented button.active { background: var(--brand); color: #fff; }

/* ── 二維碼 / 推廣 ──────────────────────── */
.qr-card { text-align: center; padding: 18px 16px; }
.qr-card .qr-img { width: 220px; height: 220px; max-width: 74vw; max-height: 74vw; display: block; margin: 0 auto; }
/* 小程序碼要向微信換取，1~3 秒才回來；先給骨架，不要給空白框 */
.qr-wrap { position: relative; width: 220px; height: 220px; max-width: 74vw; max-height: 74vw; margin: 0 auto; }
.qr-skel {
  position: absolute; inset: 0; z-index: 1; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); font-size: 12px;
}
.qr-card .mask { margin: 10px auto 0; }
.code-box {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--bg-2); border: 1px dashed var(--line);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--ink-2); word-break: break-all; text-align: left;
}
.code-box b { display: block; color: var(--muted); font-family: var(--font); font-size: 11px; font-weight: 500; margin-bottom: 3px; }
.mask { display: inline-block; margin-top: 10px; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-deep); font-size: 11.5px; }

/* ── 積分 ───────────────────────────────── */
.level-bar { height: 9px; border-radius: 999px; background: var(--line-soft); overflow: hidden; margin: 8px 0 4px; }
.level-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--accent)); }
.rule-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rule-table th, .rule-table td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.rule-table th { color: var(--muted); font-weight: 600; font-size: 11.5px; white-space: nowrap; }
.rule-table td:last-child, .rule-table th:last-child { text-align: right; white-space: nowrap; }
.rule-table .note { display: block; color: var(--muted-2); font-size: 11px; margin-top: 2px; }
.ledger-delta { font-weight: 700; white-space: nowrap; }
.ledger-delta.plus { color: var(--ok); }
.ledger-delta.minus { color: var(--danger); }

/* ── 聊天 ───────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg .bubble { padding: 9px 12px; border-radius: 14px; background: var(--bg-2); border: 1px solid var(--line-soft); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg .meta { margin-top: 3px; font-size: 10.5px; color: var(--muted-2); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .bubble { background: var(--brand); border-color: var(--brand); color: #fff; }
.msg.system { align-self: center; max-width: 100%; width: 100%; align-items: center; }
.msg.system .bubble { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 11.5px; text-align: center; padding: 6px 10px; }
.msg.blocked .bubble { background: var(--warn-soft); border-color: #f0dfb8; color: #6f4c0f; }
.composer {
  position: fixed; z-index: 60; left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r));
  bottom: calc(var(--tab-h) + 8px + var(--sab));
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 8px; display: flex; gap: 8px; align-items: flex-end; box-shadow: var(--shadow-md);
}
.main.has-composer { padding-bottom: calc(var(--tab-h) + 112px + var(--sab)); }
.composer .textarea { min-height: 44px; max-height: 132px; border: 0; background: transparent; padding: 9px 8px; }
.composer .btn { flex: 0 0 auto; }

/* ── 抽屜 / 彈窗 ────────────────────────── */
.sheet-mask {
  position: fixed; inset: 0; z-index: 90; background: rgba(20, 18, 15, .42);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.sheet-mask.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 100; left: 0; right: 0; bottom: 0;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 16px calc(18px + var(--sab));
  transform: translateY(104%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 16px; }
.sheet .sub { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; }
.sheet-actions { display: flex; gap: 9px; margin-top: 16px; }
.sheet-actions .btn { flex: 1 1 0; }

.toast {
  position: fixed; z-index: 150; left: 50%; bottom: calc(var(--tab-h) + 18px + var(--sab));
  transform: translate(-50%, 8px); max-width: min(88vw, 420px);
  padding: 10px 16px; border-radius: 11px; background: #2b2622; color: #fff;
  font-size: 13px; line-height: 1.5; text-align: center; box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #8c3a31; }
.toast.ok { background: #1f6049; }

/* ── 底部導航 / 側邊欄 ──────────────────── */
.tabbar {
  position: fixed; z-index: 80; left: 0; right: 0; bottom: 0;
  display: flex; align-items: stretch;
  min-height: var(--tab-h);
  padding: 0 calc(4px + var(--safe-r)) var(--sab) calc(4px + var(--safe-l));
  background: rgba(255,255,255,.96);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line-soft);
  justify-content: center;
}
.tabbar a, .tabbar button {
  flex: 0 1 120px; min-width: 0; min-height: 52px; padding: 7px 2px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer;
}
.tabbar .ico { font-size: 18px; line-height: 1; }
.tabbar .on { color: var(--brand); font-weight: 700; }

.sidebar { display: none; }

/* ── 桌面 ───────────────────────────────── */
@media (min-width: 900px) {
  :root { --tab-h: 0px; }
  body { font-size: 14.5px; }
  .app { flex-direction: row; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; height: 100dvh; width: 232px; flex: 0 0 232px;
    padding: 22px 14px 20px; background: var(--card); border-right: 1px solid var(--line-soft);
  }
  .sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
  .sidebar-brand img { width: 38px; height: 38px; border-radius: 11px; object-fit: cover; }
  .sidebar-brand strong { display: block; font-size: 15px; letter-spacing: .4px; }
  .sidebar-brand span { font-size: 10.5px; color: var(--muted); letter-spacing: 1px; }
  .sidebar a, .sidebar button {
    display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 9px 12px;
    border: 0; border-radius: 11px; background: transparent; color: var(--ink-2);
    font-size: 14px; cursor: pointer; text-align: left;
  }
  .sidebar a .ico, .sidebar button .ico { width: 22px; text-align: center; font-size: 15px; color: var(--muted); }
  .sidebar a.on, .sidebar button.on { background: var(--brand-soft); color: var(--brand-deep); font-weight: 700; }
  .sidebar a.on .ico, .sidebar button.on .ico { color: var(--brand); }
  .sidebar .foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line-soft); font-size: 11px; color: var(--muted-2); line-height: 1.6; }
  .appbar { display: none; }
  .tabbar { display: none; }
  .main { padding: 30px 34px 60px; max-width: 1100px; }
  .page-head h1 { font-size: 24px; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quick { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .quick a, .quick button { min-height: 88px; font-size: 12.5px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 34px; }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 460px; max-width: 92vw; transform: translate(-50%, -46%) scale(.98); border-radius: 20px; padding: 20px 22px 22px; opacity: 0; transition: opacity .18s, transform .18s; }
  .sheet.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  .sheet-grip { display: none; }
  .toast { bottom: 28px; }
  .composer {
    position: sticky; left: auto; right: auto; bottom: 16px;
    max-width: 760px; margin: 16px auto 0;
  }
  .main.has-composer { padding-bottom: 40px; }
  .hero-card { padding: 26px 28px; }
  .hero-card h1 { font-size: 28px; }
  .hero-nums { max-width: 520px; }
}

@media (min-width: 1200px) {
  .main { padding-left: 48px; padding-right: 48px; }
}

/* ── 小屏微調 ───────────────────────────── */
@media (max-width: 360px) {
  .main { padding-left: 10px; padding-right: 10px; }
  .card { padding: 13px; }
  .quick { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .quick a, .quick button { min-height: 70px; font-size: 11px; }
  .quick .ico { width: 30px; height: 30px; font-size: 14px; }
  .hero-card h1 { font-size: 20px; }
  .hero-num b { font-size: 17px; }
  .grid-2 { grid-template-columns: 1fr; }
  .auth-card { padding: 20px 16px 16px; }
  .tabbar a, .tabbar button { font-size: 11px; }
}

/* 橫屏手機：底部欄壓縮，避免遮擋 */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 899px) {
  :root { --tab-h: 50px; }
  .tabbar a, .tabbar button { flex-direction: row; gap: 5px; min-height: 44px; }
  .tabbar .ico { font-size: 15px; }
  .appbar { position: static; }
}

/* 深色模式：不自動反色，保持品牌色可讀 */
@media (prefers-color-scheme: dark) {
  :root { color-scheme: light; }
}

/* 列印（合同/確認書頁面友好） */
@media print {
  .appbar, .tabbar, .sidebar, .composer, .btn, .toast { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* ── 圖標尺寸（inline SVG，跨機型一致） ── */
.ico { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.ico svg { width: 20px; height: 20px; display: block; }
.quick .ico svg { width: 19px; height: 19px; }
.tabbar .ico svg { width: 21px; height: 21px; }
.sidebar .ico svg { width: 18px; height: 18px; }
.btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.item .arrow svg { width: 17px; height: 17px; display: block; }
.empty .ico svg { width: 30px; height: 30px; opacity: .55; }

.hero-chip svg { width: 15px; height: 15px; flex: 0 0 auto; }
.hero-chip { white-space: nowrap; }
