/* ═══════════════════════════════════════════════════════════
   iTiKo · chat interface for worker workspaces
   Brand: itiko.tech — deep night canvas, teal gradient, Exo 2 / Orbitron
   ═══════════════════════════════════════════════════════════ */

@font-face {
    font-family: 'Exo 2';
    src: url('/chat/fonts/Exo2-VF-subset.woff2') format('woff2');
    font-weight: 100 900;
    font-display: swap;
}
@font-face {
    font-family: 'Orbitron';
    src: url('/chat/fonts/Orbitron-VF-subset.woff2') format('woff2');
    font-weight: 400 900;
    font-display: swap;
}

@property --spin {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

:root {
    --bg: #05080b;
    --bg-2: #0a0f14;
    --surface: #0e151b;
    --surface-2: #121c23;
    --glass: rgb(14 21 27 / 0.72);
    --glass-strong: rgb(14 21 27 / 0.9);
    --line: rgb(255 255 255 / 0.08);
    --line-strong: rgb(255 255 255 / 0.14);
    --text: #e8f1f3;
    --muted: #9fb3ba;
    --faint: #6b7f86;
    --accent: #00a0b9;
    --accent-2: #26d9d7;
    --gradient: linear-gradient(135deg, #00a0b9, #26d9d7);
    --danger: #ff6b7a;
    --ok: #3ddc97;
    --warn: #ffc15e;
    --radius: 18px;
    --col: 780px;
    --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
    --ease: cubic-bezier(.2, .8, .2, 1);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 400 15.5px/1.65 'Exo 2', system-ui, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

::selection { background: rgb(38 217 215 / 0.3); }

/* ─── Atmosphere ─────────────────────────────────────────── */
.aurora {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.aurora::after {
    /* faint dot grid, fading out toward the bottom */
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgb(255 255 255 / 0.05) 1px, transparent 1px);
    background-size: 26px 26px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
}
.aurora i {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.32;
    animation: drift 26s var(--ease) infinite alternate;
}
.aurora i:nth-child(1) { width: 46vmax; height: 46vmax; left: -12vmax; top: -18vmax; background: #00a0b9; }
.aurora i:nth-child(2) { width: 38vmax; height: 38vmax; right: -14vmax; top: 8vmax; background: #26d9d7; opacity: 0.16; animation-duration: 32s; }
.aurora i:nth-child(3) { width: 30vmax; height: 30vmax; left: 30vw; bottom: -20vmax; background: #0e7490; opacity: 0.22; animation-duration: 38s; }
body.working .aurora i { opacity: 0.42; }
body.working .aurora i:nth-child(2) { opacity: 0.24; }

@keyframes drift {
    to { transform: translate(6vmax, 4vmax) scale(1.12); }
}

/* ─── Layout ─────────────────────────────────────────────── */
.app {
    position: relative;
    z-index: 1;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    /* without this the column grows to the widest code block or table */
    grid-template-columns: minmax(0, 1fr);
}

.top {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
    background: rgb(5 8 11 / 0.55);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
}
.brand { display: flex; flex-shrink: 0; }
.brand img { height: 28px; width: auto; }

.session {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.25;
}
.session-title {
    font-weight: 600;
    font-size: 0.95rem;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    color: var(--muted);
}
.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--faint);
    flex-shrink: 0;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgb(61 220 151 / 0.16); }
.dot.busy { background: var(--accent-2); animation: pulse 1.4s ease-in-out infinite; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }
@keyframes pulse {
    50% { box-shadow: 0 0 0 5px rgb(38 217 215 / 0.18); }
}

.top-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .2s, color .2s, transform .2s var(--ease);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: rgb(255 255 255 / 0.06); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible, .send:focus-visible, .chip:focus-visible, .option:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

/* ─── Thread ─────────────────────────────────────────────── */
.scroll {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scroll-behavior: auto;
    scrollbar-width: thin;
    scrollbar-color: rgb(255 255 255 / 0.12) transparent;
}
.thread {
    width: 100%;
    max-width: calc(var(--col) + 32px);
    margin: 0 auto;
    padding: 28px 16px 24px;
}

.hero {
    min-height: 58vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 0 8px;
    animation: rise .7s var(--ease) both;
}
.hero-mascot { width: 92px; height: 92px; margin-bottom: 22px; filter: drop-shadow(0 12px 32px rgb(0 160 185 / 0.45)); }
.hero-title {
    margin: 0;
    font-size: clamp(1.7rem, 4.5vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.15;
    background: linear-gradient(135deg, #fff 30%, #9fe9ec);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero-sub { margin: 10px 0 26px; color: var(--muted); max-width: 30rem; }

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 620px;
}
.chip {
    position: relative;
    text-align: left;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color .25s, transform .25s var(--ease), background .25s;
    animation: rise .6s var(--ease) both;
}
.chip:nth-child(2) { animation-delay: .05s; }
.chip:nth-child(3) { animation-delay: .1s; }
.chip:nth-child(4) { animation-delay: .15s; }
.chip:hover { border-color: rgb(38 217 215 / 0.45); transform: translateY(-2px); background: rgb(18 28 35 / 0.85); }
.chip small { display: block; color: var(--faint); font-size: 0.75rem; margin-top: 3px; }

@keyframes rise {
    from { opacity: 0; transform: translateY(14px); filter: blur(4px); }
    to { opacity: 1; transform: none; filter: none; }
}

/* ─── Messages ───────────────────────────────────────────── */
.msg { margin: 0 0 22px; }
.msg.enter { animation: rise .45s var(--ease) both; }

.msg-user { display: flex; justify-content: flex-end; }
.bubble {
    max-width: min(85%, 620px);
    padding: 11px 16px;
    border-radius: 20px 20px 6px 20px;
    background:
        linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
        linear-gradient(135deg, rgb(0 160 185 / 0.7), rgb(38 217 215 / 0.35)) border-box;
    border: 1px solid transparent;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    box-shadow: 0 8px 30px -12px rgb(0 160 185 / 0.35);
}
.bubble .att { display: inline-flex; gap: 6px; margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
.msg-user.pending .bubble { opacity: 0.6; }

.turn { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; }
.turn-avatar { width: 34px; height: 34px; padding-top: 2px; }
.turn-body { min-width: 0; }
.turn-body > * + * { margin-top: 12px; }

.note {
    display: flex;
    justify-content: center;
    margin: 0 0 22px;
}
.note span {
    font-size: 0.75rem;
    color: var(--faint);
    padding: 3px 12px;
    border: 1px solid var(--line);
    border-radius: 99px;
}

/* ─── Markdown ───────────────────────────────────────────── */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.75em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.3em 0 0.5em; font-weight: 700; }
.md h1 { font-size: 1.35rem; }
.md h2 { font-size: 1.18rem; }
.md h3 { font-size: 1.05rem; }
.md h4 { font-size: 1rem; color: var(--muted); }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 0.8em; }
.md li { margin: 0.2em 0; }
.md li::marker { color: var(--accent-2); }
.md a { color: var(--accent-2); text-decoration: none; border-bottom: 1px solid rgb(38 217 215 / 0.35); }
.md a:hover { border-bottom-color: var(--accent-2); }
.md strong { color: #fff; font-weight: 650; }
.md hr { border: 0; height: 1px; background: var(--line-strong); margin: 1.4em 0; }
.md blockquote {
    margin: 0 0 0.8em;
    padding: 4px 14px;
    border-left: 3px solid var(--accent);
    color: var(--muted);
    background: rgb(0 160 185 / 0.06);
    border-radius: 0 10px 10px 0;
}
.md code {
    font-family: var(--mono);
    font-size: 0.86em;
    padding: 0.12em 0.4em;
    border-radius: 6px;
    background: rgb(255 255 255 / 0.07);
    color: #bff4f3;
}
.md pre {
    position: relative;
    margin: 0 0 0.9em;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-2);
    overflow-x: auto;
    scrollbar-width: thin;
}
.md pre code { padding: 0; background: none; color: #d6e4e7; font-size: 0.84rem; line-height: 1.55; }
.table-wrap {
    margin: 0 0 0.9em;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    scrollbar-width: thin;
}
.md table { border-collapse: collapse; width: 100%; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.md th, .md td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.md th { background: rgb(255 255 255 / 0.04); color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.md tr:last-child td { border-bottom: 0; }
.md tbody tr:hover td { background: rgb(38 217 215 / 0.04); }

.copy-code {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.72rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity .2s;
}
.md pre:hover .copy-code, .copy-code:focus-visible { opacity: 1; }

.file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 2px 10px 2px 8px;
    border: 1px solid rgb(38 217 215 / 0.35) !important;
    border-radius: 10px;
    background: rgb(0 160 185 / 0.1);
    color: #bff4f3 !important;
    font-size: 0.86em;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background .2s;
}
.file-link:hover { background: rgb(0 160 185 / 0.2); }
.file-link svg { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .2s; }
.turn:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; border-radius: 9px; }
.msg-actions .icon-btn svg { width: 16px; height: 16px; }

/* ─── Tool activity ──────────────────────────────────────── */
.steps {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgb(10 15 20 / 0.6);
    overflow: hidden;
}
.steps-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.86rem;
    color: var(--muted);
}
.steps-head:hover { color: var(--text); }
.steps-head .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps-head .count { font-size: 0.74rem; color: var(--faint); }
.chev { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform .25s var(--ease); flex-shrink: 0; }
.steps.open .chev { transform: rotate(90deg); }
.steps-body { display: none; border-top: 1px solid var(--line); padding: 6px 0; }
.steps.open .steps-body { display: block; }

.step { padding: 6px 12px 6px 14px; font-size: 0.84rem; }
.step-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.step-row .label { flex-shrink: 0; color: var(--text); }
.step-row .detail {
    min-width: 0;
    font-family: var(--mono);
    font-size: 0.76rem;
    color: var(--faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.step-out {
    display: none;
    margin: 6px 0 4px 26px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg);
    font-family: var(--mono);
    font-size: 0.74rem;
    line-height: 1.5;
    color: #b9c9cd;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 260px;
    overflow-y: auto;
}
.step.open .step-out { display: block; }

.st {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
}
.st svg { width: 14px; height: 14px; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.st.done svg { stroke: var(--ok); }
.st.error svg { stroke: var(--danger); }
.st.run::before {
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgb(38 217 215 / 0.25);
    border-top-color: var(--accent-2);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.todo { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: rgb(10 15 20 / 0.6); }
.todo-title { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; letter-spacing: 0.02em; }
.todo-item { display: flex; gap: 10px; align-items: baseline; font-size: 0.88rem; padding: 3px 0; }
.todo-item .box {
    width: 14px; height: 14px; flex-shrink: 0; border-radius: 5px;
    border: 1.5px solid var(--faint); position: relative; top: 2px;
}
.todo-item.in_progress .box { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgb(38 217 215 / 0.15); }
.todo-item.completed { color: var(--faint); text-decoration: line-through; }
.todo-item.completed .box { background: var(--gradient); border-color: transparent; }

/* ─── Mascot ─────────────────────────────────────────────── */
.mascot { width: 100%; height: 100%; overflow: visible; }
.m-eye { transform-box: fill-box; transform-origin: center; animation: blink 5.5s infinite; }
.m-eye + .m-eye { animation-delay: .04s; }
.m-eyes { transition: transform .4s var(--ease); }
.m-smile { transition: d .4s var(--ease); }
@keyframes blink {
    0%, 93%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}
.thinking .m-eyes { animation: look 2.4s var(--ease) infinite; }
.thinking .m-head { animation: bob 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center bottom; }
@keyframes look {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px) translateY(-2px); }
    60% { transform: translateX(5px) translateY(-1px); }
}
@keyframes bob {
    50% { transform: translateY(-2px) rotate(-1.5deg); }
}

/* ─── Dock ───────────────────────────────────────────────── */
.dock {
    position: relative;
    width: 100%;
    max-width: calc(var(--col) + 32px);
    margin: 0 auto;
    padding: 0 16px max(14px, env(safe-area-inset-bottom));
}

.live {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 10px;
    padding: 8px 8px 8px 12px;
    border: 1px solid rgb(38 217 215 / 0.22);
    border-radius: 16px;
    background: var(--glass-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    animation: rise .35s var(--ease) both;
}
.live-mascot { width: 30px; height: 30px; flex-shrink: 0; }
.live-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.live-title {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: linear-gradient(90deg, var(--text) 0%, var(--text) 40%, var(--accent-2) 50%, var(--text) 60%, var(--text) 100%);
    background-size: 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shimmer 2.2s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.live-meta { font-size: 0.74rem; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-stop {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    background: rgb(255 255 255 / 0.04);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}
.live-stop svg { width: 12px; height: 12px; fill: currentColor; }
.live-stop:hover { background: rgb(255 107 122 / 0.12); border-color: rgb(255 107 122 / 0.45); }

/* Cards: questions from the assistant, login, offline */
.card {
    margin: 0 0 10px;
    padding: 16px;
    border-radius: var(--radius);
    background:
        linear-gradient(var(--glass-strong), var(--glass-strong)) padding-box,
        linear-gradient(135deg, rgb(0 160 185 / 0.8), rgb(38 217 215 / 0.3)) border-box;
    border: 1px solid transparent;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 18px 50px -20px rgb(0 160 185 / 0.5);
    animation: rise .4s var(--ease) both;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 650; }
.card-head .mini { width: 26px; height: 26px; flex-shrink: 0; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; }
.options { display: grid; gap: 8px; }
.option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: rgb(255 255 255 / 0.03);
    text-align: left;
    cursor: pointer;
    transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.option:hover { border-color: rgb(38 217 215 / 0.55); background: rgb(0 160 185 / 0.1); transform: translateX(2px); }
.option .num {
    display: grid; place-items: center; flex-shrink: 0;
    width: 24px; height: 24px; border-radius: 8px;
    background: rgb(255 255 255 / 0.06);
    font: 700 0.72rem/1 'Orbitron', sans-serif;
    color: var(--accent-2);
}
.option .hint-text { display: block; font-size: 0.76rem; color: var(--faint); }
.option.selected { border-color: rgb(38 217 215 / 0.5); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border: 0;
    border-radius: 13px;
    background: var(--gradient);
    color: #031216;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: filter .2s, transform .2s var(--ease);
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.97); }
.btn.ghost { background: rgb(255 255 255 / 0.06); color: var(--text); border: 1px solid var(--line-strong); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.code-row { display: flex; gap: 8px; margin-top: 12px; }
.code-row input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: var(--bg);
    color: var(--text);
    font: 0.9rem var(--mono);
    outline: none;
}
.code-row input:focus { border-color: var(--accent-2); }

/* Composer — the border turns into a slowly rotating gradient while the
   assistant works, so the state is visible without reading anything. */
.composer {
    position: relative;
    border-radius: 22px;
    box-shadow: 0 20px 60px -24px rgb(0 0 0 / 0.9);
    transition: box-shadow .3s;
}
.composer::after {
    /* the glass body */
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    border-radius: inherit;
    border: 1px solid var(--line-strong);
    background: var(--glass-strong);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.composer::before {
    /* the working ring */
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    border-radius: inherit;
    padding: 1.5px;
    background: conic-gradient(from var(--spin), transparent 0deg, #00a0b9 70deg, #26d9d7 140deg, transparent 220deg);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity .4s;
    pointer-events: none;
}
.composer > * { position: relative; z-index: 1; }
.composer:focus-within { box-shadow: 0 0 0 4px rgb(38 217 215 / 0.12), 0 20px 60px -24px rgb(0 0 0 / 0.9); }
body.working .composer::before { opacity: 1; animation: rotate 2.6s linear infinite; }
@keyframes rotate { to { --spin: 360deg; } }

.composer textarea {
    display: block;
    width: 100%;
    max-height: 40vh;
    padding: 15px 18px 4px;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.5;
    scrollbar-width: thin;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 8px 8px; }
.hint { flex: 1; font-size: 0.72rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 13px;
    background: var(--gradient);
    color: #031216;
    cursor: pointer;
    box-shadow: 0 6px 20px -6px rgb(38 217 215 / 0.6);
    transition: transform .2s var(--ease), opacity .2s, filter .2s;
}
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send:hover { filter: brightness(1.12); }
.send:active { transform: scale(0.92); }
.send:disabled { opacity: 0.35; cursor: default; box-shadow: none; filter: grayscale(0.4); }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.attachments:empty { display: none; }
.att-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 240px;
    padding: 5px 6px 5px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    background: var(--surface);
    font-size: 0.8rem;
}
.att-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip.loading { opacity: 0.6; }
.att-chip button { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0 4px; font-size: 1rem; line-height: 1; }
.att-chip button:hover { color: var(--danger); }

.to-bottom {
    position: absolute;
    left: 50%;
    bottom: 150px;
    z-index: 5;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin-left: -19px;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: var(--glass-strong);
    backdrop-filter: blur(12px);
    color: var(--text);
    cursor: pointer;
    animation: rise .3s var(--ease) both;
}
.to-bottom svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.dropzone {
    position: absolute;
    inset: 10px;
    z-index: 50;
    display: grid;
    place-items: center;
    border: 2px dashed rgb(38 217 215 / 0.6);
    border-radius: 24px;
    background: rgb(5 8 11 / 0.8);
    backdrop-filter: blur(6px);
    font-weight: 600;
    color: var(--accent-2);
    pointer-events: none;
}

/* ─── Terminal drawer ────────────────────────────────────── */
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(920px, 100vw);
    display: flex;
    flex-direction: column;
    background: #0a0c10;
    border-left: 1px solid var(--line-strong);
    transform: translateX(102%);
    transition: transform .45s var(--ease);
    box-shadow: -30px 0 80px -20px rgb(0 0 0 / 0.8);
}
.drawer.open { transform: none; }
.drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 18px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
    font-weight: 650;
}
.drawer-note { flex: 1; font-size: 0.75rem; color: var(--faint); font-weight: 400; }
.drawer iframe { flex: 1; width: 100%; border: 0; background: #0a0c10; }
.scrim { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 0.5); backdrop-filter: blur(2px); }

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
    position: fixed;
    left: 50%;
    top: max(16px, env(safe-area-inset-top));
    z-index: 60;
    max-width: calc(100vw - 32px);
    padding: 10px 16px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: var(--glass-strong);
    backdrop-filter: blur(16px);
    font-size: 0.86rem;
    transform: translate(-50%, calc(-100% - 40px));
    opacity: 0;
    transition: transform .4s var(--ease), opacity .3s;
    pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { border-color: rgb(255 107 122 / 0.5); }

/* ─── Small screens ──────────────────────────────────────── */
@media (max-width: 640px) {
    html, body { font-size: 15px; }
    .brand img { height: 24px; }
    .session { align-items: flex-start; }
    .suggestions { grid-template-columns: 1fr; }
    .chip:nth-child(n+4) { display: none; }
    .turn { grid-template-columns: 1fr; gap: 6px; }
    .turn-avatar { width: 26px; height: 26px; }
    .hint { visibility: hidden; }
    .msg-actions { opacity: 1; }
    .hero { min-height: 48vh; }
    .hero-mascot { width: 72px; height: 72px; }
    #btn-logout { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* The newest answer's avatar keeps looking around while the assistant works */
body.working #messages > .turn:last-child .m-eyes { animation: look 2.4s var(--ease) infinite; }
.md th[align="right"], .md td[align="right"] { text-align: right; }
.md th[align="center"], .md td[align="center"] { text-align: center; }

/* ═══ Launch additions (2026-10) — same tokens, new pieces ═══ */

/* Queued / failed user messages */
.msg-user { flex-wrap: wrap; }
.msg-sub { width: 100%; text-align: right; font-size: 0.74rem; color: var(--faint); margin-top: 4px; }
.msg-sub.failed { color: var(--warn); }
.msg-user.queued .bubble { border-style: dashed; }
.msg-user.failed .bubble { opacity: 0.7; border-color: rgb(255 193 94 / 0.5); }
button.link { border: 0; background: none; padding: 0; color: var(--accent-2); cursor: pointer; font: inherit; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* Options card */
.opt-hint { margin: 10px 0 0 !important; font-size: 0.8rem !important; color: var(--faint) !important; }
.btn.small { padding: 8px 14px; font-size: 0.84rem; }
.btn.small svg, .btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* File previews under an answer */
.previews { display: grid; gap: 10px; margin-top: 10px; }
.preview { border: 1px solid var(--line); border-radius: 14px; background: rgb(10 15 20 / 0.6); overflow: hidden; }
.preview-image { margin: 0; }
.preview-image img { display: block; max-width: 100%; max-height: 420px; cursor: zoom-in; background: #fff; }
.preview-image figcaption { padding: 6px 10px; }
.md img.md-img { max-width: 100%; border-radius: 12px; cursor: zoom-in; }
.preview-dash iframe { display: block; width: 100%; height: 440px; border: 0; background: #fff; }
.preview-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--line); font-size: 0.82rem; color: var(--muted); }
.preview-head > svg { width: 16px; height: 16px; fill: none; stroke: var(--accent-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.preview-head .preview-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.preview-head .icon-btn { width: 30px; height: 30px; border-radius: 9px; }
.preview-head .icon-btn svg { width: 16px; height: 16px; }
.file-link.mini { padding: 4px 6px; }
.file-link.mini svg { width: 14px; height: 14px; }
.preview-row { padding: 8px; border: 0; background: none; }
.file-link.kind-sheet { border-color: rgb(61 220 151 / 0.4) !important; }
.file-link.kind-dash { border-color: rgb(255 193 94 / 0.45) !important; }

/* Viewer drawer (PDF, dashboards, pictures) */
.drawer-head .btn.small { padding: 6px 12px; }
#viewer { z-index: 45; }
#viewer iframe { background: #fff; }

/* Header badges */
.icon-btn { position: relative; }
.badge {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 8px; background: var(--warn); color: #031216;
    font: 700 0.62rem/16px 'Orbitron', sans-serif; text-align: center;
}
#btn-tg.linked { color: var(--accent-2); }

/* Telegram promo under the suggestions */
.promo {
    display: flex; align-items: center; gap: 14px;
    width: 100%; max-width: 620px; margin-top: 14px; padding: 14px 16px;
    border-radius: 16px; text-align: left;
    background:
        linear-gradient(var(--glass), var(--glass)) padding-box,
        linear-gradient(135deg, rgb(0 160 185 / 0.7), rgb(38 217 215 / 0.25)) border-box;
    border: 1px solid transparent;
    animation: rise .6s var(--ease) .2s both;
}
.promo.linked { background: var(--glass); border: 1px solid rgb(61 220 151 / 0.35); }
.promo-icon { display: grid; place-items: center; flex-shrink: 0; width: 42px; height: 42px; border-radius: 13px; background: var(--gradient); color: #031216; }
.promo-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.promo.linked .promo-icon { background: rgb(61 220 151 / 0.2); color: var(--ok); }
.promo-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 0.86rem; color: var(--muted); }
.promo-text b { color: var(--text); font-weight: 650; }

/* Modal */
.modal {
    position: fixed; left: 50%; top: 50%; z-index: 55;
    width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
    transform: translate(-50%, -50%);
    display: flex; flex-direction: column;
    border-radius: 20px; overflow: hidden;
    background:
        linear-gradient(var(--glass-strong), var(--glass-strong)) padding-box,
        linear-gradient(135deg, rgb(0 160 185 / 0.8), rgb(38 217 215 / 0.3)) border-box;
    border: 1px solid transparent;
    backdrop-filter: blur(18px);
    box-shadow: 0 30px 80px -30px rgb(0 0 0 / 0.9);
    animation: rise .3s var(--ease) both;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 12px 18px; border-bottom: 1px solid var(--line); font-weight: 650; }
.modal-head span { flex: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; scrollbar-width: thin; }
.modal-body .muted { margin: 0 0 12px; font-size: 0.88rem; color: var(--muted); }
.modal-text {
    display: block; width: 100%; margin: 0 0 12px; padding: 12px 14px;
    border: 1px solid var(--line-strong); border-radius: 13px; background: var(--bg);
    color: var(--text); font: inherit; resize: vertical; outline: none;
}
.modal-text:focus { border-color: var(--accent-2); }
.modal-h { margin: 20px 0 10px; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); }
.tickets { display: grid; gap: 8px; }
.ticket { padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: rgb(10 15 20 / 0.5); font-size: 0.86rem; }
.ticket-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 0.78rem; color: var(--muted); }
.ticket-no { font: 700 0.74rem 'Orbitron', sans-serif; color: var(--accent-2); }
.ticket-date { margin-left: auto; color: var(--faint); }
.ticket-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ticket .md { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 0.84rem; }

@media (max-width: 640px) {
    .promo { flex-wrap: wrap; }
    .promo .btn { width: 100%; }
    .preview-dash iframe { height: 320px; }
}

/* Option just tapped: shows at once that the choice is on its way. */
.option.sending { border-color: var(--accent, #26D9D7); animation: opt-pulse .9s ease-in-out infinite; }
.option:disabled { cursor: default; }
@keyframes opt-pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .option.sending { animation: none; } }
