:root {
  --bg: #0b0b10; --surface: #15151d; --surface-2: #1d1d28; --line: #2c2c3a; --text: #f1f0f6; --muted: #a39fb4;
  --accent: #dbff6b; --accent-ink: #11140a; --violet: #8f7cff; --danger: #ff6b6b; --warn: #ffc857; --ok: #6be3a0;
  --radius: 12px; --tap: 44px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .pad { padding: 16px; } .mono, .json { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.error, .field-error { color: var(--danger); } .field-error:empty { display: none; }
.spacer { flex: 1; } .row { display: flex; align-items: center; } .gap { gap: 8px; }
.local-note { background: #2a2614; color: var(--warn); font-size: 12.5px; padding: 6px 16px; border-bottom: 1px solid #4a4220; }

.btn { min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; touch-action: manipulation; }
.btn:hover { border-color: #44445a; } .btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #5a2a2a; background: #241418; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn-round { width: var(--tap); padding: 0; border-radius: 50%; }
.btn-fab { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 26px; border: 0; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
input[type=text], input[type=search], input[type=number], select, textarea { width: 100%; min-height: var(--tap); padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
textarea { resize: vertical; min-height: 64px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); font-size: 11.5px; color: var(--muted); }
.badge-warn { color: var(--warn); background: #2c2614; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-size: 18px; letter-spacing: -.02em; }
.lang { width: auto; min-width: 72px; }
.flow-name { max-width: 320px; font-weight: 650; background: transparent; border-color: transparent; }
.flow-name:hover, .flow-name:focus { border-color: var(--line); background: var(--bg); }
.save-state { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.save-state[data-state=dirty] { color: var(--warn); } .save-state[data-state=conflict] { color: var(--danger); }

.dash { max-width: 1100px; width: 100%; margin: 0 auto; }
.dash .topbar { border: 0; background: transparent; }
.dash-head { display: grid; grid-template-columns: 1fr minmax(160px, 320px) auto; gap: 12px; align-items: center; padding: 8px 16px 16px; }
.dash-head h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.flow-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 0 16px 32px; }
.flow-card { display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: inherit; text-decoration: none; min-height: 112px; }
.flow-card:hover { border-color: var(--violet); }
.chip { display: inline-flex; align-self: flex-start; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: 12.5px; border: 1px solid var(--line); }
.st-succeeded { color: var(--ok); } .st-failed, .st-uncertain { color: var(--danger); } .st-running, .st-queued { color: var(--accent); } .st-awaiting_approval, .st-waiting { color: var(--warn); }

.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.banner { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: #2b1717; color: #ffd0d0; border-bottom: 1px solid #5a2a2a; }
.banner[hidden] { display: none; }
.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.stage { flex: 1; position: relative; min-width: 0; overflow: hidden; background:
  radial-gradient(circle, #23232f 1px, transparent 1.2px) 0 0 / 22px 22px, var(--bg); }
.canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.toolbar { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.hint { position: absolute; left: 88px; bottom: max(14px, env(safe-area-inset-bottom)); max-width: 60%; pointer-events: none; }
.edge-pop { position: absolute; transform: translate(-50%, -130%); }
.edge-pop[hidden] { display: none; }

.node-box { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.node.selected .node-box { stroke: var(--accent); stroke-width: 2.5; }
.node-bar { fill: var(--violet); } .cat-trigger .node-bar { fill: var(--accent); } .cat-logic .node-bar { fill: #ff9f6b; } .cat-data .node-bar { fill: #6bc8ff; }
.node-name { fill: var(--text); font-weight: 650; font-size: 15px; }
.node-type { fill: var(--muted); font-size: 12.5px; }
.node-status { font-size: 12px; fill: var(--muted); }
.node.st-running .node-box { stroke: var(--accent); stroke-dasharray: 6 4; }
.node.st-succeeded .node-box { stroke: var(--ok); } .node.st-succeeded .node-status { fill: var(--ok); }
.node.st-failed .node-box { stroke: var(--danger); } .node.st-failed .node-status { fill: var(--danger); }
.node.is-disabled { opacity: .5; }
.node { cursor: grab; }
.port-hit { fill: transparent; } .port-dot { fill: var(--surface-2); stroke: var(--muted); stroke-width: 2; }
.port-output .port-dot { stroke: var(--violet); }
.port-target .port-dot { stroke: var(--accent); fill: #2a3214; } .port-active .port-dot { fill: var(--accent); stroke: var(--accent); }
.port { cursor: crosshair; }
.port-label { font-size: 12px; fill: var(--muted); } .port-count { fill: var(--accent); }
.edge { fill: none; stroke: #6f6a8a; stroke-width: 2.2; } .edge-hit { fill: none; stroke: transparent; stroke-width: 22; cursor: pointer; }
.edge-g.selected .edge { stroke: var(--accent); stroke-width: 3; }
.edge-temp { stroke: var(--accent); stroke-dasharray: 6 5; pointer-events: none; }

.panel-host { display: contents; }
.panel { width: min(1080px, 72vw); border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-title { font-weight: 700; font-size: 17px; } .panel-sub { color: var(--muted); font-size: 13px; }
.panel-tabs { display: none; }
.panel-cols { flex: 1; display: grid; grid-template-columns: 1fr 1.2fr 1fr; min-height: 0; }
.col { padding: 12px 16px; overflow: auto; border-right: 1px solid var(--line); }
.col:last-child { border-right: 0; }
.col h3 { margin: 0 0 10px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.panel-foot { display: flex; justify-content: space-between; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.form label.row { flex-direction: row; gap: 8px; } .form label.row input { width: 22px; height: 22px; }
.field label { font-weight: 600; display: block; } .req { color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.preview { font-size: 13px; min-height: 18px; } .preview-label { color: var(--muted); }
.settings { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.settings summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--muted); }
.data-src { margin: 10px 0 6px; font-size: 13px; color: var(--muted); display: flex; align-items: center; }
.table-wrap { overflow: auto; max-height: 50vh; border: 1px solid var(--line); border-radius: 10px; }
.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; max-width: 260px; overflow-wrap: anywhere; }
.data-table th { position: sticky; top: 0; background: var(--surface-2); }
.map-key { border: 1px dashed var(--violet); background: transparent; border-radius: 6px; padding: 4px 8px; min-height: 32px; cursor: pointer; }
.json { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow: auto; max-height: 50vh; margin: 8px 0 0; }

.runbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: max(8px, env(safe-area-inset-bottom)); max-height: 30vh; overflow: auto; }
.runbar[hidden] { display: none; }
.chip-step { cursor: pointer; min-height: 36px; }

.sheet { position: fixed; z-index: 20; right: 16px; top: 72px; bottom: 16px; width: min(440px, calc(100vw - 32px)); background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.palette { overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.palette h4 { margin: 10px 0 2px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.palette-item { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; min-height: 56px; }
.palette-item:hover { border-color: var(--violet); }

#toasts { position: fixed; z-index: 50; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(560px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.toast-error { border-color: #5a2a2a; color: #ffd0d0; }

/* iPad portrait and phones: the node window becomes a full-screen sheet with tabs. */
@media (max-width: 900px) {
  .panel { position: fixed; inset: 0; z-index: 15; width: auto; border: 0; }
  .panel-tabs { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
  .panel-tabs .tab { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
  .panel-tabs .tab[aria-selected=true] { background: var(--surface-2); border-color: var(--violet); }
  .panel-cols { display: block; overflow: auto; }
  .col { display: none; border: 0; }
  .panel[data-tab=input] .col-input, .panel[data-tab=params] .col-params, .panel[data-tab=output] .col-output { display: block; }
  .dash-head { grid-template-columns: 1fr auto; } .dash-head input { grid-column: 1 / -1; grid-row: 2; }
  .flow-name { max-width: 40vw; }
  .hint { display: none; }
}
@media (min-width: 901px) and (max-width: 1200px) { .panel { width: 70vw; position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; } }

.auth-form{max-width:480px;margin:8vh auto;padding:24px;display:grid;gap:16px}.auth-form input{min-height:44px;width:100%}.auth-bar{display:flex;gap:16px;align-items:center;justify-content:flex-end;padding:8px 16px}.auth-bar:empty{display:none}

.reauth-overlay{position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,.8);overflow:auto;display:grid;place-content:center}.reauth-overlay .auth-form{background:#fff;color:#111;border-radius:12px;margin:24px;padding:24px}.identity-warning{color:#fff;padding:16px}

/* Publication (ENGINE-011): chip in the top bar and on flow cards, versions sheet, read-only preview. */
.pub-chip { display: inline-flex; align-items: center; align-self: flex-start; min-height: 32px; padding: 4px 12px; border-radius: 99px; font-size: 12.5px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); white-space: nowrap; touch-action: manipulation; }
.topbar .pub-chip { min-height: var(--tap); align-self: center; cursor: pointer; }
.pub-chip[data-state=current] { color: var(--ok); border-color: #2a5a40; }
.pub-chip[data-state=behind] { color: var(--warn); border-color: #4a4220; }
.version-list { overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.version-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; text-align: left; min-height: var(--tap);
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: inherit; touch-action: manipulation; }
.version-item .small { grid-column: 1 / -1; }
.version-preview { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.version-preview .stage { flex: 1; }
.version-preview .spacer { flex: 1; min-width: 0; }

/* Narrow screens and Split View (IPAD-UI-008 B1/B2): the top bar wraps instead of widening the page;
   the flow name keeps a usable width; the node window footer wraps. */
.flow-name { flex: 1 1 140px; min-width: 120px; }
/* The editor top bar never forces the page wider than the screen: it wraps to a second row. */
.editor .topbar { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 760px) {
  .editor .topbar .spacer { display: none; }
  .editor .topbar .flow-name { max-width: none; order: 0; }
  .panel-foot { flex-wrap: wrap; }
  .panel-head > * { min-width: 0; }
  .panel-tabs .tab { min-width: 0; }
}

/* UI-014: execution history */
.exec-screen { padding-bottom: 32px; }
.exec-filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; padding: 8px 16px; }
.exec-filter { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 140px; }
.exec-filter select, .exec-filter input { min-height: 44px; width: 100%; min-width: 0; font-size: 16px; }
.exec-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.exec-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 12px 14px; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none; }
.exec-row:hover { border-color: var(--violet); }
.exec-row .exec-name { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; }
.exec-row > .muted { flex: 1 1 100%; }
.exec-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; padding: 12px 16px; }
.exec-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.exec-graph-box { padding: 0 16px; }
.exec-graph { height: 320px; border: 1px solid var(--line); border-radius: var(--radius); }
.exec-h2 { font-size: 18px; margin: 16px 16px 8px; }
.exec-steps { list-style: none; margin: 0; padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }
.exec-step { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); min-width: 0; }
.exec-step-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.exec-data { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.exec-data-btn { min-height: 44px; }
.exec-json { flex: 1 1 100%; max-height: 320px; overflow: auto; margin: 0; padding: 10px; background: var(--surface-2); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.exec-live { white-space: nowrap; }
@media (max-width: 600px) { .exec-graph { height: 240px; } }
/* The dashboard bar wraps like the editor bar instead of widening the page (Split View 1/3). */
.dash .topbar { flex-wrap: wrap; row-gap: 6px; }
.dash .topbar .muted { min-width: 0; overflow-wrap: anywhere; }

/* ---- schedules (UI-015) */
.sheet-schedules { max-width: 560px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-schedules > * { flex-shrink: 0; }
.sched-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.sched-row { border: 1px solid var(--line, #d9dde3); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.sched-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.sched-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sched-actions .btn, .sched-form .btn, .sched-retarget { min-height: 44px; }
.sched-form { display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line, #d9dde3); border-radius: 12px; padding: 12px; margin: 8px 0; }
.sched-form .field { display: flex; flex-direction: column; gap: 4px; border: 0; padding: 0; margin: 0; }
.sched-form .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sched-form input, .sched-form select { font-size: 16px; min-height: 44px; padding: 6px 10px; box-sizing: border-box; max-width: 100%; }
.sched-form input[type=number] { width: 7em; }
.sched-radio { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; padding: 4px 0; font-weight: normal; }
.sched-radio input { width: 22px; height: 22px; min-height: 0; margin-top: 2px; flex: none; }
.sched-stale { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.sched-fields { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sched-fields[hidden] { display: none; }
.sched-weekdays { display: flex; flex-wrap: wrap; gap: 6px; }
.sched-weekday { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.sched-weekday input { width: 20px; height: 20px; min-height: 0; margin: 0; padding: 0; }
.sched-row, .sched-every, .sched-meta, .sched-next { overflow-wrap: anywhere; min-width: 0; }
.sched-fields input[type=text], .sched-fields input[type=time], #sched-kind { width: 100%; min-width: 0; }
.warn { color: #8a5300; }
.flow-scheduled { align-self: flex-start; }

/* Dashboard actions stay separate from the card title link on touch and keyboard. */
.dash-controls { display:flex; flex-wrap:wrap; gap:8px; }
.dash-status { margin:0; padding:0 16px 12px; }
.dash-status:empty { padding:0; }
.flow-card { min-width:0; gap:10px; }
.flow-title { font-size:18px; line-height:1.35; margin:0 0 2px; overflow-wrap:anywhere; }
.flow-title a { color:inherit; text-decoration:none; display:inline-flex; align-items:center; min-height:44px; }
.flow-title a:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.flow-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:auto; padding-top:12px; }
.flow-actions .btn { flex:1 1 auto; text-decoration:none; white-space:normal; text-align:center; min-height:44px; }
.flow-actions .flow-run { flex-basis:100%; }
.flow-run-note { margin:0; overflow-wrap:anywhere; }
.flow-run-note:empty { display:none; }
.dash-run-dialog { width:min(560px,calc(100vw - 24px)); max-height:calc(100dvh - 24px); overflow:auto; overscroll-behavior:contain; border:1px solid var(--line); border-radius:var(--radius); padding:24px; color:var(--text); background:var(--surface); }
.dash-run-dialog::backdrop { background:rgba(0,0,0,.72); }
.dash-run-dialog h2 { margin:0 0 12px; font-size:24px; }
.dash-run-name { font-weight:650; overflow-wrap:anywhere; }
.dash-run-dialog textarea { font-size:16px; min-height:112px; margin-top:6px; }
.dash-run-dialog label { display:block; }
.dash-run-footer { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:10px; margin-top:16px; }
.dash-run-ack { display:flex !important; align-items:flex-start; gap:10px; margin-top:12px; }
.dash-run-ack input { flex:0 0 22px; width:22px; height:22px; }
.dash-run-warning { border:1px solid var(--warn); border-radius:10px; padding:12px; }
.dash-run-warning a { color:var(--accent); display:inline-flex; align-items:center; min-height:44px; }
@media (max-width:700px) {
 .dash-head { grid-template-columns:1fr; }
 .dash-head input { grid-column:1; grid-row:auto; }
 .dash-controls { width:100%; }
 .dash-controls .btn { flex:1; }
 .flow-list { grid-template-columns:minmax(0,1fr); }
 .dash-run-dialog { padding:16px; }
 .dash-run-footer .btn { flex:1; }
}

/* UI-017: repeating an unconfirmed run lives inside the warning, apart from the new-run path. */
.dash-run-warning { display:flex; flex-direction:column; align-items:flex-start; gap:8px; margin-bottom:12px; }
.dash-run-warning p { margin:0; }
.dash-run-warning .btn { min-height:44px; }
#flow-run-retry-note:empty { display:none; }
@media (max-width:700px) { .dash-run-warning .btn { width:100%; } }
