:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #f1f1ee;
  --border: #e4e3de;
  --text: #1c1b19;
  --muted: #6d6b65;
  --accent: #ff6a1a;
  --accent-ink: #ffffff;
  --accent-soft: #fff0e6;
  --ok: #1f9d55;
  --warn: #c98a00;
  --err: #d64545;
  --info: #2f6fde;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Segoe UI Arabic", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --panel: #1a1a1a; --panel-2: #222221; --border: #2e2e2c; --text: #ecebe8;
    --muted: #9b9993; --accent-soft: #3a2214; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --panel: #1a1a1a; --panel-2: #222221; --border: #2e2e2c; --text: #ecebe8;
  --muted: #9b9993; --accent-soft: #3a2214; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; font-size: 15px; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), #ffb21a); display: grid; place-items: center; color: #fff; font-size: 13px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 17px; height: 17px; flex: none; }
.side .spacer { flex: 1; }
.gpu-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 12px; color: var(--muted); }
.gpu-card b { color: var(--text); font-weight: 600; }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.main { overflow: auto; min-width: 0; }
.page { padding: 26px 32px; max-width: 1280px; margin: 0 auto; }
.page.wide { max-width: none; padding: 0; height: 100%; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.done, .badge.ready { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.running, .badge.starting, .badge.downloading { color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent); }
.badge.queued, .badge.stopped, .badge.remote { color: var(--muted); }
.badge.error, .badge.not_downloaded { color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); }
.badge.cancelled { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.running::before, .badge.starting::before, .badge.downloading::before { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- playground ---------- */
.play { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
.drop { border: 2px dashed var(--border); border-radius: 14px; background: var(--panel); min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 30px; cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .icon { width: 54px; height: 54px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.drop .icon svg { width: 26px; height: 26px; }
.drop h3 { margin: 0; font-size: 17px; }
.files { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel-2); border-radius: 8px; text-align: left; }
.file-chip .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-opt { display: flex; justify-content: space-between; }
details.adv summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12.5px; margin: 6px 0 12px; }
.recent { margin-top: 26px; }

/* ---------- workspace (job view) ---------- */
.ws { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }
.ws-top { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.ws-top .title { font-weight: 600; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-progress { height: 3px; background: transparent; }
.ws-progress > i { display: block; height: 100%; background: var(--accent); transition: width .5s; }
.ws-body { display: grid; grid-template-columns: 92px minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.thumbs { border-right: 1px solid var(--border); overflow: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.thumb { position: relative; border: 2px solid transparent; border-radius: 6px; cursor: pointer; background: var(--panel-2); min-height: 60px; }
.thumb img { width: 100%; display: block; border-radius: 4px; }
.thumb.on { border-color: var(--accent); }
.thumb .n { position: absolute; bottom: 3px; right: 4px; font-size: 10.5px; font-weight: 700; background: var(--panel); border-radius: 4px; padding: 0 4px; }
.thumb .st { position: absolute; top: 3px; left: 3px; }
.viewer { overflow: auto; background: var(--panel-2); position: relative; border-right: 1px solid var(--border); }
.viewer-tools { position: sticky; top: 0; z-index: 3; display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: color-mix(in srgb, var(--panel-2) 85%, transparent); backdrop-filter: blur(6px); }
.stage { position: relative; margin: 6px auto 30px; box-shadow: 0 2px 14px rgba(0,0,0,.12); background: #fff; }
.stage img { display: block; width: 100%; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage rect { fill: transparent; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; transition: fill .1s; }
.stage rect.hl { stroke-width: 3; }
.result { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.result-tools { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.result-body { overflow: auto; flex: 1; padding: 22px 28px; }
.result-body pre.code { margin: 0; white-space: pre-wrap; word-break: break-word; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* rendered blocks */
.md { line-height: 1.65; overflow-wrap: anywhere; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--border); padding: 5px 9px; vertical-align: top; }
.md th { background: var(--panel-2); }
.md img { max-width: 100%; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.blk { position: relative; border-radius: 6px; padding-block: 4px; padding-inline: 10px 8px; margin: 0 -10px 6px; border-inline-start: 3px solid transparent; transition: background .1s; }
.blk:hover, .blk.hl { background: var(--accent-soft); }
.blk > .cat { position: absolute; top: 4px; inset-inline-end: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: 0; transition: opacity .1s; }
.blk:hover > .cat, .blk.hl > .cat { opacity: .75; }
.blk > :first-child { margin-top: 0; } .blk > :last-child { margin-bottom: 0; }
.blk.hf { opacity: .55; }
.blk canvas { max-width: 100%; border-radius: 6px; border: 1px solid var(--border); display: block; }

/* ---------- tables / lists ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--panel-2); }
.fname { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.minibar { width: 70px; height: 5px; background: var(--panel-2); border-radius: 99px; overflow: hidden; display: inline-block; vertical-align: middle; }
.minibar > i { display: block; height: 100%; background: var(--accent); }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters > * { width: auto; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* ---------- models ---------- */
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.mcard { display: flex; flex-direction: column; gap: 10px; }
.mcard .head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.mcard h3 { margin: 0; font-size: 15px; }
.mcard .desc { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.chip.star { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
pre.log { background: #0f0f0f; color: #d6d6d6; padding: 12px; border-radius: 8px; max-height: 360px; overflow: auto; font-size: 11.5px; white-space: pre-wrap; }

/* ---------- compare ---------- */
.cmp { display: grid; gap: 0; grid-auto-flow: column; grid-auto-columns: minmax(380px, 1fr); overflow-x: auto; height: calc(100vh - 62px); }
.cmp-col { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.cmp-col.doc { background: var(--panel-2); }
.cmp-head { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; background: inherit; }
.cmp-body { overflow: auto; padding: 16px 20px; flex: 1; }
.model-checks { display: flex; flex-direction: column; gap: 6px; }
.model-checks label { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.model-checks label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- misc ---------- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 50; }
.modal { width: min(460px, 92vw); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: 420px; }
.toast.err { background: var(--err); color: #fff; }
.menu { position: relative; display: inline-block; }
.menu .items { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.14); min-width: 200px; z-index: 20; padding: 4px; display: none; }
.menu.open .items { display: block; }
.menu .items button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu .items button:hover { background: var(--panel-2); }
.menu .items .sep { height: 1px; background: var(--border); margin: 4px 0; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .side { flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .side .brand, .side .spacer, .gpu-card { display: none; }
  .nav { display: flex; }
  .page { padding: 18px 16px; }
  .play, .grid2 { grid-template-columns: 1fr; }
  .ws { height: auto; }
  .ws-body { grid-template-columns: 1fr; }
  .thumbs { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .thumb { width: 64px; flex: none; }
  .viewer { max-height: 70vh; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 1fr; }
}

/* ---------- quality / review ---------- */
mark.rk { color: inherit; border-radius: 3px; padding: 0 1px; cursor: help; }
mark.r-hi { background: color-mix(in srgb, #d64545 26%, transparent); box-shadow: inset 0 -2px 0 #d64545; }
mark.r-mid { background: color-mix(in srgb, #e8a317 24%, transparent); box-shadow: inset 0 -2px 0 #e8a317; }
mark.r-ok { background: transparent; box-shadow: inset 0 -2px 0 color-mix(in srgb, #1f9d55 60%, transparent); }
.qbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; padding: 6px 8px; border-radius: 8px; background: var(--panel-2); font-size: 12.5px; }
.qbar .btn.sm { padding: 2px 8px; font-size: 12px; }
.blk .qbar { opacity: .55; transition: opacity .15s; }
.blk:hover .qbar, .blk.hl .qbar { opacity: 1; }
.qdot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.rv-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 18px; margin-bottom: 14px; align-items: start; }
.rv-img canvas { width: 100%; max-height: 520px; object-fit: contain; }
.rv-body { max-height: 420px; overflow: auto; }
@media (max-width: 980px) { .rv-card { grid-template-columns: 1fr; } }

table.vals td { padding: 6px 8px; font-size: 13px; }
table.vals td.mono { white-space: nowrap; }

.rstats { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.rstats:empty { display: none; }
.rstat { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; min-width: 260px; flex: 1; background: var(--panel, transparent); }
