/* cx-ui base styles: reset, small buttons, icons, dialogs, markdown and code blocks. Load after tokens.css.
   Class names are plain (no prefix) where apps already share them: .muted, .small, .mono, .icon-button, .meta-button. */

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[cx-cloak] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.icon-button { background: none; border: 0; border-radius: 8px; padding: 4px 8px; color: var(--muted); font-size: 16px; line-height: 1; }
.icon-button:hover { background: var(--hover); color: var(--text); }

/* Small text buttons (inline actions: "Edit", "Retry", "default") */
.meta-button { background: none; border: 0; padding: 2px 6px; margin-left: -6px; border-radius: 6px; color: var(--muted); font-size: 12px; }
.meta-button:hover { background: var(--hover); color: var(--text); }
.meta-button:disabled { opacity: .4; cursor: default; background: none; }

/* Buttons: .cx-button, .cx-button.primary (brand gradient), .cx-button.danger, and the variants below */
.cx-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 7px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 550; }
.cx-button:hover:not(:disabled) { background: var(--hover); }
.cx-button.primary { background: var(--brand-gradient); border-color: transparent; color: #fff; }
.cx-button.primary:hover:not(:disabled) { background: var(--brand-gradient); filter: brightness(1.08); }
.cx-button.danger { background: var(--danger); border-color: transparent; color: var(--surface); }
.cx-button.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.cx-button:disabled { opacity: .5; cursor: default; }
/* .block: fills its row (sign-in forms, stacked actions). .danger-outline: a delete that doesn't shout. */
.cx-button.block { display: flex; width: 100%; padding: 10px 14px; }
.cx-button.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.cx-button.danger-outline:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
/* .link: a text button inside a sentence or a table row; .link.danger, .link.strong. */
.cx-button.link { display: inline; padding: 0; border: 0; border-radius: 0; background: none; color: var(--accent);
  font-size: inherit; font-weight: inherit; text-decoration: underline; text-underline-offset: 2px; }
.cx-button.link:hover:not(:disabled) { background: none; filter: none; text-decoration-thickness: 2px; }
.cx-button.link.danger { background: none; color: var(--danger); }
.cx-button.link.strong { color: var(--text); font-weight: 600; }

/* ---------- icons (<ui-icon>, cx-ui/icon.js) ---------- */

ui-icon { display: inline-flex; width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }
ui-icon svg.icon { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
ui-icon.filled svg.icon { fill: currentColor; }
ui-icon.spin svg.icon { animation: ui-spin 1s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }
.icon-button ui-icon { width: 18px; height: 18px; }
.meta-button ui-icon { width: 15px; height: 15px; vertical-align: -0.25em; }

/* ---------- dialogs (cx-ui/dialog.js) ---------- */

.cx-dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.cx-dialog::backdrop { background: rgb(15 23 42 / .45); }
.cx-dialog form { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px 16px; }
.cx-dialog-title { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.cx-dialog-message { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.cx-dialog-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.cx-dialog-field input, .cx-dialog-field textarea { resize: vertical; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); font: inherit; font-size: 14px; }
.cx-dialog-field input:focus, .cx-dialog-field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.cx-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- markdown ---------- */

.markdown { overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown table, .markdown blockquote { margin: 0 0 14px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 22px 0 10px; line-height: 1.3; font-weight: 650; }
.markdown h1 { font-size: 1.4em; } .markdown h2 { font-size: 1.25em; } .markdown h3 { font-size: 1.1em; }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown li + li { margin-top: 4px; }
.markdown blockquote { padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--code-bg); font-weight: 600; }
.markdown code { font-family: var(--mono); font-size: .88em; background: var(--inline-code); padding: 1px 5px; border-radius: 5px; }
.markdown pre { position: relative; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }
.markdown code, .code-lang { font-variant-ligatures: none; } /* -> and => stay as typed */

/* Code blocks: header with language and actions; Mermaid diagram/code toggle; markdown preview. */
.code-block { margin: 0 0 14px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.markdown .code-block pre { margin: 0; border: 0; border-radius: 0; background: none; }
.code-block.wrap > pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 4px 3px 14px;
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.code-lang { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-actions { display: flex; gap: 2px; flex-shrink: 0; }
.code-actions button { font: inherit; font-size: 12px; padding: 3px 8px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.code-actions button:hover, .code-actions button:focus-visible { background: var(--hover); color: var(--text); }
.code-actions button[hidden] { display: none; }
.mermaid-view { padding: 16px; overflow-x: auto; background: var(--surface); text-align: center; }
.mermaid-view svg { max-width: 100%; height: auto; }
.mermaid-block.showing-diagram > pre, .mermaid-block:not(.showing-diagram):not(.mermaid-failed) > .mermaid-view { display: none; }
.mermaid-block.mermaid-failed > pre { display: block; }
.mermaid-block.mermaid-failed > .mermaid-view { text-align: left; font-size: 13px; color: var(--danger); background: none; padding: 0 16px 12px; white-space: pre-wrap; }
.md-preview { padding: 14px 16px; background: var(--surface); }
.code-block.previewing > pre, .code-block:not(.previewing) > .md-preview { display: none; }

/* highlight.js tokens, coloured from the theme */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-literal { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-template-variable { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: var(--hl-title); }
.hljs-type, .hljs-class .hljs-title, .hljs-variable.language_ { color: var(--hl-type); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-params { color: var(--hl-attr); }
.hljs-meta, .hljs-tag, .hljs-name, .hljs-deletion { color: var(--hl-meta); }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 700; }
