/* ============================================================
   ZYORA — Global stylesheet (v2, tested)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button { font: inherit; }

:root {
    --bg:        #070707;
    --bg-2:      #0d0d0d;
    --panel:     #101010;
    --panel-2:   #171717;
    --panel-3:   #1e1e1e;
    --text:      #f2f2f2;
    --text-soft: #b9b9b9;
    --muted:     #7c7c7c;
    --border:    #232323;
    --border-2:  #2e2e2e;
    --accent:    #ffffff;
    --danger:    #ff5f57;
    --success:   #8fffad;
    --warn:      #ffd166;
    --radius-sm: 10px;
    --radius:    14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-1:  0 10px 30px rgba(0,0,0,.35);
    --shadow-2:  0 20px 60px rgba(0,0,0,.5);
    --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono:      'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

html[data-theme="light"] {
    --bg:        #f6f6f4;
    --bg-2:      #efefec;
    --panel:     #ffffff;
    --panel-2:   #f3f3f0;
    --panel-3:   #e9e9e5;
    --text:      #0a0a0a;
    --text-soft: #3c3c3c;
    --muted:     #6b6b6b;
    --border:    #e2e2dc;
    --border-2:  #d6d6d0;
    --accent:    #0a0a0a;
    --shadow-1:  0 10px 30px rgba(0,0,0,.06);
    --shadow-2:  0 20px 60px rgba(0,0,0,.10);
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 15px;
    line-height: 1.55;
    min-height: 100%;
}
body { overflow-x: hidden; }

a { color: inherit; text-decoration: none; }
a:hover { opacity: .85; }
img { max-width: 100%; display: block; }
input, textarea, select, button { font-family: inherit; }

::selection { background: rgba(255,255,255,.25); color: inherit; }
html[data-theme="light"] ::selection { background: rgba(0,0,0,.12); }

* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 20px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

h1, h2, h3, h4 { font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -.045em; }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
h3 { font-size: 1.15rem; }
p  { margin: 0 0 1em; color: var(--text-soft); }
small { font-size: .82rem; color: var(--muted); }

code, pre { font-family: var(--mono); font-size: .9em; }
code {
    background: var(--panel-2);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--text);
}
pre {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
    margin: 12px 0;
    position: relative;
}
pre .code-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: var(--panel-3);
    border-bottom: 1px solid var(--border);
    font-size: .75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .08em;
}
pre .code-head button {
    background: transparent;
    border: 1px solid var(--border-2);
    color: var(--text-soft);
    padding: 3px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    transition: all .15s ease;
}
pre .code-head button:hover { background: var(--panel); color: var(--text); }
pre code {
    display: block;
    padding: 14px 16px;
    overflow-x: auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    color: var(--text);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    background: var(--panel-2);
    color: var(--text);
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
    white-space: nowrap;
    user-select: none;
}
.btn:hover   { background: var(--panel-3); }
.btn:active  { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 700;
}
.btn-primary:hover { box-shadow: 0 10px 30px rgba(255,255,255,.18); }
html[data-theme="light"] .btn-primary:hover { box-shadow: 0 10px 30px rgba(0,0,0,.15); }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-soft);
}
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255,95,87,.3); }
.btn-danger:hover { background: rgba(255,95,87,.08); }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: .82rem;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 500;
    letter-spacing: .02em;
}
.input, .textarea, select.input {
    width: 100%;
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .95rem;
    transition: border-color .15s ease, background .15s ease;
    outline: none;
}
.input:focus, .textarea:focus, select.input:focus { border-color: var(--border-2); background: var(--panel-2); }
.textarea { resize: vertical; min-height: 100px; font-family: inherit; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color .2s ease, transform .2s ease;
}
.card:hover { border-color: var(--border-2); }
.card-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.card-hd h3 { margin: 0; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    height: 62px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: color-mix(in oklab, var(--bg) 85%, transparent);
    backdrop-filter: saturate(140%) blur(14px);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

.brand-mini {
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 800; letter-spacing: -.01em;
}
.brand-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    animation: brandPulse 2.6s ease-in-out infinite;
}
@keyframes brandPulse {
    0%, 100% { transform: scale(.9); opacity: .7; }
    50%      { transform: scale(1.15); opacity: 1; }
}

.avatar-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: .82rem;
    color: var(--text);
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-main { flex: 1; padding: 24px 16px 96px; max-width: 1080px; margin: 0 auto; width: 100%; }

.page-hd { margin-bottom: 22px; }
.page-hd h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin-bottom: 4px; }
.page-hd p  { color: var(--muted); margin: 0; }

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.bottom-nav {
    position: fixed;
    left: 12px; right: 12px; bottom: 12px;
    height: 62px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: color-mix(in oklab, var(--panel) 92%, transparent);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow-2);
    z-index: 50;
    padding: 6px;
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 10px;
    border-radius: 14px;
    color: var(--muted);
    font-size: .68rem;
    font-weight: 600;
    transition: color .15s ease, background .15s ease;
    min-width: 54px;
}
.bottom-nav a svg { width: 20px; height: 20px; }
.bottom-nav a.active { color: var(--text); background: var(--panel-3); }
@media (min-width: 900px) {
    .bottom-nav { display: none; }
    .app-main { padding: 32px 24px; }
}

.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px 60px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.landing::before {
    content: "";
    position: absolute; inset: 0;
    background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.06), transparent 55%);
    pointer-events: none;
}
html[data-theme="light"] .landing::before {
    background: radial-gradient(circle at 50% 30%, rgba(0,0,0,.05), transparent 55%);
}
.landing .topbar-floating {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 24px;
}
.landing .eyebrow {
    font-size: .72rem; letter-spacing: .3em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 22px;
}
.landing h1 { font-size: clamp(2.6rem, 9vw, 5.6rem); letter-spacing: -.05em; margin: 0; }
.landing h1 .dim { color: var(--muted); }
.landing .subtitle {
    max-width: 520px; margin: 22px auto 32px; color: var(--text-soft);
    font-size: clamp(.95rem, 1.4vw, 1.05rem); line-height: 1.6;
}
.landing .cta-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.mascot-stage {
    --size: 260px;
    width: var(--size);
    height: var(--size);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    animation: mascotFloat 5s ease-in-out infinite;
    will-change: transform;
}
.mascot-glow {
    position: absolute;
    width: 78%; height: 78%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.14), transparent 65%);
    filter: blur(14px);
    animation: mascotGlow 3.4s ease-in-out infinite;
    pointer-events: none;
}
html[data-theme="light"] .mascot-glow {
    background: radial-gradient(circle, rgba(0,0,0,.10), transparent 65%);
}
.mascot-face {
    position: relative;
    width: 76%;
    height: 64%;
    border-radius: 48% 48% 46% 46%;
    background: linear-gradient(150deg, #ffffff, #d8d8d8);
    box-shadow:
        inset -14px -18px 36px rgba(0,0,0,.18),
        inset 12px 12px 28px rgba(255,255,255,.9),
        0 24px 60px rgba(0,0,0,.45);
    animation: mascotBreath 3.6s ease-in-out infinite;
    will-change: transform;
}
html[data-theme="light"] .mascot-face {
    background: linear-gradient(150deg, #0f0f0f, #050505);
}
.mascot-face::before {
    content: "";
    position: absolute;
    top: 12%; left: 14%;
    width: 34%; height: 20%;
    border-radius: 50%;
    background: rgba(255,255,255,.55);
    filter: blur(7px);
    opacity: .85;
}
html[data-theme="light"] .mascot-face::before { background: rgba(255,255,255,.10); }
.mascot-eye {
    position: absolute;
    top: 34%;
    width: 16%;
    height: 26%;
    border-radius: 50%;
    background: #070707;
    box-shadow: 0 0 0 4px rgba(0,0,0,.05), 0 0 22px rgba(255,255,255,.10);
    animation: mascotBlink 5.2s infinite;
}
html[data-theme="light"] .mascot-eye { background: #ffffff; }
.mascot-eye.l { left: 24%; }
.mascot-eye.r { right: 24%; }
.mascot-eye::after {
    content: "";
    position: absolute;
    top: 16%; left: 22%;
    width: 26%; height: 26%;
    border-radius: 50%;
    background: #ffffff;
    opacity: .85;
}
html[data-theme="light"] .mascot-eye::after { background: #000000; }
.mascot-mouth {
    position: absolute;
    bottom: 22%; left: 50%;
    transform: translateX(-50%);
    width: 14%; height: 5%;
    border-bottom: 3px solid #171717;
    border-radius: 0 0 50% 50%;
    transition: all .3s ease;
}
html[data-theme="light"] .mascot-mouth { border-bottom-color: #f2f2f2; }
.mascot-shadow {
    position: absolute;
    bottom: 2%;
    width: 55%; height: 6%;
    border-radius: 50%;
    background: #121212;
    filter: blur(3px);
    box-shadow: 0 0 26px rgba(255,255,255,.15);
    opacity: .85;
}
html[data-theme="light"] .mascot-shadow { background: #000; opacity: .35; }

.mascot-stage.is-thinking  .mascot-eye { height: 12%; top: 42%; border-radius: 6px; }
.mascot-stage.is-thinking  .mascot-face { animation-duration: 1.2s; }
.mascot-stage.is-responding .mascot-mouth {
    width: 18%; height: 9%;
    border-bottom-width: 4px;
    animation: mascotTalk .42s ease-in-out infinite alternate;
}
.mascot-stage.is-listening .mascot-glow { animation-duration: 1s; }
.mascot-stage.is-error .mascot-face { animation: mascotShake .4s ease-in-out; }
.mascot-stage.is-error .mascot-mouth {
    border-bottom-color: var(--danger);
    width: 20%; border-radius: 0 0 20% 20%;
}
.mascot-stage.is-offline .mascot-eye { opacity: .35; }
.mascot-stage.is-offline .mascot-glow { animation: none; opacity: .25; }
.mascot-stage.is-offline .mascot-mouth { width: 8%; height: 3%; border-radius: 0; }

@keyframes mascotFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
}
@keyframes mascotBreath {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.025); }
}
@keyframes mascotGlow {
    0%, 100% { transform: scale(.88); opacity: .45; }
    50%      { transform: scale(1.15); opacity: 1; }
}
@keyframes mascotBlink {
    0%, 44%, 48%, 100% { transform: scaleY(1); }
    46%, 47%           { transform: scaleY(.08); }
}
@keyframes mascotTalk {
    from { transform: translateX(-50%) scaleY(1); }
    to   { transform: translateX(-50%) scaleY(.55); }
}
@keyframes mascotShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    75%      { transform: translateX(6px); }
}
@media (max-width: 520px) {
    .mascot-stage { --size: 200px; margin-bottom: 22px; }
}
@media (max-width: 380px) {
    .mascot-stage { --size: 165px; }
}

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 18px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 30px 26px;
    box-shadow: var(--shadow-1);
}
.auth-card .brand-mini { justify-content: center; margin-bottom: 12px; font-size: 1.1rem; }
.auth-card h1 { font-size: 1.5rem; text-align: center; margin-bottom: 6px; }
.auth-card .muted { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: .92rem; }
.auth-alt { text-align: center; margin-top: 16px; color: var(--muted); font-size: .9rem; }
.auth-alt a { color: var(--text); font-weight: 600; }
.auth-error {
    background: rgba(255,95,87,.08);
    border: 1px solid rgba(255,95,87,.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: .88rem;
    margin-bottom: 14px;
}
.auth-success {
    background: rgba(143,255,173,.08);
    border: 1px solid rgba(143,255,173,.3);
    color: var(--success);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: .88rem;
    margin-bottom: 14px;
}

/* ============================================================
   CHAT LAYOUT
   ============================================================ */
.chat-app {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
}

.chat-sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.chat-sidebar .sidebar-hd {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.chat-sidebar .new-chat {
    margin: 14px;
    padding: 11px 14px;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--bg);
    border: 0;
    font-weight: 700;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: box-shadow .2s ease;
}
.chat-sidebar .new-chat:hover { box-shadow: 0 10px 26px rgba(255,255,255,.15); }

.sidebar-search { padding: 0 14px 10px; }
.sidebar-search input {
    width: 100%;
    padding: 9px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: .86rem;
    outline: none;
}
.sidebar-search input:focus { border-color: var(--border-2); }

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px 20px;
}
.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-soft);
    font-size: .9rem;
    transition: background .15s ease, color .15s ease;
    margin-bottom: 2px;
}
.conv-item:hover { background: var(--panel); color: var(--text); }
.conv-item.active { background: var(--panel-3); color: var(--text); }
.conv-item .conv-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.conv-item .conv-actions { display: none; gap: 2px; flex-shrink: 0; }
.conv-item:hover .conv-actions { display: flex; }
.conv-item .conv-actions button {
    width: 24px; height: 24px;
    border-radius: 6px;
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.conv-item .conv-actions button:hover { background: var(--panel-3); color: var(--text); }

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-foot .user-chip {
    display: flex; align-items: center; gap: 10px;
    flex: 1; min-width: 0;
    padding: 6px 8px;
    border-radius: 10px;
    cursor: pointer;
}
.sidebar-foot .user-chip:hover { background: var(--panel); }
.sidebar-foot .user-chip .meta { min-width: 0; }
.sidebar-foot .user-chip .name { font-size: .86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .user-chip .role { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg);
    overflow: hidden;
}
.chat-main .chat-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in oklab, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 5;
}
.chat-hd .title-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-hd .conv-title-editable {
    font-weight: 600;
    font-size: .95rem;
    color: var(--text);
    padding: 4px 8px;
    border-radius: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: text;
    border: 1px solid transparent;
    min-width: 0;
    max-width: 100%;
}
.chat-hd .conv-title-editable:hover { background: var(--panel-2); }
.chat-hd .model-select {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: .82rem;
    cursor: pointer;
    outline: none;
}

.messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 16px 20px;
    -webkit-overflow-scrolling: touch;
}
.messages-inner { max-width: 780px; margin: 0 auto; }

.msg {
    display: flex;
    gap: 12px;
    margin-bottom: 22px;
    animation: msgIn .3s ease both;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.msg .avatar {
    width: 30px; height: 30px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: .74rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
}
.msg.user .avatar { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.msg .body { flex: 1; min-width: 0; }
.msg .body .bubble {
    padding: 2px 0;
    font-size: .95rem;
    color: var(--text);
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.msg.user .body .bubble {
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 12px 15px;
    border-radius: 14px;
    border-top-left-radius: 4px;
    display: inline-block;
    max-width: 100%;
}
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble p:first-child { margin-top: 0; }
.msg .bubble ul, .msg .bubble ol { padding-left: 20px; margin: 8px 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3 { margin-top: 14px; margin-bottom: 8px; }
.msg .bubble blockquote {
    border-left: 3px solid var(--border-2);
    padding: 4px 12px;
    margin: 10px 0;
    color: var(--muted);
}
.msg .bubble a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.msg .bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: .88rem;
}
.msg .bubble th, .msg .bubble td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: left;
}
.msg .bubble th { background: var(--panel-2); font-weight: 600; }

.msg .msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity .2s ease;
}
.msg:hover .msg-actions { opacity: 1; }
.msg .msg-actions button {
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .74rem;
    display: inline-flex; align-items: center; gap: 4px;
}
.msg .msg-actions button:hover { background: var(--panel-2); color: var(--text); }
.msg .msg-actions button svg { width: 13px; height: 13px; }

.msg .stream-cursor {
    display: inline-block;
    width: 7px; height: 15px;
    background: var(--text);
    margin-left: 2px;
    vertical-align: -2px;
    animation: cursorBlink .9s steps(2) infinite;
}
@keyframes cursorBlink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px 20px 60px;
}
.chat-empty .mascot-stage { --size: 190px; }
.chat-empty h2 { margin: 0 0 6px; }
.chat-empty p { color: var(--muted); margin-bottom: 22px; }
.chat-empty .suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 580px;
}
.chat-empty .suggestion {
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-soft);
    font-size: .88rem;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.chat-empty .suggestion:hover { border-color: var(--border-2); background: var(--panel-2); color: var(--text); }

.composer {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in oklab, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.composer-inner {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 22px;
    transition: border-color .15s ease;
}
.composer-row:focus-within { border-color: var(--border-2); }
.composer textarea {
    flex: 1;
    background: transparent;
    border: 0;
    resize: none;
    color: var(--text);
    font-size: .95rem;
    line-height: 1.5;
    padding: 8px 4px;
    outline: none;
    max-height: 200px;
    min-height: 24px;
    font-family: inherit;
}
.composer textarea::placeholder { color: var(--muted); }

.attach-btn, .stop-btn, .send-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 0;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.attach-btn { background: transparent; color: var(--muted); }
.attach-btn:hover { background: var(--panel-2); color: var(--text); }
.send-btn { background: var(--accent); color: var(--bg); }
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.stop-btn { background: var(--danger); color: white; }
.stop-btn:hover { transform: scale(1.05); }
.stop-btn.hidden { display: none; }

.composer-hint {
    text-align: center;
    font-size: .7rem;
    color: var(--muted);
    letter-spacing: .02em;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 4px;
}
.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: .82rem;
    color: var(--text-soft);
}
.attachment-chip img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
.attachment-chip button {
    background: transparent; border: 0; color: var(--muted); cursor: pointer;
    padding: 0 2px;
}

.sidebar-scrim {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 60;
    backdrop-filter: blur(3px);
}
.sidebar-scrim.show { display: block; }

@media (max-width: 860px) {
    .chat-app { grid-template-columns: 1fr; }
    .chat-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(320px, 85vw);
        z-index: 70;
        transform: translateX(-102%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        border-radius: 0 22px 22px 0;
        box-shadow: var(--shadow-2);
    }
    .chat-sidebar.open { transform: translateX(0); }
    .chat-main .chat-hd { padding-left: 8px; }
    .messages { padding: 16px 12px 12px; }
    .msg { gap: 10px; }
    .msg .avatar { width: 28px; height: 28px; }
    .composer { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
    .composer-hint { display: none; }
}



.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: border-color .15s ease, background .15s ease;
}
.list-item:hover { border-color: var(--border-2); }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: .94rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-meta { font-size: .78rem; color: var(--muted); }

.model-card {
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease, background .15s ease;
    position: relative;
}
.model-card:hover { border-color: var(--border-2); transform: translateY(-2px); }
.model-card.selected { border-color: var(--accent); background: var(--panel-2); }
.model-card .badge {
    position: absolute;
    top: 14px; right: 14px;
    font-size: .68rem;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--panel-3);
    border: 1px solid var(--border);
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.model-card .badge.default { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.model-card h4 { margin: 0 0 6px; font-size: 1.05rem; }
.model-card p  { margin: 0; color: var(--muted); font-size: .86rem; }

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    gap: 14px;
}
.settings-row:last-child { border-bottom: 0; }
.settings-row .sr-body { flex: 1; min-width: 0; }
.settings-row .sr-body label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 3px; }
.settings-row .sr-body small { color: var(--muted); font-size: .8rem; }

.switch {
    position: relative;
    width: 44px; height: 26px;
    background: var(--border-2);
    border-radius: 20px;
    cursor: pointer;
    transition: background .2s ease;
    flex-shrink: 0;
    border: 0;
    padding: 0;
}
.switch::after {
    content: "";
    position: absolute;
    top: 3px; left: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: white;
    transition: transform .2s ease;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); background: var(--bg); }

.profile-avatar {
    width: 92px; height: 92px;
    border-radius: 50%;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1.9rem;
    overflow: hidden;
    color: var(--text);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }

.stat-card { padding: 18px; }
.stat-card .stat-num { font-size: 1.8rem; font-weight: 800; letter-spacing: -.03em; }
.stat-card .stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }

.toast-wrap {
    position: fixed;
    bottom: 20px; left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    align-items: center;
}
.toast {
    padding: 10px 16px;
    background: var(--panel-3);
    border: 1px solid var(--border-2);
    border-radius: 12px;
    font-size: .86rem;
    color: var(--text);
    box-shadow: var(--shadow-2);
    animation: toastIn .25s ease both;
    max-width: 340px;
}
.toast.success { border-color: rgba(143,255,173,.3); }
.toast.error   { border-color: rgba(255,95,87,.4); color: var(--danger); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 28px 20px 32px;
    text-align: center;
    background: var(--bg-2);
}
.site-footer .footer-inner { max-width: 600px; margin: 0 auto; }
.site-footer .brand-mini { justify-content: center; margin-bottom: 8px; font-size: 1rem; }
.site-footer .footer-tag { color: var(--text-soft); margin: 0 0 6px; font-size: .92rem; }
.site-footer .footer-copy { color: var(--muted); font-size: .78rem; margin: 0; }

.hidden { display: none !important; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.row  { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.text-muted { color: var(--muted); }
.text-soft  { color: var(--text-soft); }
.text-sm { font-size: .86rem; }
.text-xs { font-size: .76rem; }
.mono { font-family: var(--mono); }



/* ============================================================
   Reserve space at the bottom of scrollable pages so the
   fixed bottom-nav doesn't cover the developer credit.
   ============================================================ */
@media (max-width: 899px) {
    .site-footer {
        padding-bottom: 110px;
    }
}

/* On desktop (no bottom nav) keep it tight */
@media (min-width: 900px) {
    .site-footer {
        padding-bottom: 32px;
    }
}

/* ============================================================
   Chat page: footer completely hidden — composer owns the bottom
   ============================================================ */
body.chat-page .site-footer {
    display: none !important;
}

/* Restore full chat height (no 46px reservation) */
body.chat-page .chat-app {
    height: 100vh;
    height: 100dvh;
}

@media (max-width: 860px) {
    body.chat-page .chat-app {
        height: 100vh;
        height: 100dvh;
    }
    body.chat-page .composer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* ============================================================
   Custom model picker (replaces native Android select)
   ============================================================ */
.model-picker {
    position: relative;
    flex-shrink: 0;
}

.model-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .18s ease;
    white-space: nowrap;
    max-width: 180px;
}
.model-picker-btn:hover { border-color: var(--border-2); background: var(--panel-3); }
.model-picker-btn[aria-expanded="true"] {
    border-color: var(--border-2);
    background: var(--panel-3);
}

.model-picker-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-picker-caret {
    opacity: .55;
    transition: transform .2s ease;
    flex-shrink: 0;
}
.model-picker-btn[aria-expanded="true"] .model-picker-caret {
    transform: rotate(180deg);
    opacity: .85;
}

/* Menu panel — anchored to bottom of button, fixed width */
.model-picker-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(340px, calc(100vw - 24px));
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.04);
    overflow: hidden;
    z-index: 100;
    padding: 6px;
    opacity: 0;
    transform: translateY(-6px) scale(.97);
    transform-origin: top right;
    transition: opacity .16s ease, transform .16s cubic-bezier(.2,.9,.3,1.2);
}
.model-picker-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.model-picker-menu[hidden] { display: none; }

.model-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 12px;
    background: transparent;
    border: 0;
    border-radius: 12px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background .14s ease;
}
.model-option:hover,
.model-option:focus-visible {
    background: var(--panel-2);
    outline: none;
}
.model-option.is-active {
    background: var(--panel-2);
}

.model-option-check {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--border-2);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: all .18s ease;
}
.model-option.is-active .model-option-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.model-option-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.model-option-name {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.model-option-desc {
    font-size: .74rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-option-empty {
    padding: 14px 12px;
    font-size: .86rem;
    color: var(--muted);
    text-align: center;
}

/* Mobile tweak */
@media (max-width: 520px) {
    .model-picker-btn {
        padding: 6px 10px;
        font-size: .78rem;
        max-width: 140px;
    }
    .model-picker-menu {
        width: calc(100vw - 20px);
        right: -8px;
    }
    .model-option { padding: 10px; }
    .model-option-name { font-size: .86rem; }
    .model-option-desc { font-size: .7rem; }
}

/* Settings model picker — opens right-aligned, wider */
.settings-model-picker .model-picker-menu {
    right: 0;
    left: auto;
    min-width: 300px;
}
@media (max-width: 520px) {
    .settings-model-picker .model-picker-menu {
        width: calc(100vw - 40px);
        right: 0;
    }
}

/* ============================================================
   Admin — mobile-friendly user rows
   ============================================================ */
.user-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.user-row .user-info {
    flex: 1;
    min-width: 0;
}
.user-row .user-info .user-name {
    font-weight: 600;
    font-size: .94rem;
    color: var(--text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-row .user-info .user-name .role-tag {
    color: var(--muted);
    font-size: .76rem;
    font-weight: 500;
}
.user-row .user-info .user-meta {
    font-size: .78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-row .user-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.user-row .user-actions .btn {
    padding: 6px 11px;
    font-size: .78rem;
    border-radius: 8px;
    white-space: nowrap;
}

/* On mobile — stack the actions under the user info */
@media (max-width: 640px) {
    .user-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .user-row .user-info .user-name,
    .user-row .user-info .user-meta {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
    .user-row .user-actions {
        justify-content: stretch;
        border-top: 1px solid var(--border);
        padding-top: 10px;
    }
    .user-row .user-actions .btn {
        flex: 1;
        justify-content: center;
        padding: 9px 10px;
        font-size: .82rem;
    }
}

/* ============================================================
   Dashboard — mobile polish
   ============================================================ */

/* Stats grid: 2 columns on mobile */
@media (max-width: 640px) {
    .grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    .stat-card {
        padding: 14px !important;
    }
    .stat-card .stat-num {
        font-size: 1.4rem !important;
    }
    .stat-card .stat-label {
        font-size: .68rem !important;
        letter-spacing: .05em !important;
    }
}

/* Start-a-conversation card: stack the buttons vertically */
@media (max-width: 640px) {
    .card-hd {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }
    .card-hd > h3 {
        margin-bottom: 2px !important;
    }
    .card-hd .row,
    .card-hd > a.btn,
    .card-hd > div {
        width: 100% !important;
        flex-wrap: wrap !important;
    }
    .card-hd > a.btn,
    .card-hd .row > a.btn,
    .card-hd .row > button.btn {
        flex: 1 1 calc(50% - 5px) !important;
        min-width: 0 !important;
        justify-content: center !important;
        padding: 10px 12px !important;
        font-size: .88rem !important;
    }
}

/* When the CTA has two buttons, split 50/50 */
@media (max-width: 640px) {
    .card-hd .row {
        display: flex !important;
        gap: 8px !important;
    }
    .card-hd .row .btn {
        flex: 1 1 0 !important;
    }
}

/* Reserve space for the bottom nav so nothing hides behind it */
@media (max-width: 899px) {
    .app-main {
        padding-bottom: 130px !important;
    }
}

/* Recent conversation list items: cleaner spacing on mobile */
@media (max-width: 640px) {
    .list-item {
        padding: 12px !important;
    }
    .list-item .li-title {
        font-size: .9rem !important;
    }
    .list-item .li-meta {
        font-size: .74rem !important;
    }
    .card {
        padding: 16px !important;
    }
}

/* ============================================================
   Bots page — full width cards + horizontal action buttons
   ============================================================ */

/* Force single-column grid on the bots page (mobile + desktop) */
body.bots-page .grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    max-width: 720px;
    margin: 0 auto;
}

@media (min-width: 900px) {
    body.bots-page .grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Bot card */
body.bots-page .card {
    padding: 16px !important;
}

/* Action buttons row — force horizontal on mobile */
body.bots-page .card > .row.mt-2 {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    margin-top: 14px !important;
    padding-top: 14px !important;
    border-top: 1px solid var(--border);
}

body.bots-page .card > .row.mt-2 .btn {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 0 !important;
    padding: 9px 12px !important;
    font-size: .82rem !important;
    justify-content: center !important;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* "Create new bot" button — full width on mobile */
@media (max-width: 640px) {
    body.bots-page .page-hd .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 13px 18px;
    }
    body.bots-page .page-hd h1 {
        font-size: 1.9rem;
    }
    body.bots-page .page-hd p {
        font-size: .9rem;
    }
}

/* Bot avatar — bigger, cleaner */
body.bots-page .card > .row > div[style*="font-size"] {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1.6rem !important;
    flex-shrink: 0;
}

/* Reserve space so bottom nav doesn't cover content */
@media (max-width: 899px) {
    body.bots-page .app-main {
        padding-bottom: 120px !important;
    }
}

/* Bot chat avatars — image support */
.head .av img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}
.msg .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

/* Mobile: keep the same 2-column structure, just tighten it */
@media (max-width: 520px) {
    .avatar-picker {
        gap: 12px;
        padding: 14px;
    }
    .avatar-preview {
        width: 60px;
        height: 60px;
        border-radius: 14px;
    }
    .avatar-preview span {
        font-size: 1.7rem;
    }
    .avatar-controls .emoji-row .input {
        padding: 8px 10px;
        font-size: 1rem;
    }
    .avatar-controls .upload-row .btn {
        padding: 8px 12px;
        font-size: .78rem;
    }
}

/* Mobile: shrink the preview so controls have more room */
@media (max-width: 400px) {
    .avatar-picker {
        grid-template-columns: 60px 1fr;
        gap: 10px;
        padding: 12px;
    }
    .avatar-preview {
        width: 60px;
        height: 60px;
        border-radius: 14px;
    }
    .avatar-preview span {
        font-size: 1.7rem;
    }
    .avatar-controls .input {
        padding: 9px 10px;
        font-size: .95rem;
    }
    .avatar-controls .btn {
        padding: 8px 10px;
        font-size: .76rem;
    }
}

/* ============================================================
   Bot avatar picker — image only
   ============================================================ */

.avatar-picker {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 16px;
    align-items: center;
    padding: 16px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 10px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.avatar-preview {
    width: 88px;
    height: 88px;
    border-radius: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-preview .avatar-placeholder {
    font-size: 2.4rem;
    line-height: 1;
    opacity: .35;
}

.avatar-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    width: 100%;
}

.avatar-controls .btn {
    width: 100%;
    padding: 10px 14px;
    font-size: .85rem;
    margin: 0;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

@media (max-width: 400px) {
    .avatar-picker {
        grid-template-columns: 72px 1fr;
        gap: 12px;
        padding: 14px;
    }
    .avatar-preview {
        width: 72px;
        height: 72px;
        border-radius: 16px;
    }
    .avatar-preview .avatar-placeholder {
        font-size: 2rem;
    }
    .avatar-controls .btn {
        padding: 9px 12px;
        font-size: .8rem;
    }
}

/* ============================================================
   Chat — upgrade / low-token banner
   ============================================================ */
.upgrade-banner {
    flex-shrink: 0;
    padding: 0 14px;
    background: rgba(255, 95, 87, .1);
    border-top: 1px solid rgba(255, 95, 87, .35);
}
.upgrade-banner.warn {
    background: rgba(255, 209, 102, .1);
    border-top-color: rgba(255, 209, 102, .35);
}
.upgrade-inner {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    flex-wrap: wrap;
}
.upgrade-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.upgrade-text strong {
    font-size: .88rem;
    color: var(--danger);
}
.upgrade-banner.warn .upgrade-text strong {
    color: var(--warn);
}
.upgrade-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border-radius: 10px;
    background: var(--accent);
    color: var(--bg);
    font-weight: 700;
    font-size: .82rem;
    white-space: nowrap;
    transition: box-shadow .15s ease;
}
.upgrade-btn:hover {
    box-shadow: 0 8px 20px rgba(255,255,255,.2);
    opacity: 1;
}
@media (max-width: 520px) {
    .upgrade-inner {
        padding: 8px 0;
        gap: 8px;
    }
    .upgrade-text strong { font-size: .82rem; }
    .upgrade-btn { padding: 7px 14px; font-size: .78rem; }
}

/* Bot chat — top up button in footer */
.bot-topup-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    margin-bottom: 6px;
    background: var(--accent);
    color: var(--bg) !important;
    border-radius: 20px;
    font-weight: 700;
    font-size: .76rem;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease;
}
.bot-topup-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(255,255,255,.2);
    opacity: 1;
}

/* Bottom nav — 5 items fit cleanly on mobile */
@media (max-width: 899px) {
    .bottom-nav {
        padding: 4px 6px;
    }
    .bottom-nav a {
        padding: 6px 4px;
        min-width: 0;
        flex: 1;
        max-width: 72px;
    }
    .bottom-nav a svg {
        width: 19px;
        height: 19px;
    }
    .bottom-nav a span {
        font-size: .63rem;
        font-weight: 600;
        letter-spacing: -.01em;
    }
}

/* ============================================================
   Chat header — close button
   ============================================================ */
.chat-close-btn {
    color: var(--text-soft);
    background: var(--panel-2);
    border: 1px solid var(--border);
}
.chat-close-btn:hover {
    background: var(--panel-3);
    color: var(--text);
    border-color: var(--border-2);
}

/* Hide the sidebar menu on mobile if we have the close button.
   On desktop the menu is still needed to open the sidebar. */
@media (max-width: 860px) {
    .chat-hd .chat-close-btn {
        margin-right: 2px;
    }
}

/* ============================================================
   Chat header — close (✕) button
   ============================================================ */
.chat-hd .chat-close-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-soft);
    transition: all .15s ease;
}
.chat-hd .chat-close-btn:hover {
    background: rgba(255, 95, 87, .12);
    border-color: rgba(255, 95, 87, .4);
    color: var(--danger);
}
.chat-hd .chat-close-btn:active {
    transform: scale(.94);
}
.chat-hd .chat-close-btn svg {
    stroke-width: 2.2;
}

/* Chat header close button */
.chat-hd .chat-close-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-soft);
    flex-shrink: 0;
}
.chat-hd .chat-close-btn:hover {
    background: rgba(255, 95, 87, .12);
    border-color: rgba(255, 95, 87, .4);
    color: var(--danger);
}
.chat-hd .chat-close-btn:active { transform: scale(.94); }

/* Bot header — proper flex layout with close button */
.head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}
.head .info { flex: 1; min-width: 0; }
.head .zyora-badge { flex-shrink: 0; }

.bot-close-btn {
    background: transparent !important;
    border: 1px solid var(--border) !important;
    color: var(--text-soft) !important;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all .15s ease;
    width: 34px;
    height: 34px;
    border-radius: 8px;
}
.bot-close-btn:hover {
    background: rgba(255, 95, 87, .12) !important;
    border-color: rgba(255, 95, 87, .4) !important;
    color: var(--danger) !important;
}

/* Avatar image fallback — always show something */
.head .av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.head .av .av-fallback {
    font-size: 1.2rem;
    color: var(--text-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

@media (max-width: 480px) {
    .head { gap: 8px; padding: 10px 10px; }
    .head .av { width: 34px; height: 34px; }
    .head .name { font-size: .88rem; }
    .head .zyora-badge .brand { font-size: .74rem; }
    .head .zyora-badge .lbl { font-size: .54rem; }
    .bot-close-btn { width: 30px; height: 30px; border-radius: 7px; }
}

/* Bot header — avatar fallback */
.head .av .av-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-soft);
}
.head .av img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Close button aligned right in header */
.head .bot-close-btn {
    flex-shrink: 0;
    margin-left: 4px;
}

/* Hide the topbar hamburger — it only belongs on chat.php now */
body:not(.chat-page) .topbar .menu-btn,
body:not(.chat-page) .topbar #mobileMenuBtn {
    display: none !important;
}
