/* LnW AI Workbench UI — plain CSS, light and dark follow the operating system. */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --ink: #16213a;
  --muted: #5d6880;
  --line: #dde2ec;
  --line-strong: #c7cedc;
  --accent: #2250d0;
  --accent-ink: #ffffff;
  --accent-soft: #e7edfd;
  --ok: #19774a;
  --ok-soft: #e1f3e9;
  --warn: #8f5a00;
  --warn-soft: #fdf0d3;
  --bad: #b3261e;
  --bad-soft: #fce8e6;
  --violet: #6440c0;
  --violet-soft: #efe9fc;
  --topbar: #101c34;
  --topbar-ink: #e9eefb;
  --topbar-muted: #9fb0d2;
  --code-bg: #f1f3f8;
  --shadow: 0 1px 2px rgba(16, 28, 52, .06), 0 4px 16px rgba(16, 28, 52, .06);
  --radius: 10px;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1322;
    --panel: #151d31;
    --panel-2: #111a2c;
    --ink: #e3e8f4;
    --muted: #97a3bd;
    --line: #26314a;
    --line-strong: #34405c;
    --accent: #6f93ff;
    --accent-ink: #0b1224;
    --accent-soft: #1c2a52;
    --ok: #5fcf95;
    --ok-soft: #16362a;
    --warn: #f1bd57;
    --warn-soft: #3a2d12;
    --bad: #ff8a80;
    --bad-soft: #3d1b1b;
    --violet: #b59cff;
    --violet-soft: #2a2150;
    --topbar: #0a1020;
    --code-bg: #0f1728;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  min-height: 100vh;
}
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 20px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--topbar); color: var(--topbar-ink);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: .01em; }
.brand .mark {
  background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 7px;
  font-size: 12px; font-weight: 800; letter-spacing: .06em;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600;
  background: rgba(255, 255, 255, .1); color: var(--topbar-ink);
}
.chip.env { background: #f1bd57; color: #2b1d00; }
.uc-picker { display: flex; align-items: center; gap: 8px; color: var(--topbar-muted); font-size: 12.5px; white-space: nowrap; }
.uc-picker select {
  background: rgba(255, 255, 255, .08); color: var(--topbar-ink);
  border: 1px solid rgba(255, 255, 255, .18); border-radius: 7px; padding: 5px 8px; font: inherit; font-size: 13.5px;
  min-width: 190px;
}
.uc-picker select option { color: #16213a; }
.spacer { flex: 1; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--topbar-muted); }
.user b { color: var(--topbar-ink); font-weight: 600; }
.role { border: 1px solid rgba(255, 255, 255, .25); border-radius: 6px; padding: 1px 7px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }

/* tabs */
.tabs {
  position: sticky; top: 52px; z-index: 15;
  display: flex; gap: 2px; padding: 0 20px; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tabs a {
  padding: 11px 14px 10px; color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1440px; margin: 0 auto; padding: 22px 20px 60px; }
.splash { padding: 80px 0; text-align: center; color: var(--muted); font-size: 15px; }

/* page header */
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .lede { flex: 1 1 420px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 78ch; }
.page-head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.card > .card-head h3 { flex: 1; }
.card > .card-body { padding: 16px; }
/* collapsible cards: the heading toggles the body; a chevron shows the state */
.card > .card-head h3.toggle { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 8px; }
.card > .card-head h3.toggle::before { content: "▾"; display: inline-block; width: 12px; color: var(--muted); font-size: 12px; transition: transform .15s; }
.card.collapsed > .card-head h3.toggle::before { transform: rotate(-90deg); }
.card.collapsed > .card-head { border-bottom: 0; }
.card.collapsed > .card-body { display: none; }
.card > .card-head h3.toggle:hover { color: var(--accent); }
.card > .card-head h3.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.split.wide-left { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.split.narrow-left { grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); }
@media (max-width: 980px) { .split, .split.wide-left, .split.narrow-left { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 13px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn.danger:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.on-dark { color: var(--topbar-ink); border-color: rgba(255, 255, 255, .25); }
.btn.on-dark:hover:not(:disabled) { color: #fff; border-color: #fff; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }

/* forms */
.field { display: grid; gap: 5px; }
.field > span { font-weight: 600; font-size: 13px; }
.field > span .opt { color: var(--muted); font-weight: 500; }
.field .help { color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=number], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 10px; font: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tabs a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px;
}
textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* stepper */
.stepper { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
@media (max-width: 1100px) { .stepper { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stepper { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.step {
  text-align: left; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius); padding: 10px 12px; cursor: pointer; font: inherit; display: grid; gap: 2px;
}
.step:hover { border-color: var(--line-strong); }
.step .n { font-size: 11.5px; font-weight: 700; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.step .t { font-weight: 650; }
.step .k { font-size: 12px; color: var(--muted); }
.step.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.step.active .n { color: var(--accent); }

/* code, json */
pre.code {
  margin: 0; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow: auto; max-height: 460px; white-space: pre;
}
pre.logs { max-height: 520px; white-space: pre-wrap; word-break: break-word; }
.note { border-radius: 8px; padding: 10px 12px; background: var(--accent-soft); color: var(--ink); font-size: 13px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.ok { background: var(--ok-soft); }

/* tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; letter-spacing: .02em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap;
}
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: var(--panel-2); }
table.grid tr.selected td { background: var(--accent-soft); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* leaderboard: sortable headings, the primary metric highlighted */
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--accent); }
table.grid th.sorted { color: var(--ink); }
table.grid th.primary, table.grid td.primary { color: var(--accent); font-weight: 650; background: var(--accent-soft); }
table.grid.lb tr.selected td { background: var(--accent-soft); }
.lb-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 13px; }
.lb-toolbar .spacer { flex: 1; }
.lb-toolbar select { height: 30px; padding: 2px 6px; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* status pills */
.pill {
  display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 650;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.pill.InProgress, .pill.running { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.Completed, .pill.completed { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.Failed, .pill.failed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.Stopping { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.Preview { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.tag { display: inline-block; font-size: 11.5px; padding: 0 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }

/* lists */
.list { display: grid; }
.list-item {
  display: grid; gap: 2px; text-align: left; width: 100%;
  padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: inherit; cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--panel-2); }
.list-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.list-item .top { display: flex; gap: 8px; align-items: center; }
.list-item .top b { flex: 1; font-weight: 650; }
.group-label { padding: 10px 14px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* file browser */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }
.crumbs .sep { color: var(--muted); }
.entry { display: flex; align-items: center; gap: 10px; }
.entry .icon { width: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); color: var(--muted); padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.active { background: var(--accent-soft); color: var(--accent); }

/* meta list */
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; overflow-wrap: anywhere; }

.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.progress { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.editor { min-height: 520px; tab-size: 2; }
.status-line { display: flex; gap: 12px; align-items: center; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.status-line .ok { color: var(--ok); font-weight: 600; }
.status-line .bad { color: var(--bad); font-weight: 600; }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; max-width: min(460px, calc(100vw - 36px)); }
.toast { background: var(--topbar); color: var(--topbar-ink); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 13px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--ink); width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 16, 32, .45); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog p { margin: 0; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }

details > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }

/* config forms */
fieldset.form-section { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; min-width: 0; }
fieldset.form-section > legend { padding: 0 6px; font-weight: 650; font-size: 13.5px; }
code.path { margin-left: 8px; font-size: 11px; color: var(--muted); background: var(--code-bg); border-radius: 4px; padding: 0 5px; font-weight: 400; }
.scroll-checks { max-height: 190px; overflow: auto; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; gap: 4px 16px; }
textarea.invalid { outline: 2px solid color-mix(in srgb, var(--bad) 60%, transparent); }
details > summary { padding: 4px 0; }

/* working folder in the top bar */
.chip.folder { border: 1px solid rgba(255, 255, 255, .18); cursor: pointer; max-width: min(34vw, 520px); font: inherit; font-size: 12px; }
.chip.folder:hover { border-color: rgba(255, 255, 255, .5); }
.folder-label { color: var(--topbar-muted); font-weight: 600; }
.folder-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; font-weight: 500; }
/* report viewer (HTML reports and plots inside the page) */
dialog.viewer { width: min(1400px, 96vw); height: 92vh; max-height: 92vh; padding: 0; display: flex; flex-direction: column; }
dialog.viewer:not([open]) { display: none; }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.viewer-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog.viewer iframe { flex: 1; width: 100%; border: 0; background: #fff; }
/* full-width grids with search + pagination (Datasets, Use cases) */
.grid-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.grid-tools input[type=text] { max-width: 320px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid tr.clickable td b { color: var(--accent); }

/* modal forms (New dataset, New use case, Upload a version) */
dialog.modal { width: min(760px, calc(100vw - 32px)); max-height: 92vh; overflow: auto; }
dialog.modal .modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
dialog.modal .modal-head h3 { flex: 1; }
dialog.modal .modal-body { padding: 18px; }
/* file tree (Files tab) */
.tree { font-size: 13px; padding: 6px 0; }
.tree-node { display: flex; align-items: center; gap: 6px; padding: 3px 10px; cursor: pointer; white-space: nowrap; border-radius: 6px; }
.tree-node:hover { background: var(--panel-2); }
.tree-node.selected { background: var(--accent-soft); }
.tree-node .twisty { width: 14px; text-align: center; color: var(--muted); font-size: 11px; flex: none; }
.tree-node .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tree-node .meta { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.tree-node.folder .name { font-weight: 600; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--line); padding-left: 4px; }
.tree-more { padding: 2px 10px; font-size: 12px; color: var(--muted); }
/* fixes: fields in a grid keep their own height; long code never widens its card */
.form-grid { align-items: start; }
.form-grid > .field > select, .form-grid > .field > input { height: 36px; }
.stack > *, .card-body > *, details > * { min-width: 0; }
pre.code { max-width: 100%; }
pre.code.wrap { white-space: pre-wrap; word-break: break-all; }

/* feature lists */
.fl-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px dashed var(--line-strong); border-radius: 8px; background: var(--panel-2); }
.fl-bar select { max-width: 280px; }
.fl-bar .fl-label { font-weight: 600; font-size: 12.5px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 2px 14px; max-height: 260px; overflow: auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.picker label.check { font-weight: 500; }
.picker .type-tag { color: var(--muted); font-size: 11px; margin-left: 4px; }
.win-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
/* a related table in the feature discovery setup: a collapsible block with a one-line summary */
details.related-table > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
details.related-table > summary::-webkit-details-marker { display: none; }
details.related-table > summary::before { content: "▸"; color: var(--muted); font-size: 12px; margin-right: 6px; }
details.related-table[open] > summary::before { content: "▾"; }
details.related-table[open] > summary { border-bottom: 1px solid var(--line); }
details.related-table > summary:hover { color: var(--accent); }
.win-row input[type=number] { width: 84px; }
/* settings that do not apply to this use case (problem type / no target): visible, greyed, with the reason */
fieldset.form-section.na { opacity: .7; background: var(--panel-2); }
fieldset.form-section.na legend { color: var(--muted); }
.field.na > span, .check.na { color: var(--muted); }
.field.na input, .field.na select, .field.na textarea, .check.na input { opacity: .55; cursor: not-allowed; }
.na-reason { color: var(--warn); font-style: italic; }