/* AI Creative Studio — ใช้ตัวแปรสี/คอมโพเนนต์เดียวกับหน้าเดิม (index.html) */
aside { width: 100px; }
.nav-label { font-size: 9.5px; letter-spacing: .14em; color: var(--muted); text-align: center; margin: 12px 0 6px; opacity: .7; font-weight: 600; }
.nav .count.warn { background: var(--warn); color: #111; }

/* แถบคิวงานด้านบนทุกหน้า */
.jobbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; background: rgba(109,93,252,.12); border: 1px solid rgba(109,93,252,.45); border-radius: 14px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }
.jobbar .jb-run { display: inline-flex; align-items: center; gap: 8px; }
.jobbar .jb-run .pbar { width: 120px; flex: none; }
.jobbar .jb-wait { color: var(--warn); }
.jobbar .jb-done { color: var(--ok); display: inline-flex; align-items: center; gap: 6px; }
.jobbar .chip { height: 26px; font-size: 12px; }
.jobbar > .chip:last-child { margin-left: auto; }

/* Face Swap: แท็บ Head Swap / Clothes Color / แก้พร้อมกัน */
.fs-tabs { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 10px 16px 6px; margin: 0; }
.fs-pane { display: flex; flex-direction: column; gap: 16px; }
.slider { accent-color: var(--accent); width: 220px; max-width: 45vw; }
.na-row { opacity: .5; }
.wf-missing { background: rgba(251,191,36,.1); border: 1px solid rgba(251,191,36,.4); color: #fcd34d; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches .sw { width: 54px; height: 40px; border-radius: 8px; border: 2px solid var(--border); position: relative; display: flex; align-items: flex-end; justify-content: center; }
.swatches .sw span { font-size: 10px; background: rgba(0,0,0,.6); color: #fff; border-radius: 4px; padding: 0 4px; margin-bottom: 2px; }
.swatches .sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.colorpick { width: 44px; height: 36px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.people { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.people img { max-width: 100%; max-height: 360px; border-radius: 10px; align-self: flex-start; }
.brush { margin-top: 10px; }
.brush-wrap { position: relative; display: inline-block; max-width: 100%; }
.brush-wrap img { display: block; max-width: 100%; max-height: 480px; border-radius: 10px; }
.brush-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; border-radius: 10px; }
.cb-sub { margin: 0 0 10px; padding: 10px; background: var(--panel-2); border-radius: 10px; }
.step { display: flex; align-items: center; gap: 8px; margin: 12px 0 6px; cursor: pointer; }
.step input { width: 18px; height: 18px; accent-color: var(--accent); }
.fsx-out { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.fsx-job { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.fsx-prev { max-width: 100%; max-height: 420px; border-radius: 10px; align-self: flex-start; }
.ba { position: relative; display: inline-block; max-width: 100%; align-self: flex-start; border-radius: 10px; overflow: hidden; user-select: none; }
.ba img { display: block; max-width: 100%; max-height: 560px; }
.ba .ba-after { position: absolute; inset: 0; clip-path: inset(0 0 0 calc(100% - var(--p))); }
.ba .ba-after img { width: 100%; height: 100%; object-fit: contain; }
.ba .ba-range { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.ba::after { content: ""; position: absolute; top: 0; bottom: 0; left: calc(100% - var(--p)); width: 2px; background: #fff; box-shadow: 0 0 8px rgba(0,0,0,.6); pointer-events: none; }
.ba .ba-l, .ba .ba-r { position: absolute; top: 8px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 6px; pointer-events: none; }
.ba .ba-l { left: 8px; } .ba .ba-r { right: 8px; }
.ba-vid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ba-vid div { position: relative; }
.ba-vid video { width: 100%; max-height: 520px; border-radius: 10px; background: #000; }
.ba-vid .badge { position: absolute; left: 8px; top: 8px; z-index: 1; }

/* ระบบเครดิต */
.chip.wallet { border-color: rgba(52,211,153,.5); color: var(--ok); }
.bill-box { width: min(520px, 100%); padding: 22px; position: relative; overflow-y: auto; gap: 10px; }
.bill-box.wide { width: min(860px, 100%); }
.bill-box h2 { font-size: 18px; margin-bottom: 4px; }
.bill-x { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 8px; color: var(--muted); }
.bill-x:hover { background: var(--panel-3); color: #fff; }
.bill-bal { font-size: 26px; font-weight: 700; margin: 8px 0; }
.bill-bal span { font-size: 14px; font-weight: 400; color: var(--muted); }
.pkgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 6px 0 10px; }
.pkg { background: var(--panel-2); border: 2px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }
.pkg b { font-size: 22px; } .pkg span { color: var(--muted); font-size: 12px; } .pkg i { font-style: normal; font-weight: 600; color: var(--ok); margin-top: 4px; }
.pkg.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,93,252,.25); }
.qrbox { display: flex; gap: 14px; align-items: center; background: #fff; color: #111; border-radius: 12px; padding: 12px; margin: 10px 0; flex-wrap: wrap; }
.qrbox img { width: 200px; height: 200px; }
.qrbox .muted { color: #555; }
.pkgrow { display: grid; grid-template-columns: 1.4fr 1fr 1fr 34px; gap: 6px; margin-bottom: 6px; }
.bh { font-size: 14px; margin: 16px 0 8px; }

/* header */
#comfyReconnect { height: 26px; font-size: 12px; }
.status .dot.pulse { animation: dotpulse 1.4s infinite; }
@keyframes dotpulse { 50% { opacity: .35; } }

/* form bits */
.opt { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; min-width: 0; }
.opt > label { font-weight: 600; font-size: 13px; }
.opt .hint { margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.na { opacity: .38; pointer-events: none; }
.na > label::after { content: " — workflow นี้ไม่รองรับ"; font-weight: 400; font-size: 11px; color: var(--muted); }
.row.na > label::after { content: ""; }
.seed-row { display: flex; gap: 8px; align-items: center; }
.seed-row .input { flex: 1; }
.ptools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.ptools .chip { height: 28px; font-size: 12px; }
.cost { margin-top: 12px; font-size: 12px; color: var(--ok); background: rgba(52,211,153,.08); border: 1px solid rgba(52,211,153,.25); border-radius: 8px; padding: 6px 10px; display: inline-flex; gap: 6px; align-items: center; }
.cost.big { font-size: 15px; padding: 10px 14px; font-weight: 600; }
.card-inner { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.tabs button { font-size: 14px; }

/* reference images */
.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; border: 1px dashed var(--border); border-radius: 12px; padding: 8px; background: var(--panel-2); min-height: 100px; transition: .15s; }
.refs.drag { border-color: var(--accent); background: var(--panel-3); }
.refs .ref { aspect-ratio: 1; border-radius: 8px; overflow: hidden; position: relative; background: #000; }
.refs .ref img, .refs .ref video { width: 100%; height: 100%; object-fit: cover; display: block; }
.refs .ref .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.7); font-size: 13px; display: grid; place-items: center; }
.refs .ref .x:hover { background: var(--danger); }
.refs .ref .n { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.7); padding: 1px 6px; border-radius: 5px; }
.refs .add { aspect-ratio: 1; border-radius: 8px; border: 1px dashed var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: 11px; text-align: center; padding: 4px; }
.refs .add:hover { border-color: var(--accent); color: var(--text); }
.refs .add b { font-size: 20px; font-weight: 400; }
.refs.single { grid-template-columns: minmax(0, 200px); }
.refs.single .ref, .refs.single .add { aspect-ratio: 4 / 3; }

/* job results grid (AI Image / AI Video) */
.jobgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.jcard { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.jcard .jthumb { aspect-ratio: 1; background: #000 center / cover no-repeat; position: relative; display: grid; place-items: center; cursor: pointer; }
.jcard .jthumb img, .jcard .jthumb video { width: 100%; height: 100%; object-fit: contain; }
.jcard .jthumb .badge { position: absolute; left: 6px; top: 6px; }
.jcard .jbody { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.jcard .jp { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jcard .jacts { display: flex; gap: 4px; flex-wrap: wrap; }
.jcard .jacts button, .jcard .jacts a { height: 26px; padding: 0 8px; border-radius: 6px; background: var(--panel-3); font-size: 12px; display: inline-flex; align-items: center; text-decoration: none; }
.jcard .jacts button:hover, .jcard .jacts a:hover { filter: brightness(1.25); }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* status badges + progress */
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-3); color: var(--muted); white-space: nowrap; }
.badge.st-waiting { background: rgba(144,152,192,.18); }
.badge.st-paused { background: rgba(251,191,36,.16); color: var(--warn); }
.badge.st-uploading, .badge.st-queued { background: rgba(56,189,248,.16); color: #7dd3fc; }
.badge.st-running { background: rgba(109,93,252,.25); color: #c7d2fe; }
.badge.st-completed { background: rgba(52,211,153,.16); color: var(--ok); }
.badge.st-failed { background: rgba(248,113,113,.16); color: #fca5a5; }
.badge.st-cancelled { background: rgba(144,152,192,.12); color: var(--muted); }
.pbar { height: 8px; border-radius: 999px; background: var(--panel-3); overflow: hidden; flex: 1; min-width: 60px; }
.pbar i { display: block; height: 100%; background: var(--grad); width: 0; transition: width .4s; }
.qprog { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.qprog .ptext { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* queue list */
.qlist { display: flex; flex-direction: column; gap: 8px; }
.qrow { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.qrow.st-running { border-color: rgba(109,93,252,.6); }
.qthumb { width: 76px; height: 76px; border-radius: 8px; background: #000; overflow: hidden; display: grid; place-items: center; cursor: pointer; }
.qthumb img { width: 100%; height: 100%; object-fit: cover; }
.qmain { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.qprompt { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qmeta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qerr { font-size: 12px; color: #fca5a5; white-space: pre-wrap; max-height: 60px; overflow: auto; }
.qside { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.qtime { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.qacts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.qacts button, .qacts a { height: 28px; min-width: 28px; padding: 0 8px; border-radius: 6px; background: var(--panel-3); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.qacts button:hover, .qacts a:hover { filter: brightness(1.3); }
.qacts .danger:hover { background: rgba(248,113,113,.3); }

/* batch table */
.table-wrap { overflow-x: auto; }
.qtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.qtable th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.qtable td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.qtable td.p { max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qtable .tthumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #000; display: block; cursor: pointer; }
.qtable .pcell { min-width: 140px; }

/* story */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.asset { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 8px; position: relative; }
.asset.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(109,93,252,.25); }
.asset img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; cursor: pointer; }
.asset .an { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset .ad { font-size: 11px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.asset .ak { font-size: 10px; padding: 1px 6px; border-radius: 5px; background: var(--panel-3); display: inline-block; margin-bottom: 3px; }
.asset .ak.character { color: #f0abfc; } .asset .ak.product { color: #7dd3fc; } .asset .ak.environment { color: #86efac; }
.asset .use { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-top: 4px; cursor: pointer; }
.asset .aacts { position: absolute; top: 6px; right: 6px; display: none; gap: 2px; }
.asset:hover .aacts { display: flex; }
.asset .aacts button { width: 22px; height: 22px; border-radius: 5px; background: rgba(0,0,0,.6); font-size: 12px; }
.board { display: flex; flex-direction: column; gap: 12px; }
.shot { background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.shot-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.shot-head b { font-size: 13px; letter-spacing: .08em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; white-space: nowrap; }
.shot-head .shot-title { flex: 1; height: 32px; }
.shot-head .dur { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.shot-head .dur input { width: 56px; height: 32px; }
.shot-head .x { width: 32px; height: 32px; border-radius: 8px; color: var(--muted); }
.shot-head .x:hover { background: var(--panel-3); color: #fff; }
.shot-body { display: grid; grid-template-columns: 1fr 280px; gap: 12px; }
.shot-body textarea.box { min-height: 84px; }
.small-grid { grid-template-columns: repeat(3, 1fr); margin-top: 8px; }
.small-grid .opt { margin-bottom: 6px; }
.small-grid .opt label { font-size: 11px; color: var(--muted); font-weight: 500; }
.small-grid .input { height: 32px; font-size: 13px; }
.shot-refs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.shot-refs .chip { height: 26px; font-size: 12px; }
.shot-refs .chip img { width: 18px; height: 18px; border-radius: 4px; object-fit: cover; }
.shot-out { display: flex; flex-direction: column; gap: 8px; }
.shot-out .outs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shot-out .o { aspect-ratio: 1; border-radius: 8px; background: #000; position: relative; overflow: hidden; display: grid; place-items: center; cursor: pointer; }
.shot-out .o img, .shot-out .o video { width: 100%; height: 100%; object-fit: cover; }
.shot-out .o .badge { position: absolute; left: 4px; top: 4px; }
.shot-out .o .pbar { position: absolute; left: 6px; right: 6px; bottom: 6px; height: 5px; }

/* library */
.ex .acts .more { position: relative; }
.libmeta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.libmeta span { background: var(--panel-2); border-radius: 5px; padding: 0 6px; }
.menu { position: fixed; z-index: 80; background: var(--panel-3); border: 1px solid var(--border); border-radius: 10px; padding: 6px; min-width: 210px; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; flex-direction: column; }
.menu button, .menu a { text-align: left; padding: 7px 10px; border-radius: 6px; font-size: 13px; text-decoration: none; display: block; width: 100%; }
.menu button:hover, .menu a:hover { background: rgba(109,93,252,.2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.proj { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.proj:hover { border-color: var(--accent); }
.proj b { font-size: 15px; }

/* picker modal */
.pick-modal { position: fixed; inset: 0; background: rgba(0,0,0,.8); z-index: 75; display: none; place-items: center; padding: 16px; }
.pick-modal.show { display: grid; }
.pick-box { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: min(900px, 100%); max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
.pick-box .ph { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.pick-box .pg { padding: 14px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.pick-box .pg .pi { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #000; cursor: pointer; border: 2px solid transparent; }
.pick-box .pg .pi:hover { border-color: var(--accent); }
.pick-box .pg .pi img, .pick-box .pg .pi video { width: 100%; height: 100%; object-fit: cover; }

/* workflow manager */
.wf-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.wfgroup { margin-top: 12px; }
.wfgroup h3 { font-size: 11px; letter-spacing: .1em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.wfitem { padding: 10px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid transparent; cursor: pointer; margin-bottom: 6px; }
.wfitem:hover { border-color: var(--border); }
.wfitem.active { border-color: var(--accent); }
.wfitem b { font-size: 13px; }
.wfitem .tag2 { font-size: 10px; color: var(--pro); background: rgba(109,93,252,.15); padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.wfitem .keys { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.wfitem .keys span, .mapsum span { font-size: 10px; background: var(--panel-3); border-radius: 4px; padding: 0 5px; color: var(--muted); }
.mapsum { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 12px; }
.mapsum span { font-size: 11px; padding: 2px 7px; color: var(--text); }
.mapsum span i { font-style: normal; color: var(--muted); }
.nodes { display: flex; flex-direction: column; gap: 8px; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
.node { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.node.mapped { border-color: rgba(109,93,252,.5); }
.node .nh { display: flex; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.node .nh code { font-size: 11px; background: var(--panel-3); padding: 1px 6px; border-radius: 4px; color: var(--muted); }
.node .nh .ot { margin-left: auto; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.node .ni { display: grid; grid-template-columns: 150px 1fr 190px; gap: 8px; align-items: center; font-size: 12px; padding: 3px 0; border-top: 1px dashed rgba(255,255,255,.05); }
.node .ni .iv { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
.node .ni select { height: 28px; font-size: 12px; }
.node .ni select.set { border-color: var(--accent); color: #c7d2fe; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv > span:nth-child(odd) { color: var(--muted); }
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.models .mf { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.models .mf h3 { font-size: 13px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.models .mf div { font-size: 12px; color: var(--muted); word-break: break-all; padding: 2px 0; }

@media (max-width: 1200px) { .wf-layout { grid-template-columns: 1fr; } .shot-body { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .nav-label { display: none; }
  aside { width: auto; }
  .small-grid { grid-template-columns: 1fr 1fr; }
  .qrow { grid-template-columns: 60px 1fr; }
  .qrow .qside { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .qthumb { width: 60px; height: 60px; }
  .node .ni { grid-template-columns: 1fr; }
}
