/* Script generation styles, isolated from the shared workspace. */
#view-script-generation {
  --bg:#f3f4fa; --panel:#fff; --ink:#1f2337; --sub:#8a90a8; --line:#e8eaf3;
  --purple:#5b48d9; --purple-d:#3f2fb0; --purple-l:#efecff;
  --grad-green:linear-gradient(90deg,#19c37d,#0ea5e9);
  --shadow:0 1px 3px rgba(30,30,80,.06),0 8px 24px rgba(30,30,80,.06);
  --radius:14px;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
#view-script-generation [hidden] { display: none !important; }
#sg-materials, #sg-history { list-style: none; }
.sg-workspace{min-height:100%;display:grid;grid-template-columns:minmax(0,1fr) 290px}
.sg-main{width:100%;min-width:0;max-width:1150px;margin:0 auto;padding:18px 26px 64px}
.sg-crumb{color:var(--sub);font-size:12.5px;margin-bottom:10px}
.sg-crumb b{color:var(--ink)}
h1.sg-title{font-size:22px;font-weight:800;display:flex;align-items:center;gap:10px}
h1.sg-title .sg-new{background:#ff5c7a;color:#fff;font-size:11px;font-weight:800;padding:2px 9px;border-radius:9px}
.sg-subtitle{color:var(--sub);font-size:13px;margin:4px 0 16px}
/* stepper */
.sg-stepper{display:flex;align-items:center;margin-bottom:16px;background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:13px 20px}
.sg-st{display:flex;align-items:center;gap:10px;border:0;background:transparent;text-align:left;color:inherit;font:inherit;cursor:pointer}
.sg-st .sg-no{width:26px;height:26px;border-radius:50%;background:linear-gradient(135deg,#19c37d,#0ea5e9);color:#fff;font-weight:800;font-size:13px;display:flex;align-items:center;justify-content:center;flex:none}
.sg-st .sg-tt{font-weight:700;font-size:13.5px;color:var(--ink)}
.sg-st .sg-ts{display:block;font-size:11px;color:var(--sub)}
.sg-st-line{flex:1;height:2px;background:var(--grad-green);margin:0 14px;min-width:10px;border-radius:2px}
/* layout */
.sg-card{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:18px;margin-bottom:16px;scroll-margin-top:14px}
.sg-step-head{display:flex;align-items:center;gap:10px;margin-bottom:6px;flex-wrap:wrap}
.sg-step-no{width:24px;height:24px;border-radius:50%;background:linear-gradient(135deg,#19c37d,#0ea5e9);color:#fff;font-weight:800;font-size:12.5px;display:flex;align-items:center;justify-content:center;flex:none}
.sg-step-title{font-weight:800;font-size:15px}
.sg-step-sub{color:var(--sub);font-size:12px;margin:0 0 14px 34px}
.sg-tag{display:inline-block;font-size:11px;font-weight:700;padding:1px 8px;border-radius:8px;background:var(--purple-l);color:var(--purple-d)}
.sg-tag.sg-g{background:#e7f9f0;color:#0e9455}
.sg-tag.sg-b{background:#e9f2ff;color:#2563eb}
.sg-hint{font-size:12px;color:var(--sub)}
/* history */
.sg-history{position:sticky;top:16px;align-self:start;min-width:0;display:flex;flex-direction:column;margin:18px 26px 16px 0;padding:16px 14px;background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow)}
.sg-hist-head{display:flex;align-items:center;gap:8px;font-size:13.5px;font-weight:800}
.sg-history-caption{color:var(--sub);font-size:11px;margin:4px 0 12px;padding-bottom:10px;border-bottom:1px solid var(--line)}
.sg-history-list{max-height:65vh;overflow:auto}
.sg-history-foot{display:flex;gap:6px;flex-wrap:wrap;padding-top:12px}
.sg-history-foot .sg-btn{flex:1}
.sg-hitem{border:1px solid var(--line);border-radius:12px;background:#fafafe;padding:10px 12px;margin-bottom:10px}
.sg-hitem .sg-hdate{font-size:11.5px;color:var(--sub);font-weight:600;margin-bottom:6px}
.sg-hitem .sg-hrow{display:flex;gap:10px;align-items:center}
.sg-hitem .sg-hthumb{width:42px;height:42px;border-radius:9px;background:linear-gradient(135deg,#31266b,#6a52ff);display:flex;align-items:center;justify-content:center;font-size:18px;flex:none}
.sg-hitem .sg-hinfo{flex:1;min-width:0}
.sg-hitem .sg-htags{display:flex;gap:5px;flex-wrap:wrap;margin-bottom:6px}
.sg-hitem .sg-htags .sg-ht{font-size:10px;font-weight:700;border-radius:7px;padding:1px 7px;background:#eef0f8;color:#5a6078}
.sg-hitem .sg-htags .sg-ht.sg-ok{background:#e7f9f0;color:#0e9455}
.sg-hitem .sg-hbtn{display:inline-flex;align-items:center;gap:5px;background:linear-gradient(90deg,#6a52ff,#5440d8);color:#fff;font-size:11.5px;font-weight:800;border:none;border-radius:9px;padding:5px 12px;cursor:pointer}
.sg-hitem .sg-hbtn:hover{opacity:.92}
/* input */
.sg-chat{background:#fbfbfe;border:1.5px solid var(--line);border-radius:12px}
.sg-chat:focus-within{border-color:var(--purple);background:#fff;box-shadow:0 0 0 3px rgb(91 72 217 / 8%)}
.sg-chat textarea{display:block;width:100%;min-height:86px;padding:14px 14px 4px;resize:vertical;border:0;outline:0;background:transparent;font:inherit;color:inherit}
.sg-chat-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;padding:6px 10px 10px 14px}
.sg-chat #sg-materials:not(:empty){padding:0 14px 6px}
.sg-add-mat{display:inline-flex;align-items:center;gap:6px;color:var(--purple);font-size:13px;font-weight:800;cursor:pointer;background:none;border:none;padding:0}
.sg-add-mat:hover{text-decoration:underline}
.sg-filebar{display:none;align-items:center;gap:12px;background:#f6f7fd;border:1px solid var(--line);border-radius:12px;padding:10px 12px;margin-top:12px}
.sg-filebar.sg-show{display:flex}
.sg-filebar .sg-thumb{width:58px;height:36px;border-radius:6px;background:linear-gradient(135deg,#31266b,#6a52ff);display:flex;align-items:center;justify-content:center;color:#fff;font-size:14px;flex:none}
.sg-filebar .sg-meta{flex:1;min-width:0}
.sg-filebar .sg-meta b{font-size:13px;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sg-filebar .sg-meta span{font-size:11.5px;color:var(--sub)}
.sg-filebar .sg-del{border:1px solid var(--line);background:#fff;border-radius:8px;padding:5px 10px;font-size:12px;cursor:pointer;color:#8a90a8}
.sg-filebar .sg-del:hover{color:#ff5c7a;border-color:#ffc2cf}
/* duration param */
.sg-opt-lbl{font-size:13px;font-weight:800;margin:16px 0 8px}
.sg-param-row{display:flex;gap:12px;flex-wrap:wrap}
.sg-param{border:1px solid var(--line);border-radius:11px;padding:11px 13px;background:#fbfbfe;min-width:0}
.sg-param .sg-pl{font-weight:800;font-size:13px;margin-bottom:8px;display:flex;align-items:center;gap:8px}
.sg-param .sg-pl .sg-pk{font-size:11px;color:var(--sub);font-weight:600}
.sg-dur-box{display:flex;align-items:center;gap:8px}
.sg-dur-btn{width:30px;height:30px;border:1px solid var(--line);border-radius:8px;background:#fff;color:var(--purple);font-size:17px;font-weight:800;cursor:pointer;line-height:1}
.sg-dur-btn:hover{border-color:var(--purple);background:var(--purple-l)}
.sg-dur-in{width:70px;text-align:center;border:1px solid var(--line);border-radius:8px;padding:5px 6px;font-size:14px;font-weight:800;color:var(--ink);outline:none;background:#fff}
.sg-dur-in:focus{border-color:var(--purple)}
.sg-dur-unit{font-weight:800;font-size:13px;color:#4a4f66}
.sg-dur-max{font-size:11px;color:#ff5c7a;font-weight:800;margin-left:2px}
.sg-param-tip{font-size:11.5px;color:var(--sub);margin-top:8px}
.sg-param-tip b{color:var(--purple-d)}
/* buttons */
.sg-btn{border:none;border-radius:10px;padding:9px 16px;font-weight:700;font-size:13px;cursor:pointer;white-space:nowrap}
.sg-btn.sg-ghost{background:#fff;border:1px solid var(--line);color:#4a4f66}
.sg-btn.sg-ghost:hover{border-color:var(--purple);color:var(--purple)}
.sg-btn.sg-pri{background:linear-gradient(90deg,#6a52ff,#5440d8);color:#fff;box-shadow:0 6px 16px rgba(91,72,217,.3)}
.sg-btn.sg-pri:disabled{opacity:.5;cursor:not-allowed;box-shadow:none}
.sg-btn.sg-sm{padding:6px 12px;font-size:12px;border-radius:8px}
.sg-btn.sg-blue{background:linear-gradient(90deg,#2563eb,#1d4ed8);color:#fff;box-shadow:0 6px 16px rgba(37,99,235,.28)}
.sg-next-row{display:flex;justify-content:flex-end;gap:10px;margin-top:14px;align-items:center;flex-wrap:wrap}
.sg-count{display:inline-flex;align-items:center;gap:6px;font-size:13px;font-weight:700;white-space:nowrap}
.sg-count .sg-dur-in{width:60px}
/* ai bar */
.sg-ai-bar{display:none;align-items:flex-start;gap:10px;background:linear-gradient(90deg,#efecff,#e9f7ff);border:1px solid #ddd6ff;border-radius:12px;padding:11px 14px;margin-top:14px;font-size:12.5px;color:#4a4468;line-height:1.65}
.sg-ai-bar.sg-show{display:flex}
.sg-ai-bar .sg-sp{width:14px;height:14px;border:2px solid #c9bef7;border-top-color:var(--purple);border-radius:50%;animation:sg-spin .8s linear infinite;flex:none;margin-top:3px}
.sg-ai-bar .sg-sp.sg-ok{animation:none;border:none;background:linear-gradient(135deg,#19c37d,#0ea5e9);color:#fff;font-size:9px;display:flex;align-items:center;justify-content:center;border-radius:50%;width:15px;height:15px;margin-top:3px}
@keyframes sg-spin{to{transform:rotate(360deg)}}
.sg-ai-bar b{color:var(--purple-d)}
/* script table */
.sg-script-tabs{display:flex;gap:6px;flex-wrap:wrap;margin:12px 0}
.sg-script-tab{background:#fff;border:1px solid var(--line);border-radius:8px;padding:6px 10px;color:var(--ink);font:inherit;font-size:12.5px;cursor:pointer}
.sg-script-tab:hover,.sg-script-tab[aria-selected="true"]{border-color:var(--purple);background:var(--purple-l);color:var(--purple-d)}
.sg-script-error{border:1px solid #ffc2cf;border-radius:10px;padding:10px 12px;background:#fff5f7;color:#a4324e}
.sg-tbl-wrap{border:1px solid var(--line);border-radius:12px;overflow:auto;margin-top:6px}
table.sg-script{border-collapse:collapse;width:100%;min-width:760px;font-size:12.5px;table-layout:fixed}
table.sg-script th{background:#f6f7fd;color:#5a6078;font-weight:800;font-size:12px;text-align:left;padding:9px 10px;border-bottom:1px solid var(--line);position:sticky;top:0;z-index:1}
table.sg-script td{padding:7px 10px;border-bottom:1px solid #eef0f6;vertical-align:top}
table.sg-script tr:last-child td{border-bottom:none}
table.sg-script tr:hover td{background:#fcfcff}
table.sg-script .sg-c-no{width:42px;text-align:center;color:var(--purple-d);font-weight:800}
table.sg-script .sg-c-time{width:150px}
table.sg-script .sg-c-desc{width:auto}
table.sg-script .sg-c-cam{width:180px}
table.sg-script .sg-c-line{width:160px}
table.sg-script .sg-c-op{width:82px;text-align:center;white-space:nowrap}
table.sg-script .sg-cell-ta{width:100%;border:1px solid transparent;border-radius:7px;padding:5px 7px;font-size:12.5px;font-family:inherit;resize:none;outline:none;background:transparent;line-height:1.5;color:#3a3f55;min-height:36px}
table.sg-script .sg-cell-ta:hover{background:#f6f7fd;border-color:var(--line)}
table.sg-script .sg-cell-ta:focus{background:#fff;border-color:var(--purple)}
.sg-insert-row,.sg-del-row{display:inline-grid;place-items:center;vertical-align:top;background:#fff;border:1px solid var(--line);border-radius:7px;width:26px;height:26px;padding:0;cursor:pointer;font-size:14px;line-height:1}
.sg-insert-row{margin-inline-end:6px;color:var(--purple-d)}
.sg-insert-row:hover{border-color:var(--purple)}
.sg-del-row{color:#a6abc4}
.sg-del-row:hover{color:#ff5c7a;border-color:#ffc2cf}
.sg-edit-tip{font-size:11.5px;color:var(--sub);margin-top:10px;display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.sg-edit-tip .sg-tag{font-size:10px}
.sg-toolbar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-top:10px}
.sg-toolbar .sg-sep{width:1px;height:22px;background:var(--line);margin:0 2px}
/* empty state */
.sg-empty{border:1.5px dashed #cfd0e4;border-radius:12px;background:#fafafe;padding:34px 18px;text-align:center;color:var(--sub)}
.sg-empty .sg-ic{font-size:30px;margin-bottom:8px}
.sg-empty b{display:block;color:#5a6078;font-size:13.5px;margin-bottom:4px}
/* toast */
.sg-toast{position:fixed;left:50%;bottom:34px;transform:translateX(-50%) translateY(20px);background:#1f2337;color:#fff;font-size:13px;font-weight:600;padding:10px 20px;border-radius:12px;box-shadow:0 10px 30px rgba(0,0,0,.3);opacity:0;pointer-events:none;transition:.25s;z-index:99}
.sg-toast.sg-show{opacity:1;transform:translateX(-50%) translateY(0)}

#view-script-generation button:disabled { cursor: not-allowed; opacity: .5; }
#view-script-generation button:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.sg-filebar img { object-fit: cover; }
.sg-ai-bar[data-error="true"] { border-color: #ffc2cf; background: #fff5f7; color: #a4324e; }
.sg-ai-bar[data-error="true"] .sg-sp { display: none; }
.sg-history-status { padding: 12px 0; text-align: center; overflow-wrap: anywhere; }
.sg-history-status:empty { display: none; }
.sg-history-status[data-error="true"] { color: #a4324e; }
.sg-hitem .sg-ht { overflow-wrap: anywhere; }

.sg-history-dialog {
  width: min(1000px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sg-history-dialog::backdrop { background: rgba(31, 35, 55, .55); }
.sg-history-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sg-history-dialog-head h2 { font-size: 17px; }
.sg-history-dialog h3 { margin: 12px 0 4px; font-size: 13px; }
.sg-history-dialog .sg-hint { margin-top: 8px; }
.sg-history-dialog .sg-hint:empty { display: none; }
.sg-history-dialog .sg-hint[data-error="true"] { color: #a4324e; }
.sg-history-dialog td, .sg-preview-requirements { white-space: pre-wrap; overflow-wrap: anywhere; }
.sg-preview-requirements { margin-bottom: 14px; }

@media (max-width: 1180px) {
  .sg-workspace { grid-template-columns: minmax(0, 1fr) 236px; }
  .sg-main { padding: 16px; }
  .sg-history { margin: 16px 16px 16px 0; }
}
@media (max-width: 1000px) {
  .sg-workspace { grid-template-columns: minmax(0, 1fr); }
  .sg-history { position: static; margin: 0 16px 16px; }
}
@media (max-width: 630px) {
  .sg-main { padding: 12px; }
  .sg-history { margin-inline: 12px; }
  .sg-card { padding: 12px; }
  .sg-stepper { padding: 10px; }
  .sg-st { gap: 4px; }
  .sg-st .sg-ts { display: none; }
  .sg-st-line { margin-inline: 4px; }
  .sg-step-sub { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sg-ai-bar .sg-sp { animation-duration: 2s; }
  .sg-toast { transition: none; }
}
