/*
 * The design system of the WebUI. One theme: dark, minimal. Every color, size and radius is a token in :root; the components below only use tokens.
 * Contrast of the text tokens on the surfaces is checked by a test (ThemeTest). See docs/webui.md, "Design system".
 */
:root {
  color-scheme: dark;

  /* surfaces, from the page to the raised */
  --bg: #0c0e12;
  --surface: #12151b;
  --surface-2: #181c23;
  --surface-3: #1f242d;
  --border: #262c36;
  --border-strong: #343c49;

  /* text */
  --text: #e8ebf0;
  --text-muted: #a1abba;
  --text-faint: #8590a0;

  /* accent and meaning */
  --accent: #8aa4ff;
  --accent-ink: #0a0d14;
  --success: #46c98b;
  --warning: #f0b84a;
  --danger: #f47c75;
  --info: #7cc4ff;

  /* tints for badges, notices and hovers (the colors above at low opacity) */
  --accent-tint: rgba(138, 164, 255, 0.14);
  --success-tint: rgba(70, 201, 139, 0.14);
  --warning-tint: rgba(240, 184, 74, 0.14);
  --danger-tint: rgba(244, 124, 117, 0.14);
  --info-tint: rgba(124, 196, 255, 0.14);

  /* type */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 22px;

  /* space and shape */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 6px;
  --radius: 10px;
  --sidebar: 244px;
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--text-md)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }
::selection { background: var(--accent-tint); }
code, kbd { font-family: var(--mono); font-size: var(--text-sm); }
code { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1px 6px; word-break: break-all; }
small { font-size: var(--text-xs); }
p { margin: 0 0 var(--space-3); }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--text-xl); margin-bottom: var(--space-4); }
h2 { font-size: var(--text-lg); margin: var(--space-5) 0 var(--space-3); }
.muted, .subtitle { color: var(--text-muted); }
.subtitle { margin: var(--space-1) 0 0; }

/* the application shell: sidebar and content */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-4) var(--space-3); background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-2); color: var(--text); font-weight: 650; font-size: var(--text-lg); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: var(--space-3); }
.nav-title { margin: 0 0 var(--space-1); padding: 0 var(--space-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.nav-group a { display: block; padding: 6px var(--space-2); margin-bottom: 2px; border-radius: var(--radius-sm); color: var(--text-muted); }
.nav-group a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-group a[aria-current="page"] { background: var(--accent-tint); color: var(--accent); font-weight: 550; }
.sidebar-foot .btn { align-self: flex-start; }
.sidebar-foot { display: flex; flex-direction: column; gap: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.who { display: flex; align-items: center; gap: var(--space-3); }
.who strong { display: block; line-height: 1.2; }
.who small { color: var(--text-muted); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text); font-weight: 600; }
.build { color: var(--text-faint); }
.content { min-width: 0; }
main { padding: var(--space-6) var(--space-6) 64px; max-width: 1240px; }
main.bare { max-width: none; padding: 0; }
.banner { margin: 0; padding: var(--space-2) var(--space-5); background: var(--warning-tint); color: var(--warning); border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.banner code { background: transparent; border-color: var(--warning); }

/* the title block of a page */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.page-header h1 { margin: 0; }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* panels, cards */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4); }
.panel > h2:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-4); }
.card { display: flex; flex-direction: column; gap: 2px; padding: var(--space-4) var(--space-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color 0.12s, background 0.12s; }
.card:hover { border-color: var(--border-strong); background: var(--surface-2); text-decoration: none; }
.card-label { color: var(--text-muted); font-size: var(--text-sm); }
.card-value { font-size: 30px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.card-detail { color: var(--text-faint); font-size: var(--text-sm); }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--border); }
.attention li:first-child { border-top: 0; }
.attention li span { flex: 1; }
.empty { margin: 0; padding: var(--space-4) 0; color: var(--text-muted); }
.empty.ok { color: var(--success); }
.problem { max-width: 520px; margin: 12vh auto 0; text-align: center; }
.problem h1 { margin-bottom: var(--space-2); }
.problem .btn { margin-top: var(--space-3); }

/* tables */
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; text-align: left; padding: var(--space-2) var(--space-3); color: var(--text-faint); font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border-strong); background: var(--surface); }
td { padding: 10px var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td:last-child { white-space: nowrap; }
td form, td details { display: inline-flex; vertical-align: middle; }
main > table, #list > table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: var(--space-4); }
main > table th, #list > table th { background: var(--surface-2); }

/* forms and buttons */
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 10px; min-height: 32px; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:hover, select:hover, textarea:hover { border-color: #46505f; }
input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: var(--ring); border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { min-height: 0; accent-color: var(--accent); }
textarea { font-family: var(--mono); font-size: var(--text-sm); width: 100%; }
select { padding-right: 28px; }
label { color: var(--text-muted); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-3); font-size: var(--text-sm); }
.field > span { color: var(--text-muted); }
main form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
main td form, main .panel form { margin: 0; }
main > form, #list > form { padding: var(--space-3) 0; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500; color: var(--text); background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 5px 12px; min-height: 32px; cursor: pointer; transition: background 0.12s, border-color 0.12s; }
button:hover, .btn:hover { background: #29303b; border-color: #46505f; text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #a1b6ff; border-color: #a1b6ff; }
.btn.ghost, button.link { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover, button.link:hover { background: var(--surface-3); color: var(--text); }
.btn.small, td button { min-height: 28px; padding: 2px 10px; font-size: var(--text-sm); }
.btn.block { width: 100%; }
.btn.danger, button[hx-confirm] { color: var(--danger); background: transparent; border-color: rgba(244, 124, 117, 0.35); }
.btn.danger:hover, button[hx-confirm]:hover { background: var(--danger-tint); border-color: var(--danger); }
button.link { padding: 0 var(--space-2); }
details { margin: 0; }
summary { cursor: pointer; color: var(--text-muted); padding: 2px var(--space-2); border-radius: var(--radius-sm); list-style: none; user-select: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--text-faint); transition: transform 0.12s; }
details[open] > summary::before { transform: rotate(90deg); }
summary:hover { background: var(--surface-3); color: var(--text); }
details[open] { background: transparent; }
details > form { padding: var(--space-2) var(--space-2) 0; }
details.engine { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-4); margin-bottom: var(--space-2); }
details.engine summary { padding: var(--space-2) 0; color: var(--text); }
details.engine ul { margin: var(--space-2) 0 var(--space-2) var(--space-5); padding: 0; color: var(--text-muted); }

/* badges and notices */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: var(--text-xs); font-weight: 550; line-height: 20px; background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border-strong); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--success-tint); color: var(--success); border-color: transparent; }
.badge.warn { background: var(--warning-tint); color: var(--warning); border-color: transparent; }
.badge.bad { background: var(--danger-tint); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-tint); color: var(--info); border-color: transparent; }
.notice, p.error, p.info { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); border: 1px solid var(--border); border-left-width: 3px; background: var(--surface); }
.notice.error, p.error { color: var(--danger); background: var(--danger-tint); border-color: rgba(244, 124, 117, 0.3); border-left-color: var(--danger); }
p.info, .notice.info { color: var(--success); background: var(--success-tint); border-color: rgba(70, 201, 139, 0.3); border-left-color: var(--success); }
/* Feedback of a request (errors, a new token, a form that continues a flow) lives in #flash, outside the lists that refresh themselves. */
.flash { display: flex; flex-direction: column; gap: var(--space-2); }
.flash:not(:empty) { margin-bottom: var(--space-4); }
.flash .notice { position: relative; padding-right: 44px; margin: 0; }
.flash .notice.confirm { color: var(--text); background: var(--surface); }
.flash .notice > .panel { margin: 0; border: 0; padding: 0; background: transparent; }
.flash-close { position: absolute; top: 6px; right: 8px; min-height: 0; padding: 0 8px; border: 0; background: transparent; color: inherit; font-size: 20px; line-height: 1.4; }
.flash-close:hover { background: transparent; opacity: 0.7; }
.flash code { user-select: all; cursor: copy; }
td.error { color: var(--danger); white-space: normal; }
ul.errors { color: var(--danger); }

/* sign-in */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-5); padding: var(--space-5); }
.auth-brand { display: flex; align-items: center; gap: var(--space-3); font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.auth-brand svg { color: var(--accent); }
.auth-card { width: 100%; max-width: 380px; padding: var(--space-6); display: block; }
.auth-card h1 { margin-bottom: var(--space-1); }
.auth-card .subtitle { margin-bottom: var(--space-5); }
.auth-card .field input { width: 100%; }
.auth-key { color: var(--text-faint); font-size: var(--text-sm); text-align: center; max-width: 380px; }
.auth-key code { display: inline-block; margin-top: var(--space-1); }

/* the lists that refresh themselves */
#list { min-height: 2rem; }

/* the blueprint editor */
#blueprint-editor { display: grid; grid-template-columns: 200px minmax(0, 1fr) 300px; gap: var(--space-3); min-height: 30rem; margin-bottom: var(--space-3); }
#blueprint-editor aside { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); overflow: auto; }
#blueprint-editor aside h2 { margin: 0 0 var(--space-3); font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
#palette button { display: flex; width: 100%; margin-bottom: var(--space-2); justify-content: flex-start; }
#drawflow { height: 30rem; border: 1px solid var(--border); border-radius: var(--radius); background-color: var(--bg); background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 20px 20px; }
#drawflow .drawflow-node { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius); width: 200px; padding: var(--space-3); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
#drawflow .drawflow-node:hover { border-color: #46505f; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
#drawflow .drawflow-node.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(0, 0, 0, 0.35); }
#drawflow .drawflow-node .node-title { font-weight: 600; }
#drawflow .drawflow-node small { display: block; color: var(--text-muted); }
#drawflow .drawflow-node .ports { color: var(--text-faint); }
#drawflow .drawflow-node .input, #drawflow .drawflow-node .output { width: 14px; height: 14px; background: var(--surface-3); border: 2px solid var(--accent); }
#drawflow .drawflow-node .input:hover, #drawflow .drawflow-node .output:hover { background: var(--accent); }
#drawflow .drawflow-node .inputs, #drawflow .drawflow-node .outputs { width: 0; }
#drawflow .connection .main-path { stroke: var(--text-faint); stroke-width: 2px; }
#drawflow .connection .main-path:hover, #drawflow .connection .main-path.selected { stroke: var(--accent); }
textarea.invalid { border-color: var(--danger); }
#blueprint-meta { margin-top: var(--space-3); display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: flex-start; }

/* below 900 px the sidebar becomes a bar on top */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: var(--space-3); border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: var(--space-1); flex-basis: 100%; order: 3; }
  .nav-group { display: contents; }
  .nav-title { display: none; }
  .nav-group a { margin: 0; }
  .sidebar-foot { flex-direction: row; align-items: center; margin-left: auto; padding: 0; border: 0; }
  .build { display: none; }
  main { padding: var(--space-5) var(--space-4) 48px; }
  .page-header { flex-direction: column; }
  #blueprint-editor { grid-template-columns: minmax(0, 1fr); }
  main > table, #list > table { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* pages in the design system (second part): tables, rows of actions, forms, tags */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-4); }
.table-wrap th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
.table-wrap th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
.table-wrap table { margin: 0; }
.table-wrap th { background: var(--surface-2); }
td.actions, th.actions { text-align: right; width: 1%; white-space: nowrap; }
.row-actions { display: inline-flex; align-items: center; gap: var(--space-2); justify-content: flex-end; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, .nowrap { white-space: nowrap; }
td.message { font-family: var(--mono); font-size: var(--text-sm); white-space: pre-wrap; word-break: break-word; }
tr.log td { vertical-align: top; }
.fabric-line { padding: 1px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tag { display: inline-block; padding: 0 8px; border-radius: var(--radius-sm); background: var(--surface-3); border: 1px solid var(--border); color: var(--text-muted); font-size: var(--text-sm); line-height: 20px; }
.stat { color: var(--text-muted); margin-left: var(--space-4); font-size: var(--text-sm); }
details.engine summary strong { color: var(--text); }
.hint { color: var(--text-muted); font-size: var(--text-sm); margin: calc(-1 * var(--space-2)) 0 var(--space-3); }
code.fp { cursor: copy; }
code.fp:hover { border-color: var(--accent); }
code.copied { border-color: var(--success); color: var(--success); }
.facts dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-5); margin: 0 0 var(--space-3); }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; }

/* forms: labelled fields in a row, checkboxes, popovers */
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); }
.form-row .field { margin: 0; }
.form-row > .btn, .form-row > button { align-self: flex-end; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 32px; color: var(--text-muted); font-size: var(--text-md); align-self: flex-end; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-4) var(--space-3); margin: 0 0 var(--space-3); min-width: 0; }
fieldset.roles { display: inline-flex; gap: var(--space-4); align-items: center; padding: 0 var(--space-4); min-height: 40px; align-self: flex-end; }
legend { color: var(--text-faint); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; padding: 0 var(--space-2); }
.field small { color: var(--text-faint); }
details.popover { position: relative; }
details.popover > summary { border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--text); min-height: 28px; display: inline-flex; align-items: center; padding: 2px 10px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
details.popover > summary::before { content: none; }
details.popover > summary:hover { background: #29303b; }
.popover-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 280px; display: flex; flex-direction: column; align-items: stretch; gap: var(--space-3); padding: var(--space-4); text-align: left; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); white-space: normal; }
details.popover.wide .popover-body { min-width: 520px; }
.popover-body .form-row { align-items: flex-end; }
.confirm { border-color: var(--accent); }
.confirm h2 { margin-top: 0; }
@media (max-width: 900px) { .table-wrap { overflow-x: auto; } details.popover.wide .popover-body { min-width: 0; width: 86vw; } .popover-body { right: auto; left: 0; } }

.token-share p { margin: 0 0 var(--space-2); }
.token-share svg.qr { display: block; width: 220px; max-width: 100%; height: auto; margin: var(--space-3) 0; border-radius: var(--radius-sm); }
