/* KAS Support Chat (demo). Visual identity of the AI Workflow Survey and the AI Gateway console:
   ALL-INKL red #E4003A, black, white, light grey panels, heavy uppercase headings, the brand-mark avatar. */

:root {
    color-scheme: light;
    --brand: #E4003A;
    --brand-dark: #B8002F;
    --brand-tint: #FDECF1;
    --ink: #0b0b0b;
    --text: #3a3a38;
    --muted: #6b6a66;
    --bg: #FFFFFF;
    --surface: #FFFFFF;
    --soft: #F5F5F4;
    --line: #E4E3E0;
    --ok: #0a7a0a;
    --ok-tint: #E7F4E7;
    --warn: #8a5a00;
    --warn-tint: #FFF4DB;
    --bad: #b42323;
    --bad-tint: #FCEAEA;
    --user: #1d1d1b;
    --radius: 6px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .06);
    --font: "ProximaNova", "Proxima Nova", "Montserrat", "Segoe UI", Arial, Helvetica, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --wrap: 1240px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --brand: #FF2E5F;
        --brand-dark: #FF5C80;
        --brand-tint: #3A1420;
        --ink: #f0efec;
        --text: #d6d5d0;
        --muted: #a3a29b;
        --bg: #121211;
        --surface: #1a1a19;
        --soft: #232322;
        --line: #33332f;
        --ok: #5cc95c;
        --ok-tint: #17301a;
        --warn: #f0b542;
        --warn-tint: #352a10;
        --bad: #f07272;
        --bad-tint: #3a1919;
        --user: #2c2c2a;
        --shadow: none;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 var(--font); display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; background: radial-gradient(900px 420px at 85% -120px, rgba(228, 0, 58, .07), transparent 70%), linear-gradient(180deg, var(--soft) 0%, var(--bg) 360px); }
a { color: var(--brand); }
h2 { color: var(--ink); font-size: 15px; font-weight: 900; text-transform: uppercase; letter-spacing: .02em; margin: 0 0 10px; }
h3 { color: var(--ink); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin: 18px 0 8px; }
h4 { color: var(--ink); font-size: 16px; margin: 12px 0 4px; }
code { font: 13px var(--mono); background: var(--soft); padding: 1px 5px; border-radius: 4px; color: var(--ink); }
.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid rgba(228, 0, 58, .35); outline-offset: 2px; }

/* ---- Header ------------------------------------------------------------ */

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand svg { width: 40px; height: 34px; flex: none; }
.brand-mark { fill: var(--brand); }
.brand-cut { fill: var(--surface); }
.brand-name { font-size: 21px; font-weight: 900; font-style: italic; text-transform: uppercase; letter-spacing: -.01em; line-height: 1; }
.brand-name b { color: var(--brand); font-weight: 900; }
.chip { display: inline-flex; align-items: center; background: var(--brand-tint); color: var(--brand-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; }

.mode-switch { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 4px; }
.mode-switch button {
    display: flex; flex-direction: column; align-items: flex-start; gap: 1px; border: 0; background: transparent; color: var(--text);
    font: 800 13px/1.15 var(--font); text-transform: uppercase; letter-spacing: .02em; padding: 7px 16px; border-radius: 999px; cursor: pointer;
}
.mode-switch button small { font-size: 11px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--muted); }
.mode-switch button.on { background: var(--ink); color: var(--bg); }
.mode-switch button.on small { color: var(--bg); opacity: .75; }
.mode-switch button:not(.on):hover { color: var(--brand); }

/* ---- Layout -------------------------------------------------------------- */

.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; padding-top: 24px; padding-bottom: 40px; align-items: start; }
@media (max-width: 960px) { .chat-layout { grid-template-columns: 1fr; } }
.side-col { position: sticky; top: 88px; display: grid; gap: 16px; }
@media (max-width: 960px) { .side-col { position: static; } }

.mode-banner { border-radius: var(--radius); padding: 12px 16px; font-size: 14px; margin-bottom: 20px; border-left: 4px solid; color: var(--ink); }
.mode-banner.mode-gateway { background: var(--ok-tint); border-color: var(--ok); }
.mode-banner.mode-direct { background: var(--warn-tint); border-color: var(--warn); }

/* ---- Messages ------------------------------------------------------------ */

.thread { display: flex; flex-direction: column; gap: 18px; min-height: 40vh; }
.msg { display: flex; gap: 12px; align-items: flex-start; animation: bubbleIn .35s cubic-bezier(.2, .8, .2, 1) both; }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; background: var(--surface); box-shadow: 0 4px 14px rgba(0, 0, 0, .1); display: grid; place-items: center; }
.avatar svg { width: 25px; height: 21px; }
.bubbles { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.bubble { max-width: 100%; background: var(--surface); color: var(--ink); border-radius: 4px 18px 18px 18px; padding: 13px 18px; box-shadow: var(--shadow); border: 1px solid transparent; }
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .2em 0 .8em; padding-left: 1.3em; }
.bubble li { margin: .15em 0; }
.bubble pre { background: var(--soft); border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; font: 13px/1.5 var(--mono); }
.bubble blockquote { margin: .3em 0 .8em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.bubble.typing { display: inline-flex; gap: 5px; padding: 15px 18px; }
.bubble.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); animation: dot 1s infinite; }
.bubble.typing i:nth-child(2) { animation-delay: .15s; }
.bubble.typing i:nth-child(3) { animation-delay: .3s; }
.streaming .avatar { animation: bob .9s ease-in-out infinite; }

.msg-user { flex-direction: column; align-items: flex-end; }
.msg-user .bubble { background: var(--user); color: #fff; border-radius: 18px 18px 4px 18px; max-width: min(620px, 88%); white-space: normal; word-break: break-word; }
.msg-time { font-size: 11px; color: var(--muted); }

.msg-error .bubble { background: var(--bad-tint); border-color: var(--bad); }
.msg-error .bubble strong { color: var(--bad); }
.err-code { font-size: 12px; color: var(--muted); }
.flag-bubble { background: var(--warn-tint); font-size: 13px; }

.msg-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--muted); align-items: center; }
.mode-tag { font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 1px 7px; border-radius: 4px; }
.mode-tag.mode-gateway { background: var(--ok-tint); color: var(--ok); }
.mode-tag.mode-direct { background: var(--warn-tint); color: var(--warn); }
.flag-tag { font-weight: 800; color: var(--brand); }

.msg-note { margin-left: 54px; display: block; font-size: 14px; background: var(--soft); border-left: 4px solid var(--ok); border-radius: var(--radius); padding: 10px 14px; color: var(--ink); }
.msg-note p { margin: .2em 0; }
.msg-note ul { margin: .3em 0; padding-left: 1.2em; font-family: var(--mono); font-size: 13px; }
.msg-note.note-denied, .msg-note.note-cancelled { border-left-color: var(--bad); }
.note-tool { display: inline-block; font: 700 11px var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--ink); }

.action-card { width: 100%; max-width: 560px; background: var(--surface); border: 2px solid var(--brand); border-radius: 12px; padding: 12px 16px; }
.action-card.status-done { border-color: var(--ok); }
.action-card.status-denied, .action-card.status-cancelled { border-color: var(--line); opacity: .8; }
.action-head { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.action-status { color: var(--muted); }
.action-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 10px 0; font-size: 14px; }
.action-card dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.action-card dd { margin: 0; color: var(--ink); white-space: pre-wrap; word-break: break-word; }
.action-buttons { display: flex; gap: 8px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.suggestion { border: 1px solid var(--line); background: var(--soft); color: var(--ink); font: 600 13px/1.3 var(--font); padding: 8px 12px; border-radius: 999px; cursor: pointer; text-align: left; }
.suggestion:hover { border-color: var(--brand); color: var(--brand); }

/* ---- Composer ------------------------------------------------------------ */

.composer { position: sticky; bottom: 12px; margin-top: 24px; display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .08); }
.composer textarea { width: 100%; min-height: 48px; max-height: 260px; border: 0; resize: none; font: 400 16px/1.45 var(--font); color: var(--ink); background: transparent; padding: 10px; }
.composer textarea:focus { outline: none; }
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(228, 0, 58, .15); }
.composer-hint { grid-column: 1 / -1; margin: 0 10px; font-size: 11px; color: var(--muted); }
.new-chat { margin: 10px 0 0; text-align: right; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px;
    border: 2px solid var(--brand); border-radius: var(--radius); background: var(--brand); color: #fff;
    font: 800 14px/1 var(--font); text-transform: uppercase; letter-spacing: .03em; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn[disabled] { opacity: .5; cursor: progress; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn-small { min-height: 34px; padding: 0 14px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--soft); color: var(--ink); border-color: var(--muted); }
.btn-link { background: none; border: 0; padding: 0; color: var(--muted); font: 600 13px var(--font); cursor: pointer; text-decoration: underline; }
.send-btn { align-self: end; }

/* ---- Side panels --------------------------------------------------------- */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); font-size: 14px; }
.path { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; font-weight: 700; }
.path li { padding: 4px 8px; border-radius: 4px; background: var(--soft); color: var(--ink); }
.path li + li::before { content: "→"; margin: 0 6px 0 -2px; color: var(--muted); font-weight: 400; }
.path li.hub { background: var(--ok-tint); color: var(--ok); }
.path-direct li:last-child { background: var(--warn-tint); color: var(--warn); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 5px 14px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.facts dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.facts dd.bad { color: var(--bad); font-weight: 700; }
.warn-box, .ok-box { margin: 0; padding: 10px 12px; border-radius: var(--radius); font-size: 13px; }
.warn-box { background: var(--warn-tint); color: var(--ink); border-left: 3px solid var(--warn); }
.ok-box { background: var(--ok-tint); color: var(--ink); border-left: 3px solid var(--ok); }
.flags { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.flags li { padding: 6px 8px; background: var(--brand-tint); border-radius: var(--radius); color: var(--ink); }
.stage { display: inline-block; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; background: var(--surface); border: 1px solid var(--line); }
.turns { width: 100%; border-collapse: collapse; font-size: 12px; }
.turns th, .turns td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; font-variant-numeric: tabular-nums; }
.turns th { color: var(--muted); font-weight: 800; text-transform: uppercase; font-size: 10px; letter-spacing: .04em; }
.turns tr.bad td { color: var(--bad); }

.scenarios form { display: grid; gap: 8px; }
.scenario { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--soft); border-radius: 10px; padding: 9px 12px; cursor: pointer; font: inherit; color: var(--ink); }
.scenario strong { font-size: 13px; }
.scenario span { font-size: 12px; color: var(--muted); }
.scenario:hover:not([disabled]) { border-color: var(--brand); }
.scenario:hover:not([disabled]) strong { color: var(--brand); }
.scenario[disabled] { opacity: .5; cursor: not-allowed; }

.site-footer { background: var(--soft); color: var(--muted); font-size: 12px; }
.site-footer .wrap { padding-top: 16px; padding-bottom: 16px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

body.is-busy .send-btn { cursor: progress; }

@keyframes bubbleIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .msg, .streaming .avatar, .bubble.typing i { animation: none; } }
@media (max-width: 640px) { .mode-switch button { padding: 6px 10px; } .msg-note { margin-left: 0; } .brand-name { font-size: 18px; } }

/* ---- Login and user menu ------------------------------------------------- */

.login-wrap { display: grid; place-items: center; padding-top: 64px; padding-bottom: 64px; }
.login-box { width: 100%; max-width: 420px; padding: 28px; }
.login-box h1 { color: var(--ink); font-size: 26px; font-weight: 900; text-transform: uppercase; margin: 0 0 6px; }
.login-form { display: grid; gap: 6px; margin-top: 16px; }
.login-form label { font-size: 13px; font-weight: 700; color: var(--ink); margin-top: 8px; }
.login-form input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font: 400 16px var(--font); }
.login-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(228, 0, 58, .15); }
.login-form .btn { margin-top: 16px; }
.error-box { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; background: var(--bad-tint); color: var(--ink); border-left: 3px solid var(--bad); }
.user-menu { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; }
.user-name { font-weight: 700; color: var(--ink); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-header .wrap { row-gap: 8px; }
