/* ============================================================
   AI 文档图解工作台 — 样式
   浅色主题
   ============================================================ */

:root {
  --bg:        #f5f7fb;
  --bg-soft:   #eef1f7;
  --paper:     #ffffff;
  --line:      #e3e8f0;
  --line-2:    #d3dae6;
  --text:      #1f2733;
  --text-2:    #5b6675;
  --text-3:    #8b95a5;
  --brand:     #2f6bff;
  --brand-dk:  #1f4fd8;
  --brand-lt:  #eaf0ff;
  --ok:        #16a34a;
  --warn:      #d97706;
  --err:       #dc2626;
  --shadow-sm: 0 1px 2px rgba(20,32,60,.06), 0 1px 3px rgba(20,32,60,.05);
  --shadow-md: 0 6px 20px rgba(20,32,60,.10), 0 2px 6px rgba(20,32,60,.06);
  --shadow-lg: 0 18px 50px rgba(20,32,60,.16);
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC",
          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 20px;
  background: rgba(255,255,255,.88);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b7bff, #7a5cff);
  color: #fff; font-weight: 700; font-size: 17px;
  box-shadow: 0 3px 10px rgba(59,123,255,.34);
}

.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .2px; }
.brand-text p {
  margin: 0; font-size: 12px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw;
}

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none; border: 1px solid var(--line-2);
  background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: var(--r-sm);
  font-size: 13.5px; font-family: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .06s;
}
.btn:hover { background: var(--bg-soft); border-color: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(47,107,255,.28);
}
.btn.primary:hover { background: var(--brand-dk); border-color: var(--brand-dk); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.btn.big { padding: 11px 30px; font-size: 15px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  appearance: none; border: 0; background: transparent;
  width: 28px; height: 28px; border-radius: 6px;
  font-size: 15px; color: var(--text-3); cursor: pointer; line-height: 1;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* 导出下拉 */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 268px; padding: 6px;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  z-index: 80;
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu button {
  display: block; width: 100%; text-align: left;
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 10px; border-radius: 7px; font-family: inherit;
  font-size: 13.5px; color: var(--text);
}
.menu button:hover { background: var(--brand-lt); }
.menu button b { display: block; font-weight: 600; }
.menu button span { display: block; font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ---------------- 欢迎页 ---------------- */
.welcome {
  max-width: 900px; margin: 0 auto; padding: 52px 20px 70px;
}

.drop {
  background: var(--paper);
  border: 2px dashed var(--line-2);
  border-radius: var(--r-lg);
  padding: 46px 28px 40px;
  text-align: center;
  transition: border-color .18s, background .18s, transform .18s;
}
.drop.over { border-color: var(--brand); background: var(--brand-lt); transform: scale(1.008); }
.drop-icon { color: var(--brand); margin-bottom: 8px; }
.drop h2 { margin: 6px 0 8px; font-size: 20px; font-weight: 650; }
.drop-sub { margin: 0 0 22px; color: var(--text-2); font-size: 13.5px; }
.drop-sub b { color: var(--text); }
.drop-hint { min-height: 20px; margin: 14px 0 0; font-size: 12.5px; color: var(--text-3); }

.steps {
  list-style: none; margin: 34px 0 0; padding: 0;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.steps li {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.steps .num {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-lt); color: var(--brand);
  font-size: 12.5px; font-weight: 700; margin-top: 2px;
}
.steps b { font-size: 14px; }
.steps p { margin: 3px 0 0; font-size: 12.5px; color: var(--text-2); line-height: 1.6; }

/* ---------------- 工作区 ---------------- */
.workspace { max-width: 900px; margin: 0 auto; padding: 28px 20px 90px; }

.paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  padding: 54px 60px 60px;
  min-height: 50vh;
}

.doc { outline: none; }

.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 {
  line-height: 1.4; margin: 1.5em 0 .6em; font-weight: 650;
}
.doc h1 { font-size: 25px; margin-top: 0; }
.doc h2 { font-size: 20px; }
.doc h3 { font-size: 17px; }
.doc h4, .doc h5, .doc h6 { font-size: 15px; }
.doc p { margin: 0 0 1em; }
.doc ul, .doc ol { margin: 0 0 1em; padding-left: 1.6em; }
.doc li { margin-bottom: .35em; }
.doc blockquote {
  margin: 0 0 1em; padding: 6px 16px;
  border-left: 3px solid var(--line-2); color: var(--text-2);
  background: var(--bg-soft); border-radius: 0 6px 6px 0;
}
.doc code {
  font-family: var(--mono); font-size: .88em;
  background: var(--bg-soft); padding: 2px 5px; border-radius: 4px;
}
.doc pre {
  background: #f7f9fc; border: 1px solid var(--line);
  padding: 12px 14px; border-radius: 8px; overflow-x: auto;
}
.doc pre code { background: none; padding: 0; }
.doc img { max-width: 100%; }
.doc table { border-collapse: collapse; margin: 0 0 1em; width: 100%; font-size: 14px; }
.doc th, .doc td { border: 1px solid var(--line-2); padding: 6px 10px; text-align: left; }
.doc th { background: var(--bg-soft); font-weight: 600; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }

.doc [data-block] { position: relative; }
.doc [data-block]:hover::before {
  content: ""; position: absolute; left: -34px; top: 4px; bottom: 4px;
  width: 3px; border-radius: 2px; background: var(--brand-lt);
}

/* ---------------- 插入的图解块 ---------------- */
.insert {
  position: relative;
  margin: 14px 0 22px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: #fcfdff;
  overflow: hidden;
}
.insert[data-state="loading"] { background: #fbfcff; }
.insert[data-state="error"] { border-color: #f5c2c2; background: #fff7f7; }

.insert-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 7px 10px 7px 12px;
  background: linear-gradient(180deg,#f7f9fe,#f2f5fc);
  border-bottom: 1px solid var(--line);
}
.insert-title {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  display: flex; align-items: center; gap: 7px; min-width: 0;
}
.insert-title .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand); flex: none;
}
.insert-title .tt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.insert-tools { display: flex; gap: 2px; flex: none; }
.insert-tools button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 12px; color: var(--text-3);
  padding: 4px 8px; border-radius: 5px; white-space: nowrap;
}
.insert-tools button:hover { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }
.insert-tools button[data-act="del"]:hover { color: var(--err); }

.insert-body { padding: 16px 14px; text-align: center; overflow-x: auto; }
.insert-body svg { max-width: 100%; height: auto; }
.insert-body img { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto; }

.insert-src {
  padding: 8px 14px 12px; font-size: 11.5px; color: var(--text-3);
  border-top: 1px dashed var(--line); line-height: 1.6;
  text-align: left;
}
.insert-src b { color: var(--text-2); font-weight: 600; }

.insert-loading { padding: 30px 0; color: var(--text-3); font-size: 13px; }
.insert-loading .spinner { margin: 0 auto 10px; }
.insert-err { color: var(--err); font-size: 12.5px; padding: 12px; text-align: left; word-break: break-word; }

.doc-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding: 0 4px;
  font-size: 12.5px; color: var(--text-3);
}

/* ---------------- 选区工具条 ---------------- */
.sel-toolbar {
  position: absolute; z-index: 90;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 12px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; box-shadow: var(--shadow-lg);
  animation: pop .13s ease-out;
  max-width: min(92vw, 620px);
}
.st-label {
  font-size: 11.5px; color: var(--text-3); white-space: nowrap;
  border-right: 1px solid var(--line); padding-right: 10px;
}
.st-btns { display: flex; gap: 2px; flex-wrap: nowrap; overflow-x: auto; }
.st-btns button {
  appearance: none; border: 0; cursor: pointer; font-family: inherit;
  font-size: 13px; font-weight: 500; color: var(--text);
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
  background: transparent; transition: background .13s, color .13s;
}
.st-btns button:hover { background: var(--brand); color: #fff; }

/* ---------------- 忙碌遮罩 ---------------- */
.busy {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  background: rgba(240,243,250,.72);
  backdrop-filter: blur(3px);
}
.busy-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: 26px 34px; text-align: center; min-width: 240px;
}
.busy-card p { margin: 14px 0 12px; font-size: 13.5px; color: var(--text-2); }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--brand-lt); border-top-color: var(--brand);
  animation: spin .75s linear infinite;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 130;
  display: grid; place-items: center;
  background: rgba(22,30,45,.42);
  padding: 20px;
}
.modal-card {
  width: min(760px, 100%);
  background: #fff; border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
  display: flex; flex-direction: column; max-height: 86vh;
}
.modal-card.small { width: min(560px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.modal-tip { margin: 12px 16px 0; font-size: 12.5px; color: var(--text-2); }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.modal-foot.right { justify-content: flex-end; }
#codeArea {
  flex: 1; min-height: 300px; border: 0; outline: none; resize: none;
  padding: 14px 16px; font-family: var(--mono); font-size: 13px;
  line-height: 1.65; color: #1f2733; background: #fbfcfe; tab-size: 2;
}
#promptArea {
  margin: 10px 16px 0; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line-2); border-radius: 8px;
  font-family: inherit; font-size: 13.5px; outline: none; line-height: 1.6;
}
#promptArea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-lt); }
.err { color: var(--err); font-size: 12.5px; }

/* ---------------- 设置抽屉 ---------------- */
.mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(22,30,45,.34);
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 110;
  width: min(430px, 94vw);
  background: #fff; border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(102%);
  transition: transform .24s cubic-bezier(.22,.7,.3,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.drawer-body { flex: 1; overflow-y: auto; padding: 6px 18px 40px; }

.field { margin: 16px 0; }
.field > label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field .val { float: right; font-weight: 500; color: var(--brand); font-family: var(--mono); }
.field input[type="text"], .field input[type="url"],
.field input[type="password"], .field input[type="number"], .field select {
  width: 100%; padding: 8px 11px; font-family: inherit; font-size: 13.5px;
  color: var(--text); background: #fff;
  border: 1px solid var(--line-2); border-radius: 8px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-lt);
}
.field input[type="range"] { width: 100%; accent-color: var(--brand); }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.6; }

.warn { margin: 6px 0 0; font-size: 11.5px; line-height: 1.6; color: #b00020; font-weight: 600; min-height: 0; }
.warn:empty { display: none; }
.hint code, .faq code {
  font-family: var(--mono); font-size: 11px;
  background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; color: #3c4a5e;
}
.drawer hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

.test-result { margin-left: 10px; font-size: 12.5px; }
.test-result.ok { color: var(--ok); }
.test-result.bad { color: var(--err); }

.faq {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 13px; margin: 14px 0; background: #fbfcfe;
}
.faq summary {
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before { content: "▸ "; color: var(--text-3); }
.faq[open] summary::before { content: "▾ "; }
.faq ol, .faq ul { margin: 10px 0 6px; padding-left: 20px; font-size: 12.5px; color: var(--text-2); line-height: 1.85; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; z-index: 200;
  transform: translate(-50%, 24px);
  padding: 10px 18px; border-radius: 999px;
  background: #1f2733; color: #fff; font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #b91c1c; }
.toast.ok { background: #15803d; }

/* ---------------- 打印 ---------------- */
@media print {
  .topbar, .sel-toolbar, .doc-foot, .insert-tools, .toast,
  .mask, .drawer, .modal, .busy { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  .workspace { max-width: none; padding: 0; }
  .paper { border: 0; box-shadow: none; padding: 0; border-radius: 0; }
  .insert { break-inside: avoid; page-break-inside: avoid; page-break-before: auto; }
  .insert-head { background: #f5f5f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc [data-block]:hover::before { display: none; }
  .insert-body svg { max-width: 100% !important; }
}

/* ---------------- 窄屏 ---------------- */
@media (max-width: 720px) {
  .paper { padding: 28px 20px 34px; }
  .workspace, .welcome { padding-left: 12px; padding-right: 12px; }
  .brand-text p { max-width: 30vw; }
  .top-actions .btn.ghost { display: none; }
  .doc h1 { font-size: 21px; }
  .sel-toolbar { border-radius: 14px; flex-wrap: wrap; }
}
