:root {
  --background: #ffffff;
  --surface: #ffffff;
  --foreground: #171717;
  --muted: #5f6368;
  --border: #d9dbdf;
  --accent: #171717;
  --accent-text: #ffffff;
  --danger: #c5221f;
  --danger-text: #ffffff;
  --danger-soft: rgba(197, 34, 31, 0.1);
  --amber: #b06000;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --success-soft: rgba(30, 142, 62, 0.12);
  --success: #1e8e3e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --surface: #111214;
    --foreground: #ededed;
    --muted: #a1a5ab;
    --border: #2c2e33;
    --accent: #ededed;
    --accent-text: #0a0a0a;
    --danger: #ea4335;
    --danger-text: #ffffff;
    --amber: #fbbc04;
    --success: #5bb974;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { font-size: clamp(1rem, calc(0.40625rem + min(1.3vh, 0.8vw)), 1.5rem); }
body { margin: 0; background: var(--background); color: var(--foreground); font-family: Arial, Helvetica, sans-serif; line-height: 1.45; }
a { color: inherit; text-underline-offset: 4px; }
h1 { font-size: 1.6rem; margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: 0.02em; }

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-box { width: 100%; max-width: 24rem; display: flex; flex-direction: column; gap: 1.25rem; }
.auth-footer { display: flex; flex-direction: column; gap: 0.75rem; font-size: 0.9rem; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }

.account-page { max-width: 42rem; margin: 0 auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.field input, .field select { font: inherit; font-size: 1rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--surface); color: var(--foreground); width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--foreground); outline-offset: 1px; }

.button { font: inherit; font-size: 0.95rem; padding: 0.6rem 1rem; border-radius: 0.5rem; border: 1px solid var(--border); background: transparent; color: var(--foreground); cursor: pointer; }
.button:disabled { opacity: 0.55; cursor: default; }
.button-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.button-danger { background: var(--danger); color: var(--danger-text); border-color: var(--danger); }
.button-wide { width: 100%; }

.alert { border-radius: 0.5rem; padding: 0.7rem 0.9rem; font-size: 0.92rem; border: 1px solid; }
.alert-error { background: var(--danger-soft); border-color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: var(--success); }
.alert-amber { background: var(--amber-soft); border-color: var(--amber); }
.alert-info { border-color: var(--border); }

.card { border: 1px solid var(--border); border-radius: 0.75rem; background: var(--surface); padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.confirm-panel { border: 1px solid var(--danger); border-radius: 0.5rem; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.75rem; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list > li { padding: 0.8rem 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.6rem; }
.list > li:first-child { border-top: 0; padding-top: 0; }
.tag { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.5rem; color: var(--muted); }
.language-choice { display: flex; gap: 0.5rem; }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.link-button[aria-current='true'] { font-weight: 700; text-decoration: none; }

@media (pointer: coarse) {
  .button, .field input, .field select { min-height: 2.75rem; }
}

.monitor-page { max-width: 76rem; margin: 0 auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }
.monitor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
/* On a phone the events come right after the applications: they are why you open this page. */
@media (max-width: 800px) {
  .monitor-grid { grid-template-columns: minmax(0, 1fr); }
  .monitor-grid > .stack { display: contents; }
  monitor-event-types-card { order: 1; }
}
.button-link { display: block; text-align: center; text-decoration: none; }
.row-tight { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); flex: none; }
.dot-connected { background: var(--success); }
.dot-disconnected { background: var(--danger); }
.dot-webhook { background: var(--amber); }
.live-status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--amber); }
.live-status-on { color: var(--success); }
.live-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; }
.live-status-on .live-dot { animation: live-pulse 2s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: 0.35; } }
.event-head { font: inherit; color: inherit; background: none; border: 0; padding: 0; width: 100%; cursor: pointer; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; text-align: left; }
.event-seq { min-width: 2.5rem; font-variant-numeric: tabular-nums; }
.event-type { font-weight: 600; overflow-wrap: anywhere; }
.event-time { margin-left: auto; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.event-subject { overflow-wrap: anywhere; }
.event-data { margin: 0; padding: 0.7rem; border: 1px solid var(--border); border-radius: 0.5rem; font-size: 0.85rem; overflow-x: auto; }
.event-row-new { animation: event-in 1.2s ease-out; }
@keyframes event-in { from { background: var(--success-soft); } }
@media (prefers-reduced-motion: reduce) { .live-status-on .live-dot, .event-row-new { animation: none; } }

/* Circuit */
input.field, select.field, textarea.field { font: inherit; font-size: 0.95rem; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--surface); color: var(--foreground); width: 100%; }
input.field:focus, select.field:focus, textarea.field:focus { outline: 2px solid var(--foreground); outline-offset: 1px; }
.field-small { width: auto; font-size: 0.85rem; padding: 0.3rem 0.5rem; }
.field-label { font-size: 0.85rem; color: var(--muted); }
.code, textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.danger-text { color: var(--danger); }
.empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; }
h3 { font-size: 0.95rem; margin: 0; font-weight: 600; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 1.25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar select.field { width: auto; }
.page { max-width: 60rem; margin: 0 auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }
.page-wide { max-width: 90rem; }
.tag-red { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.flow-list { display: flex; flex-direction: column; }
.flow-line { display: flex; align-items: center; gap: 0.75rem; padding: 0.8rem 0; border-top: 1px solid var(--border); text-decoration: none; flex-wrap: wrap; }
.flow-line:first-child { border-top: 0; }
.flow-name { font-weight: 600; }

/* Run page: runs left, Steps in the middle, details right */
.run-grid { display: grid; grid-template-columns: minmax(12rem, 1fr) minmax(0, 2.2fr) minmax(14rem, 1.3fr); gap: 1.25rem; align-items: start; }
.run-list { gap: 0.4rem; }
.run-line { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.5rem; border-radius: 0.5rem; text-decoration: none; font-size: 0.9rem; }
.run-line:hover { background: var(--amber-soft); }
.run-line-active { background: var(--success-soft); font-weight: 600; }
.run-line .muted { margin-left: auto; font-size: 0.8rem; }
.dot-green, .dot-completed { background: var(--success); }
.dot-running, .dot-waiting { background: var(--amber); }
.dot-no, .dot-failed, .dot-invalid, .dot-stopped, .dot-undone, .dot-undo-failed { background: var(--danger); }
.run-steps { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.run-detail { position: sticky; top: 1rem; }

.start-box { font: inherit; color: inherit; text-align: left; display: flex; flex-direction: column; gap: 0.25rem; border: 2px solid var(--foreground); border-radius: 0.75rem; padding: 0.7rem 1rem; background: var(--surface); min-width: 16rem; cursor: pointer; }
.step-row { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: nowrap; padding: 0.25rem; border-radius: 0.75rem; position: relative; }
.step-row::before { content: ""; position: absolute; left: 50%; top: -0.6rem; height: 0.6rem; border-left: 2px solid var(--border); }
.step-column { display: flex; flex-direction: column; align-items: stretch; gap: 0.4rem; }
.step { font: inherit; color: inherit; text-align: left; display: flex; flex-direction: column; gap: 0.2rem; width: 15rem; border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 0.6rem; background: var(--surface); padding: 0.6rem 0.75rem; cursor: pointer; }
.step .tag { align-self: flex-start; }
.step-label { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.step-name { font-weight: 600; overflow-wrap: anywhere; }
.step-status { font-size: 0.8rem; }
.step-error { font-size: 0.8rem; color: var(--danger); }
.step-selected { outline: 2px solid var(--foreground); outline-offset: 2px; }
.step-red { border-color: var(--danger); border-left-color: var(--danger); background: var(--danger-soft); }
.step-green { border-left-color: var(--success); }
.step-green .step-status { color: var(--success); }
.step-running, .step-waiting { border-left-color: var(--amber); }
.step-running .step-status, .step-waiting .step-status { color: var(--amber); }
.step-no, .step-failed, .step-invalid, .step-undo-failed { border-left-color: var(--danger); }
.step-no .step-status, .step-failed .step-status, .step-invalid .step-status, .step-undo-failed .step-status { color: var(--danger); }
.step-undone { border-left-style: dashed; opacity: 0.75; }
.step-not-started { opacity: 0.6; }
.undo-box { font: inherit; color: var(--muted); font-size: 0.8rem; text-align: left; border: 1px dashed var(--border); border-radius: 0.5rem; background: transparent; padding: 0.4rem 0.6rem; cursor: pointer; }

/* Builder: palette left, canvas in the middle, editor right */
.builder { display: flex; flex-direction: column; gap: 0.75rem; padding: 1rem 1.25rem; height: calc(100vh - 3.5rem); }
.builder-top .flow-name-input { width: 18rem; font-weight: 600; }
.builder-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 16rem minmax(0, 1fr) 22rem; gap: 1rem; }
.builder-left, .builder-right { overflow-y: auto; gap: 0.75rem; }
.palette-item { display: flex; flex-direction: column; gap: 0.15rem; border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.55rem 0.7rem; cursor: grab; background: var(--surface); }
.palette-item:active { cursor: grabbing; }
.canvas { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 0.75rem; cursor: grab; background-color: var(--background); background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 1.25rem 1.25rem; touch-action: none; }
.canvas-inner { position: absolute; left: 0; top: 0; padding: 2rem; display: flex; flex-direction: column; align-items: center; gap: 0.6rem; transform-origin: 0 0; min-width: 100%; }
.canvas-item { display: flex; justify-content: center; width: 100%; }
.zoom-controls { position: absolute; right: 0.75rem; top: 0.75rem; z-index: 2; display: flex; align-items: center; gap: 0.4rem; background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.25rem; }
.zoom-controls .button { padding: 0.2rem 0.6rem; }
.drop-zone { height: 0.6rem; width: 15rem; border-radius: 0.5rem; border: 1px dashed transparent; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--muted); transition: height 0.12s; }
.drop-zone span { display: none; }
.drop-visible { height: 2.2rem; border-color: var(--border); }
.drop-visible span { display: inline; }
.drop-active { border-color: var(--success); background: var(--success-soft); }
.step-row.drop-active { outline: 2px dashed var(--success); }

.mapping-line, .payload-line { display: grid; grid-template-columns: minmax(6rem, 1fr) minmax(0, 1.6fr) auto; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
.payload-builder { display: flex; flex-direction: column; gap: 0.5rem; }
.payload-name { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; overflow-wrap: anywhere; }
.payload-add { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.payload-add input.field { flex: 1; min-width: 7rem; width: auto; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; }
.modal { position: fixed; z-index: 21; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(46rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; }

@media (max-width: 1000px) {
  .run-grid, .builder-grid { grid-template-columns: minmax(0, 1fr); }
  .builder { height: auto; }
  .canvas { min-height: 28rem; }
  .run-detail { position: static; }
}
