/* Ask views — the generative UI in Ask answers (ask_ui.py, frontend/ask-openui).
   Colours are X-ray's theme tokens (style.css / style-light.css), so a view follows the
   reader's theme; the only literals here are the categorical series palette, validated for
   colour-blind separation on X-ray's own surfaces in both themes (dataviz validate_palette:
   dark against #1c1c1e, light against #ffffff — adjacent pairs pass every gate). Slot order
   is the CVD-safety mechanism: never re-order or cycle it. */
:root {
  --xu-c1: #3987e5; --xu-c2: #d95926; --xu-c3: #199e70; --xu-c4: #c98500;
  --xu-c5: #d55181; --xu-c6: #008300; --xu-c7: #9085e9; --xu-c8: #e66767;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --xu-c1: #2a78d6; --xu-c2: #eb6834; --xu-c3: #1baf7a; --xu-c4: #eda100;
    --xu-c5: #e87ba4; --xu-c6: #008300; --xu-c7: #6250d6; --xu-c8: #e34948;
  }
}
:root[data-theme="light"] {
  --xu-c1: #2a78d6; --xu-c2: #eb6834; --xu-c3: #1baf7a; --xu-c4: #eda100;
  --xu-c5: #e87ba4; --xu-c6: #008300; --xu-c7: #6250d6; --xu-c8: #e34948;
}

/* ── the mount point and its states ── */
.ask-ui { margin: 8px 0 12px; min-width: 0; }
.ask-ui-pending > .ask-ui-fallback { opacity: .55; }
.ask-ui-pending { position: relative; }
.ask-ui-pending::before { content: "drawing the view…"; display: block; font-size: 11px; color: var(--dimmer); margin-bottom: 4px; }
.ask-ui-failed::before { content: "interactive view unavailable — its content as text:"; display: block; font-size: 11px; color: var(--dimmer); margin-bottom: 4px; }
.ask-live-text { white-space: pre-wrap; }
.xu-fallback { border: 1px dashed var(--line-2); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.xu-fallback pre { white-space: pre-wrap; font-size: 11.5px; max-height: 260px; overflow: auto; }

/* ── layout ── */
.xu-stack { display: flex; flex-direction: column; gap: 10px; }
.xu-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.xu-row > * { flex: 1 1 240px; min-width: 0; }
.xu-section { display: flex; flex-direction: column; gap: 8px; }
.xu-section-h { font-size: 13px; font-weight: 650; color: var(--text); margin-top: 4px; }
.xu-sub { color: var(--dim); font-weight: 400; font-size: 12px; }
.xu-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.xu-title { font-size: 12.5px; font-weight: 600; color: var(--text); margin: 0 0 6px; line-height: 1.35; }
.xu-text { margin: 0; font-size: 13.5px; line-height: 1.5; }
.xu-dimtxt { color: var(--dim); }
.xu-pad { padding: 6px 2px; font-size: 12px; }
.xu-collapse { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; background: var(--panel); }
.xu-collapse > summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--dim); padding: 2px 0; }
.xu-collapse[open] > summary { margin-bottom: 8px; color: var(--text); }
.xu-collapse-b { display: flex; flex-direction: column; gap: 10px; padding-bottom: 6px; }
.xu-tabs-h { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 10px; overflow-x: auto; }
.xu-tabs-h button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--dim); font: inherit; font-size: 12.5px; padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.xu-tabs-h button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.xu-tabs-h button:hover { color: var(--text); }
.xu-tabs-b > div { display: flex; flex-direction: column; gap: 10px; }

/* ── tones ── */
.xu-good { --xu-tone: var(--good); } .xu-warn { --xu-tone: var(--warn); } .xu-bad { --xu-tone: var(--bad); }
.xu-info { --xu-tone: var(--accent); } .xu-neutral { --xu-tone: var(--dim); }
.xu-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--xu-tone, var(--dim)); flex: none; }

.xu-callout { border: 1px solid color-mix(in srgb, var(--xu-tone, var(--accent)) 45%, var(--line)); background: color-mix(in srgb, var(--xu-tone, var(--accent)) 9%, var(--panel));
  border-left: 3px solid var(--xu-tone, var(--accent)); border-radius: 8px; padding: 8px 12px; }
.xu-callout-t { font-weight: 650; font-size: 13.5px; display: flex; gap: 8px; align-items: baseline; }
.xu-callout-t .xu-dot { position: relative; top: -1px; }
.xu-callout-b { font-size: 13px; color: var(--text); margin-top: 3px; line-height: 1.5; padding-left: 16px; }

/* ── figures ── */
.xu-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.xu-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px 8px; position: relative; overflow: hidden; min-width: 0; }
.xu-kpi[class*="xu-good"], .xu-kpi[class*="xu-warn"], .xu-kpi[class*="xu-bad"] { border-left: 3px solid var(--xu-tone); }
.xu-kpi-l { font-size: 11.5px; color: var(--dim); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.xu-kpi-v { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; color: var(--text); }
.xu-kpi-d { font-size: 11.5px; color: var(--dim); margin-top: 2px; line-height: 1.35; }
.xu-kpi.xu-good .xu-kpi-l::before, .xu-kpi.xu-warn .xu-kpi-l::before, .xu-kpi.xu-bad .xu-kpi-l::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--xu-tone); margin-right: 6px; vertical-align: 1px; }
.xu-spark { display: block; margin-top: 4px; }

.xu-stack > .xu-gauge, .xu-section > .xu-gauge, .xu-tabs-b .xu-gauge { align-self: flex-start; }
.xu-gauge { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; text-align: center; min-width: 150px; }
.xu-gauge svg { display: block; margin: 0 auto; }
.xu-gauge-v { font-size: 17px; font-weight: 650; }
.xu-gauge-l { font-size: 12.5px; font-weight: 600; }
.xu-gauge-d { font-size: 11.5px; color: var(--dim); }
.xu-meters { display: flex; flex-direction: column; gap: 8px; }
.xu-meter-h { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.xu-meter-h b { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.xu-meter-bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 3px; overflow: hidden; }
.xu-meter-bar span { display: block; height: 100%; border-radius: 3px; }
.xu-meter-d { font-size: 11.5px; color: var(--dim); margin-top: 2px; }

/* ── charts ── */
.xu-chart, .xu-heat { position: relative; }
.xu-plot { position: relative; }
.xu-plot svg { display: block; overflow: visible; }
.xu-ax { font-size: 10.5px; fill: var(--chart-ink-muted); font-variant-numeric: tabular-nums; }
.xu-ax-l { fill: var(--chart-ink-sec); font-size: 11.5px; }
.xu-val { fill: var(--chart-ink-sec); }
.xu-tip { position: absolute; z-index: var(--z-popover, 65); pointer-events: none; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 6px 9px; font-size: 11.5px; min-width: 120px; max-width: 260px; box-shadow: 0 6px 18px rgba(0, 0, 0, .28); }
.xu-tip-h { font-weight: 600; margin-bottom: 3px; color: var(--text); }
.xu-tip-r { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--dim); }
.xu-tip-r i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }
.xu-tip-r b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; padding-left: 10px; }
.xu-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }
.xu-leg { background: none; border: 0; padding: 0; font: inherit; font-size: 11.5px; color: var(--dim); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.xu-leg i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.xu-leg.off { opacity: .4; text-decoration: line-through; }
.xu-leg:hover { color: var(--text); }

.xu-donut-b { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.xu-donut-v { font-size: 15px; font-weight: 650; }
.xu-donut-l { list-style: none; margin: 0; padding: 0; flex: 1 1 180px; display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.xu-donut-l li { display: grid; grid-template-columns: 12px 1fr auto 46px; gap: 6px; align-items: center; padding: 1px 4px; border-radius: 4px; cursor: default; }
.xu-donut-l li.on { background: var(--panel-2); }
.xu-donut-l i { width: 10px; height: 10px; border-radius: 3px; }
.xu-donut-l span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xu-donut-l b { font-weight: 600; font-variant-numeric: tabular-nums; }
.xu-donut-l em { font-style: normal; color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }

.xu-heat-t { border-collapse: separate; border-spacing: 2px; font-size: 10.5px; width: 100%; table-layout: fixed; }
.xu-heat-t th { color: var(--chart-ink-muted); font-weight: 400; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.xu-heat-t tbody th { text-align: right; color: var(--chart-ink-sec); padding-right: 6px; }
.xu-heat-t td { height: 24px; border-radius: 3px; text-align: center; color: var(--text); font-variant-numeric: tabular-nums; }
.xu-heat-t td span { font-size: 10px; opacity: .9; }

.xu-wf-rows { display: flex; flex-direction: column; gap: 3px; }
.xu-wf-r { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 64px; gap: 8px; align-items: center; font-size: 12px; }
.xu-wf-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xu-wf-track { position: relative; height: 14px; background: color-mix(in srgb, var(--line) 45%, transparent); border-radius: 3px; }
.xu-wf-track span { position: absolute; top: 2px; bottom: 2px; border-radius: 3px; min-width: 2px; }
.xu-wf-v { text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); }

/* ── tables ── */
.xu-tablecard { padding-bottom: 6px; }
.xu-table-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.xu-filter { font: inherit; font-size: 12px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; width: 150px; }
.xu-tablewrap { overflow-x: auto; }
.xu-table { border-collapse: collapse; font-size: 12.5px; width: 100%; font-variant-numeric: tabular-nums; }
.xu-table th { text-align: left; font-weight: 600; color: var(--dim); font-size: 11.5px; border-bottom: 1px solid var(--line-2); padding: 0; white-space: nowrap; }
.xu-table th button { background: none; border: 0; font: inherit; color: inherit; padding: 5px 12px 5px 0; cursor: pointer; }
.xu-table th button:hover { color: var(--text); }
.xu-table td { padding: 5px 12px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.xu-table tr:last-child td { border-bottom: none; }
.xu-table .num { text-align: right; }
.xu-table th.num button { padding-left: 12px; }
.xu-table td.num { padding-left: 12px; white-space: nowrap; }
.xu-table th:last-child button, .xu-table td:last-child { padding-right: 0; }
.xu-table tbody tr:hover td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.xu-cmp-t th { font-weight: 500; color: var(--text); font-size: 12.5px; padding: 5px 12px 5px 0; }
.xu-cmp-t tbody th { border-bottom: 1px solid var(--line); }
.xu-cmp-t tbody tr:last-child th { border-bottom: none; }
.xu-cmp-t thead th { color: var(--dim); font-size: 11.5px; }
.xu-more { background: none; border: 0; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; padding: 6px 0 0; }
.xu-pill { display: inline-block; font-size: 11px; line-height: 16px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--dim); white-space: nowrap; }
.xu-pill.xu-good, .xu-pill.xu-warn, .xu-pill.xu-bad { color: var(--xu-tone); border-color: color-mix(in srgb, var(--xu-tone) 55%, transparent); background: color-mix(in srgb, var(--xu-tone) 10%, transparent); }

/* ── lists ── */
.xu-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.xu-list li { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.xu-list li:last-child { border-bottom: none; }
.xu-list-t { font-size: 13px; font-weight: 550; }
.xu-list-d { font-size: 12px; color: var(--dim); margin-top: 1px; line-height: 1.4; }
.xu-list-m { font-size: 12px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.xu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.xu-tile { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; color: var(--text); text-decoration: none; min-width: 0; }
a.xu-tile:hover { border-color: var(--line-2); background: var(--panel-2); }
.xu-tile .xu-dot { margin-top: 5px; }
.xu-st-ok { --xu-tone: var(--good); } .xu-st-warn { --xu-tone: var(--warn); } .xu-st-bad { --xu-tone: var(--bad); }
.xu-st-idle { --xu-tone: var(--line-2); } .xu-st-unknown { --xu-tone: transparent; }
.xu-st-unknown .xu-dot { border: 1px dashed var(--dim); width: 6px; height: 6px; }
.xu-st-bad { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); background: color-mix(in srgb, var(--bad) 7%, transparent); }
.xu-st-warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.xu-grid-n { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xu-grid-d { font-size: 11.5px; color: var(--dim); line-height: 1.35; }

.xu-tl { list-style: none; margin: 0; padding: 0 0 0 4px; position: relative; }
.xu-tl::before { content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 1px; background: var(--line-2); }
.xu-tl li { position: relative; padding: 0 0 10px 30px; }
.xu-tl li:last-child { padding-bottom: 0; }
.xu-tl-i { position: absolute; left: 0; top: 0; width: 19px; height: 19px; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--xu-tone, var(--dim));
  color: var(--xu-tone, var(--dim)); font-size: 10.5px; line-height: 16px; text-align: center; font-weight: 700; }
.xu-tl-time { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.xu-tl-t { font-size: 13px; font-weight: 550; }
.xu-tl-d { font-size: 12px; color: var(--dim); line-height: 1.4; }

.xu-steps { list-style: none; margin: 0; padding: 0; counter-reset: xs; display: flex; flex-direction: column; gap: 6px; }
.xu-steps li { padding: 4px 8px; border-radius: 6px; }
.xu-steps li.now { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.xu-steps label { display: flex; gap: 8px; align-items: baseline; cursor: pointer; font-size: 13px; }
.xu-steps input { accent-color: var(--good); margin: 0; position: relative; top: 1px; }
.xu-steps li.done .xu-steps-t { text-decoration: line-through; color: var(--dim); }
.xu-steps-d { font-size: 12px; color: var(--dim); margin-left: 22px; line-height: 1.4; }

.xu-code { padding: 0; overflow: hidden; }
.xu-code-h { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--dim); padding: 5px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.xu-code-h button { background: none; border: 1px solid var(--line-2); border-radius: 5px; color: var(--dim); font: inherit; font-size: 11px; padding: 1px 8px; cursor: pointer; }
.xu-code-h button:hover { color: var(--text); }
.xu-code pre { margin: 0; padding: 8px 10px; font-family: var(--mono); font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre; max-height: 320px; }

.xu-tags, .xu-links { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.xu-tags-h { font-size: 11.5px; color: var(--dim); margin-right: 2px; }
.xu-linkchip { font-size: 12.5px; border: 1px solid var(--line-2); border-radius: 999px; padding: 2px 10px; color: var(--accent); text-decoration: none; background: var(--panel); }
.xu-linkchip:hover { border-color: var(--accent); }

/* ── the reader's next move ── */
.xu-follow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.xu-follow-h { font-size: 11.5px; color: var(--dim); margin-right: 2px; }
.xu-follow-b, .xu-choice-b { display: flex; flex-wrap: wrap; gap: 6px; }
.xu-follow-b button, .xu-choice-b button { font: inherit; font-size: 12.5px; text-align: left; border-radius: 999px; padding: 4px 12px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text); }
.xu-follow-b button:hover:not(:disabled), .xu-choice-b button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.xu-follow-b button:disabled, .xu-choice-b button:disabled { opacity: .55; cursor: default; }
.xu-follow-b button.sent, .xu-choice-b button.sent { border-color: var(--accent); background: var(--accent-dim); opacity: 1; }
.xu-choice { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.xu-choice-q { font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
.xu-choice-b button:first-child { background: var(--accent); border-color: var(--accent); color: #fff; }
.xu-choice-b button:first-child:hover:not(:disabled) { color: #fff; filter: brightness(1.1); }

.xu-approval { border-left: 3px solid var(--xu-tone, var(--accent)); }
.xu-approval-h { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.xu-approval-t { font-size: 13.5px; font-weight: 600; margin: 4px 0 2px; }
.xu-approval-d { font-size: 12.5px; color: var(--dim); }
.xu-approval-go { margin-top: 8px; font: inherit; font-size: 12.5px; border-radius: 6px; padding: 5px 12px; cursor: pointer; border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); }
.xu-approval-go:disabled { opacity: .5; cursor: default; border-color: var(--line-2); background: none; }
.xu-approval-n { font-size: 11px; margin-top: 4px; }
.xu-flash { outline: 2px solid var(--warn); outline-offset: 3px; transition: outline-color .3s; }
