/* 3D viewer, 3D batch, and app-wide small features (gallery stars/search, compare slider, drop overlay, …) */

/* ---------- 3D viewer */
.v3d { display: flex; flex-direction: column; gap: 8px; width: 100%; min-width: 0; }
.v3d-main { display: flex; gap: 8px; min-height: 0; }
.v3d-stage { position: relative; flex: 1; min-width: 0; height: min(68vh, 640px); min-height: 280px; border-radius: var(--r-s); overflow: hidden;
  background: #15181f; touch-action: none; }
.v3d.compact .v3d-stage { height: 300px; min-height: 220px; }
.v3d-stage.bg-dark { background: #15181f; } .v3d-stage.bg-grey { background: #6b7080; } .v3d-stage.bg-light { background: #e9ecf2; }
.v3d-stage.bg-clear { background-color: #888;
  background-image: linear-gradient(45deg, #9a9a9a 25%, transparent 25%, transparent 75%, #9a9a9a 75%), linear-gradient(45deg, #9a9a9a 25%, transparent 25%, transparent 75%, #9a9a9a 75%);
  background-size: 20px 20px; background-position: 0 0, 10px 10px; }
.v3d-canvas { display: block; width: 100%; height: 100%; outline: none; cursor: grab; }
.v3d-canvas:active { cursor: grabbing; }
.v3d-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.v3d-load { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #cfd5e2; background: rgba(13,15,20,.55); text-align: center; padding: 20px; }
.v3d-load .bar { width: min(240px, 70%); }
.v3d-load.err { color: #ffb3bf; } .v3d-load.err .spinner, .v3d-load.err .bar { display: none; }
.v3d-stats { position: absolute; left: 8px; bottom: 8px; display: grid; grid-template-columns: auto auto; gap: 1px 10px; font-size: .76rem;
  background: rgba(10,12,18,.62); color: #e8eaf0; padding: 6px 9px; border-radius: 8px; pointer-events: none; backdrop-filter: blur(4px); }
.v3d-stats:empty { display: none; }
.v3d-stats > div { display: contents; }
.v3d-stats span { opacity: .72; } .v3d-stats b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.v3d-hint { position: absolute; right: 8px; top: 8px; font-size: .74rem; color: #e8eaf0; background: rgba(10,12,18,.5); padding: 3px 8px; border-radius: 6px;
  pointer-events: none; transition: opacity .4s; }
.v3d-hint.gone { opacity: 0; }
.v3d-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.v3d-bar .btn.small { padding: 4px 8px; }
.v3d-bar .btn.on { background: var(--accent); color: #fff; }
.v3d-glyph { display: inline-flex; width: 18px; justify-content: center; font-size: 1rem; line-height: 1; }
.v3d-seg button { padding: 4px 10px; font-size: .84rem; }
.v3d-sp { flex: 1; }
.v3d-src { flex: 0 0 32%; max-width: 360px; background: var(--panel-2); border-radius: var(--r-s); padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.v3d-src img { width: 100%; flex: 1; min-height: 0; object-fit: contain; border-radius: 6px; background: var(--mask-bg); }
.v3d-src-cap { font-size: .78rem; }
.v3d:fullscreen { background: var(--bg); padding: 10px; }
.v3d:fullscreen .v3d-main { flex: 1; } .v3d:fullscreen .v3d-stage { height: auto; }
.v3d.compact .v3d-lbl { display: none; }
.viewer.is-mesh { grid-template-columns: minmax(0, 1fr) 300px; }
.viewer.is-mesh .viewer-media { display: block; background: none; min-height: 0; }
.latest3d { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.latest3d-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.latest3d .v3d-src { flex-basis: 30%; }
.head-link { margin-left: auto; align-self: center; }
.task-head { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }

/* standalone viewer page */
.v3d-page .v3d-open { margin: 0 0 8px; }
.v3d-path, .b3-path { flex: 1; min-width: 220px; }
.v3d-page-title { font-size: .82rem; margin-bottom: 8px; word-break: break-all; }
.v3d-page-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; align-items: start; }
.v3d-page-host { min-width: 0; }
.v3d-empty { border: 2px dashed var(--line-2); border-radius: var(--r); min-height: 340px; justify-content: center; }
.v3d-browse { padding: 12px; max-height: 76vh; overflow: auto; }
.v3d-browse h3 { font-size: .92rem; margin: 4px 0 6px; }
.v3d-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.v3d-li { display: flex; gap: 6px; align-items: center; text-align: left; border: none; background: transparent; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: .86rem; min-width: 0; }
.v3d-li span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v3d-li:hover { background: var(--hover); }
.v3d-cwd { word-break: break-all; padding: 2px 6px 4px; }

/* mesh thumbnails */
.mthumb.m3d.has-img { display: block; padding: 0; }
.mthumb.m3d img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mthumb.m3d.rendering::after { content: ''; position: absolute; inset: auto 8px 8px auto; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.m3d-badge { position: absolute; left: 6px; top: 6px; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--accent); color: #fff; }

/* ---------- gallery extras */
.g-tools { margin: -4px 0 12px; }
.g-search { flex: 1; min-width: 180px; max-width: 420px; }
.g-thumb { position: relative; }
.fav-btn { position: absolute; right: 6px; top: 6px; width: 30px; height: 30px; border-radius: 50%; border: none; display: grid; place-items: center; cursor: pointer;
  background: rgba(10,12,18,.5); color: #fff; opacity: 0; transition: opacity .15s; }
.fav-btn .ico { width: 16px; height: 16px; }
.fav-btn.on { opacity: 1; color: #ffc940; }
.g-thumb:hover .fav-btn, .fav-btn:focus-visible { opacity: 1; }
.fav-btn.big { position: static; opacity: 1; background: var(--hover); color: var(--muted); width: 34px; height: 34px; }
.fav-btn.big.on { color: #f0a42b; }
.g-dl { position: absolute; right: 6px; bottom: 6px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(10,12,18,.5); color: #fff; opacity: 0; transition: opacity .15s; }
.g-thumb:hover .g-dl { opacity: 1; }
@media (hover: none) { .fav-btn, .g-dl { opacity: .85; } }
.fav-filter.on { background: rgba(240,164,43,.18); color: var(--warn); border-color: transparent; }
.set-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: .84rem; background: var(--panel-2); border-radius: 8px; padding: 6px 10px; }
.set-grid span:nth-child(2n) { text-align: right; word-break: break-word; }

/* before/after slider */
.viewer-media { position: relative; }
.cmp-toggle { position: absolute; left: 10px; top: 10px; z-index: 2; background: rgba(10,12,18,.6); color: #fff; border-color: transparent; }
.cmp-toggle.on { background: var(--accent); }
.cmp { position: relative; display: inline-block; max-width: 100%; user-select: none; touch-action: none; cursor: ew-resize; line-height: 0; }
.cmp > img { max-width: 100%; max-height: 74vh; display: block; }
.cmp-clip { position: absolute; left: 0; top: 0; bottom: 0; overflow: hidden; }
.cmp-clip img { display: block; max-width: none; max-height: none; object-fit: fill; }
.cmp-handle { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 6px rgba(0,0,0,.6); pointer-events: none; }
.cmp-handle span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; background: #fff; color: #222;
  display: grid; place-items: center; font-size: 1rem; line-height: 1; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.cmp-tag { position: absolute; top: 10px; font-size: .74rem; padding: 2px 8px; border-radius: 6px; background: rgba(10,12,18,.6); color: #fff; line-height: 1.4; pointer-events: none; }
.cmp-tag.l { left: 10px; top: 48px; } .cmp-tag.r { right: 10px; }

/* ---------- 3D batch */
.b3 { display: flex; flex-direction: column; gap: 16px; }
.b3-src { display: flex; flex-direction: column; gap: 12px; }
.b3-folder { display: flex; flex-direction: column; gap: 6px; }
.b3-opts { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.b3-opts .ctl { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.b3-opts input[type=number] { width: 220px; max-width: 100%; }
.b3-drop { min-height: 110px; }
.b3-upload { display: flex; flex-direction: column; gap: 10px; }
.b3-up-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.b3-up { position: relative; border-radius: 8px; overflow: hidden; background: var(--mask-bg); aspect-ratio: 1; cursor: pointer; outline: 2px solid transparent; }
.b3-up img { width: 100%; height: 100%; object-fit: cover; display: block; }
.b3-up.sel { outline-color: var(--accent); }
.b3-up.grouped { outline: 2px dashed var(--accent-2); }
.b3-up.sel.grouped { outline-style: solid; outline-color: var(--accent); }
.b3-up-name { position: absolute; left: 0; right: 0; bottom: 0; font-size: .7rem; padding: 2px 5px; background: rgba(10,12,18,.65); color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b3-up-x { position: absolute; right: 3px; top: 3px; width: 22px; height: 22px; font-size: .7rem; background: rgba(10,12,18,.6); color: #fff; border-radius: 50%; }
.b3-plan .card { display: flex; flex-direction: column; gap: 10px; }
.b3-plan-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.b3-plan-head h2 { margin: 0; flex: 1; min-width: 200px; }
.b3-actions select, .b3-actions input { max-width: 180px; }
.b3-num { width: 110px; }
.btn.disabled { opacity: .5; pointer-events: none; }
.chip.st-done { border-color: var(--ok); } .chip.st-error { border-color: var(--err); } .chip.st-running, .chip.st-finalizing { border-color: var(--accent); }
.b3-table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--r-s); }
.b3-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.b3-table th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); z-index: 1; white-space: nowrap; }
.b3-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.b3-table tr.off td { opacity: .45; }
.b3-table tr.off td:first-child { opacity: 1; }
.b3-table select { max-width: 170px; }
.b3-name { width: 100%; min-width: 150px; }
.b3-name-t { font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b3-prompt { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b3-imgs { display: flex; gap: 4px; align-items: center; }
.b3-imgs img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--mask-bg); cursor: zoom-in; }
.b3-big { max-width: 100%; max-height: 70vh; display: block; margin: auto; }
.b3-st { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; min-width: 120px; }
.b3-st .bar { flex-basis: 100%; }
.b3-st .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.b3-st.st-running .status-dot, .b3-st.st-starting_services .status-dot, .b3-st.st-finalizing .status-dot { background: var(--accent); animation: pulse 1.2s infinite; }
.b3-st.st-done .status-dot { background: var(--ok); } .b3-st.st-error .status-dot { background: var(--err); } .b3-st.st-queued .status-dot { background: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
.b3-step { flex-basis: 100%; font-size: .74rem; }
.b3-row-acts { display: flex; gap: 4px; }
.b3-recent-list { display: flex; flex-wrap: wrap; gap: 6px; }
.b3-viewer { display: flex; flex-direction: column; gap: 8px; }
.b3-browse { max-height: 55vh; overflow: auto; }

/* ---------- prompt history */
.prompt-wrap { position: relative; }
.hist-pop { position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 20; width: min(520px, 100%); max-height: 300px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-s); box-shadow: var(--shadow); padding: 4px; }
.hist-item { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 7px 9px; border-radius: 6px; cursor: pointer;
  font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item:hover { background: var(--hover); }

/* ---------- drop overlay, shortcuts, memory warning, bell */
.drop-overlay { position: fixed; inset: 0; z-index: 80; display: none; place-items: center; background: rgba(47,163,123,.14);
  border: 3px dashed var(--accent); pointer-events: none; }
.drop-overlay > div { display: flex; flex-direction: column; align-items: center; gap: 8px; background: var(--panel); padding: 18px 26px; border-radius: var(--r); box-shadow: var(--shadow); }
body.dragging-files .drop-overlay { display: grid; }
.kb-help { display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; font-size: .9rem; }
.kb-row .kbd { justify-self: start; }
.mem-warn p { margin: 0 0 10px; }
#notifyBtn.on-soft { color: var(--accent); }

@media (max-width: 900px) {
  .viewer.is-mesh { grid-template-columns: 1fr; }
  .v3d-page-grid { grid-template-columns: 1fr; }
  .v3d-main { flex-direction: column; }
  .v3d-src { max-width: none; flex-basis: auto; flex-direction: row; align-items: center; }
  .v3d-src img { width: 96px; height: 96px; flex: none; }
  .v3d-stage { height: 56vh; }
  .v3d-lbl { display: none; }
}
@media (max-width: 560px) {
  .v3d-stage { height: 50vh; min-height: 240px; }
  .v3d-stats { font-size: .7rem; }
  .v3d-hint { display: none; }
  .kb-row { grid-template-columns: 110px 1fr; }
  .head-link { margin-left: 0; }
  .b3-opts input[type=number] { width: 100%; }
  .b3-opts .ctl { flex: 1 1 100%; }
}
