/* Ventify — Modern UI */

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

:root {
    --primary: #ea6a50;
    --primary-light: #f08070;
    --primary-dark: #d85a40;
    --primary-bg: rgba(234, 106, 80, 0.06);
    --accent: #2a3951;
    --bg: #fafaf8;
    --bg-card: #FFFFFF;
    --bg-sidebar: #2a3951;
    --bg-hover: rgba(234, 106, 80, 0.06);
    --bg-input: #FFFFFF;
    --border: #e0e0de;
    --border-light: #f0f0ee;
    --text: #2a3951;
    --text-secondary: #6f93a1;
    --text-muted: #96a3a1;
    --user-bubble: #2a3951;
    --user-bubble-text: #FFFFFF;
    --assistant-bubble: #FFFFFF;
    --assistant-bubble-text: #2a3951;
    --tool-bg: #fafaf8;
    --tool-border: #e0e0de;
    --error: #EF4444;
    --success: #22C55E;
    --shadow-sm: 0 1px 3px rgba(42, 57, 81, 0.06);
    --shadow-md: 0 4px 12px rgba(42, 57, 81, 0.08);
    --shadow-lg: 0 8px 30px rgba(42, 57, 81, 0.12);
    --radius: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --sidebar-text: #e0e0de;
    --sidebar-text-muted: rgba(224, 224, 222, 0.5);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(234, 106, 80, 0.2);
}

[data-theme="dark"] {
    --primary: #ea6a50;
    --primary-light: #f08070;
    --primary-dark: #d85a40;
    --primary-bg: rgba(234, 106, 80, 0.1);
    --accent: #6f93a1;
    --bg: #1a1f2e;
    --bg-card: #252b3b;
    --bg-sidebar: #141a28;
    --bg-hover: rgba(234, 106, 80, 0.08);
    --bg-input: #252b3b;
    --border: #3a4052;
    --border-light: #2a3040;
    --text: #e0e0de;
    --text-secondary: #6f93a1;
    --text-muted: #5a6a80;
    --user-bubble: #6f93a1;
    --user-bubble-text: #FFFFFF;
    --assistant-bubble: #252b3b;
    --assistant-bubble-text: #e0e0de;
    --tool-bg: #252b3b;
    --tool-border: #3a4052;
    --error: #F87171;
    --success: #4ADE80;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --sidebar-text: #e0e0de;
    --sidebar-text-muted: rgba(224, 224, 222, 0.4);
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(234, 106, 80, 0.2);
}

[data-theme="dark"] .msg-bubble pre { background: #1a1f2e !important; }
[data-theme="dark"] .rec-bar { background: #252b3b; border-color: #3a4052; }
[data-theme="dark"] .rec-stop-btn { background: #e0e0de; color: #1a1f2e; }
[data-theme="dark"] .rename-dialog { background: #252b3b; }
[data-theme="dark"] .rename-dialog input { background: #1a1f2e; }

* {
    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: none;
    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(--sidebar-text);
    letter-spacing: -0.5px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    flex-shrink: 0;
    height: 28px;
    width: auto;
}

.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);
}

.sidebar-header {
    border-bottom-color: var(--sidebar-border);
}

.new-chat-btn {
    background: var(--primary);
}
.new-chat-btn:hover {
    background: var(--primary-dark);
}

.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(--sidebar-border); border-radius: 4px; }

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

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

.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;
}

/* ── Conversation Actions Button ── */

.conv-actions-btn {
    display: flex;
    opacity: 0;
    pointer-events: none;
    width: 28px;
    height: 28px;
    min-width: 28px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    padding: 0;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 4px;
    transition: opacity 0.1s;
}
.conv-actions-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.conv-item:hover .conv-actions-btn { opacity: 1; pointer-events: auto; }

/* ── Conversation Context Menu ── */

.conv-context-menu {
    position: absolute;
    right: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    padding: 4px;
    z-index: 110;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.12s, transform 0.12s;
}
.conv-context-menu.show { opacity: 1; transform: scale(1); }

.conv-menu-item {
    padding: 8px 12px;
    font-size: 14px;
    border-radius: 7px;
    cursor: pointer;
    color: var(--text);
}
.conv-menu-item:hover { background: var(--bg-hover); }
.conv-menu-danger { color: var(--error); }
.conv-menu-danger:hover { background: #FDE8E8; }

/* ── Rename Dialog ── */

.rename-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.rename-dialog {
    background: #FFFFFF;
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    animation: modalIn 0.2s ease;
}

.rename-dialog h3 {
    font-size: 17px;
    font-weight: 700;
    margin: 0 0 16px;
}

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

.rename-dialog input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(234, 106, 80, 0.08);
}

.rename-dialog-btns {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

.rename-dialog-btns button {
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
}

.rename-cancel {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border) !important;
}
.rename-cancel:hover { background: var(--border-light); }

.rename-save {
    background: var(--primary);
    color: white;
}
.rename-save:hover { background: var(--primary-dark); }

/* ── Archived Section ── */

.archived-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--sidebar-border);
}

.archived-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    border-radius: 8px;
    user-select: none;
}
.archived-header:hover { background: var(--sidebar-hover); }

.archived-arrow {
    font-size: 9px;
    transition: transform 0.2s;
    display: inline-block;
}
.archived-arrow.open { transform: rotate(90deg); }

.archived-count {
    margin-left: auto;
    background: var(--sidebar-border);
    padding: 1px 7px;
    border-radius: var(--radius-full);
    font-size: 11px;
    color: var(--sidebar-text-muted);
}

.archived-item { opacity: 0.6; }
.archived-item:hover { opacity: 1; }

/* ── Sidebar Footer ── */

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--sidebar-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(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.usage-bar {
    height: 6px;
    background: var(--sidebar-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(--sidebar-text-muted);
}

.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);
}

/* ── Sidebar Actions Row ── */

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-action-btn {
    width: 34px;
    height: 34px;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
    flex-shrink: 0;
}
.sidebar-action-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.sidebar-action-btn svg { width: 18px; height: 18px; }

.sidebar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-username {
    font-size: 13px;
    font-weight: 500;
    color: var(--sidebar-text);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Dark Mode Toggle ── */

.theme-toggle {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 12px;
    border: none;
    background: var(--border);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.2s;
}
.theme-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
[data-theme="dark"] .theme-toggle {
    background: var(--primary);
}
[data-theme="dark"] .theme-toggle::after {
    transform: translateX(18px);
}

.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: 0;
    padding: 0;
    border-bottom: none;
    display: none;
    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: none;
}

.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;
    flex-shrink: 0;
    background: var(--primary-bg);
}

.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: #0F172A; 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); }
}

/* ── Thinking / Reasoning Block ── */

.thinking-block {
    margin-bottom: 12px;
    max-width: 600px;
    animation: fadeIn 0.2s ease;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--tool-bg);
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    user-select: none;
    transition: background 0.15s;
}

.thinking-header:hover {
    background: var(--bg-hover);
}

.thinking-icon {
    display: flex;
    align-items: center;
    color: var(--primary);
}

.thinking-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.thinking-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    margin-left: 4px;
}

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

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

.thinking-arrow {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.thinking-block.collapsed .thinking-arrow {
    transform: rotate(-90deg);
}

.thinking-body {
    padding: 8px 14px 12px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-muted);
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.5;
    border-top: 1px solid var(--border-light);
}

.thinking-block.collapsed .thinking-body {
    display: none;
}

/* ── WebSocket Reconnect Banner ── */

.ws-reconnect-banner {
    padding: 6px 16px;
    background: #FFF8E1;
    border-bottom: 1px solid #FFE082;
    color: #F57F17;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    flex-shrink: 0;
}

[data-theme="dark"] .ws-reconnect-banner {
    background: rgba(255, 193, 7, 0.1);
    border-color: rgba(255, 193, 7, 0.2);
    color: #FFD54F;
}

/* 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(234, 106, 80, 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;
}

/* ── Record Button ── */

.rec-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: color 0.2s;
}
.rec-btn:hover { color: var(--text-primary); }

/* ── Recording Bar ── */

.rec-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: #FFF;
    border-bottom: 1px solid #E2E8F0;
    flex-shrink: 0;
    overflow: hidden;
}
.rec-indicator {
    width: 10px; height: 10px;
    min-width: 10px;
    border-radius: 2px;
    background: #EF4444;
}
.rec-timer {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #0F172A;
    white-space: nowrap;
}
.rec-hint {
    font-size: 13px;
    color: #9CA3B0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.rec-stop-btn {
    margin-left: auto;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    background: #0F172A;
    color: #FFF;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.rec-stop-btn:hover { opacity: 0.85; }

/* ── Attach Button ── */

.attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: color 0.2s;
}
.attach-btn:hover { color: var(--primary); }

/* ── Drag & Drop ── */

.chat-area.drag-over {
    background: var(--primary-bg);
    outline: 2px dashed var(--primary);
    outline-offset: -4px;
}

/* ── Mic Button ── */

.mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    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: 18px; height: 18px; }
.mic-btn:hover { color: var(--primary); }
.mic-btn.recording {
    color: #EF4444;
    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); }
}
.mic-btn.unsupported { display: none; }

/* ── Voice Language Bar ── */

.voice-lang-bar {
    display: none;
    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);
}

/* ── Auth Pages ── */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #fafaf8 0%, #fff 50%, rgba(234, 106, 80, 0.04) 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(234, 106, 80, 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;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 14px;
    color: var(--text);
}

.setting-row select {
    padding: 6px 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    outline: none;
    max-width: 180px;
}

.setting-row select:focus { border-color: var(--primary-light); }

.switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.switch-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch input:checked + .switch-slider {
    background: var(--primary);
}

.switch input:checked + .switch-slider::after {
    transform: translateX(20px);
}

.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); }
    .conv-actions-btn { opacity: 1; pointer-events: auto; }
    .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 size) ── */
    .mic-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    .mic-btn svg { width: 20px; height: 20px; max-width: 20px; max-height: 20px; }


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

    /* ── Navbar — thin, frosted (mobile only) ── */
    .navbar {
        display: flex;
        height: 44px;
        padding: 0 8px;
        border-bottom: none;
        background: rgba(255,255,255,0.85);
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }
    [data-theme="dark"] .navbar {
        background: rgba(11, 17, 32, 0.85);
    }

    .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 .thinking-block {
        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 .thinking-block.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: var(--bg);
    }

    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: var(--bg);
    }
    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;
    }
}
