/* =====================================================
   AI Studio — xAI-inspired design
   Color tokens from /AI/xai-design/DESIGN.md
   ===================================================== */

:root {
    /* Brand & Accent */
    --primary: #ffffff;
    --on-primary: #0a0a0a;

    --ink: #ffffff;
    --ink-hover: #fafaf7;
    --body: #dadbdf;
    --body-mid: #7d8187;
    --mute: #7d8187;

    --hairline: #212327;
    --canvas: #0a0a0a;
    --canvas-soft: #1a1c20;
    --canvas-card: #191919;
    --canvas-mid: #363a3f;

    --accent-sunset: #ff7a17;
    --accent-dusk: #7c3aed;
    --accent-twilight: #c4b5fd;
    --accent-breeze: #a0c3ec;
    --accent-midnight: #0d1726;

    /* Shape & spacing */
    --r-sm: 8px;
    --r-pill: 9999px;
    --space-2: 2px;
    --space-4: 4px;
    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-24: 24px;
    --space-32: 32px;
    --space-48: 48px;
    --space-64: 64px;

    /* Type — Inter as Universal Sans substitute, JetBrains Mono for caption-mono */
    --font-display: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;

    --t-display-xl: 96px / 96px 'Inter', system-ui, sans-serif;
    --t-display-md: 48px / 48px 'Inter', system-ui, sans-serif;
    --t-display-sm: 32px / 36px 'Inter', system-ui, sans-serif;
    --t-body-md: 16px / 24px 'Inter', system-ui, sans-serif;
    --t-body-sm: 14px / 20px 'Inter', system-ui, sans-serif;
    --t-caption-mono: 14px / 20px 'JetBrains Mono', ui-monospace, monospace;
    --t-caption-mono-sm: 12px / 16px 'JetBrains Mono', ui-monospace, monospace;
    --t-button: 14px / 20px 'Inter', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
}

textarea, input, select {
    font-family: inherit;
    color: inherit;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--canvas-mid); }

/* =====================================================
   Top Nav
   ===================================================== */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 var(--space-24);
    background: var(--canvas);
    border-bottom: 1px solid var(--hairline);
    position: relative;
    z-index: 50;
}

.top-nav-left {
    display: flex;
    align-items: center;
    gap: var(--space-12);
}

.top-nav-logo {
    height: 22px;
    width: auto;
}

.top-nav-eyebrow {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--body);
}

.top-nav-right {
    display: flex;
    align-items: center;
    gap: var(--space-12);
}

.quota-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
    padding: 4px 12px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    font-size: 12px;
    transition: border-color 0.15s;
}

.quota-pill:hover { border-color: var(--canvas-mid); }

.quota-label {
    font-family: var(--font-mono);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
}

.quota-value {
    color: var(--accent-sunset);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.quota-pill.is-low .quota-value { color: #ff7b72; }

/* =====================================================
   Layout
   ===================================================== */
.layout {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* =====================================================
   Sidebar
   ===================================================== */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--canvas);
    border-right: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    padding: var(--space-24) var(--space-12);
    gap: var(--space-24);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--space-12);
    padding: 10px var(--space-12);
    border-radius: var(--r-sm);
    color: var(--body);
    font-size: 14px;
    font-weight: 400;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.sidebar-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-item:hover {
    background: var(--canvas-soft);
    color: var(--ink);
}

.sidebar-item.active {
    background: var(--canvas-soft);
    color: var(--ink);
}

.sidebar-item.active::before {
    content: '';
    width: 2px;
    height: 16px;
    background: var(--primary);
    border-radius: 1px;
    margin-left: -10px;
    margin-right: -2px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: var(--space-16);
    border-top: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.sidebar-eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--body-mid);
    padding: 0 var(--space-12);
}

.sidebar-model-btn {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    padding: 10px var(--space-12);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    color: var(--ink);
    font-size: 14px;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
}

.sidebar-model-btn:hover {
    border-color: var(--canvas-mid);
    background: var(--canvas-soft);
}

.sidebar-model-vendor {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
    flex-shrink: 0;
}

.sidebar-model-name {
    flex: 1;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-model-chevron {
    width: 14px;
    height: 14px;
    color: var(--body-mid);
    flex-shrink: 0;
}

/* =====================================================
   Main / Views
   ===================================================== */
.main {
    flex: 1;
    min-width: 0;
    position: relative;
    background: var(--canvas);
    overflow: hidden;
}

.view {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* =====================================================
   Chat View
   ===================================================== */
.view-chat {
    background: var(--canvas);
}

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-32) var(--space-32) var(--space-16);
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.chat-welcome {
    margin: auto;
    text-align: center;
    max-width: 640px;
    padding: var(--space-32) 0;
}

.eyebrow-mono {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--body);
    margin-bottom: var(--space-16);
}

.display-headline {
    font-family: var(--font-display);
    font-size: 48px;
    font-weight: 400;
    line-height: 48px;
    letter-spacing: -1.2px;
    color: var(--ink);
    margin-bottom: var(--space-16);
}

/* Chat messages */
.msg {
    display: flex;
    gap: var(--space-12);
    max-width: 78%;
    margin-bottom: var(--space-24);
    animation: msgIn 0.2s ease;
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.ai { align-self: flex-start; }

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 500;
    margin-top: 2px;
}

.msg.user .msg-avatar {
    background: var(--primary);
    color: var(--on-primary);
}

.msg.ai .msg-avatar {
    background: transparent;
    border: 1px solid var(--hairline);
    color: var(--accent-sunset);
    font-family: var(--font-mono);
}

.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg.user .msg-body { align-items: flex-end; }
.msg.ai .msg-body { align-items: flex-start; }

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--r-sm);
    line-height: 1.65;
    font-size: 14px;
    word-break: break-word;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    color: var(--ink);
}

.msg.user .msg-bubble {
    border-bottom-right-radius: 2px;
}

.msg.ai .msg-bubble {
    border-bottom-left-radius: 2px;
}

/* Reasoning block */
.reasoning-block {
    width: 100%;
    margin-bottom: 6px;
    border-left: 2px solid var(--accent-dusk);
    border-radius: 0 4px 4px 0;
    background: rgba(124, 58, 237, 0.08);
    overflow: hidden;
}

.reasoning-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    user-select: none;
    color: var(--body-mid);
    font-size: 12px;
}

.reasoning-header:hover { background: rgba(124, 58, 237, 0.12); }
.reasoning-header .think-label { color: var(--accent-twilight); font-weight: 500; }
.reasoning-header .think-time { font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.reasoning-header .think-arrow {
    margin-left: auto;
    transition: transform 0.2s;
    font-size: 10px;
    opacity: 0.5;
}
.reasoning-header.expanded .think-arrow { transform: rotate(90deg); }

.reasoning-body {
    padding: 0 12px 8px;
    color: var(--body-mid);
    font-size: 12px;
    font-style: italic;
    line-height: 1.6;
    display: none;
    white-space: pre-wrap;
}

.reasoning-block.expanded .reasoning-body { display: block; }

.msg-bubble .content { white-space: pre-wrap; }
.msg-bubble .content.typing::after { content: '...'; animation: typing 1s infinite; }

@keyframes typing {
    0%   { content: '.'; }
    33%  { content: '..'; }
    66%  { content: '...'; }
}

/* Markdown inside AI bubbles */
.msg-bubble .content p { margin: 5px 0; }
.msg-bubble .content p:first-child { margin-top: 0; }
.msg-bubble .content p:last-child { margin-bottom: 0; }
.msg-bubble .content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.88em;
}
.msg-bubble .content pre {
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
    position: relative;
}
.msg-bubble .content pre code { background: none; padding: 0; }
.msg-bubble .content pre .code-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--hairline);
    border-radius: 4px;
    color: var(--body);
    cursor: pointer;
    padding: 3px 8px;
    font-size: 11px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.msg-bubble .content pre:hover .code-copy { opacity: 1; }
.msg-bubble .content pre .code-copy:hover { color: var(--ink); }
.msg-bubble .content blockquote {
    border-left: 2px solid var(--accent-dusk);
    margin: 8px 0;
    padding-left: 12px;
    color: var(--body);
}
.msg-bubble .content a { color: var(--accent-sunset); }
.msg-bubble .content ul, .msg-bubble .content ol { padding-left: 20px; margin: 5px 0; }
.msg-bubble .content table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.msg-bubble .content th, .msg-bubble .content td {
    border: 1px solid var(--hairline);
    padding: 6px 10px;
    text-align: left;
}
.msg-bubble .content th { background: rgba(255, 255, 255, 0.05); }
.msg-bubble .content h1, .msg-bubble .content h2,
.msg-bubble .content h3, .msg-bubble .content h4 {
    color: var(--accent-sunset);
    margin: 10px 0 6px;
    font-weight: 500;
}
.msg-bubble .content img { max-width: 100%; border-radius: var(--r-sm); }

.msg.error .msg-bubble {
    background: rgba(218, 54, 51, 0.1);
    border-color: #ff7b72;
    color: #ff7b72;
}

/* Message meta */
.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 18px;
    padding: 0 2px;
}
.msg.user .msg-meta { justify-content: flex-end; }
.msg.ai .msg-meta { justify-content: flex-start; }

.msg-action {
    background: none;
    border: none;
    color: var(--body-mid);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: color 0.15s;
    opacity: 0;
}
.msg:hover .msg-action,
.msg-action:focus { opacity: 1; }
.msg-action:hover { color: var(--ink); }
.msg-action svg { width: 12px; height: 12px; }
.msg-action.copied { color: var(--accent-sunset); }

.msg-token {
    background: none;
    border: none;
    color: var(--body-mid);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    position: relative;
    opacity: 0;
}
.msg.ai:hover .msg-token { opacity: 1; }
.msg-token:hover { color: var(--ink); }

.token-tip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11px;
    color: var(--body);
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
}
.token-tip span { color: var(--accent-sunset); }
.msg-token:hover .token-tip { display: block; }

/* Attachments in user bubble */
.attach-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.attach-row img {
    max-width: 120px;
    max-height: 80px;
    border-radius: 4px;
    border: 1px solid var(--hairline);
    object-fit: cover;
    cursor: pointer;
}
.attach-row audio {
    max-width: 200px;
    height: 32px;
}

/* Chat input panel */
.chat-input-panel {
    border-top: 1px solid var(--hairline);
    background: var(--canvas);
    padding: var(--space-12) var(--space-32) var(--space-16);
    flex-shrink: 0;
}

.attach-preview {
    display: none;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: var(--space-8);
    align-items: center;
}
.attach-preview.show { display: flex; }

.attach-thumb {
    position: relative;
    display: inline-block;
}
.attach-thumb img {
    max-width: 80px;
    max-height: 60px;
    border-radius: 4px;
    border: 1px solid var(--hairline);
    object-fit: cover;
    cursor: pointer;
}
.attach-thumb audio {
    height: 32px;
}
.attach-thumb .remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    cursor: pointer;
    font-size: 10px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-row {
    display: flex;
    gap: var(--space-8);
    align-items: flex-end;
}

.attach-btn {
    width: 44px;
    height: 56px;
    border-radius: var(--r-pill);
    background: var(--canvas-soft);
    color: var(--body-mid);
    border: 1px solid var(--hairline);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 300;
    transition: all 0.15s;
    flex-shrink: 0;
    position: relative;
}
.attach-btn.show { display: flex; }
.attach-btn:hover { border-color: var(--canvas-mid); color: var(--ink); }
.attach-btn .attach-count {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--accent-sunset);
    color: var(--on-primary);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

#chatInput {
    flex: 1;
    resize: none;
    height: 56px;
    min-height: 44px;
    min-width: 0;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    color: var(--ink);
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s;
    font-family: var(--font-display);
}
#chatInput:focus { border-color: var(--canvas-mid); }
#chatInput::placeholder { color: var(--body-mid); }

.send-btn {
    height: 56px;
    min-width: 88px;
    padding: 0 var(--space-16);
    border-radius: var(--r-pill);
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    font-size: 13px;
    font-weight: 400;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: background 0.15s;
    flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--ink-hover); }
.send-btn:disabled {
    background: var(--hairline);
    color: var(--body-mid);
    cursor: not-allowed;
}
.send-btn.stop { background: var(--accent-sunset); color: var(--on-primary); }
.send-btn.stop:hover { background: #e06910; }
.send-btn svg { width: 16px; height: 16px; }

.input-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-8);
    gap: var(--space-12);
    flex-wrap: wrap;
}

.token-counter {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
}

.think-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 400;
    border: 1px solid var(--hairline);
    background: transparent;
    color: var(--body-mid);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.think-btn svg { width: 11px; height: 11px; }
.think-btn:hover { border-color: var(--canvas-mid); color: var(--ink); }
.think-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}
.think-btn.hidden { display: none; }

/* =====================================================
   TTS View
   ===================================================== */
.view-tts {
    overflow-y: auto;
}

.tts-shell {
    max-width: 760px;
    margin: 0 auto;
    padding: var(--space-48) var(--space-24) var(--space-32);
    display: flex;
    flex-direction: column;
    gap: var(--space-24);
}

.tts-header {
    text-align: center;
    margin-bottom: var(--space-16);
}

.tts-headline {
    font-size: 40px;
    line-height: 44px;
    letter-spacing: -0.8px;
}

.tts-tabs {
    display: flex;
    gap: var(--space-8);
    padding: 4px;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    align-self: center;
}

.tts-tab {
    padding: 8px 20px;
    border-radius: var(--r-pill);
    color: var(--body);
    font-size: 13px;
    font-weight: 400;
    transition: all 0.15s;
}

.tts-tab:hover { color: var(--ink); }

.tts-tab.active {
    background: var(--primary);
    color: var(--on-primary);
}

.tts-content {
    background: var(--canvas-card);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    padding: var(--space-24);
    display: flex;
    flex-direction: column;
    gap: var(--space-16);
}

.tts-panel {
    display: none;
    flex-direction: column;
    gap: var(--space-16);
}

.tts-panel.active {
    display: flex;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.field-label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
}

.field-textarea,
.field-input,
.field-select {
    width: 100%;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    color: var(--ink);
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font-display);
    outline: none;
    transition: border-color 0.15s;
}

.field-textarea {
    min-height: 88px;
    resize: vertical;
    line-height: 1.5;
}

.field-textarea:focus,
.field-input:focus,
.field-select:focus { border-color: var(--canvas-mid); }

.field-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237d8187' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 36px;
    cursor: pointer;
}

.field-select option {
    background: var(--canvas-soft);
    color: var(--ink);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-16);
}

.char-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--body-mid);
    text-align: right;
}

.style-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.style-tag {
    padding: 4px 12px;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    font-size: 12px;
    color: var(--body);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.style-tag:hover {
    border-color: var(--canvas-mid);
    color: var(--ink);
}

.style-tag.selected {
    border-color: var(--primary);
    color: var(--ink);
    background: rgba(255, 255, 255, 0.06);
}

.tts-examples {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    padding: var(--space-12);
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
}

.examples-eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
}

.example-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.example-item {
    padding: 8px 12px;
    background: var(--canvas-card);
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    font-size: 12px;
    color: var(--body);
    cursor: pointer;
    transition: all 0.15s;
}

.example-item:hover {
    border-color: var(--canvas-mid);
    color: var(--ink);
}

.upload-area {
    border: 1px dashed var(--hairline);
    border-radius: var(--r-pill);
    padding: var(--space-24);
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--canvas-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--canvas-mid);
    background: var(--canvas-card);
}

.upload-icon {
    font-size: 24px;
    color: var(--body-mid);
    font-weight: 300;
}

.upload-text {
    color: var(--body);
    font-size: 13px;
}

.upload-hint {
    color: var(--body-mid);
    font-size: 11px;
    font-family: var(--font-mono);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.file-preview {
    display: none;
    margin-top: var(--space-8);
    padding: var(--space-12) var(--space-16);
    background: var(--canvas-card);
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    align-items: center;
    gap: var(--space-12);
}

.file-preview.show { display: flex; }

.file-preview-icon {
    font-size: 20px;
    color: var(--accent-sunset);
}

.file-preview-info { flex: 1; min-width: 0; }

.file-preview-name {
    font-size: 13px;
    color: var(--ink);
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--body-mid);
    margin-top: 2px;
}

.file-preview-remove {
    background: none;
    border: none;
    color: var(--body-mid);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.file-preview-remove:hover {
    color: #ff7b72;
    background: rgba(255, 123, 114, 0.1);
}

.tts-action {
    display: flex;
    flex-direction: column;
    gap: var(--space-12);
}

.primary-btn {
    width: 100%;
    padding: 12px 24px;
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    border-radius: var(--r-pill);
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.15s;
    font-family: var(--font-display);
}

.primary-btn:hover:not(:disabled) { background: var(--ink-hover); }
.primary-btn:disabled {
    background: var(--hairline);
    color: var(--body-mid);
    cursor: not-allowed;
}

.tts-status {
    text-align: center;
    font-size: 12px;
    min-height: 16px;
    color: var(--body-mid);
    font-family: var(--font-mono);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.tts-status.loading { color: #ffc107; }
.tts-status.success { color: #28a745; }
.tts-status.error { color: #dc3545; }

.tts-audio {
    display: none;
    flex-direction: column;
    gap: var(--space-12);
    padding: var(--space-16);
    background: var(--canvas-card);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
}

.tts-audio.show { display: flex; }

.tts-audio audio {
    width: 100%;
    border-radius: var(--r-sm);
}

.ghost-btn {
    padding: 8px 16px;
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    font-size: 13px;
    transition: border-color 0.15s, background 0.15s;
    align-self: flex-start;
}

.ghost-btn:hover {
    border-color: var(--canvas-mid);
    background: var(--canvas-soft);
}

.spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================
   Modal — Model Picker
   ===================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-24);
    animation: overlayIn 0.18s ease;
}

.modal-overlay[hidden] {
    display: none;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    background: var(--canvas-card);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    width: 100%;
    max-width: 720px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.18s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-16) var(--space-24);
    border-bottom: 1px solid var(--hairline);
    flex-shrink: 0;
}

.modal-title {
    font-size: 16px;
    font-weight: 400;
    color: var(--ink);
}

.modal-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--body-mid);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
    background: var(--canvas-soft);
    color: var(--ink);
}

.modal-body {
    display: grid;
    grid-template-columns: 200px 1fr;
    flex: 1;
    min-height: 0;
}

.modal-pane {
    display: flex;
    flex-direction: column;
    padding: var(--space-16) 0;
    min-height: 0;
    overflow: hidden;
}

.modal-pane-vendors {
    border-right: 1px solid var(--hairline);
}

.pane-eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--body-mid);
    padding: 0 var(--space-16) var(--space-8);
    flex-shrink: 0;
}

.vendor-list,
.model-list {
    list-style: none;
    overflow-y: auto;
    padding: 0 var(--space-8) var(--space-8);
    flex: 1;
    min-height: 0;
}

.vendor-list li,
.model-list li {
    padding: 8px 12px;
    border-radius: var(--r-sm);
    color: var(--body);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-8);
}

.vendor-list li:hover,
.model-list li:hover {
    background: var(--canvas-soft);
    color: var(--ink);
}

.vendor-list li.active,
.model-list li.active {
    background: var(--canvas-soft);
    color: var(--ink);
}

.vendor-list li.active::after {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    flex-shrink: 0;
}

.model-list li.active {
    color: var(--ink);
}

.model-list li.active::after {
    content: '✓';
    color: var(--accent-sunset);
    font-size: 12px;
}

.vendor-list .vendor-name {
    font-weight: 500;
    color: var(--ink);
}

.vendor-list .vendor-count {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--body-mid);
    letter-spacing: 1px;
}

.model-list .model-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-8);
    width: 100%;
    min-width: 0;
}

.model-list .model-name {
    font-weight: 400;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-list .model-id {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--body-mid);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 50%;
    text-align: right;
}

.model-list .model-badges {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.model-badge {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 2px 6px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-pill);
    color: var(--body-mid);
}

.model-badge.think { color: var(--accent-twilight); border-color: rgba(196, 181, 253, 0.3); }
.model-badge.multi { color: var(--accent-sunset); border-color: rgba(255, 122, 23, 0.3); }
.model-badge.free { color: #28a745; border-color: rgba(40, 167, 69, 0.3); }

.model-list .empty {
    padding: 12px;
    color: var(--body-mid);
    font-size: 12px;
    text-align: center;
}

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 768px) {
    .sidebar { width: 64px; padding: var(--space-16) var(--space-8); }
    .sidebar-item span { display: none; }
    .sidebar-item { justify-content: center; }
    .sidebar-item.active::before { display: none; }
    .sidebar-eyebrow { display: none; }
    .sidebar-model-btn { flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; }
    .sidebar-model-vendor { font-size: 9px; }
    .sidebar-model-name { font-size: 11px; }
    .sidebar-model-chevron { display: none; }
    .sidebar-footer { padding-top: var(--space-12); }
    .sidebar-history { display: none !important; }

    /* design 规定 hero 在 mobile 缩到 48px；display-md 也是 48px，不变 */
    .tts-headline { font-size: 32px; line-height: 36px; letter-spacing: -0.6px; }

    .chat-scroll { padding: var(--space-16); }
    .chat-input-panel { padding: var(--space-8) var(--space-16) var(--space-12); }
    .input-meta { flex-direction: column; align-items: stretch; gap: var(--space-8); }
    .msg { max-width: 92%; }

    .form-row { grid-template-columns: 1fr; }

    .modal-body { grid-template-columns: 1fr; }
    .modal-pane-vendors {
        border-right: none;
        border-bottom: 1px solid var(--hairline);
        max-height: 140px;
    }
    .modal-pane { padding: var(--space-12) 0; }

    .top-nav { padding: 0 var(--space-12); }
    .quota-pill { display: none; }
}

/* ==================== Sidebar history (inline, below Arena) ==================== */
.sidebar-history {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}
.sidebar-history[hidden] {
    display: none !important;
}

.sidebar-history-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 14px 8px;
}
.sidebar-history-head .sidebar-eyebrow {
    margin: 0;
}
.sidebar-history-new {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--hairline);
    color: var(--body-mid);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
}
.sidebar-history-new:hover {
    background: rgba(99, 102, 241, 0.18);
    color: #c7d2fe;
    border-color: rgba(99, 102, 241, 0.3);
}

.sidebar-history-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0 6px 8px;
    margin: 0 6px;
}
.sidebar-history-empty {
    color: var(--body-mid);
    font-size: 12px;
    padding: 14px 8px;
    text-align: center;
    line-height: 1.6;
}

.sidebar-history-item {
    position: relative;
    padding: 8px 10px;
    margin-bottom: 2px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.sidebar-history-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.sidebar-history-item.active {
    background: rgba(99, 102, 241, 0.14);
}
.sidebar-history-item-title:hover {
    background: rgba(255, 255, 255, 0.04);
}
.sidebar-history-item-edit {
    width: 100%;
    box-sizing: border-box;
    background: transparent;
    border: 1px solid rgba(99, 102, 241, 0.6);
    border-radius: 6px;
    color: #f1f5f9;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    padding: 2px 6px;
    margin: -3px -7px 2px;
    outline: none;
    font-family: inherit;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.18);
}
.sidebar-history-item-edit:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}
.sidebar-history-item-time {
    color: var(--body-mid);
    font-size: 11px;
}
.sidebar-history-item-pin-icon {
    color: var(--accent-sunset, #fbbf24);
    font-size: 10px;
    margin-right: 4px;
    flex-shrink: 0;
    line-height: 1;
    display: inline-block;
}

.sidebar-history-item-title {
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    overflow: hidden;
    white-space: nowrap;
    padding-right: 32px;
    margin-bottom: 2px;
    cursor: text;
    border-radius: 4px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent 100%);
            mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent 100%);
}
.sidebar-history-item-title-text {
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
    display: block;
}

.sidebar-history-item-menu {
    position: absolute;
    top: 6px;
    right: 6px;
}
.sidebar-history-item-menu-btn {
    background: transparent;
    border: none;
    color: var(--body-mid);
    width: 22px;
    height: 22px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s;
    font-family: inherit;
}
.sidebar-history-item:hover .sidebar-history-item-menu-btn {
    display: flex;
}
.sidebar-history-item-menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}
.sidebar-history-item-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 120px;
    background: #1f1f1f;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: none;
    flex-direction: column;
}
.sidebar-history-item-dropdown.show {
    display: flex;
}
.sidebar-history-item-dropdown-item {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    padding: 7px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12.5px;
    text-align: left;
    font-family: inherit;
    transition: background 0.12s;
}
.sidebar-history-item-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.07);
}
.sidebar-history-item-dropdown-item.is-danger {
    color: #f87171;
}
.sidebar-history-item-dropdown-item.is-danger:hover {
    background: rgba(248, 81, 73, 0.12);
}

/* 置顶项：背景轻微区分 */
.sidebar-history-item.is-pinned {
    background: rgba(251, 191, 36, 0.05);
}
.sidebar-history-item.is-pinned:hover {
    background: rgba(251, 191, 36, 0.08);
}

/* 窄屏（侧边栏变窄）下：让历史列表的标题字号小一点 */
@media (max-width: 1100px) {
    .sidebar-history-item-title { font-size: 12px; }
    .sidebar-history-item-time { font-size: 10px; }
}

/* ==================== xAI-style Confirm Dialog ==================== */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 950;
    animation: confirmFadeIn 0.15s ease;
}
@keyframes confirmFadeIn { from { opacity: 0; } to { opacity: 1; } }

.confirm-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(360px, calc(100vw - 32px));
    background: #1f1f1f;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 24px;
    z-index: 960;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    animation: confirmPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    color: #fff;
}
@keyframes confirmPopIn {
    from { opacity: 0; transform: translate(-50%, -47%) scale(0.96); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.confirm-dialog[hidden],
.confirm-overlay[hidden] {
    display: none !important;
}

.confirm-title {
    font-size: 15px;
    font-weight: 500;
    color: #fff;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

.confirm-message {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 20px;
    word-wrap: break-word;
    word-break: break-word;
}

.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.confirm-btn {
    height: 32px;
    padding: 0 16px;
    border-radius: 9999px;
    border: none;
    font-size: 13px;
    font-weight: 400;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.12s;
    line-height: 1;
}
.confirm-btn-cancel {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.6);
}
.confirm-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}
.confirm-btn-ok {
    background: rgba(255, 255, 255, 0.9);
    color: #141414;
}
.confirm-btn-ok:hover {
    background: #fff;
}
.confirm-btn-ok.is-danger {
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #ef4444;
}
.confirm-btn-ok.is-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}
