/* 前台（登入、問答、改密碼）樣式。白底；品牌色沿用舊 /kb 的深綠。不連外部字型與 CDN。 */
:root {
    --brand: #1a6b54;
    --brand-dark: #13513f;
    --brand-soft: #e8f3ef;
    --brand-ring: rgba(26, 107, 84, .18);
    --ink: #1f2937;
    --ink-2: #374151;
    --muted: #6b7280;
    --line: #e5e7eb;
    --surface: #f7f8f9;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --success-soft: #ecfdf3;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --font: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: #fff; font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button, input, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 品牌標誌 ── */
.brand { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #2f8f72); color: #fff; display: grid; place-items: center; font-size: 17px; box-shadow: 0 2px 6px rgba(26, 107, 84, .3); }

/* ── 按鈕與表單 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: 10px 18px; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:focus-visible, .btn-ghost:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-ring); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #cfd4dc; background: var(--surface); }
.btn-block { width: 100%; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--ink-2); }
.input { width: 100%; padding: 11px 14px; border: 1px solid #d0d5dd; border-radius: 10px; background: #fff; transition: border-color .15s, box-shadow .15s; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.input.is-invalid { border-color: var(--danger); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .reveal { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); padding: 6px 8px; cursor: pointer; border-radius: 8px; }
.input-wrap .reveal:hover { color: var(--ink); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.alert { border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; display: flex; gap: 8px; align-items: flex-start; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecdca; }
.alert-success { background: var(--success-soft); color: #067647; border: 1px solid #abefc6; }
.alert-info { background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #c4e2d7; }
.alert ul { margin: 0; padding-left: 18px; }

/* ── 登入、改密碼（置中卡片） ── */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), #fff 60%); }
.auth-main { flex: 1; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px 28px; box-shadow: 0 12px 32px rgba(16, 24, 40, .08); }
.auth-card .brand { margin-bottom: 20px; }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

/* ── 問答頁：頁首 ── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 12px; }
.topbar .spacer { flex: 1; }
.top-link { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; display: inline-flex; gap: 6px; align-items: center; }
.top-link:hover { background: var(--surface); }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: #fff; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.usermenu .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 24px rgba(16, 24, 40, .1); padding: 6px; }
.usermenu .menu .who { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.usermenu .menu a, .usermenu .menu button { display: flex; width: 100%; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; border: 0; background: none; text-align: left; color: var(--ink-2); text-decoration: none; font-size: 14px; cursor: pointer; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--surface); }

/* ── 問答頁：主體 ── */
.chat { flex: 1; width: 100%; max-width: 820px; margin: 0 auto; padding: 24px 20px 8px; }
.flash-wrap { width: 100%; max-width: 820px; margin: 16px auto 0; padding: 0 20px; }
.flash-wrap .alert { margin-bottom: 0; }
.welcome { text-align: center; padding: 40px 0 8px; }
.welcome h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: .01em; }
.welcome p { color: var(--muted); margin: 0; }
.scope-bar { max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scope-label { font-size: 13px; color: var(--muted); display: inline-flex; gap: 4px; align-items: center; margin-right: 2px; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 999px; padding: 3px 12px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; transition: all .15s; }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: #a9d3c4; color: var(--brand-dark); font-weight: 600; }
.chip:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-ring); }
.samples { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 28px 0 0; }
.sample { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--ink-2); display: flex; gap: 10px; align-items: flex-start; transition: border-color .15s, box-shadow .15s; }
.sample:hover { border-color: #a9d3c4; box-shadow: var(--shadow); }
.sample i { color: var(--brand); margin-top: 2px; }

.thread { display: flex; flex-direction: column; gap: 22px; }
.msg-user { align-self: flex-end; max-width: 85%; background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word; }
.msg-bot { display: flex; gap: 12px; align-items: flex-start; }
.bot-avatar { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 16px; }
.bot-body { flex: 1; min-width: 0; }
.answer { line-height: 1.8; word-break: break-word; }
.answer h2, .answer h3 { font-size: 16px; margin: 16px 0 6px; color: var(--brand-dark); }
.answer p { margin: 6px 0; }
.answer ul, .answer ol { margin: 6px 0; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer code { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; font-size: 13px; }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin: 0 2px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-dark); font-size: 11px; font-weight: 700; text-decoration: none; vertical-align: 2px; }
.cite:hover { background: var(--brand); color: #fff; }
.sources { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.sources summary { cursor: pointer; padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--ink-2); background: var(--surface); list-style: none; display: flex; gap: 8px; align-items: center; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary .caret { margin-left: auto; transition: transform .15s; }
.sources[open] summary .caret { transform: rotate(180deg); }
.sources ol { list-style: none; margin: 0; padding: 4px 0; }
.sources li { display: flex; gap: 10px; align-items: center; padding: 8px 14px; font-size: 14px; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.sources li:first-child { border-top: 0; }
.sources li.flash { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--brand-soft); } to { background: transparent; } }
.src-no { flex: 0 0 auto; min-width: 22px; height: 22px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; font-weight: 700; display: grid; place-items: center; color: var(--muted); }
.src-icon { color: var(--muted); font-size: 16px; }
.src-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-loc { color: var(--muted); font-size: 13px; white-space: nowrap; }
.src-img { flex: 0 0 auto; font-size: 13px; text-decoration: none; display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; }
.src-img:hover { border-color: var(--brand); }
.bot-actions { display: flex; gap: 6px; margin-top: 8px; }
.icon-btn { border: 1px solid transparent; background: none; color: var(--muted); border-radius: 8px; padding: 4px 8px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.icon-btn:hover { background: var(--surface); color: var(--ink); }
.thinking { color: var(--muted); display: flex; gap: 10px; align-items: center; padding-top: 4px; }
.dots { display: inline-flex; gap: 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); opacity: .3; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.bot-error { background: var(--danger-soft); border: 1px solid #fecdca; color: var(--danger); border-radius: 12px; padding: 10px 14px; display: flex; gap: 8px; align-items: flex-start; }

/* ── 問答頁：輸入列 ── */
.composer-wrap { position: sticky; bottom: 0; background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 28%); padding: 20px 20px 14px; }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; border: 1px solid #d0d5dd; border-radius: 16px; padding: 8px 8px 8px 16px; background: #fff; box-shadow: 0 6px 20px rgba(16, 24, 40, .08); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring), 0 6px 20px rgba(16, 24, 40, .08); }
.composer textarea { flex: 1; border: 0; resize: none; outline: none; padding: 8px 0; max-height: 168px; line-height: 1.6; background: transparent; }
.send { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 18px; cursor: pointer; transition: background .15s, opacity .15s; }
.send:hover { background: var(--brand-dark); }
.send:disabled { opacity: .35; cursor: not-allowed; }
.composer-note { max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--muted); }
.composer-note kbd { font-family: inherit; font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }
.empty-perm { max-width: 520px; margin: 48px auto; text-align: center; }
.empty-perm i { font-size: 40px; color: var(--muted); }

@media (max-width: 640px) {
    .topbar-inner { padding: 8px 12px; }
    .top-link span { display: none; }
    .usermenu summary .top-link { display: none; }
    .usermenu summary { padding-right: 6px; }
    .chat { padding: 16px 14px 8px; }
    .welcome { padding-top: 20px; }
    .welcome h1 { font-size: 22px; }
    .composer-wrap { padding: 16px 10px 10px; }
    .src-loc { display: none; }
    .msg-user { max-width: 92%; }
}
