:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cdd5e0;
  --text: #17202e;
  --text-2: #5b6779;
  --primary: #2f6fed;
  --primary-hover: #1f5bd6;
  --primary-soft: #eaf1ff;
  --violet: #7c4dff;
  --violet-soft: #f1ecff;
  --success: #138a52;
  --success-soft: #e6f6ee;
  --warn: #a35d00;
  --warn-soft: #fff4e0;
  --danger: #c4372f;
  --danger-soft: #fdecea;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; letter-spacing: -.015em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1440px; margin: 0 auto; padding: 18px 24px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; text-decoration: none; color: inherit; }
.brand > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.tagline { color: var(--text-2); font-size: 13.5px; }
.logo { width: 38px; height: 38px; border-radius: 10px; flex: none; position: relative; background: var(--primary); }
.logo::before, .logo::after { content: ""; position: absolute; border-radius: 50%; inset: 0; margin: auto; }
.logo::before { width: 18px; height: 18px; border: 3px solid #fff; }
.logo::after { width: 6px; height: 6px; background: #fff; }
.top-pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 4px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.pill.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-muted { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.pill-ok { background: var(--success-soft); color: var(--success); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--danger-soft); color: var(--danger); }
.pill-info { background: var(--primary-soft); color: var(--primary); }
.pill-violet { background: var(--violet-soft); color: var(--violet); }

/* ---------- page / cards ---------- */
.page { max-width: 1440px; margin: 0 auto; padding: 14px 24px 56px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.page-head { display: flex; align-items: center; gap: 14px; margin: 8px 0 18px; flex-wrap: wrap; }
.page-head .spacer { min-width: 8px; }
.crumb { color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 550; }
.crumb:hover { color: var(--primary); }
.title-btn { background: none; border: 0; padding: 2px 6px; margin-left: -6px; border-radius: 8px; cursor: text; text-align: left; }
.title-btn:hover { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; transition: .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 46px; padding: 0 20px; font-size: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: #dbe7ff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible, .task:focus-within, .model:focus-within {
  outline: 3px solid var(--primary-soft); outline-offset: 1px;
}
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px; flex: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* ---------- projects home ---------- */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; overflow: hidden; text-decoration: none; color: inherit; transition: .15s; position: relative; }
.project-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.mosaic { aspect-ratio: 16/9; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; background: #e8edf4; }
.mosaic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mosaic.n1 img { grid-column: span 2; grid-row: span 2; }
.mosaic.n2 img { grid-row: span 2; }
.mosaic.n3 img:first-child { grid-row: span 2; }
.mosaic.empty { display: grid; place-items: center; grid-template-columns: 1fr; color: var(--text-2); font-size: 13px; }
.project-meta { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.project-meta strong { font-size: 15.5px; }
.new-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 210px;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: transparent; cursor: pointer; color: var(--text-2);
}
.new-card:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.new-card .plus { font-size: 34px; line-height: 1; }
.hero { padding: 34px 28px; display: flex; gap: 24px; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; }
.hero-steps { display: flex; gap: 22px; flex-wrap: wrap; }
.hero-step { display: flex; gap: 10px; align-items: flex-start; max-width: 240px; }
.hero-step b { display: block; }
.step-num {
  width: 24px; height: 24px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700; background: var(--primary-soft); color: var(--primary);
}

/* ---------- project workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }
.media-panel { padding: 16px; }
.annotate { padding: 18px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }

.dropzone {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); transition: .15s;
}
.dropzone strong { color: var(--text); display: block; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); outline: none; }
.dropzone.big { flex-direction: column; text-align: center; padding: 44px 16px; }
.uploads { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.upload-row { font-size: 13px; display: grid; grid-template-columns: minmax(0, 1fr) 70px; gap: 10px; align-items: center; }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile {
  position: relative; border: 2px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface);
  cursor: pointer; transition: border-color .12s, transform .12s;
}
.tile:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.tile.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tile .thumb { aspect-ratio: 4/3; background: #e8edf4; display: block; width: 100%; object-fit: cover; }
.tile .sel {
  position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .92); border: 1.5px solid var(--border-strong); cursor: pointer; z-index: 2;
}
.tile.selected .sel { background: var(--primary); border-color: var(--primary); }
.tile .sel svg { opacity: 0; }
.tile.selected .sel svg { opacity: 1; }
.tile .kind {
  position: absolute; top: 8px; right: 8px; background: rgba(15, 23, 42, .72); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
}
.tile .info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 5px; }
.tile .name { font-size: 13.5px; font-weight: 600; }
.tile .status { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-height: 22px; }
.tile .mini-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .6); }
.tile .mini-bar span { display: block; height: 100%; background: var(--primary); transition: width .4s; }
.empty-grid { padding: 36px 10px; text-align: center; color: var(--text-2); }

/* ---------- annotate panel ---------- */
.a-step { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.a-step:last-of-type { border-bottom: 0; margin-bottom: 8px; }
.a-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.tasks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.task {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 11px; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface); transition: .12s;
}
.task input { position: absolute; opacity: 0; pointer-events: none; }
.task:hover { border-color: var(--border-strong); }
.task .t-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-bottom: 2px; }
.task strong { font-size: 14px; }
.task span.d { font-size: 12.3px; color: var(--text-2); line-height: 1.4; }
.task.detect .t-icon { background: var(--primary-soft); color: var(--primary); }
.task.segment .t-icon { background: var(--violet-soft); color: var(--violet); }
.task.detect.on { border-color: var(--primary); background: #f7faff; }
.task.segment.on { border-color: var(--violet); background: #faf8ff; }
.task .tag { position: absolute; top: 10px; right: 10px; }

.targets { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.target { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; transition: border-color .15s; }
.target:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.target-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.target-fields .desc { grid-column: 1 / -1; }
.label-row { display: flex; gap: 6px; min-width: 0; }
.swatch {
  position: relative; flex: none; width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  background: var(--c); border: 1px solid rgba(0, 0, 0, .12); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
}
.swatch:hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55), 0 0 0 3px var(--primary-soft); }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.dot-c { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.target-prompt { margin-top: 7px; font-size: 12px; color: var(--text-2); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.target-prompt code {
  background: var(--primary-soft); color: var(--primary); padding: 1px 7px; border-radius: 6px;
  font: 600 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-word;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); min-width: 0; }
input[type=text], input[type=number], input[type=password] {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 14px;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input.invalid { border-color: var(--danger); }
input[type=range] { width: 100%; accent-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 12.5px; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.models { display: flex; flex-direction: column; gap: 6px; }
.model {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px 11px;
  border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; transition: .12s;
}
.model:hover { border-color: var(--border-strong); }
.model.on { border-color: var(--primary); background: #f7faff; }
.model input { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.model .m-name { font-weight: 600; font-size: 14px; }
.model .m-note { font-size: 12px; color: var(--text-2); }
.model .m-price { font-size: 12px; font-weight: 600; color: var(--text-2); text-align: right; }

details.settings summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; }
details.settings summary::-webkit-details-marker { display: none; }
details.settings summary::after {
  content: ""; margin-left: auto; width: 7px; height: 7px; border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2);
  transform: rotate(45deg); transition: transform .15s;
}
details.settings[open] summary::after { transform: rotate(-135deg); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.span-2 { grid-column: span 2; }

.run-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.run-box .btn { width: 100%; }
.budget { display: flex; flex-direction: column; gap: 5px; }
.meter { height: 6px; background: #e3e9f2; border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.meter.warn span { background: var(--warn); }
.meter.bad span { background: var(--danger); }

.alert { padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13.5px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: #234aa8; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(23, 32, 46, .45); display: grid; place-items: center; padding: 18px; }
.viewer-panel { background: var(--surface); border-radius: 16px; width: min(1400px, 100%); height: min(900px, 100%); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 70px rgba(16, 24, 40, .3); }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.viewer-head h2 { font-size: 16px; }
.viewer-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.stage { background: #0f1520; display: grid; place-items: center; min-height: 0; position: relative; overflow: hidden; }
.stage img, .stage video { max-width: 100%; max-height: 100%; display: block; }
.stage .stage-msg { color: #c9d3e0; text-align: center; padding: 20px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.stage .overlay-progress { position: absolute; left: 16px; right: 16px; bottom: 16px; background: rgba(15, 21, 32, .82); color: #fff; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.stage .overlay-progress .bar { background: rgba(255, 255, 255, .2); margin-top: 6px; }
.viewer-side { border-left: 1px solid var(--border); padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.side-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); margin-top: 6px; }
.run-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.run-card .labels { display: flex; flex-wrap: wrap; gap: 5px; }
.run-card .labels code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 7px 9px; }
.stat .v { font-size: 18px; font-weight: 700; }
.stat .k { font-size: 11.5px; color: var(--text-2); }
.dl { display: flex; flex-wrap: wrap; gap: 6px; }
.run-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.run-list button {
  width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 3px; cursor: pointer;
}
.run-list button:hover { border-color: var(--border-strong); }
.run-list button.active { border-color: var(--primary); background: #f7faff; }
.run-list .r-top { display: flex; align-items: center; gap: 6px; }
.run-list .r-sub { font-size: 12px; color: var(--text-2); }

.bar { height: 8px; border-radius: 999px; background: #e8edf4; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: inherit; transition: width .4s ease; }
.bar-fill.indeterminate { width: 35% !important; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: #d5dde8; border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- dialogs & toasts ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 22px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(16, 24, 40, .25); }
dialog::backdrop { background: rgba(23, 32, 46, .35); }
dialog h3 { font-size: 18px; margin-bottom: 8px; }
dialog input { margin-top: 10px; }
dialog .alert { margin-top: 10px; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: #17202e; color: #fff; padding: 11px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 10px 30px rgba(16, 24, 40, .3); animation: pop .2s ease; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .annotate { position: static; max-height: none; }
  .viewer-body { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 1fr) auto; }
  .viewer-side { border-left: 0; border-top: 1px solid var(--border); max-height: 45vh; }
}
@media (max-width: 600px) {
  .topbar { padding: 14px 16px 4px; flex-wrap: wrap; }
  .tagline { display: none; }
  .page { padding: 10px 16px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tasks { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .viewer { padding: 0; }
  .viewer-panel { border-radius: 0; height: 100%; }
  .viewer-head { flex-wrap: wrap; }
  .hero { padding: 22px 18px; }
}
