/* BypAI web app. Shares the admin panel's palette so the two read as one product,
   but none of its layout - this is a chat surface, not a dashboard. */

/* ── tokens ─────────────────────────────────────────────────────────────── */
:root {
    --bg: #0b0c11;
    --panel: #0e1016;
    --card: #13161e;
    --card-hi: #181c26;
    --line: #272b37;
    --line-hi: #3d4453;
    --text: #e7e9f0;
    --dim: #8891a6;
    --faint: #5b6173;
    --accent: #6c8cff;
    --accent-2: #a46cff;
    --good: #3ecf8e;
    --warn: #f3b44c;
    --bad: #ff5c7a;

    --grad: linear-gradient(100deg, var(--accent), var(--accent-2));
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 18px;
    --sidebar: 268px;
    --thread: 760px;
    --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--line-hi); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── brand ──────────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    width: 28px; height: 28px; border-radius: var(--r-sm);
    background: var(--grad) center / cover no-repeat;
    display: grid; place-items: center; overflow: hidden; flex: 0 0 28px;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-name { font-weight: 500; letter-spacing: -.01em; color: var(--dim); }
.brand-name b { color: var(--text); font-weight: 700; }

/* ── buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--card-hi); border-color: var(--line-hi); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grad); border: 0; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { width: 100%; }

.icon-btn {
    display: grid; place-items: center;
    width: 32px; height: 32px; flex: 0 0 32px;
    border: 0; background: transparent; color: var(--faint);
    border-radius: var(--r-sm); cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--card-hi); color: var(--text); }

.link {
    border: 0; background: none; padding: 0;
    color: var(--accent); cursor: pointer; text-decoration: underline;
}

/* ── sign in ────────────────────────────────────────────────────────────── */
.gate {
    min-height: 100%;
    display: grid; place-items: center;
    padding: 24px;
    background:
        radial-gradient(60rem 40rem at 50% -10rem, rgba(108, 140, 255, .16), transparent 70%),
        var(--bg);
}
.gate-card {
    width: 100%; max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 28px;
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .7);
    animation: rise .5s var(--ease) both;
}
.gate-card h1 { font-size: 22px; margin: 22px 0 4px; font-weight: 650; letter-spacing: -.02em; }
.gate-sub { margin: 0 0 20px; color: var(--faint); font-size: 14px; }
.gate-swap { margin: 16px 0 0; text-align: center; color: var(--faint); font-size: 13.5px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.field > span em { color: var(--faint); font-style: normal; }
.field input {
    width: 100%; padding: 10px 12px;
    background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.field input:focus {
    outline: 0; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 140, 255, .18);
}

.alert {
    padding: 10px 12px; border-radius: var(--r-sm);
    font-size: 13.5px; margin-bottom: 14px;
    animation: rise .25s var(--ease) both;
}
.alert.bad { background: rgba(255, 92, 122, .1); border: 1px solid rgba(255, 92, 122, .35); color: #ffb3c2; }

/* ── shell ──────────────────────────────────────────────────────────────── */
.app { display: flex; height: 100%; }

.sidebar {
    width: var(--sidebar); flex: 0 0 var(--sidebar);
    background: var(--panel);
    border-right: 1px solid rgba(255, 255, 255, .06);
    display: flex; flex-direction: column;
    padding: 14px 12px;
    min-height: 0;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 14px; }

.new-chat { justify-content: flex-start; margin-bottom: 14px; }
.new-chat svg { width: 16px; height: 16px; color: var(--accent); }

.chats { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; min-height: 0; }
.chat-day { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); padding: 14px 8px 6px; }

.chat-row {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: var(--r-sm);
    color: var(--dim); cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease);
    animation: fade .25s var(--ease) both;
}
.chat-row:hover { background: var(--card-hi); color: var(--text); }
.chat-row.on { background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--text); }
.chat-row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-row .row-btns { display: flex; gap: 2px; opacity: 0; transition: opacity .15s var(--ease); }
.chat-row:hover .row-btns, .chat-row.on .row-btns { opacity: 1; }
.chat-row .icon-btn { width: 26px; height: 26px; flex: 0 0 26px; }
.chat-row .icon-btn svg { width: 15px; height: 15px; }
.chat-row input {
    flex: 1; min-width: 0; padding: 2px 6px;
    background: var(--bg); border: 1px solid var(--accent); border-radius: 6px;
    font-size: 14px;
}

.side-foot { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }

.meter { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.meter-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--dim); }
.meter-row b { color: var(--text); font-weight: 600; }
.bar { height: 5px; background: var(--line); border-radius: 3px; margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--grad); transition: width .6s var(--ease); }
.bar i.low { background: var(--warn); }
.bar i.out { background: var(--bad); }
.meter-note { font-size: 11.5px; color: var(--faint); margin-top: 6px; }

.user-card {
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--r); padding: 8px 10px;
}
.avatar {
    width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px;
    background: var(--grad); display: grid; place-items: center;
    font-size: 13px; font-weight: 600; color: #fff; text-transform: uppercase;
}
.user-name { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── main ───────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(8px);
    position: sticky; top: 0; z-index: 5;
}
.chat-title {
    flex: 1; margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.model-pick { position: relative; display: flex; align-items: center; }
.model-pick select {
    appearance: none;
    padding: 7px 30px 7px 12px;
    background: var(--card); border: 1px solid var(--line); border-radius: 999px;
    font-size: 13px; color: var(--dim); cursor: pointer;
    transition: border-color .15s var(--ease), color .15s var(--ease);
}
.model-pick select:hover { border-color: var(--line-hi); color: var(--text); }
.model-pick .caret { position: absolute; right: 9px; width: 14px; height: 14px; color: var(--faint); pointer-events: none; }

.banner {
    margin: 10px auto 0; max-width: var(--thread); width: calc(100% - 36px);
    padding: 9px 13px; border-radius: var(--r-sm);
    background: rgba(243, 180, 76, .08); border: 1px solid rgba(243, 180, 76, .3);
    color: #f7d59a; font-size: 13px;
}

.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 8px 18px 0; }
.thread-inner { max-width: var(--thread); margin: 0 auto; padding-bottom: 16px; }

/* ── messages ───────────────────────────────────────────────────────────── */
.msg { display: flex; gap: 14px; padding: 18px 0; animation: rise .35s var(--ease) both; }
.msg + .msg { border-top: 1px solid rgba(255, 255, 255, .05); }

.msg .who {
    width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 700; text-transform: uppercase;
}
.msg.user .who { background: var(--card-hi); border: 1px solid var(--line); color: var(--dim); }
.msg.bot .who { background: var(--grad); color: #fff; }
.msg.bot .who img { width: 100%; height: 100%; border-radius: 9px; object-fit: cover; }

.msg .body { flex: 1; min-width: 0; }
.msg .body > *:first-child { margin-top: 0; }
.msg .body > *:last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 12px; overflow-wrap: anywhere; }
.msg .body h1, .msg .body h2, .msg .body h3 { margin: 20px 0 10px; font-weight: 650; letter-spacing: -.01em; }
.msg .body h1 { font-size: 20px; }
.msg .body h2 { font-size: 17px; }
.msg .body h3 { font-size: 15.5px; }
.msg .body ul, .msg .body ol { margin: 0 0 12px; padding-left: 22px; }
.msg .body li { margin: 4px 0; }
.msg .body a { color: var(--accent); }
.msg .body blockquote {
    margin: 0 0 12px; padding: 2px 0 2px 14px;
    border-left: 3px solid var(--line-hi); color: var(--dim);
}
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.msg .body code {
    background: var(--card-hi); border: 1px solid var(--line);
    padding: 1px 5px; border-radius: 5px;
    font-family: "Cascadia Code", Consolas, "SF Mono", monospace; font-size: 13px;
}
.msg .body table { border-collapse: collapse; margin: 0 0 12px; display: block; overflow-x: auto; }
.msg .body th, .msg .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; font-size: 14px; }
.msg .body th { background: var(--card); font-weight: 600; }

.code {
    position: relative; margin: 0 0 14px;
    background: #080a0f; border: 1px solid var(--line); border-radius: var(--r);
    overflow: hidden;
}
.code-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px 6px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code code {
    background: none; border: 0; padding: 0;
    font-family: "Cascadia Code", Consolas, "SF Mono", monospace; font-size: 13px;
    line-height: 1.55; color: #d7e0f5;
}
.copy {
    border: 0; background: transparent; color: var(--faint);
    font-size: 12px; padding: 3px 8px; border-radius: 6px; cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease);
}
.copy:hover { background: var(--card-hi); color: var(--text); }
.copy.done { color: var(--good); }

.msg .fail {
    padding: 10px 13px; border-radius: var(--r-sm);
    background: rgba(255, 92, 122, .09); border: 1px solid rgba(255, 92, 122, .32);
    color: #ffb3c2; font-size: 14px;
}

/* The caret only exists while text is arriving, so it never sits under a finished reply. */
.cursor {
    display: inline-block; width: 7px; height: 15px;
    background: var(--accent); border-radius: 2px;
    vertical-align: -2px; margin-left: 2px;
    animation: blink 1s steps(2, start) infinite;
}

.dots { display: inline-flex; gap: 5px; padding: 4px 0; }
.dots i {
    width: 6px; height: 6px; border-radius: 50%; background: var(--faint);
    animation: bounce 1.2s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

/* ── empty state ────────────────────────────────────────────────────────── */
.hello { padding: 12vh 0 0; text-align: center; animation: rise .5s var(--ease) both; }
.hello .mark {
    width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 16px;
    background: var(--grad) center / cover no-repeat; overflow: hidden;
    box-shadow: 0 14px 40px -12px rgba(108, 140, 255, .7);
}
.hello .mark img { width: 100%; height: 100%; object-fit: cover; }
.hello h2 { margin: 0 0 6px; font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.hello p { margin: 0 0 24px; color: var(--faint); }

.starters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 560px; margin: 0 auto; }
.starter {
    text-align: left; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
    color: var(--dim); font-size: 14px; cursor: pointer;
    transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.starter:hover { background: var(--card-hi); border-color: var(--line-hi); color: var(--text); transform: translateY(-1px); }
.starter b { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }

/* ── composer ───────────────────────────────────────────────────────────── */
.jump {
    position: absolute; left: 50%; transform: translateX(-50%);
    bottom: 132px; z-index: 6;
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 14px; border-radius: 999px;
    background: var(--card-hi); border: 1px solid var(--line-hi); color: var(--dim);
    font-size: 13px; cursor: pointer;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .8);
    animation: rise .25s var(--ease) both;
}
.jump:hover { color: var(--text); border-color: var(--accent); }
.jump svg { width: 15px; height: 15px; }

.composer-wrap {
    padding: 10px 18px 14px;
    background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.composer {
    position: relative;
    max-width: var(--thread); margin: 0 auto;
    display: flex; align-items: flex-end; gap: 8px;
    padding: 8px 8px 8px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108, 140, 255, .14); }
.composer textarea {
    flex: 1; resize: none; border: 0; background: none; outline: 0;
    padding: 8px 0; max-height: 40vh; line-height: 1.55;
}
.composer textarea::placeholder { color: var(--faint); }

.send {
    width: 36px; height: 36px; flex: 0 0 36px;
    display: grid; place-items: center;
    border: 0; border-radius: 11px; cursor: pointer;
    background: var(--grad); color: #fff;
    transition: filter .15s var(--ease), opacity .15s var(--ease), transform .1s var(--ease);
}
.send:hover { filter: brightness(1.1); }
.send:active { transform: translateY(1px); }
.send:disabled { opacity: .35; cursor: default; filter: none; }
.send.stop { background: var(--card-hi); border: 1px solid var(--line-hi); color: var(--text); }

.hint { max-width: var(--thread); margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--faint); }

/* ── toast ──────────────────────────────────────────────────────────────── */
.toast {
    position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
    z-index: 40; max-width: min(520px, calc(100vw - 32px));
    padding: 11px 16px; border-radius: var(--r);
    background: var(--card-hi); border: 1px solid var(--line-hi);
    box-shadow: 0 18px 40px -14px rgba(0, 0, 0, .85);
    font-size: 14px;
    animation: rise .25s var(--ease) both;
}
.toast.bad { border-color: rgba(255, 92, 122, .5); color: #ffb3c2; }

/* ── motion ─────────────────────────────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
    .thread { scroll-behavior: auto; }
}

/* ── mobile ─────────────────────────────────────────────────────────────── */
.only-mobile { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
    .only-mobile { display: grid; }

    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 20;
        transform: translateX(-100%);
        transition: transform .25s var(--ease);
        box-shadow: 0 0 60px rgba(0, 0, 0, .6);
    }
    .app.open .sidebar { transform: none; }

    .scrim {
        display: block; position: fixed; inset: 0; z-index: 15;
        background: rgba(0, 0, 0, .55);
        opacity: 0; pointer-events: none; transition: opacity .25s var(--ease);
    }
    .app.open .scrim { opacity: 1; pointer-events: auto; }

    .starters { grid-template-columns: 1fr; }
    .thread { padding: 8px 14px 0; }
    .composer-wrap { padding: 8px 12px 12px; }
    .hello { padding-top: 8vh; }
}
