:root {
  --bg: #0d0d0d;
  --center: #1c1c1c;
  --panel: #2b2b2b;
  --panel-2: #262626;
  --head: #333;
  --line: #161616;
  --text: #a6a6a6;
  --text-dim: #737373;
  --text-hi: #e6e6e6;
  --accent: #4f8fe6;
  --track: #121212;
  --lw: 252px;
  --rw: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 12px/1.35 "Segoe UI", system-ui, -apple-system, sans-serif; overflow: hidden; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #1e1e1e; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 5px; border: 2px solid #1e1e1e; }
::-webkit-scrollbar-thumb:hover { background: #555; }

#app { display: grid; grid-template-rows: 46px 1fr auto; height: 100vh; }

/* Top bar */
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: #0a0a0a; border-bottom: 1px solid #000; }
.brand { display: flex; align-items: baseline; gap: 8px; color: #8d8d8d; }
.brand .logo { font-size: 20px; color: #cfcfcf; transform: translateY(2px); }
.brand .brand-name { font-size: 16px; letter-spacing: .5px; color: #cfcfcf; font-weight: 300; }
.brand .brand-sub { font-size: 11px; color: #666; }
#modules { display: flex; align-items: center; gap: 4px; }
#modules button { background: none; border: 0; color: #666; font-size: 17px; font-weight: 300; cursor: pointer; padding: 4px 8px; }
#modules button:hover { color: #bbb; }
#modules button.active { color: #f0f0f0; }
#modules .sep { color: #3a3a3a; font-size: 16px; }

/* Workspace */
#workspace { display: grid; grid-template-columns: var(--lw) 1fr var(--rw); min-height: 0; }
.sidepanel { background: var(--panel); overflow-y: auto; overflow-x: hidden; min-height: 0; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.mod-panel { min-height: 100%; display: flex; flex-direction: column; }
#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--center); }
.view { flex: 1; min-height: 0; position: relative; }

/* Sections */
.section { border-bottom: 1px solid var(--line); }
.section-head { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 12px; background: var(--head); color: #cfcfcf; cursor: pointer; font-size: 12.5px; position: sticky; top: 0; z-index: 2; border-top: 1px solid #3b3b3b; }
.section-head .title { flex: 1; text-align: right; letter-spacing: .2px; }
.section-head .tri { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid #9a9a9a; transition: transform .15s; order: 3; margin-left: 8px; }
.section.closed .section-head .tri { transform: rotate(90deg); }
.section.closed .section-body { display: none; }
.section-body { padding: 8px 0 10px; }
.head-extra { display: flex; gap: 2px; order: -1; }
.head-extra button { background: none; border: 0; color: #9a9a9a; cursor: pointer; font-size: 15px; width: 22px; height: 22px; border-radius: 3px; line-height: 1; }
.head-extra button:hover { background: #444; color: #fff; }
#left .section-head .title { text-align: left; order: 1; }
#left .section-head .tri { order: 0; margin: 0 4px 0 0; }
#left .head-extra { order: 2; }

.subhead { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 4px; color: #8b8b8b; font-size: 11.5px; }
.subhead .line { flex: 1; height: 1px; background: #3a3a3a; margin: 0 8px; }

/* Sliders */
.srow { display: grid; grid-template-columns: 96px 1fr 46px; align-items: center; gap: 8px; height: 23px; padding: 0 12px; }
.srow label { text-align: right; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.srow.changed label { color: #d6d6d6; }
.srow.disabled { opacity: .35; pointer-events: none; }
.strack { position: relative; height: 14px; cursor: pointer; }
.strack::before { content: ""; position: absolute; left: 0; right: 0; top: 6px; height: 2px; background: var(--track); border-radius: 1px; box-shadow: 0 1px 0 #3a3a3a; }
.strack.grad::before { height: 3px; top: 5.5px; background: inherit; background-image: inherit; opacity: .9; box-shadow: none; }
.strack.grad { background-image: none; }
.sfill { position: absolute; top: 6px; height: 2px; background: #6a6a6a; pointer-events: none; }
.strack.grad .sfill { display: none; }
.sthumb { position: absolute; top: 2px; width: 9px; height: 10px; margin-left: -4.5px; background: #c9c9c9; clip-path: polygon(50% 100%, 0 30%, 0 0, 100% 0, 100% 30%); pointer-events: none; }
.srow:hover .sthumb { background: #fff; }
.sval { width: 46px; background: transparent; border: 1px solid transparent; color: #cfcfcf; text-align: right; padding: 1px 3px; border-radius: 2px; font-size: 11.5px; }
.sval:hover { border-color: #3d3d3d; }
.sval:focus { outline: none; background: #e8e8e8; color: #111; }

/* Buttons & form controls */
.btn { background: #3c3c3c; border: 1px solid #1b1b1b; color: #cfcfcf; padding: 4px 10px; border-radius: 3px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #484848; color: #fff; }
.btn:active { background: #2f2f2f; }
.btn.primary { background: #2f6fca; border-color: #1d4f99; color: #fff; }
.btn.primary:hover { background: #3a7ddb; }
.btn.sm { padding: 2px 8px; font-size: 11px; }
.btn.on { background: #5a5a5a; color: #fff; }
.btn:disabled { opacity: .4; pointer-events: none; }
.iconbtn { background: none; border: 1px solid transparent; color: #a8a8a8; width: 28px; height: 26px; border-radius: 3px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.iconbtn:hover { background: #3c3c3c; color: #fff; }
.iconbtn.on { background: #4a4a4a; border-color: #5c5c5c; color: #fff; }
.iconbtn svg { width: 17px; height: 17px; }
.seg { display: inline-flex; border: 1px solid #1b1b1b; border-radius: 3px; overflow: hidden; }
.seg button { background: #383838; border: 0; padding: 3px 10px; color: #aaa; cursor: pointer; border-right: 1px solid #1b1b1b; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: #626262; color: #fff; }
.seg button:hover:not(.on) { background: #444; }
select, input.txt { background: #1e1e1e; color: #ddd; border: 1px solid #111; border-radius: 3px; padding: 3px 6px; }
select:focus, input.txt:focus { outline: 1px solid #4f8fe6; }
.row { display: flex; align-items: center; gap: 8px; padding: 3px 12px; }
.row.right { justify-content: flex-end; }
.row .lbl { width: 96px; text-align: right; flex: none; }
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; color: #aaa; }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 2px 0; }

/* Library grid */
#grid { position: absolute; inset: 0; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cell, 170px), 1fr)); gap: 4px; padding: 8px; align-content: start; }
.cell { position: relative; background: #3d3d3d; border: 1px solid #232323; border-radius: 2px; aspect-ratio: 1 / 1.08; display: flex; flex-direction: column; padding: 4px 6px 4px; cursor: default; }
.cell:hover { background: #474747; }
.cell.selected { background: #6e6e6e; border-color: #8d8d8d; }
.cell.current { background: #8a8a8a; }
.cell .idx { position: absolute; top: 2px; left: 6px; font-size: 22px; font-weight: 700; color: rgba(255,255,255,.09); pointer-events: none; }
.cell .tb { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 14px 4px 4px; }
.cell img { max-width: 100%; max-height: 100%; box-shadow: 0 2px 6px rgba(0,0,0,.55); background: #222; }
.cell .meta { display: flex; align-items: center; justify-content: space-between; height: 18px; font-size: 11px; color: #ddd; }
.cell .stars { letter-spacing: 1px; color: #e6e6e6; font-size: 11px; }
.cell .stars .off { color: rgba(255,255,255,.18); }
.cell .flag { position: absolute; top: 4px; right: 6px; font-size: 12px; }
.cell .badge { position: absolute; bottom: 24px; right: 8px; font-size: 10px; background: rgba(0,0,0,.55); color: #ddd; padding: 0 4px; border-radius: 2px; }
.cell.rejected img { opacity: .35; }
.cell .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; color: #222; font-size: 10.5px; }
.cell.selected .name, .cell.current .name { color: #111; }
#empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #777; text-align: center; padding: 20px; }
#empty-state h2 { font-weight: 300; color: #bbb; font-size: 24px; margin: 0; }
#empty-state p { margin: 0; max-width: 460px; line-height: 1.6; }

/* Develop view */
#viewport { position: absolute; inset: 0; overflow: hidden; background: var(--center); }
#viewport.zoomed { overflow: auto; cursor: grab; }
#viewport.zoomed.panning { cursor: grabbing; }
#stage-wrap { min-width: 100%; min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 0; }
#viewport:not(.zoomed) #stage-wrap { padding: 0; }
#stage { position: relative; flex: none; box-shadow: 0 0 0 1px #000, 0 6px 24px rgba(0,0,0,.45); }
#main-canvas { display: block; width: 100%; height: 100%; }
#overlay { position: absolute; inset: 0; }
#viewport.tool-wb #overlay { cursor: crosshair; }
#viewport.tool-mask #overlay { cursor: crosshair; }
#ba-labels { position: absolute; top: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 0; pointer-events: none; }
#ba-labels span { background: rgba(0,0,0,.6); color: #ddd; padding: 2px 10px; border-radius: 2px; font-size: 11px; margin: 0 6px; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 13px; pointer-events: none; }
.split-line { position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: rgba(255,255,255,.8); pointer-events: none; }

/* Crop overlay */
.crop-box { position: absolute; box-shadow: 0 0 0 9999px rgba(0,0,0,.6); outline: 1px solid rgba(255,255,255,.9); cursor: move; }
#overlay.crop-wrap { overflow: hidden; cursor: alias; }
.crop-box .gl { position: absolute; background: rgba(255,255,255,.35); pointer-events: none; }
.crop-box .gl.v { top: 0; bottom: 0; width: 1px; }
.crop-box .gl.h { left: 0; right: 0; height: 1px; }
.ch { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid #fff; background: rgba(0,0,0,.3); }
.ch-nw { left: 0; top: 0; cursor: nwse-resize; } .ch-ne { left: 100%; top: 0; cursor: nesw-resize; }
.ch-sw { left: 0; top: 100%; cursor: nesw-resize; } .ch-se { left: 100%; top: 100%; cursor: nwse-resize; }
.ch-n { left: 50%; top: 0; cursor: ns-resize; } .ch-s { left: 50%; top: 100%; cursor: ns-resize; }
.ch-w { left: 0; top: 50%; cursor: ew-resize; } .ch-e { left: 100%; top: 50%; cursor: ew-resize; }

/* Mask overlay */
.mask-svg { position: absolute; inset: 0; overflow: visible; }
.mask-svg .pin { fill: #888; stroke: #fff; stroke-width: 2; cursor: pointer; }
.mask-svg .pin.sel { fill: #4f8fe6; }
.mask-svg .hdl { fill: #fff; stroke: #222; stroke-width: 1; cursor: pointer; }
.mask-svg .geo { fill: none; stroke: #fff; stroke-width: 1.2; pointer-events: none; filter: drop-shadow(0 0 1px #000); }
.mask-svg .geo.dash { stroke-dasharray: 4 4; opacity: .8; }
.mask-svg .bcur { fill: none; stroke: #fff; stroke-width: 1; pointer-events: none; filter: drop-shadow(0 0 1px #000); }

/* Toolbars */
.toolbar { height: 36px; background: #2b2b2b; border-top: 1px solid #111; display: flex; align-items: center; gap: 6px; padding: 0 10px; flex: none; }
.toolbar .spacer { flex: 1; }
.toolbar .tsep { width: 1px; height: 18px; background: #444; margin: 0 4px; }
.toolbar input[type=range] { width: 110px; accent-color: #bbb; }
.toolbar .lbl { color: #888; }
.stars-ui { display: inline-flex; gap: 1px; cursor: pointer; font-size: 14px; }
.stars-ui span { color: #4a4a4a; }
.stars-ui span.on { color: #ddd; }
.stars-ui span:hover { color: #fff; }
.flags-ui { display: inline-flex; gap: 2px; }

/* Filmstrip */
#filmstrip-wrap { background: #191919; border-top: 1px solid #000; }
#filmstrip-bar { height: 24px; display: flex; align-items: center; gap: 10px; padding: 0 12px; color: #8a8a8a; font-size: 11.5px; background: #222; border-bottom: 1px solid #111; }
#filmstrip-bar b { color: #ccc; font-weight: 400; }
#filmstrip { height: 82px; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; padding: 6px 8px; }
#filmstrip.collapsed { display: none; }
.fs-item { flex: none; height: 68px; width: 76px; background: #383838; border: 1px solid #222; display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.fs-item img { max-width: 70px; max-height: 60px; }
.fs-item.selected { background: #5e5e5e; }
.fs-item.current { background: #9a9a9a; }
.fs-item .fst { position: absolute; bottom: 0; left: 2px; font-size: 9px; color: #eee; text-shadow: 0 0 2px #000; }

/* Left panels */
.list-item { display: flex; align-items: center; gap: 8px; padding: 3px 12px 3px 22px; cursor: pointer; color: #b5b5b5; }
.list-item:hover { background: #363636; color: #eee; }
.list-item.active { background: #4a4a4a; color: #fff; }
.list-item .count { margin-left: auto; color: #777; font-size: 11px; }
.list-item.folder { padding-left: 12px; color: #c9c9c9; }
.list-item .ftri { width: 0; height: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 5px solid #8a8a8a; transition: transform .12s; }
.list-item.open .ftri { transform: rotate(90deg); }
.preset-item { padding-left: 30px; }
.history-item { padding-left: 12px; justify-content: space-between; }
.history-item.future { color: #666; }
.panel-buttons { display: flex; gap: 6px; padding: 10px 12px; margin-top: auto; border-top: 1px solid var(--line); }
.panel-buttons .btn { flex: 1; }
#navigator { display: block; width: 100%; background: #1a1a1a; cursor: pointer; }
.nav-wrap { padding: 0; position: relative; }
.searchbox { margin: 4px 12px 6px; width: calc(100% - 24px); }

/* Histogram */
.histo-wrap { position: relative; padding: 8px 10px 4px; background: #222; }
.histo-wrap canvas { display: block; width: 100%; height: 110px; background: #1a1a1a; border: 1px solid #111; }
.clip-ind { position: absolute; top: 12px; width: 0; height: 0; border: 6px solid transparent; cursor: pointer; opacity: .5; }
.clip-ind.l { left: 14px; border-top-color: #888; border-left-color: #888; }
.clip-ind.r { right: 14px; border-top-color: #888; border-right-color: #888; }
.clip-ind.hot.l { border-top-color: #4f8fe6; border-left-color: #4f8fe6; opacity: 1; }
.clip-ind.hot.r { border-top-color: #e64f4f; border-right-color: #e64f4f; opacity: 1; }
.clip-ind.active { opacity: 1; outline: 1px solid #fff; }
.histo-info { display: flex; justify-content: space-between; color: #888; font-size: 11px; padding: 4px 2px 2px; min-height: 18px; }
.toolstrip { display: flex; justify-content: center; gap: 4px; padding: 6px; background: #262626; border-bottom: 1px solid var(--line); }
.drawer { background: #242424; border-bottom: 1px solid var(--line); padding: 6px 0 10px; }
.drawer-title { padding: 4px 12px 6px; color: #ddd; font-size: 12.5px; display: flex; justify-content: space-between; align-items: center; }

/* Curve */
.curve-wrap { padding: 4px 12px; }
.curve-wrap canvas { display: block; width: 100%; aspect-ratio: 1; background: #1c1c1c; border: 1px solid #111; cursor: crosshair; touch-action: none; }
.curve-ch { display: flex; gap: 4px; justify-content: center; padding: 2px 12px 6px; }
.curve-ch button { width: 26px; height: 22px; border: 1px solid #1b1b1b; background: #383838; border-radius: 11px; cursor: pointer; color: #bbb; font-size: 10px; }
.curve-ch button.on { outline: 2px solid #ddd; }

/* Wheels */
.wheels { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 4px; padding: 4px 8px; }
.wheel-box { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.wheel-box .wl { color: #aaa; font-size: 11px; }
.wheel-box canvas { cursor: crosshair; touch-action: none; }
.wheel-box .wv { font-size: 10.5px; color: #777; height: 14px; }
.wheel-box .srow { grid-template-columns: 1fr 34px; padding: 0 2px; width: 100%; gap: 4px; }
.wheel-box .srow label { display: none; }
.wheel-box .sval { width: 34px; }

/* Tabs */
.tabs { display: flex; gap: 0; padding: 2px 12px 8px; }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; color: #8a8a8a; cursor: pointer; padding: 4px 2px; }
.tabs button.on { color: #eee; border-bottom-color: #bbb; }

/* Masks */
.mask-create { display: flex; gap: 4px; padding: 2px 12px 8px; flex-wrap: wrap; }
.mask-create .btn { flex: 1; }
.mask-list { margin: 0 12px 8px; background: #1d1d1d; border: 1px solid #111; border-radius: 3px; min-height: 28px; }
.mask-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; cursor: pointer; border-bottom: 1px solid #262626; }
.mask-row:last-child { border-bottom: 0; }
.mask-row.sel { background: #3a4a63; color: #fff; }
.mask-row .mn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mask-row .iconbtn { width: 22px; height: 20px; }
.mask-row .iconbtn svg { width: 14px; height: 14px; }
.mask-empty { padding: 8px; color: #666; text-align: center; font-size: 11px; }
.hint { color: #777; font-size: 11px; padding: 2px 12px 6px; line-height: 1.45; }

/* Right panel library */
.meta-table { width: 100%; border-collapse: collapse; }
.meta-table td { padding: 2px 12px; vertical-align: top; }
.meta-table td:first-child { color: #7c7c7c; text-align: right; width: 42%; white-space: nowrap; }
.meta-table td:last-child { color: #cfcfcf; word-break: break-word; user-select: text; }
.qd-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 6px; padding: 2px 12px; }
.qd-row > span { text-align: right; }
.qd-btns { display: flex; gap: 2px; }
.qd-btns button { flex: 1; background: #383838; border: 1px solid #1b1b1b; color: #bbb; cursor: pointer; padding: 2px 0; font-size: 11px; border-radius: 2px; }
.qd-btns button:hover { background: #4a4a4a; color: #fff; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #2e2e2e; border: 1px solid #111; box-shadow: 0 10px 40px rgba(0,0,0,.6); border-radius: 4px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal-title { padding: 12px 16px; font-size: 14px; color: #eee; border-bottom: 1px solid #1d1d1d; }
.modal-body { padding: 14px 16px; overflow: auto; color: #bbb; user-select: text; }
.modal-body p { margin: 0 0 8px; line-height: 1.5; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid #1d1d1d; }
.modal-btns button { background: #444; border: 1px solid #1b1b1b; color: #ddd; padding: 5px 14px; border-radius: 3px; cursor: pointer; }
.modal-btns button.primary { background: #2f6fca; color: #fff; border-color: #1d4f99; }
.modal-btns button:hover { filter: brightness(1.15); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }
.exp-sec { border: 1px solid #222; border-radius: 3px; padding: 8px 10px; margin-bottom: 10px; background: #292929; }
.exp-sec h4 { margin: 0 0 8px; font-weight: 400; color: #ddd; font-size: 12.5px; }
.exp-line { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.exp-line > label:first-child { width: 120px; text-align: right; color: #999; }
.progress { height: 6px; background: #1a1a1a; border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; background: #4f8fe6; width: 0; transition: width .2s; }

/* Context menu */
.ctxmenu { position: fixed; background: #2f2f2f; border: 1px solid #111; box-shadow: 0 6px 20px rgba(0,0,0,.5); padding: 4px 0; min-width: 190px; z-index: 200; border-radius: 3px; }
.ctxmenu .item { padding: 5px 16px; color: #ccc; cursor: pointer; position: relative; display: flex; justify-content: space-between; gap: 16px; }
.ctxmenu .item:hover { background: #2f6fca; color: #fff; }
.ctxmenu .item.disabled { color: #666; pointer-events: none; }
.ctxmenu .sep { height: 1px; background: #444; margin: 4px 0; }
.ctxmenu .sub { display: none; position: absolute; left: 100%; top: -5px; }
.ctxmenu .item:hover > .sub { display: block; }

/* Toasts / dropzone / import overlay */
#toasts { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 300; align-items: center; pointer-events: none; }
.toast { background: rgba(30,30,30,.96); border: 1px solid #000; color: #ddd; padding: 8px 16px; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.5); transition: opacity .3s; max-width: 560px; }
.toast.error { border-color: #a33; color: #fbb; }
.toast.ok { border-color: #2c6a2c; }
.toast.out { opacity: 0; }
#dropzone { position: fixed; inset: 12px; border: 3px dashed #4f8fe6; background: rgba(20,30,50,.75); color: #fff; font-size: 22px; font-weight: 300; display: flex; align-items: center; justify-content: center; z-index: 400; pointer-events: none; border-radius: 8px; }
#busy { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 350; display: flex; align-items: center; justify-content: center; }
#busy .box { background: #2e2e2e; border: 1px solid #111; padding: 18px 24px; border-radius: 4px; min-width: 320px; color: #ddd; }
#fatal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #111; color: #ddd; z-index: 999; text-align: center; padding: 40px; font-size: 15px; }
