/* 圖標與直式畫布。控制面板以實際可視區域定位，不改變生成影片的比例。 */
.ui-icon { display: inline-block; width: 16px; height: 16px; flex: none; vertical-align: -3px; background: currentColor; -webkit-mask: var(--icon-url) center/contain no-repeat; mask: var(--icon-url) center/contain no-repeat; }
.icon-trash-2 { --icon-url: url('/icons/trash-2.svg'); }
.icon-check { --icon-url: url('/icons/check.svg'); }
.icon-volume-2 { --icon-url: url('/icons/volume-2.svg'); }
.icon-volume-x { --icon-url: url('/icons/volume-x.svg'); }
.icon-rotate-ccw { --icon-url: url('/icons/rotate-ccw.svg'); }
.icon-audio-lines { --icon-url: url('/icons/audio-lines.svg'); }
.icon-film { --icon-url: url('/icons/film.svg'); }
.icon-camera { --icon-url: url('/icons/camera.svg'); }
.icon-download { --icon-url: url('/icons/download.svg'); }
.icon-maximize-2 { --icon-url: url('/icons/maximize-2.svg'); }
.icon-chevron-down { --icon-url: url('/icons/chevron-down.svg'); }
.icon-layers { --icon-url: url('/icons/layers.svg'); }
.icon-skip-forward { --icon-url: url('/icons/skip-forward.svg'); }
.icon-wand-sparkles { --icon-url: url('/icons/wand-sparkles.svg'); }
.icon-step-back { --icon-url: url('/icons/step-back.svg'); }
.icon-step-forward { --icon-url: url('/icons/step-forward.svg'); }
.icon-ellipsis { --icon-url: url('/icons/ellipsis.svg'); }
.video-audio-frame { position: relative; min-width: 0; width: 100%; }
.media.vid > .video-audio-frame, .cc-thumb > .video-audio-frame, .ref > .video-audio-frame, .thumb > .video-audio-frame { height: 100%; }
.video-audio-toggle { position: absolute; z-index: 4; right: 6px; top: 6px; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border: 1px solid #ffffff28; border-radius: 8px; background: #202226ed; color: #e6eaf0; cursor: pointer; }
.cc-thumb .video-audio-toggle { right: 0; top: 0; }
.error-full { white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; max-height: 65dvh; font: 12px/1.6 var(--mono); user-select: text; }
.cv-toolbar .danger { width: 32px; display: inline-grid; place-items: center; padding: 0; border-radius: 8px; background: #202226; color: #c8cdd5; border: 1px solid #ffffff28; }
.cv-toolbar .danger:hover { color: #efb7b0; background: #3b2828; border-color: #bc817b66; }
.cv-ntool .danger .ui-icon { margin-right: 5px; }
.cc-mobile-head { display: none; }
.cc-pop { z-index: 35; overscroll-behavior: contain; }
.cc-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: -8px; margin: -8px -8px 8px; padding: 6px 12px; background: #262626; border-bottom: 1px solid #ffffff12; z-index: 1; font-size: 13px; }
.cc-pop-head button { min-height: 36px; padding: 6px 10px; border: 0; border-radius: 8px; background: #333; color: #e6e6e6; cursor: pointer; }
.cc-pop .pp { width: auto; max-width: 100%; }
.cv-menu { overflow-y: auto; overscroll-behavior: contain; }
.cc-thumb-review { position: absolute; top: 2px; right: 2px; z-index: 2; }
.cc-thumb-review .material-review-state { display: none; }
.cc-thumb-review .material-review-button:not(.material-review-complete) { width: 26px; height: 26px; min-height: 26px; padding: 0; border: 1px solid #ffffff36; border-radius: 8px; background: #252a32; color: #e9eef7; font-size: 0; }
.cc-thumb-review .material-review-button:not(.material-review-complete)::before { content: '…'; font: 16px/1 sans-serif; }
.cc-thumb .acts { top: auto; bottom: 2px; }

@media (max-width: 860px) {
  body:has(#tab-canvas:not([hidden])) { overflow: hidden; overscroll-behavior: none; }
  .topbar .wordmark { display: none; }
  .topbar .tabs { flex: 1; min-width: 0; }
  .topbar .me { flex: none; }
  .topbar .tabs button, .topbar #meBtn { min-height: 44px; }
  .canvas-tab { height: calc(100dvh - 52px); min-height: 0; }
  .cv-toolbar { top: 8px; left: 8px; right: 8px; max-width: none; }
  .cv-toolbar .group { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 8px minmax(0, 1.1fr) repeat(3, 44px); gap: 2px; padding: 4px; background: #1c1c1cf5; }
  .cv-toolbar .cv-proj, .cv-toolbar select { width: 100%; max-width: 100%; min-width: 0; height: 44px; padding: 0 4px; font-size: 12px; }
  .cv-toolbar button { min-height: 44px; min-width: 44px; }
  .cv-toolbar .saved { grid-column: 1 / -1; text-align: right; }
  .cv-toolbar .saved:empty { display: none; }
  .cv-dock { height: auto; min-height: 54px; justify-content: space-between; padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)); }
  .cv-dock .dock-btn { width: 44px; height: 44px; flex: none; }
  .cv-dock .dock-sep { margin: 0; }
  .cv-dock .zoom-val { min-width: 34px; }
  .cv-dock button[title='快捷鍵'] { display: none; }
  .cv-keyboard .cv-dock { display: none; }
  .cv-ntool { padding: 4px; gap: 4px; border-radius: 12px; max-height: 60px; background: #232323; }
  .cv-ntool button { min-height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 8px 12px; }
  .cv-composer { min-width: 0; border-radius: 16px; padding: 0 10px 10px; gap: 8px; overflow-y: auto; overscroll-behavior: contain; background: #232323; }
  .cc-mobile-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; position: sticky; top: 0; z-index: 4; background: #232323; color: #cfd2d7; font-size: 12px; }
  .cc-fold { min-height: 44px; padding: 6px 8px; background: none; color: #d6d9df; border: 0; border-radius: 8px; cursor: pointer; }
  .cv-composer.is-folded { padding-bottom: 0; }
  .cv-composer.is-folded > :not(.cc-mobile-head) { display: none; }
  .cc-top { flex-wrap: nowrap; overflow-x: auto; min-height: 44px; scrollbar-width: none; }
  .cc-top .cc-grow, .cc-top > .tiny, .cc-top .cc-icon { display: none; }
  .cc-chip { height: 44px; flex: none; padding: 0 10px; }
  .cc-refs { min-height: 70px; padding-bottom: 3px; touch-action: pan-x; overscroll-behavior-x: contain; }
  .cc-thumb { width: 70px; height: 70px; touch-action: pan-x; }
  .cc-thumb .acts { display: none; }
  .cv-composer .cc-prompt { min-height: 64px; height: 64px; max-height: 140px; font-size: 16px; line-height: 1.5; }
  .cc-bar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 64px; gap: 6px; align-items: center; }
  .cc-bar .cc-sel { height: 44px; width: 100%; min-width: 0; padding: 0 8px; display: block; overflow: hidden; text-overflow: ellipsis; font-size: 12px; text-align: left; }
  .cc-bar .cc-sel:nth-of-type(1) { grid-column: 1; grid-row: 1; }
  .cc-bar .cc-sel:nth-of-type(2) { grid-column: 2; grid-row: 1; }
  .cc-bar .cc-sel:nth-of-type(3) { grid-column: 1 / 3; grid-row: 2; }
  .cc-bar .mi, .cc-bar .ratio-ico, .cc-bar .cc-div, .cc-bar .cc-grow { display: none; }
  .cc-bar .cc-cost { grid-column: 3; grid-row: 2; font-size: 11px; white-space: nowrap; text-align: right; }
  .cc-bar .cc-send { grid-column: 3; grid-row: 1; justify-self: end; width: 44px; height: 44px; }
  .cc-pop { border-radius: 16px; padding: 8px; background: #262626; }
  .cc-pop .pl { min-width: 0; width: 100%; }
  .cc-pop .pi, .cc-pop-head button, .cv-menu button, .cv-menu .menu-item { min-height: 44px; }
  .cc-pop .pn { min-width: 0; overflow-wrap: anywhere; }
  .cc-pop .pn .sub { overflow-wrap: anywhere; }
  .cc-pop .pp { padding: 4px; }
  .cc-pop .pp-num { font-size: 16px; min-height: 44px; }
  .cc-pop .pp-ratios { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cc-pop-head { top: -8px; }
  .cv-menu.context-menu { width: auto; max-height: none; }
  .context-menu .context-star { width: 36px; height: 44px; }
  .context-shortcut { display: none; }
}
@media (pointer: coarse) {
  .video-audio-toggle { width: 44px; height: 44px; }
  .material-review-complete { width: 44px; height: 44px; min-height: 44px; border: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
  .material-review-complete::before { z-index: 1; }
  .material-review-complete::after { content: ''; position: absolute; inset: 9px; border-radius: 8px; background: #202226f2; border: 1px solid #ffffff28; box-shadow: 0 2px 8px #0004; }
  .cv-asset-review .material-review-complete { width: 44px; height: 44px; min-height: 44px; background: transparent; border: 0; box-shadow: none; }
  .cc-thumb-review { top: -5px; right: -5px; }
  .cc-thumb-review .material-review-button:not(.material-review-complete) { width: 44px; height: 44px; }
}

/* 導演助手按鈕放在畫布底部工具列；手機用捏合縮放，把 −／＋ 讓出空間給它 */
@media (max-width: 860px) {
  .cv-dock .dock-btn.dock-agent { width: auto; padding: 0 12px; }
  .cv-dock .dock-zoom { display: none; }
}

/* 工作台參考素材：審核勾勾放在右上角 ✕ 的正下方，和左上角編號分開 */
.ref .material-review-control { left: auto; right: 4px; align-items: flex-end; }
@media (pointer: coarse) {
  .ref .material-review-control { top: 28px; right: -5px; }
  .ref .material-review-complete { width: 40px; height: 40px; min-height: 40px; }
  .ref .material-review-complete::after { inset: 8px; }
}

/* 手機：節點工具列改成換行顯示（以前橫向捲動、右邊的「建立副本」「更多操作」看不到） */
@media (max-width: 860px) {
  .cv-ntool { flex-wrap: wrap; overflow: visible; max-height: none; row-gap: 2px; justify-content: flex-start; white-space: normal; }
  .cv-ntool .nt-sep { display: none; }
  .cv-ntool button { white-space: nowrap; }
}
/* 勾勾圖示一律絕對置中，不受按鈕裡的文字影響 */
.material-review-complete::before { position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; z-index: 1; }

/* 手機：導演助手改成底部面板，預設約 1/3～1/2 畫面高，不再滿版 */
@media (max-width: 860px) {
  .agent { top: auto; bottom: 0; left: 0; right: 0; width: 100%; height: 46dvh; max-height: 50dvh; min-height: 300px; border-left: 0; border-top: 1px solid var(--line-2); border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.5); z-index: 70; }
  .agent .a-head { padding: 8px 12px; }
  .agent .a-ctx { padding: 4px 12px; font-size: 11px; }
  .agent .a-settings { padding: 6px 12px; gap: 4px; }
  .agent .a-knowledge { max-height: 120px; }
  .agent .a-log { padding: 10px 12px; }
  .agent .a-empty { padding: 0; font-size: 13px; }
  .agent .a-input { grid-template-columns: 1fr auto; align-items: end; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .agent .a-input textarea { min-height: 44px; height: 44px; max-height: 120px; resize: none; font-size: 16px; }
  .agent .a-input .btn { min-height: 44px; }
}
/* 手機：管理頁卡片別被表格撐寬；表格可以左右滑 */
#adminBody { grid-template-columns: minmax(0, 1fr); }
#adminBody > .card { min-width: 0; }
@media (max-width: 860px) {
  #adminBody > .card { overflow-x: auto; }
  #adminBody table { min-width: 560px; }
}
/* 素材庫卡片：「處理未完成」不要被擠成直排 */
.asset .row { flex-wrap: wrap; }
.asset .material-review-state { white-space: nowrap; }
/* 手機導演助手：輸入框放大到約面板一半高，面板用到上限 1/2 畫面 */
@media (max-width: 860px) {
  .agent { height: 50dvh; }
  .agent .a-ctx { display: none; }
  .agent .a-settings > label { grid-template-columns: 56px 1fr; }
  .agent .a-input { grid-template-columns: 1fr; }
  .agent .a-input textarea { height: 22dvh; min-height: 120px; max-height: none; }
  .agent .a-input .btn { justify-self: end; min-height: 40px; }
}
/* 手機導演助手：模型和知識庫並排一列；送出鍵放輸入框右邊，留空間給對話內容 */
@media (max-width: 860px) {
  .agent .a-settings { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .agent .a-settings > label { grid-template-columns: 1fr; font-size: 0; }
  .agent .a-settings > label select { font-size: 13px; }
  .agent .a-settings .a-knowledge { white-space: nowrap; }
  .agent .a-settings .a-knowledge[open] { grid-column: 1 / -1; white-space: normal; }
  .agent .a-input { grid-template-columns: 1fr auto; }
  .agent .a-input textarea { height: 20dvh; min-height: 110px; }
}
