/* =========================================================
   LLM 101 互動教學｜PART 02 · 跑起 AI
   附錄 A～D 的表單／卡片樣式（appendix.css）
   - 只包含 p2-* 元件；共用版面與 .btn／.callout／.glossary／.ref-list 留在 main.css。
   - 使用 main.css 的 design tokens，不改 :root。
   - 斷點沿用 859px／460px；390px 為單欄。
   ========================================================= */

/* [hidden] 必須蓋過 .p2-field／.p2-unknown-badge 的 display，否則隱藏失效。 */
.p2-field[hidden],
.p2-unknown-badge[hidden],
.p2-error[hidden],
.p2-inline-note[hidden],
.p2-row-note[hidden] {
  display: none !important;
}

/* ---------- 卡片外框與狀態 ---------- */
.p2-card {
  margin: 26px 0 8px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.p2-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin-bottom: 6px;
}

.p2-card-title {
  margin: 0;
  font-size: 1.06rem;
  line-height: 1.45;
}

.p2-card-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.6;
}

.p2-state {
  margin: 0;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .79rem;
  font-weight: 700;
  line-height: 1.5;
}

.p2-state[data-state="editing"],
.p2-state[data-state="partial"] {
  border-color: var(--warn);
  background: var(--warn-weak);
  color: var(--warn);
}

.p2-state[data-state="complete"],
.p2-state[data-state="ready"] {
  border-color: var(--ok);
  background: var(--ok-weak);
  color: var(--ok);
}

.p2-state[data-state="has-unknown"],
.p2-state[data-state="needs-check"] {
  border-color: var(--warn);
  background: var(--warn-weak);
  color: var(--warn);
}

.p2-state[data-state="copied"] {
  border-color: var(--primary);
  background: var(--primary-weak);
  color: var(--primary);
}

.p2-note,
.p2-help,
.p2-print-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.7;
}

.p2-print-hint {
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

/* ---------- 表單基本結構 ---------- */
.p2-form {
  margin-top: 14px;
}

.p2-fieldset {
  min-width: 0;
  margin: 18px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.p2-fieldset > legend {
  padding: 0 8px;
  color: var(--primary);
  font-size: .84rem;
  font-weight: 800;
  letter-spacing: .04em;
}

.p2-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.p2-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.p2-field-wide {
  grid-column: 1 / -1;
}

.p2-field > label,
.p2-label {
  display: block;
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.55;
}

.p2-req,
.p2-opt {
  margin-left: 4px;
  font-size: .72rem;
  font-weight: 700;
}

.p2-req { color: var(--warn); }
.p2-opt { color: var(--muted); }

.p2-input,
.p2-select,
.p2-textarea {
  width: 100%;
  min-height: 42px;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .95rem;
  line-height: 1.5;
}

.p2-textarea {
  min-height: 78px;
  resize: vertical;
}

.p2-input:focus-visible,
.p2-select:focus-visible,
.p2-textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.p2-input[readonly],
.p2-textarea[readonly] {
  background: var(--code-bg);
  color: var(--text);
}

.p2-input::placeholder,
.p2-textarea::placeholder {
  color: var(--muted);
  opacity: .9;
}

/* ---------- 單選／多選 chips ---------- */
.p2-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
  padding: 2px 0;
}

.p2-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .84rem;
  line-height: 1.45;
  cursor: pointer;
}

.p2-choice input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
  flex: 0 0 auto;
}

.p2-choice:hover {
  border-color: var(--primary);
}

.p2-choice:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.p2-choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-weak);
  font-weight: 700;
}

.p2-choice:has(input:disabled) {
  cursor: default;
}

/* ---------- 說明、錯誤與待查 ---------- */
.p2-error {
  margin: 0;
  color: var(--danger);
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.6;
}

.p2-field.has-error .p2-input,
.p2-field.has-error .p2-select,
.p2-field.has-error .p2-textarea {
  border-color: var(--danger);
}

.p2-field.is-unknown .p2-input,
.p2-field.is-unknown .p2-textarea {
  border-style: dashed;
  background: var(--surface-2);
  color: var(--muted);
}

.p2-unknown-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--warn);
  border-radius: 999px;
  background: var(--warn-weak);
  color: var(--warn);
  font-size: .7rem;
  font-weight: 800;
  vertical-align: 1px;
}

.p2-inline-note {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  background: var(--warn-weak);
  color: var(--text);
  font-size: .8rem;
  line-height: 1.65;
}

.p2-readonly {
  margin: 0;
  padding: .55rem .65rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .9rem;
  line-height: 1.55;
}

/* ---------- 動作列 ---------- */
.p2-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.p2-actions .btn {
  min-height: 42px;
}

.p2-actions .p2-note {
  flex: 1 1 220px;
  margin: 0;
}

/* ---------- 附錄 B 的下載選擇卡 ---------- */
.p2-download-card .p2-verdict {
  font-weight: 800;
  color: var(--primary);
}

.p2-download-card .p2-copied-hint {
  margin: 10px 0 0;
}

/* ---------- 附錄 C 的紀錄卡 ---------- */
.p2-record {
  min-width: 0;
  margin: 18px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.p2-record > legend {
  padding: 0 8px;
  color: var(--primary);
  font-size: .86rem;
  font-weight: 800;
}

.p2-record-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 4px;
}

.p2-record-state {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.p2-record-state[data-state="partial"] { color: var(--warn); }
.p2-record-state[data-state="complete"] { color: var(--ok); }

.p2-record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px 16px;
  margin-top: 12px;
}

.p2-record-example {
  border-style: dashed;
  background: var(--surface-2);
}

.p2-record-example .p2-input,
.p2-record-example .p2-select,
.p2-record-example .p2-textarea {
  background: var(--surface);
  color: var(--muted);
}

.p2-record-example .p2-record-state {
  color: var(--muted);
}

.p2-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  vertical-align: 1px;
}

.p2-record .p2-actions {
  margin-top: 14px;
}

/* ---------- 附錄 D 的框架選擇列 ---------- */
.p2-framework-row {
  min-width: 0;
  margin: 18px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.p2-framework-row > legend {
  padding: 0 8px;
  color: var(--primary);
  font-size: .86rem;
  font-weight: 800;
}

.p2-row-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px 16px;
  margin-top: 12px;
}

.p2-framework-row.is-needs-check {
  border-color: var(--warn);
  background: var(--warn-weak);
}

.p2-row-note {
  margin: 10px 0 0;
  color: var(--warn);
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.65;
}

/* ---------- 參考資料 URL ---------- */
.p2-ref-url {
  margin: 2px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .76rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------- 手機 ---------- */
@media (max-width: 859px) {
  .p2-card {
    padding: 16px;
    border-radius: 16px;
  }

  .p2-grid,
  .p2-record-grid,
  .p2-row-grid {
    grid-template-columns: 1fr;
  }

  .p2-fieldset {
    padding: 13px;
  }

  .p2-input,
  .p2-select,
  .p2-textarea {
    font-size: 16px;
  }

  .p2-actions .btn {
    flex: 1 1 100%;
    min-height: 44px;
  }

  .p2-choice {
    min-height: 44px;
  }
}

@media (max-width: 460px) {
  .p2-card {
    padding: 14px;
  }

  .p2-card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .p2-state {
    align-self: flex-start;
  }
}

/* ---------- 列印：只留卡片本體 ---------- */
@media print {
  .p2-card,
  .p2-record,
  .p2-framework-row {
    border-color: #999;
    background: #fff !important;
    box-shadow: none;
    break-inside: avoid;
  }

  .p2-actions,
  .p2-state,
  .p2-record-state,
  .p2-print-hint,
  .p2-inline-note,
  .p2-row-note {
    display: none !important;
  }

  .p2-input,
  .p2-select,
  .p2-textarea,
  .p2-readonly {
    border-color: #999;
    background: #fff !important;
    color: #000 !important;
  }

  .p2-fieldset,
  .p2-record,
  .p2-framework-row {
    break-inside: avoid;
  }
}
