:root {
  --bg: #f6f6f7; --card: #fff; --line: #e4e4e7; --line-soft: #efeff1; --fg: #1c1c21; --muted: #6b6b74;
  --accent: var(--fg); --green: #189a58; --red: #c93a3a; --amber: #b45309; --hover: #f9f9fa;
  --green-text: color-mix(in srgb, var(--green) 70%, black); --red-text: color-mix(in srgb, var(--red) 70%, black);
  --amber-text: color-mix(in srgb, var(--amber) 70%, black); --accent-text: var(--fg);
  --radius: 6px; --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 13px/1.5 var(--font); accent-color: var(--fg); }
h1, h2, p { margin: 0; }
[hidden] { display: none; }
a { color: inherit; text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.icon { flex: none; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* shell */
.shell { display: grid; grid-template-columns: 212px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px; font-size: 14px; font-weight: 600; flex: none; }
.brand-mark { display: block; width: 22px; height: 22px; }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.nav-group { margin-top: 12px; }
.nav-title { padding: 0 8px 4px; font-size: 12px; color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border-radius: var(--radius-sm); }
.nav-item:hover { background: var(--bg); }
.nav-item[aria-current="page"] { background: #ececee; color: var(--fg); font-weight: 600; }
.side-foot { flex: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot-ok { background: var(--green); }
.dot-bad { background: var(--red); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; min-height: 46px; padding: 6px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-crumbs, .topbar-actions, .topbar-lead { display: flex; align-items: center; gap: 8px; min-width: 0; }
.menu-btn { display: none; flex: none; align-items: center; justify-content: center; height: 36px; min-width: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--fg); font: inherit; cursor: pointer; }
.menu-btn:hover { background: var(--bg); }
.scrim { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30; background: rgb(0 0 0 / .35); }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.crumb[aria-current="page"] { color: var(--fg); font-weight: 600; }
.content { width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 18px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.page-title { min-width: 0; }
.page-head h1:focus { outline: none; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }

/* card and rows */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 8px 16px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-controls { display: flex; align-items: center; gap: 8px; }
.card-foot { display: flex; justify-content: center; padding: 12px; border-top: 1px solid var(--line-soft); }
.card-foot:empty { display: none; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 16px; border-top: 1px solid var(--line-soft); }
.row:hover { background: var(--hover); }
.row:focus-visible { outline-offset: -2px; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-id { color: var(--muted); }
.row-badges { display: flex; gap: 6px; flex: none; }
.row-time { flex: none; min-width: 148px; text-align: right; color: var(--muted); white-space: nowrap; }

/* buttons, inputs, badges */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--fg); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--card); }
.btn-primary:hover { background: #3a3a42; }
.btn-danger { background: var(--red); border-color: var(--red); color: var(--card); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 88%, black); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn[aria-busy="true"]::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.input, .select { height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--fg); font: inherit; }
.input { width: 100%; }
.input[aria-invalid="true"] { border-color: var(--red); }
.label { display: block; margin-bottom: 4px; font-weight: 600; }
.field-error { margin-top: 4px; font-size: 12px; color: var(--red); }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 4px; font-size: 11px; white-space: nowrap; }
.badge-neutral { background: var(--bg); color: var(--muted); }
.badge-green { background: color-mix(in srgb, var(--green) 12%, white); color: var(--green-text); }
.badge-red { background: color-mix(in srgb, var(--red) 12%, white); color: var(--red-text); }
.badge-amber { background: color-mix(in srgb, var(--amber) 12%, white); color: var(--amber-text); }
.badge-accent { background: var(--fg); color: var(--card); }

/* empty, skeleton */
.empty { display: grid; justify-items: center; gap: 4px; padding: 40px 16px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 4px; border-radius: 50%; background: var(--bg); color: var(--muted); }
.empty-title { font-size: 14px; font-weight: 600; }
.empty-action { margin-top: 12px; }
.skeleton-row { display: grid; gap: 6px; min-height: 48px; padding: 10px 16px; border-top: 1px solid var(--line-soft); }
.skeleton-bar { height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--line-soft), var(--bg), var(--line-soft)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton-wide { width: 40%; }
.skeleton-narrow { width: 20%; }

/* toast and dialog */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: min(520px, 92vw); padding: 8px 16px; border-radius: 6px; background: var(--fg); color: var(--card); cursor: pointer; }
.toast-error { background: var(--red); }
.dialog { width: min(420px, 92vw); padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--fg); }
.dialog::backdrop { background: rgb(0 0 0 / .35); }
.dialog-title { font-size: 14px; font-weight: 600; }
.dialog-body { margin-top: 8px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* connection page */
.connect { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--bg); }
.connect-card { width: min(360px, 100%); display: grid; gap: 20px; padding: 32px 28px 28px; border: 1px solid var(--line); }
.connect-head { display: grid; justify-items: center; gap: 2px; text-align: center; }
.brand-mark-lg { width: 44px; height: 44px; margin-bottom: 10px; }
.connect-title { font-size: 20px; font-weight: 600; letter-spacing: .02em; }
.connect-sub { padding-left: .3em; color: var(--muted); letter-spacing: .3em; }
.connect-notice { color: var(--red); }
.connect-form { display: grid; gap: 12px; }
.connect-form .input { height: 36px; }
.connect-form .btn { margin-top: 4px; height: 36px; }

/* task detail: header, tabs, key/value grid, code blocks, callouts */
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; min-width: 0; }
.wrap { overflow-wrap: anywhere; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.btn-sm { height: 24px; padding: 0 8px; font-size: 12px; }
.btn[hidden] { display: none; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tab:hover { color: var(--fg); }
.tab[aria-current="page"] { border-bottom-color: var(--fg); color: var(--fg); font-weight: 600; }
.tab-body, .stack, .inv, .inv-body { display: grid; gap: 16px; min-width: 0; }
.back-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.snapshot-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; padding: 0 16px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips code { padding: 1px 6px; border-radius: var(--radius-sm); background: var(--bg); }
.code { margin: 0 16px 16px; padding: 12px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font: 12px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; }
.code.result-text { max-height: 420px; }
.code.prompt { max-height: 360px; }
.ph { padding: 0 3px; border-radius: 3px; background: #ececee; color: var(--fg); }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line-soft); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 16px; border-top: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.table thead th { border-top: 0; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table td { overflow-wrap: anywhere; }
.card > p, .card > .inv-note { padding: 0 16px 16px; }
.card > p:first-child { padding-top: 16px; }
/* Loose card body content owns no spacing of its own. The lists (.rows), tables
   (.table-wrap), key/value grids (.kv), code blocks (.code), empty/skeleton states
   and .fbody keep their internal insets instead. */
.card > .callout, .card > .wait, .card > .form, .card > .inv, .card > .wait-actions,
.card > .grid2, .card > .check-row, .card > .field, .card > .chips, .card > .form-actions,
.card > .card-inset { margin: 0 16px 16px; }
.card > .inv { padding-bottom: 0; }
.raw summary { padding: 12px 16px; cursor: pointer; font-weight: 600; }
.sub { margin: 0 16px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.plain { margin: 0; padding: 0 16px 16px 32px; }
.callout { overflow-wrap: anywhere; padding: 10px 12px; border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius-sm); background: var(--card); color: var(--fg); }
.callout-info { border-color: var(--line); border-left: 3px solid var(--fg); background: var(--bg); }
.callout-warn { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 10%, white); }
.callout-danger { border-color: var(--red); background: color-mix(in srgb, var(--red) 8%, white); }
.link { color: var(--fg); text-decoration: underline; text-decoration-color: var(--muted); }
.link:hover, .link-btn:hover { text-decoration-color: var(--fg); }
.row-sub { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; color: var(--muted); }
.row-reason { color: var(--red-text); overflow-wrap: anywhere; }
.row-times { display: grid; flex: none; min-width: 148px; text-align: right; white-space: nowrap; }
.inv-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.inv-note:empty { display: none; }

/* run form and timer */
.form { display: grid; gap: 8px; }
.textarea { width: 100%; min-height: 120px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--fg); font: 13px/1.5 var(--mono); resize: vertical; }
.textarea[aria-invalid="true"] { border-color: var(--red); }
/* #190: the script source editor. The gutter is a sibling column with the textarea's exact
   font and line-height, so one logical line stays one row. wrap="off" keeps a long line on
   one visual row, and the scroll listener keeps the column pinned to the textarea's offset.
   The gutter is size-contained so its line list never sets the editor height: the textarea
   keeps its rows=18 box and scrolls internally. Its width fits five digits (65537 lines) in
   a border-box calc, its 9px top inset is its own 1px border plus 8px padding to match the
   textarea's 1px border plus 8px padding, and its 24px bottom padding keeps its scroll range
   past the textarea's so the scrollTop sync is never clamped. */
.code-editor { display: flex; align-items: stretch; min-width: 0; }
.code-editor .textarea { flex: 1 1 auto; min-width: 0; }
.code-gutter { flex: none; contain: size; width: calc(5ch + 15px); padding: 8px 8px 24px 6px; border: 1px solid var(--line); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--bg); color: var(--muted); font: 13px/1.5 var(--mono); text-align: right; white-space: pre; overflow: hidden; user-select: none; pointer-events: none; }
.form-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.count { font-variant-numeric: tabular-nums; color: var(--muted); }
.count-over { color: var(--red-text); font-weight: 600; }
.form-actions, .wait-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.reasons { margin: 0; padding-left: 18px; color: var(--muted); }
.reasons:empty { display: none; }
.wait { display: grid; justify-items: start; gap: 8px; }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 4px; background: var(--bg); color: var(--fg); font-size: 13px; font-variant-numeric: tabular-nums; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton-bar, .btn[aria-busy="true"]::before { animation: none; }
}
.copy-fallback { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 20; width: min(560px, 92vw); padding: 8px 10px; border: 1px solid var(--fg); border-radius: var(--radius-sm); background: var(--card); color: var(--fg); font: 12px/1.5 var(--mono); resize: none; }

/* task form (create and edit) and lifecycle buttons */
.form-page { display: grid; gap: 16px; min-width: 0; max-width: 960px; }
.tform, .form-cards, .fsection, .rows-edit, .conflict { display: grid; gap: 16px; min-width: 0; }
.form-top, .form-summary { display: grid; gap: 8px; min-width: 0; }
.form-top:empty, .form-summary:empty { display: none; }
.fcard { min-width: 0; margin: 0; padding: 0; }
.fcard > legend { float: left; width: 100%; padding: 12px 16px 0; }
.fbody { clear: both; display: grid; gap: 12px; min-width: 0; padding: 12px 16px 16px; }
.fgroup { min-width: 0; margin: 0; padding: 0; border: 0; }
.fgroup > legend { padding: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.check-row { display: flex; flex-wrap: wrap; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; min-width: 0; }
.field { display: grid; align-content: start; gap: 4px; min-width: 0; }
.field .label { margin-bottom: 0; }
.field-wide { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.hint:empty { display: none; }
.field .select, .field .textarea { max-width: 100%; }
.select { min-width: 0; }
.field .select { width: 100%; }
.input[readonly] { background: var(--bg); color: var(--muted); }
.frow { display: grid; gap: 12px; min-width: 0; margin: 0; padding: 12px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
.frow-legend { padding: 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.frow-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; min-width: 0; }
.frow-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* Enum values are one row per value so that "" and embedded newlines round-trip exactly. */
.enum-block { display: grid; gap: 8px; min-width: 0; }
.enum-rows { display: grid; gap: 8px; min-width: 0; }
.enum-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; min-width: 0; }
/* One row = one value; a value may contain a newline, so this is a one-row textarea. */
.enum-row .textarea { min-height: 32px; padding: 6px 10px; resize: none; }
.enum-row .btn { margin-bottom: 22px; }
.chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.summary-title { font-weight: 600; }
.summary-list { margin: 6px 0 0; padding-left: 18px; }
.link-btn { padding: 0; border: 0; background: none; color: var(--fg); font: inherit; text-align: left; text-decoration: underline; text-decoration-color: var(--muted); cursor: pointer; overflow-wrap: anywhere; }
.conflict:focus { outline: none; }
.conflict-note { color: var(--red-text); }
.lifecycle { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lifecycle-host { min-width: 0; }

/* Narrow screens: the sidebar is a drawer over a scrim. NARROW in app.js mirrors this breakpoint. */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(280px, 86vw); height: auto; box-shadow: 0 0 24px rgb(0 0 0 / .2); }
  .sidebar.is-open { display: flex; }
  .menu-btn { display: inline-flex; }
  .nav-item { height: 40px; }
  .btn, .btn-sm { height: 32px; }
  .crumbs { flex-wrap: wrap; white-space: normal; overflow-wrap: anywhere; }
  .card-head { flex-wrap: wrap; }
  .card-controls { flex-wrap: wrap; }
  .row { flex-wrap: wrap; gap: 8px 12px; }
  .row-main { flex: 1 1 100%; }
  .row-time, .row-times { min-width: 0; margin-left: auto; }
  .table { min-width: 520px; }
  .table td { overflow-wrap: break-word; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}
