/* Image Lab UI. Same token approach as the WorkGuard admin UI (copied, not shared). No inline styles: CSP style-src 'self'. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #121212;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a6fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e3edfb;
  --good: #11833a;
  --good-soft: #e3f4e8;
  --warn: #9a6400;
  --warn-soft: #fbf0d9;
  --bad: #c03030;
  --bad-soft: #fbe6e6;
  --info-soft: #ecebf7;
  --info: #4b48a8;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --radius: 10px;
  --font: "Segoe UI", "Heebo", "Rubik", Arial, system-ui, sans-serif;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1b1b1a;
    --surface-2: #242422;
    --border: #31312e;
    --text: #f2f2f0;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #4a8fec;
    --accent-soft: #1d2f47;
    --good: #4cc775;
    --good-soft: #15301f;
    --warn: #e7b84a;
    --warn-soft: #362a10;
    --bad: #f07070;
    --bad-soft: #3a1a1a;
    --info-soft: #25243d;
    --info: #a9a6f0;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1b1b1a; --surface-2: #242422; --border: #31312e; --text: #f2f2f0; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #4a8fec; --accent-soft: #1d2f47; --good: #4cc775; --good-soft: #15301f; --warn: #e7b84a; --warn-soft: #362a10;
  --bad: #f07070; --bad-soft: #3a1a1a; --info-soft: #25243d; --info: #a9a6f0;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.98rem; }
p { margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.error { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; font-size: 0.92rem; }
.note { background: var(--warn-soft); color: var(--text); border-inline-start: 4px solid var(--warn); padding: 8px 12px; border-radius: 6px; font-size: 0.9rem; }

/* controls */
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-good { color: var(--good); border-color: var(--good); }
.btn-bad { color: var(--bad); border-color: var(--bad); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 3px 10px; font-size: 0.86rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; min-height: 96px; }
.field { display: grid; gap: 4px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { flex: none; }
.brand-lg { font-size: 1.2rem; }
.demo-badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }

/* shell */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; gap: 10px; align-items: center; font-size: 0.9rem; color: var(--text-2); }
.nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px 0; border-bottom: 1px solid var(--border); background: var(--surface); }
.nav a { padding: 8px 12px; border-radius: 8px 8px 0 0; color: var(--text-2); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; }
.nav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav .sep { width: 1px; background: var(--border); margin: 6px 4px; }
main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 48px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.between { justify-content: space-between; }

/* create */
.create { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .create { grid-template-columns: minmax(0, 1fr); } }
.levels { display: grid; gap: 6px; }
.level { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.level input { width: auto; }
.level:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tag { font-size: 0.72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { padding: 6px 12px; cursor: pointer; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* job detail */
.result-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.kpi { background: var(--surface-2); padding: 10px 12px; display: grid; gap: 2px; }
.kpi b { font-size: 1.15rem; overflow-wrap: anywhere; }
.kpi b.long { font-size: 0.9rem; white-space: normal; }
.kpi span { font-size: 0.8rem; color: var(--muted); }
.image-box { display: grid; place-items: center; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 20px 20px; border: 1px solid var(--border); border-radius: 8px; min-height: 220px; padding: 8px; }
.image-box img { max-width: 100%; max-height: 560px; border-radius: 4px; display: block; }
.status-box { display: grid; place-items: center; text-align: center; gap: 8px; min-height: 220px; border: 1px dashed var(--border); border-radius: 8px; padding: 16px; color: var(--text-2); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.prompt-box { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 0.88rem; direction: ltr; text-align: left; font-family: var(--mono); }

/* trace */
.trace { display: grid; gap: 0; }
.attempt-title { font-weight: 700; font-size: 0.86rem; color: var(--muted); padding: 10px 0 4px; border-bottom: 1px solid var(--border); }
.step { display: grid; grid-template-columns: 170px 70px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 0.9rem; }
.step .layer { font-weight: 600; }
.step .meta { color: var(--muted); font-size: 0.8rem; text-align: left; }
.step details { grid-column: 3 / -1; }
.step summary { cursor: pointer; color: var(--accent); font-size: 0.82rem; }
@media (max-width: 700px) { .step { grid-template-columns: minmax(0, 1fr) auto; } .step .summary-text, .step details { grid-column: 1 / -1; } .step .meta { grid-column: 1 / -1; text-align: start; } }
.chip { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 9px; border-radius: 999px; white-space: nowrap; text-align: center; }
.d-pass, .d-allow, .s-done { background: var(--good-soft); color: var(--good); }
.d-rewrite, .s-running, .s-queued { background: var(--accent-soft); color: var(--accent); }
.d-block, .s-blocked { background: var(--bad-soft); color: var(--bad); }
.d-error, .s-error { background: var(--warn-soft); color: var(--warn); }
.d-skip, .d-info { background: var(--info-soft); color: var(--info); }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.tbl { overflow-x: auto; }

/* lists */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: grid; grid-template-rows: auto 1fr; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile .thumb { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 2rem; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .body { padding: 8px 10px; display: grid; gap: 4px; font-size: 0.85rem; align-content: start; }
.tile .prompt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.label-card .thumb { aspect-ratio: auto; }
.label-card .thumb img { height: auto; object-fit: contain; max-height: 320px; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 4px; box-shadow: var(--shadow); }
.stat b { font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar.hot i { background: var(--bad); }

/* hebrew */
.heb-grid { display: grid; gap: 10px; }
.heb-row { display: grid; grid-template-columns: 120px repeat(var(--cols, 3), minmax(0, 1fr)); gap: 10px; align-items: start; }
.heb-cell { display: grid; gap: 6px; }
.heb-cell img { width: 100%; border-radius: 6px; border: 1px solid var(--border); }
@media (max-width: 760px) { .heb-row { grid-template-columns: minmax(0, 1fr); } }
.selected { outline: 3px solid var(--accent); }
