/* app.css — 工作室介面樣式 */
:root {
  --bg: #ffffff;
  --panel: #fdf1f3;
  --panel-2: #f8dfe4;
  --ink: #1c1417;
  --sub: #79646a;
  --line: #eccdd3;
  --accent: #E11D48;      /* 玫瑰紅：Instagram 視覺社群的操作色 */
  --accent-ink: #ffffff;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
}

.topbar { padding: 28px 24px 8px; max-width: 1100px; margin: 0 auto; }
.topbar h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.04em; }
.tagline { margin: 4px 0 0; color: var(--sub); font-size: 0.95rem; }

/* 步驟列 */
.stepper {
  display: flex; gap: 8px; flex-wrap: wrap;
  max-width: 1100px; margin: 18px auto 0; padding: 0 24px;
}
.step {
  padding: 8px 14px; border-radius: 999px;
  background: var(--panel); color: var(--sub);
  border: 1px solid var(--line); font-size: 0.9rem;
}
.step b { margin-right: 4px; }
.step.current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.step.done { color: var(--ink); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 80px; }

.step-panel { display: none; }
.step-panel.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

h2 { font-size: 1.15rem; margin: 26px 0 8px; }
.hint { color: var(--sub); font-size: 0.9rem; margin: 0 0 14px; }

textarea, input[type="text"], input[type="password"], select {
  width: 100%; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; font: inherit;
}
textarea { resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 16px; flex-wrap: wrap; margin: 14px 0; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--sub); min-width: 200px; }
.field.grow { flex: 1; }
.mode-field { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.mode-field legend { padding: 0 6px; }
.mode-field label { display: inline-flex; gap: 6px; margin-right: 16px; color: var(--ink); align-items: baseline; }
.mode-field label.unavailable { opacity: 0.4; }
.mode-field.wide { width: 100%; }
.mode-field.wide label { display: flex; flex-wrap: wrap; padding: 6px 0; }
.mode-field.wide small { flex-basis: 100%; margin-left: 24px; color: var(--sub); }
.checks label { display: inline-flex; gap: 8px; margin-right: 20px; }

/* 預覽內行內編輯器（路徑 B） */
.bar-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-editor {
  padding: 12px 14px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px; background: var(--panel-2);
}
.inline-editor label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--sub); }
.inline-actions { display: flex; gap: 8px; }
.inline-actions .save { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 700; }

.actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
button { font: inherit; cursor: pointer; border-radius: 999px; border: none; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 26px; font-weight: 700;
}
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-ghost {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); padding: 12px 22px;
}
.btn-small {
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); padding: 6px 14px; font-size: 0.85rem;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 摘要編輯卡 */
.editor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.edit-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.edit-card-head { font-weight: 700; color: var(--accent); font-size: 0.85rem; letter-spacing: 0.05em; }
.edit-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--sub); }

/* 風格選擇 */
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.style-option {
  background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 14px; text-align: left;
  display: flex; flex-direction: column; gap: 6px; color: var(--ink);
}
.style-option:hover { border-color: var(--sub); }
.style-option.selected { border-color: var(--accent); background: var(--panel-2); }
.swatches { display: flex; gap: 5px; }
.swatches i { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.15); }
.style-name { font-weight: 700; }
.style-desc { font-size: 0.8rem; color: var(--sub); }

/* 預覽 */
.preview-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-top: 10px; }
.preview-cell {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.preview-cell canvas { width: 100%; height: auto; display: block; }
.preview-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; color: var(--sub); font-size: 0.85rem;
}

/* Toast */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 22px; border-radius: 999px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all 0.25s ease;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .step-panel.active { animation: none; }
  #toast { transition: none; }
}
@media (max-width: 640px) {
  .row { flex-direction: column; align-items: stretch; }
}

/* 四軸新增元素 */
input[type="file"] {
  width: 100%; background: var(--panel); color: var(--sub);
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 9px 12px; font: inherit;
}
input[type="number"] {
  width: 100%; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font: inherit;
}
.uploaded-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #e6f7ee; border: 1px solid #a7e8c4; color: #0d7a44;
  border-radius: 999px; padding: 5px 13px; font-size: 0.78rem; margin: 6px 8px 0 0;
}
optgroup { background: var(--panel); color: var(--sub); }

/* 卡片操作按鈕（步驟 2） */
.edit-card-head { display: flex; justify-content: space-between; align-items: center; }
.card-ops { display: flex; gap: 5px; }
.card-ops .op {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; width: 30px; height: 28px; font-size: 0.85rem; padding: 0;
}
.card-ops .op.danger:hover { border-color: #dc2626; color: #dc2626; }

/* 拖曳排序 / 合併拆分 */
.drag-handle { cursor: grab; color: var(--sub); font-size: 1rem; margin-right: 6px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.edit-card.dragging { opacity: 0.45; }
.edit-card.drop-target { border-color: var(--accent); }

/* 分級提示 */
#toast.error { background: #ff6b5e; color: #2a0703; }
#toast.success { background: #5fd39a; color: #04240f; }

/* 字數計數 */
.cnt { float: right; font-size: 0.72rem; color: var(--sub); }
.cnt.over { color: #dc2626; font-weight: 700; }

/* 生圖進度條 */
#gen-progress { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; }
#gen-progress[hidden] { display: none; }
.gp-label { font-size: 0.85rem; color: var(--sub); white-space: nowrap; }
.gp-bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.gp-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

/* 放大預覽 */
#lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 16, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; cursor: zoom-out; padding: 24px;
}
#lightbox[hidden] { display: none; }
#lightbox img { max-width: min(92vw, 640px); max-height: 82vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.lb-hint { color: var(--sub); font-size: 0.82rem; }

/* 步驟列可點擊 */
.stepper .step { cursor: pointer; }
.stepper .step:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 自訂素材列表 */
.element-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px;
}
.el-thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.el-name { min-width: 90px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.element-row label { display: flex; flex-direction: column; gap: 3px; font-size: 0.72rem; color: var(--sub); }
.element-row select { padding: 6px 10px; min-width: 96px; }
.el-del:hover { border-color: #dc2626; color: #dc2626; }

/* ---------- API 金鑰設定（BYOK） ---------- */
.key-panel {
  margin: 14px 0; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 4px 16px;
}
.key-panel > summary {
  cursor: pointer; font-weight: 700; padding: 12px 0; min-height: 44px;
  display: flex; align-items: center; list-style-position: inside;
}
.key-panel[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.key-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin: 10px 0; }
.key-row .field { min-width: 0; }
.key-panel .key-input { background: var(--bg); }
.key-status { color: var(--sub); font-size: 0.85rem; min-height: 44px; display: inline-flex; align-items: center; }
.key-status.set { color: #15803d; font-weight: 700; }
.key-btns { display: inline-flex; gap: 8px; }
.key-btns .btn-ghost, #btn-keys-clear-all { min-height: 44px; padding: 10px 16px; }
.btn-ghost.danger { color: var(--accent); border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
@media (max-width: 640px) {
  .key-row { flex-direction: column; align-items: stretch; }
  .key-btns .btn-ghost { flex: 1; }
}

/* ---------- 404 頁 ---------- */
.notfound { max-width: 560px; margin: 12vh auto; padding: 0 16px; text-align: center; }
.notfound .code { font-size: 4rem; font-weight: 800; color: var(--accent); margin: 0; }
.notfound a.btn-primary { border-radius: 999px; display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
