/* memos.ai — Modern UI */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --primary-dark: #5A4BD1;
    --primary-bg: #F0EEFF;
    --bg: #FAFAFA;
    --bg-card: #FFFFFF;
    --bg-sidebar: #F5F3FF;
    --bg-hover: #F0EDFF;
    --bg-input: #FFFFFF;
    --border: #E8E5F0;
    --border-light: #F0EDF5;
    --text: #1A1A2E;
    --text-secondary: #6B7080;
    --text-muted: #9CA3B0;
    --user-bubble: #6C5CE7;
    --user-bubble-text: #FFFFFF;
    --assistant-bubble: #FFFFFF;
    --assistant-bubble-text: #1A1A2E;
    --tool-bg: #F8F7FC;
    --tool-border: #E8E5F0;
    --error: #E74C3C;
    --success: #27AE60;
    --shadow-sm: 0 1px 3px rgba(108, 92, 231, 0.06);
    --shadow-md: 0 4px 12px rgba(108, 92, 231, 0.08);
    --shadow-lg: 0 8px 30px rgba(108, 92, 231, 0.12);
    --radius: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    height: -webkit-fill-available;
    margin: 0;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */

.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
}
@supports (-webkit-touch-callout: none) {
    .app-layout {
        height: -webkit-fill-available;
    }
}

/* ── Sidebar ── */

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    margin-bottom: 12px;
}

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.new-chat-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    min-height: 0;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--primary-bg); color: var(--primary-dark); }

.conv-item .conv-title {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.conv-item .conv-date {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

/* ── Sidebar Footer ── */

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.usage-section {
    margin-bottom: 10px;
}

.usage-section:last-of-type {
    margin-bottom: 12px;
}

.usage-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.usage-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 3px;
}

.usage-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.usage-detail {
    font-size: 12px;
    color: var(--text-secondary);
}

.pro-badge {
    display: inline-block;
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.upgrade-btn {
    width: 100%;
    padding: 9px 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.upgrade-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.upgrade-btn.pro-active {
    background: var(--primary-bg);
    color: var(--primary);
    cursor: default;
    font-weight: 700;
}

/* ── Main Area ── */

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Navbar ── */

.navbar {
    height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    flex-shrink: 0;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
    color: var(--text-secondary);
}

.menu-toggle:hover { background: var(--border-light); }

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s;
    position: relative;
}

.icon-btn:hover {
    background: var(--border-light);
    color: var(--text);
}

.icon-btn svg { width: 20px; height: 20px; }

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    padding: 6px;
    display: none;
    z-index: 100;
}

.dropdown-menu.show { display: block; }

.dropdown-menu a, .dropdown-menu span {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text);
    text-decoration: none;
}

.dropdown-menu a:hover { background: var(--border-light); }
.dropdown-menu .label { color: var(--text-muted); font-size: 12px; cursor: default; }

/* ── Chat Messages ── */

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

.messages-container {
    max-width: 780px;
    margin: 0 auto;
}

.welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.welcome p {
    color: var(--text-muted);
    font-size: 16px;
}

/* Message bubbles */
.msg {
    display: flex;
    margin-bottom: 16px;
    gap: 12px;
    animation: fadeIn 0.2s ease;
}

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

.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.msg.assistant .msg-avatar {
    background: var(--primary-bg);
    color: var(--primary);
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
}

.msg.user .msg-bubble {
    background: var(--user-bubble);
    color: var(--user-bubble-text);
    border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
    background: var(--assistant-bubble);
    color: var(--assistant-bubble-text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.msg.system .msg-bubble {
    background: #FFF5F5;
    color: var(--error);
    border: 1px solid #FDE8E8;
    font-size: 14px;
}

.msg-content {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.msg.user .msg-content { align-items: flex-end; }
.msg.assistant .msg-content { align-items: flex-start; }

.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.msg-bubble .prose { max-width: none; }
.msg-bubble p { margin: 0 0 8px 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble code { font-size: 13px; background: rgba(0,0,0,0.05); padding: 2px 5px; border-radius: 4px; }
.msg-bubble pre { background: #1A1A2E; color: #E0E0E0; padding: 14px; border-radius: 10px; overflow-x: auto; margin: 8px 0; }
.msg-bubble pre code { background: none; padding: 0; color: inherit; }
.msg.user .msg-bubble code { background: rgba(255,255,255,0.15); }
.msg.user .msg-bubble pre { background: rgba(0,0,0,0.2); color: #F0F0F0; }

/* Tool calls */
.tool-call {
    margin-bottom: 12px;
    max-width: 600px;
    animation: fadeIn 0.2s ease;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--tool-bg);
    border: 1px solid var(--tool-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    transition: all 0.15s;
    user-select: none;
}

.tool-header:hover { background: var(--bg-hover); border-color: var(--primary-light); }
.tool-header .tool-icon { font-size: 15px; }
.tool-header .tool-name { font-weight: 600; color: var(--primary-dark); }
.tool-header .tool-summary { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-header .tool-arrow { margin-left: auto; color: var(--text-muted); transition: transform 0.2s; font-size: 12px; }
.tool-header.open .tool-arrow { transform: rotate(180deg); }

.tool-body {
    display: none;
    padding: 12px 14px;
    border: 1px solid var(--tool-border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--bg-card);
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.tool-body.open { display: block; }
.tool-body.error { color: var(--error); }

.tool-loading {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.tool-loading span {
    width: 5px;
    height: 5px;
    background: var(--primary-light);
    border-radius: 50%;
    animation: dotPulse 1.2s ease-in-out infinite;
}

.tool-loading span:nth-child(2) { animation-delay: 0.2s; }
.tool-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: flex-start;
}

.typing-dots {
    padding: 14px 18px;
    background: var(--assistant-bubble);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--primary-light);
    border-radius: 50%;
    animation: dotPulse 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Input Bar ── */

.input-bar {
    padding: 16px 24px 20px;
    background: var(--bg);
    flex-shrink: 0;
    border-top: 1px solid var(--border-light);
}

.input-wrapper {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.08);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    padding: 8px 0;
    min-height: 24px;
    max-height: 180px;
    overflow-y: auto;
    background: transparent;
    color: var(--text);
}

.input-wrapper textarea::placeholder { color: var(--text-muted); }

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.send-btn svg { width: 18px; height: 18px; }

/* ── Input Actions Row ── */

.input-actions {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

/* ── Mic Button ── */

.mic-btn {
    display: none;
}

/* ── Voice Language Bar ── */

.voice-lang-bar {
    display: none;
}

/* ── Auth Pages ── */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #F5F3FF 0%, #FAFAFA 50%, #F0EEFF 100%);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}

.auth-card .logo {
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 28px;
}

.auth-card .error-msg {
    color: var(--error);
    font-size: 14px;
    text-align: center;
    margin-bottom: 12px;
    min-height: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg);
    color: var(--text);
}

.form-group input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.08);
}

.captcha-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.captcha-row img {
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.captcha-refresh {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
}

.captcha-refresh:hover { background: var(--primary-bg); }

.auth-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.auth-btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.auth-btn.loading { opacity: 0.7; pointer-events: none; }

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 12px;
}

.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-link {
    display: block;
    text-align: center;
    color: var(--primary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    padding: 8px;
    border-radius: 8px;
}

.auth-link:hover { background: var(--primary-bg); }

/* ── Modal ── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 28px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
}

.modal .section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.modal .section-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 10px;
    margin-bottom: 6px;
}

.key-item .key-info {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
}

.key-item .key-name {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
    font-family: inherit;
}

.key-item .revoke-btn {
    background: none;
    border: none;
    color: var(--error);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
}

.key-item .revoke-btn:hover { background: #FDE8E8; }

.key-created-alert {
    background: #F0FFF4;
    border: 1px solid #C6F6D5;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 13px;
}

.key-created-alert code {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    word-break: break-all;
    user-select: all;
    background: rgba(0,0,0,0.03);
    padding: 6px 8px;
    border-radius: 6px;
}

.create-key-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.create-key-row input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

.create-key-row input:focus { border-color: var(--primary-light); }

.create-key-row button {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.create-key-row button:hover { background: var(--primary-dark); }

.modal-divider {
    height: 1px;
    background: var(--border);
    margin: 18px 0;
}

.account-info {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.account-info .mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text);
    font-size: 13px;
}

.modal-close {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 16px;
    color: var(--text-secondary);
}

.modal-close:hover { background: var(--border-light); }

/* badge */
.badge-revoked {
    font-size: 10px;
    background: #FDE8E8;
    color: var(--error);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
}

/* ── History toggle (hidden on desktop) ── */

.history-toggle {
    display: none;
}

/* ── Responsive ── */

@media (max-width: 768px) {

    /* ── Sidebar ── */
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 99; display: none;
    }
    .sidebar-overlay.show { display: block; }
    .menu-toggle { display: flex; }

    /* ── Mic button (mobile only) ── */
    .mic-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        border-radius: 50%;
        border: none;
        background: none;
        color: var(--text-muted);
        cursor: pointer;
        flex-shrink: 0;
        transition: color 0.2s, background 0.2s;
        padding: 0;
        overflow: hidden;
    }
    .mic-btn svg { width: 20px; height: 20px; max-width: 20px; max-height: 20px; }
    .mic-btn.recording {
        color: #E74C3C;
        background: rgba(231, 76, 60, 0.1);
        animation: micPulse 1.5s ease-in-out infinite;
    }
    @keyframes micPulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.3); }
        50% { box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
    }

    /* ── Voice language bar ── */
    .voice-lang-bar {
        padding: 4px 0;
        gap: 8px;
        flex-wrap: wrap;
    }
    .voice-lang-bar.show {
        display: flex !important;
    }
    .lang-chip {
        padding: 5px 14px;
        font-size: 13px;
        font-weight: 600;
        font-family: inherit;
        border: 1.5px solid var(--border);
        border-radius: 20px;
        background: none;
        color: var(--text-secondary);
        cursor: pointer;
        transition: all 0.15s;
    }
    .lang-chip.active {
        background: var(--primary);
        color: #FFF;
        border-color: var(--primary);
    }


    @media (max-width: 380px) {
        .upgrade-btn { font-size: 0; }
        .upgrade-btn::after { content: 'Upgrade'; font-size: 13px; }
    }

    /* ── Navbar — thin, frosted ── */
    .navbar {
        height: 44px;
        padding: 0 8px;
        border-bottom: none;
        background: rgba(255,255,255,0.85);
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }

    .history-toggle {
        display: flex;
        background: none;
        border: none;
        padding: 8px;
        cursor: pointer;
        border-radius: 8px;
        color: var(--text-muted);
    }
    body.mobile-history .history-toggle { color: var(--primary); }

    /* ══════════════════════════════════════════════
       FOCUS MODE — the default mobile experience
       Two-panel: response on top, input on bottom
       ══════════════════════════════════════════════ */

    /* Kill all desktop constraints */
    .messages-container {
        max-width: none !important;
        margin: 0 !important;
        width: 100% !important;
    }
    .input-wrapper {
        max-width: none !important;
        margin: 0 !important;
    }

    /* ── Top panel: response area ── */
    body:not(.mobile-history) .chat-area {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0;
        min-height: 0;
    }

    body:not(.mobile-history) .messages-container {
        padding: 24px 20px;
        display: flex;
        flex-direction: column;
        min-height: 100%;
    }

    /* Hide old messages — only show focus-visible ones */
    body:not(.mobile-history) .messages-container .msg {
        display: none !important;
    }
    body:not(.mobile-history) .messages-container .tool-call {
        display: none !important;
    }
    body:not(.mobile-history) .messages-container .msg.focus-visible {
        display: flex !important;
    }
    body:not(.mobile-history) .messages-container .tool-call.focus-visible {
        display: block !important;
    }
    body:not(.mobile-history) .messages-container .welcome {
        display: flex !important;
    }

    /* User message in focus mode — small, muted, top */
    body:not(.mobile-history) .msg.user.focus-visible {
        justify-content: flex-start;
        margin-bottom: 20px;
    }
    body:not(.mobile-history) .msg.user.focus-visible .msg-content {
        align-items: flex-start;
        max-width: 100%;
    }
    body:not(.mobile-history) .msg.user.focus-visible .msg-bubble {
        background: none;
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 500;
        padding: 0;
        border-radius: 0;
        letter-spacing: -0.01em;
    }

    /* Assistant response in focus mode — large, clean prose */
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-avatar {
        display: none;
    }
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-content {
        max-width: 100%;
    }
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-bubble {
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        font-size: 20px;
        line-height: 1.75;
        color: var(--text);
        letter-spacing: -0.01em;
    }
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-bubble p {
        margin: 0 0 16px 0;
    }
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-bubble code {
        font-size: 16px;
    }
    body:not(.mobile-history) .msg.assistant.focus-visible .msg-bubble pre {
        font-size: 14px;
        border-radius: 12px;
        padding: 16px;
    }

    /* Tool calls in focus — subtle, compact */
    body:not(.mobile-history) .tool-call.focus-visible {
        max-width: 100%;
        margin-bottom: 8px;
    }
    body:not(.mobile-history) .tool-call.focus-visible .tool-header {
        padding: 6px 10px;
        font-size: 11px;
        border-radius: 10px;
        opacity: 0.6;
    }

    /* Timestamps hidden */
    body:not(.mobile-history) .msg-time {
        display: none;
    }

    /* ── Bottom panel: input area ── */
    body:not(.mobile-history) .input-bar {
        flex-shrink: 0;
        min-height: 35vh;
        display: flex;
        flex-direction: column;
        padding: 0;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
        border-top: 1px solid var(--border-light);
        background: #FBFBFD;
    }

    body:not(.mobile-history) .input-wrapper {
        flex: 1;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 12px 20px 0 !important;
        gap: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    body:not(.mobile-history) .input-wrapper:focus-within {
        border-color: transparent !important;
        box-shadow: none !important;
    }

    body:not(.mobile-history) .input-wrapper textarea {
        flex: 1;
        min-height: 80px;
        max-height: none !important;
        font-size: 18px;
        line-height: 1.55;
        padding: 0;
        resize: none;
        color: var(--text);
    }
    body:not(.mobile-history) .input-wrapper textarea::placeholder {
        color: var(--text-muted);
        font-size: 18px;
    }

    /* Actions row — pushed up with margin */
    body:not(.mobile-history) .input-actions {
        align-self: flex-end;
        margin-top: 12px;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    body:not(.mobile-history) .input-wrapper .send-btn {
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: var(--primary);
    }
    body:not(.mobile-history) .input-wrapper .send-btn svg {
        width: 22px; height: 22px;
    }
    body:not(.mobile-history) .mic-btn {
        width: 52px;
        height: 52px;
    }
    body:not(.mobile-history) .mic-btn svg { width: 24px; height: 24px; }
    body:not(.mobile-history) .input-wrapper .send-btn svg {
        width: 18px; height: 18px;
    }

    /* ══════════════════════════════════════════════
       HISTORY MODE — traditional scrollable chat
       ══════════════════════════════════════════════ */

    body.mobile-history .chat-area {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0;
        display: block;
    }

    body.mobile-history .messages-container {
        padding: 12px 16px;
        display: block;
        min-height: auto;
    }

    body.mobile-history .messages-container .msg {
        display: flex !important;
        margin-bottom: 6px;
        gap: 8px;
    }
    body.mobile-history .messages-container .tool-call {
        display: block !important;
        max-width: 100%;
    }

    body.mobile-history .msg-avatar { display: none; }

    body.mobile-history .msg-content { max-width: 100%; }

    body.mobile-history .msg-bubble {
        border-radius: 18px;
        padding: 10px 14px;
        font-size: 15px;
        line-height: 1.5;
    }
    body.mobile-history .msg.user .msg-bubble {
        border-bottom-right-radius: 4px;
    }
    body.mobile-history .msg.assistant .msg-bubble {
        background: var(--bg);
        border: none;
        box-shadow: none;
        border-bottom-left-radius: 4px;
    }
    body.mobile-history .msg-time { display: none; }

    body.mobile-history .input-bar {
        min-height: auto;
        flex-shrink: 0;
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        border-top: 1px solid var(--border-light);
        background: #FBFBFD;
    }
    body.mobile-history .input-wrapper {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-end !important;
        padding: 8px 12px !important;
        gap: 8px !important;
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    body.mobile-history .input-wrapper:focus-within {
        box-shadow: none !important;
    }
    body.mobile-history .input-wrapper textarea {
        min-height: 24px;
        max-height: 120px;
        font-size: 16px;
    }
    body.mobile-history .send-btn {
        width: 36px; height: 36px;
        border-radius: 50%;
        flex-shrink: 0;
    }
}
