/* AIBotLite inference site.
   No framework, no build step, no inline styles - the page's Content-Security-Policy
   allows styles and scripts only from this origin, so anything that works here has
   to be in this file. */

:root {
    --bg: #101317;
    --panel: #171b21;
    --panel-2: #1d222a;
    --line: #2a313b;
    --text: #e6e9ee;
    --muted: #8b95a5;
    --accent: #4f8cff;
    --accent-dim: #2f4f80;
    --ok: #3fbf7f;
    --warn: #d9a441;
    --err: #e0655f;
    --radius: 10px;
    --max: 46rem;
}

* { box-sizing: border-box; }

/* The gate and the app are toggled with the hidden attribute, and a `display`
   rule below would otherwise win over it. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
}

/* ----------------------------------------------------------------- top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .6rem 1rem;
    background: rgba(16, 19, 23, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: center; gap: .55rem; }
.mark {
    width: .7rem; height: .7rem; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, .18);
}
.name { font-weight: 600; letter-spacing: .01em; }

.status { display: flex; gap: .4rem; flex-wrap: wrap; }

.pill {
    font-size: 11.5px;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .2rem .5rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: var(--panel);
}
.pill.on { color: var(--ok); border-color: #245c41; }
.pill.off { color: var(--err); border-color: #5c2b28; }
.pill.busy { color: var(--warn); border-color: #5c4720; }

/* -------------------------------------------------------------------- main */

main {
    flex: 1;
    width: 100%;
    max-width: var(--max);
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* -------------------------------------------------------------------- gate */

.gate { flex: 1; display: flex; align-items: center; justify-content: center; }

.card {
    width: 100%;
    max-width: 24rem;
    padding: 1.4rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.card h1 { margin: 0 0 .35rem; font-size: 1.15rem; font-weight: 600; }
.card p { margin: 0 0 1rem; }

label {
    display: block;
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    margin: .8rem 0 .3rem;
}

input, textarea {
    width: 100%;
    padding: .6rem .7rem;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, .12);
}

button {
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid transparent;
}

/* Only the sign-in card: the composer's Send button is sized by the rules in
   the composer section below, and a margin-top here would push it out of line
   with the microphone button. */
#login-form button {
    margin-top: .9rem;
    padding: .55rem .95rem;
    color: #fff;
    background: var(--accent);
    font-weight: 550;
}
#login-form button:hover { background: #3f79e6; }

button:disabled { opacity: .45; cursor: default; }

.link {
    background: none;
    border: none;
    color: var(--muted);
    padding: .2rem 0;
    font-size: 13px;
    text-decoration: underline;
    text-decoration-color: transparent;
}
.link:hover { color: var(--text); text-decoration-color: currentColor; }

.error { color: var(--err); font-size: 13.5px; min-height: 1.2em; margin: .8rem 0 0 !important; }
.muted { color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------------ thread */

.thread {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding-bottom: 1rem;
}

.empty { color: var(--muted); text-align: center; margin-top: 3rem; }

.msg {
    padding: .65rem .8rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg.user {
    align-self: flex-end;
    background: #1b2534;
    border-color: #2c3d57;
    max-width: 85%;
}

/* An assistant turn is a container of blocks (thinking, tool calls, answer),
   so it must not inherit pre-wrap - the rendered markdown handles its own
   whitespace, and pre-wrap would double every newline the parser produced. */
.msg.assistant {
    align-self: stretch;
    background: var(--panel);
    white-space: normal;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

.answer > *:first-child, .thinking-body > *:first-child { margin-top: 0; }
.answer > *:last-child, .thinking-body > *:last-child { margin-bottom: 0; }

.answer p { margin: .4rem 0; }
.answer h3, .answer h4, .answer h5, .answer h6 {
    margin: .9rem 0 .4rem;
    font-size: 1rem;
    line-height: 1.35;
}
.answer h3 { font-size: 1.06rem; }

.answer ul, .answer ol { margin: .4rem 0; padding-left: 1.4rem; }
.answer li { margin: .15rem 0; }
.answer li > ul, .answer li > ol { margin: .15rem 0; }

.answer blockquote {
    margin: .5rem 0;
    padding: .1rem .8rem;
    border-left: 3px solid var(--accent-dim);
    color: var(--muted);
}

.answer hr { margin: .8rem 0; border: none; border-top: 1px solid var(--line); }

.answer code {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 13px;
    padding: .1rem .3rem;
    border-radius: 4px;
    background: var(--panel-2);
}

.answer pre {
    margin: .5rem 0;
    padding: .6rem .7rem;
    overflow-x: auto;
    background: #0c0f13;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.answer pre code {
    display: block;
    padding: 0;
    background: none;
    white-space: pre;
    line-height: 1.45;
}

.answer table {
    margin: .5rem 0;
    border-collapse: collapse;
    width: 100%;
    font-size: 13.5px;
    display: block;
    overflow-x: auto;
}
.answer th, .answer td {
    padding: .35rem .55rem;
    border: 1px solid var(--line);
    text-align: left;
}
.answer th { background: var(--panel-2); font-weight: 600; }
.answer .align-center { text-align: center; }
.answer .align-right { text-align: right; }

.answer a { color: var(--accent); text-decoration: underline; }

/* Thinking and tool calls are collapsible: they explain what happened without
   sitting between the question and the answer. */
.thinking, .tool {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    overflow: hidden;
}

.thinking > summary, .tool > summary {
    padding: .35rem .6rem;
    cursor: pointer;
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    list-style: none;
}
.thinking > summary::before, .tool > summary::before {
    content: "▸";
    display: inline-block;
    margin-right: .4rem;
    transition: transform .12s ease;
}
.thinking[open] > summary::before, .tool[open] > summary::before { transform: rotate(90deg); }
.thinking > summary:hover, .tool > summary:hover { color: var(--text); }

/* Open while it streams, so the visitor sees the model working. */
.thinking[open] > summary { color: var(--accent); }

.thinking-body {
    padding: .1rem .7rem .6rem;
    color: var(--muted);
    font-size: 13.5px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 22rem;
    overflow-y: auto;
}

.tool-name { color: var(--warn); }

.tool-args, .tool-result {
    margin: 0 .5rem .5rem;
    padding: .45rem .55rem;
    max-height: 18rem;
    overflow: auto;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 12.5px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #0c0f13;
    border-radius: 6px;
}
.tool-result { border-top: 1px solid var(--line); color: var(--muted); }

.turn-note {
    margin: 0;
    font-size: 13.5px;
    color: var(--muted);
}
.turn-note.failed-note { color: var(--err); }

.msg.system {
    align-self: stretch;
    background: none;
    border-style: dashed;
    color: var(--muted);
    font-size: 13.5px;
}

.msg.failed { border-color: #5c2b28; }

.meta {
    display: block;
    margin-top: .4rem;
    font-size: 11.5px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

/* A caret while an answer is still arriving. It goes after the last line of
   rendered markdown, not after the block that happens to end the answer. */
.answer.typing > *:last-child::after {
    content: "▍";
    color: var(--accent);
    animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* ---------------------------------------------------------------- composer */

.composer-wrap {
    position: sticky;
    bottom: 0;
    padding-top: .6rem;
    background: linear-gradient(to bottom, rgba(16, 19, 23, 0), var(--bg) 22%);
}

.notice {
    margin: 0 0 .5rem;
    padding: .5rem .7rem;
    font-size: 13.5px;
    border-radius: 8px;
    border: 1px solid #5c4720;
    background: #241f14;
    color: #e8cfa0;
}

.composer {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
    padding: .5rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

/* One height for everything in the composer row, so the first line of the
   textarea and both buttons share a baseline instead of each sizing itself. */
#input {
    flex: 1;
    max-height: 12rem;
    min-height: 2.3rem;
    resize: none;
    border: none;
    background: none;
    padding: .4rem .3rem;
}
#input:focus { box-shadow: none; }

.actions { display: flex; gap: .4rem; align-items: center; }

#send {
    height: 2.3rem;
    padding: 0 1rem;
    color: #fff;
    background: var(--accent);
    font-weight: 550;
}
#send:hover { background: #3f79e6; }

.icon {
    width: 2.3rem;
    height: 2.3rem;
    display: grid;
    place-items: center;
    background: var(--panel-2);
    border-color: var(--line);
}
.icon:hover { border-color: var(--accent-dim); }

.dot {
    width: .8rem;
    height: .8rem;
    border-radius: 50%;
    background: var(--muted);
}
.icon[aria-pressed="true"] { border-color: var(--err); background: #2a1a1a; }
.icon[aria-pressed="true"] .dot { background: var(--err); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* A simple paperclip drawn with borders, so the attach button needs no icon
   font or inline SVG (the CSP allows neither). */
.clip {
    width: .55rem;
    height: 1.05rem;
    border: 2px solid var(--muted);
    border-top: none;
    border-radius: 0 0 .55rem .55rem;
    transform: rotate(45deg);
}
.icon:hover .clip { border-color: var(--text); }

/* Images staged before sending, and images inside a sent message. */
.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: .5rem;
}

.attachment {
    position: relative;
    width: 4.5rem;
    height: 4.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--panel-2);
}
.attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.attachment-remove {
    position: absolute;
    top: .15rem;
    right: .15rem;
    width: 1.2rem;
    height: 1.2rem;
    padding: 0;
    line-height: 1;
    font-size: 15px;
    border-radius: 50%;
    color: #fff;
    background: rgba(0, 0, 0, .6);
    border: none;
}
.attachment-remove:hover { background: var(--err); }

.msg-image {
    display: block;
    max-width: 16rem;
    max-height: 16rem;
    margin-top: .4rem;
    border-radius: 8px;
    border: 1px solid var(--line);
}
.msg.user .msg-image { margin-left: auto; }

.composer-tools {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .35rem .2rem 0;
    font-size: 12.5px;
    color: var(--muted);
}

.timer { font-variant-numeric: tabular-nums; color: var(--err); }
.counter { margin-left: auto; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--err); }

@media (max-width: 34rem) {
    main { padding: .6rem; }
    .status .pill { font-size: 10.5px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; }
}
