/* Optimizer panel styles. Colors are tokens; dark values follow the OS setting. */
:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --ink: #16222b;
  --muted: #5a6872;
  --line: #d6dde2;
  --accent: #1d5c78;
  --accent-ink: #ffffff;
  --accent-soft: #e1edf2;
  --ok: #2c7443;
  --ok-soft: #e2f1e6;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #f8e3e1;
  --f-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1519;
    --surface: #172027;
    --surface-2: #1c262e;
    --ink: #e2e9ed;
    --muted: #93a1ab;
    --line: #2b3842;
    --accent: #6cb3d2;
    --accent-ink: #0d1a20;
    --accent-soft: #1a3340;
    --ok: #6fc68c;
    --ok-soft: #173223;
    --warn: #e2a64c;
    --warn-soft: #3a2a10;
    --bad: #f08a80;
    --bad-soft: #3d1c1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--f-body); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; margin: 0; text-wrap: balance; }
h1 { font-size: 1.5rem; line-height: 1.2; }
a { color: var(--accent); }
code, .mono { font-family: var(--f-mono); font-size: .88em; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---- */
.bar { display: flex; align-items: center; gap: 20px; padding: 0 22px; min-height: 52px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font: 600 1rem var(--f-display); color: var(--ink); text-decoration: none; }
.brand svg { color: var(--accent); }
.bar-nav { display: flex; gap: 16px; }
.bar-nav a { color: var(--muted); text-decoration: none; }
.bar-nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.spacer { flex: 1; }
.user { color: var(--muted); font-size: .85rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar form { margin: 0; }

.switcher { position: relative; }
.switcher summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; background: var(--surface-2); }
.switcher summary::-webkit-details-marker { display: none; }
.switcher summary::after { content: "▾"; color: var(--muted); }
.switcher-label { color: var(--muted); font-size: .8rem; }
.switcher-menu { position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; min-width: 220px; max-height: 60vh; overflow-y: auto; margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .3); }
.switcher-menu li { padding: 0; }
.switcher-menu li.muted { padding: 7px 10px; }
.switcher-menu a { display: block; padding: 7px 10px; border-radius: 5px; color: var(--ink); text-decoration: none; }
.switcher-menu a:hover { background: var(--surface-2); }
.switcher-menu a[aria-current="true"] { background: var(--accent-soft); font-weight: 600; }

/* ---- page ---- */
.page { max-width: 1200px; margin: 0 auto; padding: 22px 26px 40px; display: grid; gap: 18px; }
.crumbs { display: flex; gap: 6px; color: var(--muted); font-size: .82rem; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs b { color: var(--ink); font-weight: 500; }
.titlerow { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }

.messages { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.message { padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); }
.message.success { background: var(--ok-soft); }
.message.warning { background: var(--warn-soft); }
.message.error { background: var(--bad-soft); }

/* ---- cards and tables ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.card-bd { padding: 16px 18px; display: grid; gap: 12px; }
.card-bd p { margin: 0; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font: 600 .7rem var(--f-body); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.rowlink { color: var(--ink); font-weight: 600; text-decoration: none; }
.rowlink:hover { color: var(--accent); }
.empty { display: grid; gap: 6px; justify-items: center; text-align: center; padding: 28px 12px; color: var(--muted); }
.empty b { color: var(--ink); }

.kind { font: 600 .68rem var(--f-body); letter-spacing: .07em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.kind-full { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); color: var(--accent); }
.kind-midcycle { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); color: var(--warn); }

/* ---- buttons and forms ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 500 .85rem var(--f-body); white-space: nowrap; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.sm { padding: 4px 9px; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; align-content: start; }
.field label { font-weight: 500; font-size: .85rem; }
.field input, .field select, .field textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.errors { margin: 0; padding: 9px 12px 9px 28px; border-radius: 8px; background: var(--bad-soft); color: var(--ink); }

.login { max-width: 380px; width: 100%; margin: 12vh auto 0; }

.small { font-size: .8rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.actions, .card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-actions { justify-content: flex-end; }
.card-hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.card-hd h2 { font: 600 .95rem var(--f-body); }
.card-ft { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 10px 10px; }
.with-badges { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.plain-list { margin: 0; padding-left: 18px; color: var(--muted); }
.dialog { max-width: 560px; width: 100%; }

/* ---- form layout ---- */
.field .label { font-weight: 500; font-size: .85rem; }
.field .help { color: var(--muted); font-size: .78rem; }
.field-error { color: var(--bad); font-size: .8rem; margin: 0; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.input-locked { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; background: var(--surface-2); color: var(--muted); }
.grid { display: grid; gap: 14px 18px; }
.grid-name { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.grid-params { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); align-items: start; }
.grid-files { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; margin-bottom: 14px; }
.grid-files .field { min-width: 0; }
.grid-files select { min-width: 0; width: 100%; }
.grid-toggles { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 18px; }
.params { border-top: 1px solid var(--line); padding-top: 16px; }
.toggle { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.toggle input { margin: 3px 0 0; accent-color: var(--accent); }
.toggle small { display: block; color: var(--muted); font-size: .76rem; }
.advanced { border-top: 1px dashed var(--line); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
.advanced-toggles:has(.toggle) { margin-top: 14px; }
.advanced .help { color: var(--muted); font-size: .78rem; margin: 12px 0 0; }

.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: fit-content; max-width: 100%; }
.seg-option { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; padding: 9px 16px; min-width: 240px; cursor: pointer; border-right: 1px solid var(--line); }
.seg-option:last-child { border-right: 0; }
.seg-option input { grid-row: span 2; margin: 3px 0 0; accent-color: var(--accent); }
.seg-option small { color: var(--muted); font-size: .76rem; }
.seg-option:has(input:checked) { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.seg-option:has(input:checked) b { color: var(--accent); }

.command { display: flex; gap: 8px; align-items: flex-start; }
.cmd { flex: 1; min-width: 0; margin: 0; font: .8rem/1.6 var(--f-mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-all; }
.cmd-invalid { font-family: var(--f-body); background: var(--warn-soft); }
.cmd-invalid ul { margin: 4px 0 0; padding-left: 18px; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-variant-numeric: tabular-nums; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.inline-form { display: grid; gap: 4px; }
.inline-form-row { display: flex; gap: 8px; }
.inline-form input { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; width: 260px; max-width: 100%; }
.inline-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- configuration page ---- */
.titlerow-main { min-width: 0; }
.titlerow-main .sub { word-break: break-all; }
.columns { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.card-hd .count { color: var(--muted); font-weight: 400; margin-left: 6px; }
.banner { padding: 9px 12px; border-radius: 8px; font-size: .85rem; background: var(--accent-soft); }
.banner.warn { background: var(--warn-soft); }

.upload { display: grid; gap: 8px; margin: 0; }
.drop { position: relative; display: flex; align-items: center; gap: 14px; padding: 14px; border: 1.5px dashed color-mix(in srgb, var(--accent) 55%, var(--line)); border-radius: 9px; background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.drop:hover, .drop:focus-within { background: var(--accent-soft); }
.drop svg { color: var(--accent); flex: none; }
.drop small { display: block; color: var(--muted); font-size: .78rem; }
/* The file input covers the whole drop zone, so clicking or dropping anywhere on it works. */
.drop input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-status { display: flex; align-items: center; gap: 12px; }
.upload-status:has([data-upload-status]:empty):has(progress[hidden]) { display: none; }
.upload-status progress { flex: 1; max-width: 240px; accent-color: var(--accent); }

.requirements { display: grid; gap: 8px; }
.requirements h3 { font: 600 .72rem var(--f-body); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.requirements ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.req { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; align-items: start; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); }
.req-mark { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: .75rem; font-weight: 700; }
.req-found .req-mark { color: var(--ok); background: var(--ok-soft); }
.req-missing .req-mark { color: var(--bad); background: var(--bad-soft); }
.req-problem .req-mark { color: var(--warn); background: var(--warn-soft); }
.req-optional .req-mark { color: var(--muted); border: 1px solid var(--line); }
.req-missing { background: color-mix(in srgb, var(--bad-soft) 55%, transparent); }
.req-problem { background: color-mix(in srgb, var(--warn-soft) 60%, transparent); }
.req-body { display: grid; gap: 1px; min-width: 0; }
.req-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.req-tag { font: 600 .65rem var(--f-body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.req-detail { font-size: .82rem; overflow-wrap: anywhere; }
.req-missing .req-detail { color: var(--bad); }
.req-problem .req-detail { color: var(--warn); }
.req-optional .req-detail { color: var(--muted); }
.req-purpose { color: var(--muted); font-size: .75rem; }

.check-col { width: 32px; }
.check-col input { accent-color: var(--accent); }
.fname { font-family: var(--f-mono); font-size: .8rem; word-break: break-all; }
.nowrap { white-space: nowrap; }
.folder summary { cursor: pointer; }
.folder-files { list-style: none; margin: 8px 0 0; padding: 0 0 0 14px; display: grid; gap: 4px; max-height: 320px; overflow-y: auto; }
.folder-files li { display: flex; justify-content: space-between; gap: 12px; font-size: .8rem; }
.folder-files .muted { white-space: nowrap; }

/* ---- runs ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font: 500 .76rem var(--f-body); white-space: nowrap; vertical-align: middle; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-lg { font-size: .85rem; padding: 4px 12px; }
.pill-succeeded { color: var(--ok); background: var(--ok-soft); }
.pill-failed { color: var(--bad); background: var(--bad-soft); }
.pill-running { color: var(--accent); background: var(--accent-soft); }
.pill-running::before { animation: pulse 1.4s ease-in-out infinite; }
.pill-queued, .pill-cancelled { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill-running::before { animation: none; } }

.run-live { display: grid; gap: 18px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.facts > div { padding: 10px 14px; border-right: 1px solid var(--line); display: grid; gap: 2px; min-width: 0; }
.facts > div:last-child { border-right: 0; }
.facts dt { color: var(--muted); font: 600 .68rem var(--f-body); letter-spacing: .07em; text-transform: uppercase; }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.banner.bad { background: var(--bad-soft); }
.banner.stale { display: grid; gap: 8px; }
.banner.stale p, .banner.stale form { margin: 0; }
.log { margin: 0; font: .76rem/1.6 var(--f-mono); background: #0f171c; color: #c9d6dd; padding: 12px 16px; max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-all; border-radius: 0 0 10px 10px; }
.log-note { margin: 0; padding: 6px 16px; font-size: .78rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.diff { color: var(--warn); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.actions form { margin: 0; }

@media (max-width: 960px) {
  .columns { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .grid-name { grid-template-columns: 1fr; }
  .grid-files { grid-template-columns: 1fr; }
  .seg-option { min-width: 0; border-right: 0; }
  .bar { padding: 8px 16px; gap: 12px; }
  .page { padding: 18px 16px 32px; }
  .user { display: none; }
}
