/* ==========================================================================
   AI-AMM v2 — 介面樣式
   設計原則：
     1. 以可讀性優先：正文 16px、行高 1.75、對比度符合 WCAG AA
     2. 顯示／隱藏一律使用 [hidden] 屬性，不與 display 類別混用（避免權重衝突）
     3. 所有互動元素都有明顯的 :focus-visible 外框
     4. 不依賴任何 CDN，離線環境仍可完整運作
   ========================================================================== */

/* ── 設計權杖 ─────────────────────────────────────────────────────────── */
:root {
  --c-bg:        #f6f7fb;
  --c-surface:   #ffffff;
  --c-surface-2: #f9fafb;
  --c-border:    #e4e7ec;
  --c-border-2:  #d0d5dd;
  --c-text:      #1f2937;
  --c-text-2:    #475467;
  --c-text-3:    #98a2b3;
  --c-primary:   #4f46e5;
  --c-primary-d: #4338ca;
  --c-primary-l: #eef2ff;
  --c-tier1:     #2563eb;
  --c-tier1-l:   #eff6ff;
  --c-tier2:     #059669;
  --c-tier2-l:   #ecfdf5;
  --c-tier3:     #d97706;
  --c-tier3-l:   #fffbeb;
  --c-danger:    #dc2626;
  --c-danger-l:  #fef2f2;
  --c-warn:      #b45309;
  --c-warn-l:    #fffbeb;
  --c-ok:        #059669;
  --c-ok-l:      #ecfdf5;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --sh-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
  --sh-2: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --sh-3: 0 12px 24px -6px rgba(16, 24, 40, .12), 0 4px 8px -4px rgba(16, 24, 40, .08);

  --fs: 16px;
  --rail-w: 232px;
  --wrap: 1280px;

  --f-sans: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", -apple-system,
            BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* 使用者可在後台調整字級 */
body[data-font-scale="80"] { --fs: 14px; }
body[data-font-scale="90"] { --fs: 15px; }
body[data-font-scale="110"] { --fs: 17px; }
body[data-font-scale="120"] { --fs: 19px; }
body[data-font-scale="130"] { --fs: 20px; }

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

html { scroll-behavior: smooth; scroll-padding-top: 84px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  font-family: var(--f-sans);
  font-size: var(--fs);
  line-height: 1.75;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .5em; font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 1em; }
a { color: var(--c-primary-d); text-underline-offset: 3px; }
a:hover { color: var(--c-primary); }
code { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 5px; padding: .1em .35em; font-size: .9em; }

/* 統一的焦點樣式 */
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--c-primary) 45%, white);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 工具類 */
.muted   { color: var(--c-text-3); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .78rem; }
.mt-2    { margin-top: .5rem; }
.mt-3    { margin-top: .9rem; }
.req     { color: var(--c-danger); font-size: .74rem; font-weight: 700;
           background: var(--c-danger-l); border-radius: 999px; padding: .05em .5em; margin-left: .35em;
           display: inline-block; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--c-primary); color: #fff; padding: 10px 18px; border-radius: 0 0 var(--r-md) 0;
}
.skip-link:focus { left: 0; }

/* ── 頂部列 ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}
.topbar__inner {
  max-width: var(--wrap); margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand__mark {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-primary), #7c3aed);
  color: #fff; font-weight: 900; font-size: .95rem;
  display: flex; align-items: center; justify-content: center; letter-spacing: .02em;
}
.brand__text { min-width: 0; }
.brand__text strong { display: block; font-size: 1rem; font-weight: 800; }
.brand__text small { display: block; font-size: .75rem; color: var(--c-text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: 999px; padding: 5px 12px; font-size: .8rem; color: var(--c-text-2);
  white-space: nowrap;
}
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-ok); }
.chip--count .chip__dot { background: var(--c-primary); }

/* ── 按鈕 ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: inherit; font-size: .9rem; font-weight: 700; line-height: 1.2;
  padding: 9px 16px; border-radius: var(--r-md);
  border: 1px solid var(--c-border-2); background: var(--c-surface); color: var(--c-text);
  cursor: pointer; transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
  text-decoration: none; white-space: nowrap; max-width: 100%;
}
.btn:hover:not(:disabled) { background: var(--c-surface-2); border-color: var(--c-text-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; box-shadow: var(--sh-1); }
.btn--primary:hover:not(:disabled) { background: var(--c-primary-d); border-color: var(--c-primary-d); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--c-text-2); }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-2); border-color: var(--c-border); }
.btn--sm { padding: 6px 12px; font-size: .82rem; }
.btn--lg { padding: 13px 24px; font-size: .98rem; }
.btn--icon { padding: 8px; width: 38px; height: 38px; }
.btn--danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn--danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.btn--block { width: 100%; }

/* 載入中的按鈕 */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: #fff; animation: spin .7s linear infinite;
}
.btn.is-loading:not(.btn--primary):not(.btn--danger)::after { color: var(--c-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 設定面板 ─────────────────────────────────────────────────────────── */
.settings { border-top: 1px solid var(--c-border); background: var(--c-surface); }
.settings__grid {
  max-width: var(--wrap); margin: 0 auto; padding: 20px;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 28px;
}

/* ── 表單元件 ─────────────────────────────────────────────────────────── */
.field { display: block; }
.field + .field { margin-top: 16px; }
.field__label { display: block; font-weight: 700; font-size: .88rem; margin-bottom: 6px; color: var(--c-text); }
.field__hint { font-size: .8rem; color: var(--c-text-3); margin: 6px 0 0; }
.field__inline { display: flex; gap: 8px; align-items: center; }
.field__inline .input { flex: 1; }

.input {
  width: 100%; font-family: inherit; font-size: .92rem; color: var(--c-text);
  background: var(--c-surface); border: 1px solid var(--c-border-2);
  border-radius: var(--r-md); padding: 10px 13px; line-height: 1.6;
  transition: border-color .15s, box-shadow .15s;
}
.input:hover { border-color: var(--c-text-3); }
.input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-l); }
.input::placeholder { color: var(--c-text-3); }
.input--area { resize: vertical; min-height: 68px; }
.input--sm { padding: 7px 11px; font-size: .85rem; }
select.input { cursor: pointer; }

.range { width: 100%; accent-color: var(--c-primary); }
.range__out { display: inline-block; font-size: .82rem; color: var(--c-text-2); font-weight: 700; margin-top: 2px; }

.check, .radio {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: .88rem; padding: 5px 0; cursor: pointer; color: var(--c-text-2);
}
.check input, .radio input {
  margin: 3px 0 0; flex: 0 0 auto; width: 17px; height: 17px; accent-color: var(--c-primary); cursor: pointer;
}
.check--sm { font-size: .82rem; }
.check:hover span, .radio:hover span { color: var(--c-text); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .8rem; font-weight: 700; color: var(--c-text-2); white-space: nowrap; flex: 0 0 auto; }
.switch__text { white-space: nowrap; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--c-border-2);
  position: relative; transition: background .18s; flex: 0 0 42px;
}
.switch__thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: var(--sh-1); transition: transform .18s;
}
.switch input:checked + .switch__track { background: var(--c-ok); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 3px solid color-mix(in srgb, var(--c-primary) 45%, white); outline-offset: 2px; }

.disclosure {
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  background: var(--c-surface-2); margin-top: 18px;
}
.disclosure > summary {
  cursor: pointer; padding: 11px 16px; font-weight: 700; font-size: .87rem; color: var(--c-text-2);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "▸"; color: var(--c-primary); transition: transform .15s; }
.disclosure[open] > summary::before { transform: rotate(90deg); }
.disclosure__body { padding: 4px 16px 16px; }

/* ── 版面骨架 ─────────────────────────────────────────────────────────── */
.shell {
  max-width: var(--wrap); margin: 0 auto; padding: 24px 20px 60px;
  display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); gap: 28px;
  align-items: start;
}

/* 側欄 */
.rail { position: sticky; top: 84px; min-width: 0; }
.rail__title { font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--c-text-3); margin: 0 0 10px 4px; }
.rail__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail__item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: var(--r-md); text-decoration: none; color: var(--c-text-2);
  font-size: .89rem; font-weight: 600; border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.rail__item:hover { background: var(--c-surface); color: var(--c-text); }
.rail__item.is-active { background: var(--c-surface); color: var(--c-primary-d); border-left-color: var(--c-primary); box-shadow: var(--sh-1); }
.rail__code {
  width: 24px; height: 24px; flex: 0 0 24px; border-radius: 7px; background: var(--c-surface-2);
  border: 1px solid var(--c-border); color: var(--c-text-2);
  font-size: .74rem; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.rail__item.is-active .rail__code { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.rail__label { flex: 1; }
.rail__state { width: 9px; height: 9px; border-radius: 50%; background: var(--c-border-2); flex: 0 0 9px; }
.rail__state.is-done { background: var(--c-ok); }
.rail__state.is-busy { background: var(--c-warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.rail__foot { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--c-border); }
.progress__bar { height: 7px; border-radius: 999px; background: var(--c-border); overflow: hidden; }
.progress__bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--c-primary), #7c3aed); border-radius: 999px; transition: width .3s; }
.progress__text { font-size: .78rem; color: var(--c-text-3); margin: 8px 0 12px; }

/* 主內容 */
.workspace { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

/* ── 卡片 ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-xl); box-shadow: var(--sh-1); overflow: hidden;
  scroll-margin-top: 84px;
}
.card__head { display: flex; gap: 16px; padding: 22px 26px 0; }
.card__title { margin: 0 0 6px; }
.card__desc { margin: 0; color: var(--c-text-2); font-size: .92rem; }
.card__body { padding: 22px 26px; }
.card__foot {
  padding: 16px 26px 22px; display: flex; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--c-border); background: var(--c-surface-2);
}
.step-badge {
  flex: 0 0 42px; width: 42px; height: 42px; border-radius: var(--r-md);
  background: var(--c-primary-l); color: var(--c-primary-d);
  font-weight: 900; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center;
}
.step-badge--star { background: #fef3c7; color: #92400e; }
.card--export { border-color: #c7d2fe; }

/* 子卡片 */
.subcard {
  border: 1px solid var(--c-border); border-radius: var(--r-lg);
  padding: 18px 20px; background: var(--c-surface);
}
.subcard + .subcard { margin-top: 18px; }
.subcard--muted { background: var(--c-surface-2); }
.subcard--accent { border-color: #c7d2fe; background: #f8faff; }
.subcard__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.subcard__head h3 { margin: 0; }
.hint { font-size: .78rem; color: var(--c-text-3); }

/* ── 三層級 ───────────────────────────────────────────────────────────── */
.tier-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.tier { border: 1px solid var(--c-border); border-top: 4px solid var(--c-border-2); border-radius: var(--r-lg); padding: 16px 18px; background: var(--c-surface); display: flex; flex-direction: column; }
.tier--1 { border-top-color: var(--c-tier1); background: linear-gradient(180deg, var(--c-tier1-l), #fff 42%); }
.tier--2 { border-top-color: var(--c-tier2); background: linear-gradient(180deg, var(--c-tier2-l), #fff 42%); }
.tier--3 { border-top-color: var(--c-tier3); background: linear-gradient(180deg, var(--c-tier3-l), #fff 42%); }
.tier__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.tier__head h3 { margin: 0; font-size: .95rem; display: flex; align-items: center; gap: 7px; }
.tier__num { font-size: .72rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: rgba(0,0,0,.05); }
.tier--1 .tier__num { background: var(--c-tier1-l); color: var(--c-tier1); }
.tier--2 .tier__num { background: var(--c-tier2-l); color: var(--c-tier2); }
.tier--3 .tier__num { background: var(--c-tier3-l); color: var(--c-tier3); }
.tier__tag { font-size: .7rem; font-weight: 700; color: var(--c-text-3); border: 1px solid var(--c-border); border-radius: 999px; padding: 2px 8px; }
.tier__desc { font-size: .82rem; color: var(--c-text-3); margin: 0 0 12px; }
.tier__label { font-size: .76rem; font-weight: 800; color: var(--c-text-2); text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 4px; }
.tier__body { flex: 1; display: flex; flex-direction: column; }
.tier__opts { margin-top: 10px; }
.tier__opts.is-locked { opacity: .45; pointer-events: none; filter: grayscale(.7); }
.tier .input { font-size: .86rem; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot--1 { background: var(--c-tier1); }
.dot--2 { background: var(--c-tier2); }
.dot--3 { background: var(--c-tier3); }

/* ── 網格 ─────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tier-objectives { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }

/* 策略／素材的膠囊勾選 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--c-border-2); border-radius: 999px; padding: 7px 14px;
  font-size: .84rem; background: var(--c-surface); color: var(--c-text-2);
  transition: background .15s, border-color .15s, color .15s;
}
.chip-check:hover { border-color: var(--c-primary); color: var(--c-text); }
.chip-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip-check:has(input:checked) { background: var(--c-primary-l); border-color: var(--c-primary); color: var(--c-primary-d); font-weight: 700; }
.chip-check:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--c-primary) 45%, white); outline-offset: 2px; }

/* 評量列 */
.eval-rows { display: grid; gap: 14px; }
.eval-row { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 12px 16px; margin: 0; }
.eval-row legend { font-weight: 800; font-size: .86rem; padding: 0 6px; color: var(--c-text-2); }

/* ── RAG 來源清單 ─────────────────────────────────────────────────────── */
.rag-preview { margin-top: 20px; border: 1px solid #c7d2fe; background: #f8faff; border-radius: var(--r-lg); padding: 16px 18px; }
.rag-preview__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.rag-preview__head h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.badge { font-size: .72rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--c-primary-l); color: var(--c-primary-d); }
.badge--keyword { background: #fef3c7; color: #92400e; }
.badge--hybrid { background: var(--c-ok-l); color: var(--c-ok); }

.source-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.source-card {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  padding: 12px 14px; position: relative; cursor: default;
}
.source-card__tag {
  position: absolute; top: 10px; right: 12px;
  font-size: .7rem; font-weight: 800; color: #fff; background: var(--c-primary);
  border-radius: 5px; padding: 1px 7px;
}
.source-card__meta { font-size: .76rem; color: var(--c-text-3); margin-bottom: 6px; padding-right: 42px; }
.source-card__title { font-weight: 700; font-size: .88rem; margin-bottom: 4px; }
.source-card__snippet { font-size: .82rem; color: var(--c-text-2); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.source-card__score { font-size: .72rem; color: var(--c-text-3); margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.source-card.is-empty { text-align: center; color: var(--c-text-3); font-size: .86rem; padding: 22px; }
.source-list--compact { grid-template-columns: 1fr; }

/* ── AI 輸出區 ────────────────────────────────────────────────────────── */
.output { border-top: 1px solid var(--c-border); padding: 22px 26px; background: var(--c-surface-2); }
.output__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.output__title { font-size: .95rem; font-weight: 800; display: flex; align-items: center; gap: 8px; margin: 0; }
.output__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.output__body { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 18px 22px; }
.output__warn { background: var(--c-warn-l); border: 1px solid #fde68a; color: var(--c-warn); border-radius: var(--r-md); padding: 10px 14px; font-size: .84rem; margin-bottom: 12px; }

/* AI 產出的排版 */
.prose { font-size: .95rem; color: var(--c-text); }
.prose h3 { font-size: 1.05rem; color: var(--c-primary-d); margin: 20px 0 8px; }
.prose h4 { font-size: .97rem; color: var(--c-tier1); margin: 16px 0 6px; }
.prose h5 { font-size: .92rem; margin: 14px 0 4px; }
.prose p  { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 6px 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 5px; }
.prose strong { color: var(--c-primary-d); }
.prose table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .88rem; }
.prose th, .prose td { border: 1px solid var(--c-border-2); padding: 7px 11px; text-align: left; }
.prose th { background: var(--c-surface-2); font-weight: 800; }
.prose blockquote { margin: 10px 0; padding: 8px 16px; border-left: 4px solid var(--c-primary-l); background: var(--c-surface-2); color: var(--c-text-2); }
.prose .tier-block { border-left: 3px solid var(--c-border-2); padding-left: 14px; margin: 14px 0; }
.prose .tier-block[data-tier="1"] { border-left-color: var(--c-tier1); }
.prose .tier-block[data-tier="2"] { border-left-color: var(--c-tier2); }
.prose .tier-block[data-tier="3"] { border-left-color: var(--c-tier3); }

/* 串流中的游標 */
.streaming .output__body::after {
  content: "▌"; color: var(--c-primary); animation: blink 1s step-end infinite; margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* 對齊檢核的判定 */
.verdict { display: grid; gap: 10px; }
.verdict__row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: var(--r-md); font-size: .88rem; }
.verdict__row--ok { background: var(--c-ok-l); border: 1px solid #a7f3d0; }
.verdict__row--bad { background: var(--c-warn-l); border: 1px solid #fde68a; }
.verdict__row--none { background: var(--c-surface-2); border: 1px solid var(--c-border); color: var(--c-text-3); }
.verdict__icon { font-weight: 900; }

/* ── n8n 結果 ─────────────────────────────────────────────────────────── */
.n8n-results { display: grid; gap: 12px; margin-top: 16px; }
.n8n-card { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 14px 16px; background: var(--c-surface); }
.n8n-card img { max-width: 100%; border-radius: var(--r-sm); }
.n8n-video { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--c-border); }
.n8n-video:last-child { border-bottom: 0; }
.n8n-video img { width: 132px; height: 74px; object-fit: cover; border-radius: var(--r-sm); flex: 0 0 132px; }
.n8n-video__t { font-weight: 700; font-size: .87rem; }
.n8n-video__c { font-size: .76rem; color: var(--c-text-3); }
.n8n-error { color: var(--c-danger); background: var(--c-danger-l); border: 1px solid #fecaca; border-radius: var(--r-sm); padding: 10px 14px; font-size: .85rem; }

/* ── 雙語介面 ─────────────────────────────────────────────────────────── */
/* 與舊版（ADDIE_Beta_20260914）相同做法：
   body 有 .lang-zh 時顯示 <span class="zh">，否則顯示 <span class="en">。
   動態文字（toast／confirm／選項）由 assets/js/i18n.js 處理。 */
body.lang-zh .en { display: none !important; }
body:not(.lang-zh) .zh { display: none !important; }

/* ── 學習目標挑選器 ───────────────────────────────────────────────────── */
/* grid 用 minmax(0,1fr)：預設的 auto 最小值會讓下拉選單的長選項把整張卡撐寬 */
.pe-picker { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 14px; border: 1px solid var(--c-border); border-radius: var(--r-md); background: var(--c-surface-2); margin-bottom: 12px; }
.pe-picker > * { min-width: 0; }
.pe-picker__row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; }
/* .input 預設 width:100%，在 flex 版面會把整列撐滿 → 這裡改成由 flex 決定寬度，
   並允許縮到比內容更窄（min-width:0），否則 <select> 會用最長選項的寬度撐破容器 */
.pe-picker__row .input { flex: 1 1 200px; width: auto; min-width: 0; max-width: 100%; }
.pe-picker__row .input--sm { flex: 1 1 180px; width: auto; min-width: 0; }
.pe-picker__row #pe-select { flex: 1 1 320px; width: auto; min-width: 0; }
.pe-picker .field__hint { margin: 0; }
@media (max-width: 720px) {
  .pe-picker__row { flex-direction: column; align-items: stretch; }
  .pe-picker__row .input, .pe-picker__row .btn { width: 100%; flex-basis: auto; }
}

/* ── AI 素材建議 ──────────────────────────────────────────────────────── */
.media-suggest { display: grid; gap: 12px; margin-top: 12px; }
.media-suggest__row { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 12px 14px; background: var(--c-surface); }
.media-suggest__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.media-suggest__head strong { font-size: .84rem; color: var(--c-primary-d); }
.media-suggest__text { margin: 0; font-size: .88rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.badge--ai { background: var(--c-ok-l); color: var(--c-ok); }
.badge--manual { background: #fef3c7; color: #92400e; }

/* ── 匯出區 ───────────────────────────────────────────────────────────── */
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.summary-item { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 12px 16px; }
.summary-item__k { display: block; font-size: .74rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--c-text-3); }
.summary-item__v { display: block; font-size: 1.25rem; font-weight: 800; color: var(--c-primary-d); }
.export-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.preview-frame { margin-top: 20px; border: 1px solid var(--c-border); border-radius: var(--r-lg); overflow: hidden; }
.preview-frame__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); }
.preview-frame__head h3 { margin: 0; font-size: .95rem; }
.preview-frame__actions { display: flex; gap: 8px; }
#preview-iframe { width: 100%; height: 620px; border: 0; background: #fff; display: block; }

/* ── 橫幅與提示 ───────────────────────────────────────────────────────── */
.banner { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; border-radius: var(--r-md); padding: 12px 18px; font-size: .88rem; }
.banner--info { background: var(--c-primary-l); border: 1px solid #c7d2fe; color: #3730a3; }
.banner--warn { background: var(--c-warn-l); border: 1px solid #fde68a; color: var(--c-warn); }
.banner strong { font-weight: 800; }

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, 92vw); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-primary); border-radius: var(--r-md);
  box-shadow: var(--sh-3); padding: 12px 16px; font-size: .87rem;
  animation: toast-in .22s ease-out;
}
.toast--ok { border-left-color: var(--c-ok); }
.toast--warn { border-left-color: var(--c-warn); }
.toast--error { border-left-color: var(--c-danger); }
.toast__close { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--c-text-3); font-size: 1rem; line-height: 1; padding: 0 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── 抽屜 ─────────────────────────────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 94vw); z-index: 140;
  background: var(--c-surface); border-left: 1px solid var(--c-border); box-shadow: var(--sh-3);
  display: flex; flex-direction: column; animation: drawer-in .22s ease-out;
}
@keyframes drawer-in { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.drawer__head h2 { margin: 0; font-size: 1.05rem; }
.drawer__body { padding: 20px; overflow-y: auto; }
.drawer__body h3 { font-size: .95rem; margin: 20px 0 8px; color: var(--c-primary-d); }
.drawer__body h3:first-child { margin-top: 0; }
.drawer__body ul, .drawer__body ol { padding-left: 20px; }
.drawer__body li { margin-bottom: 6px; font-size: .89rem; }
.scrim { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 130; }

/* ── 頁尾 ─────────────────────────────────────────────────────────────── */
.page-foot { text-align: center; color: var(--c-text-3); font-size: .82rem; padding: 10px 0 30px; }
.page-foot a { color: var(--c-text-2); }

/* ── 響應式 ───────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .tier-grid, .tier-objectives, .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  /* minmax(0,1fr) 而非 1fr：1fr 的最小值是 auto，子項（側欄的橫向清單）會把整頁撐寬 */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; min-width: 0; }
  .rail__list { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 6px; }
  .rail__item { flex: 0 0 auto; border-left: 0; border-bottom: 3px solid transparent; }
  .rail__item.is-active { border-left: 0; border-bottom-color: var(--c-primary); }
  .rail__state { display: none; }
  .rail__foot { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
  .settings__grid { grid-template-columns: 1fr; gap: 18px; }
}
@media (max-width: 760px) {
  .grid--2, .grid--3, .tier-grid, .tier-objectives, .summary-grid { grid-template-columns: 1fr; }
  .card__head, .card__body, .card__foot, .output { padding-left: 18px; padding-right: 18px; }
  .topbar__inner { flex-wrap: wrap; }
  .brand__text small { display: none; }
  .export-actions .btn { width: 100%; }
  /* 英文標籤比中文長，窄螢幕上允許換行，避免按鈕撐破卡片 */
  .btn { white-space: normal; text-align: center; }
}

/* ── 列印（教案預覽友善）──────────────────────────────────────────────── */
@media print {
  .topbar, .rail, .card__foot, .output__actions, .toasts, .drawer, .scrim, .preview-frame__head { display: none !important; }
  body { background: #fff; }
  .shell { display: block; padding: 0; }
  .card { box-shadow: none; border: 0; }
}
