:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --primary-light: #A29BFE;
    --bg: #F5F6FA;
    --sidebar-bg: #2D3436;
    --text: #2D3436;
    --text-light: #636E72;
    --border: #DFE6E9;
    --white: #FFFFFF;
    --danger: #E17055;
    --success: #00B894;
    --warning: #FDCB6E;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overflow-x: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
body { background: var(--bg); color: var(--text); }

/* Login */
.login-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #6C5CE7 0%, #A29BFE 50%, #74B9FF 100%);
    display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 20px;
}
.login-overlay.hidden { display: none; }
.login-box {
    background: var(--white); border-radius: 20px; padding: 48px 36px 40px;
    width: 100%; max-width: 400px;
    box-shadow: 0 25px 80px rgba(108, 92, 231, 0.3); text-align: center;
}
.login-box .logo { font-size: 48px; margin-bottom: 8px; }
.login-box h2 { font-size: 24px; margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-light); font-size: 14px; margin-bottom: 30px; }
.login-box input {
    width: 100%; padding: 14px 18px; border: 2px solid var(--border);
    border-radius: 12px; font-size: 15px; outline: none; margin-bottom: 14px;
    transition: border-color 0.3s; font-family: inherit; background: #F8F9FA;
}
.login-box input:focus { border-color: var(--primary); background: var(--white); }
.login-btn {
    width: 100%; padding: 14px; background: var(--primary); color: var(--white);
    border: none; border-radius: 12px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: all 0.3s; margin-top: 6px;
}
.login-btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 8px 24px rgba(108,92,231,0.3); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.login-error { color: var(--danger); font-size: 13px; min-height: 22px; margin-bottom: 4px; }

/* App layout */
.app { display: flex; flex-direction: column; height: 100vh; height: calc(var(--vh, 1vh) * 100); }
.app.hidden { display: none; }

/* Top bar */
.topbar {
    background: var(--white); border-bottom: 1px solid var(--border);
    padding: 0 20px; display: flex; align-items: center; height: 50px; flex-shrink: 0;
    justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-brand { font-size: 16px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 6px; }
.topbar-brand img { width: 24px; height: 24px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 13px; color: var(--text-light); }
.topbar-btn {
    background: none; border: 1px solid var(--border); color: var(--text-light);
    padding: 5px 14px; border-radius: 6px; font-size: 12px; cursor: pointer;
    transition: all 0.2s; font-family: inherit;
}
.topbar-btn:hover { border-color: var(--primary); color: var(--primary); }
.topbar-btn.primary { background: var(--primary); color: #fff; border: none; }
.topbar-btn.primary:hover { background: var(--primary-dark); }

/* Tab bar */
.tabbar {
    background: var(--white); border-bottom: 2px solid var(--border);
    display: flex; padding: 0 20px; flex-shrink: 0;
}
.tab-item {
    padding: 12px 24px; cursor: pointer; font-size: 14px; font-weight: 500;
    color: var(--text-light); border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: all 0.3s; display: flex; align-items: center; gap: 6px;
}
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-item:hover { color: var(--primary); }

/* Main area */
.main-area { flex: 1; display: flex; min-height: 0; }

/* Sidebar — hamburger overlay on all screen sizes */
.sidebar {
    width: 300px; background: var(--sidebar-bg); color: #fff;
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 100;
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%); transition: transform 0.3s ease;
    padding-top: env(safe-area-inset-top, 0px);
}
.sidebar.open { transform: translateX(0); }
.sidebar-top { padding: 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.new-chat-btn {
    width: 100%; padding: 10px; background: var(--primary); color: #fff;
    border: none; border-radius: 10px; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all 0.3s; display: flex; align-items: center;
    justify-content: center; gap: 6px; font-family: inherit;
}
.new-chat-btn:hover { background: var(--primary-dark); }
.sidebar-search { padding: 10px 16px 6px; }
.sidebar-search input {
    width: 100%; padding: 8px 12px; background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;
    color: #fff; font-size: 13px; outline: none; font-family: inherit;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,0.3); }
.sidebar-search input:focus { border-color: var(--primary-light); }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* Global search results */
.search-results {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--white); border-radius: 0 0 12px 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.15); z-index: 200;
    max-height: 60vh; overflow-y: auto; margin: 0 10px;
}
.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
.search-result-group {
    padding: 8px 12px 4px;
    font-size: 11px; font-weight: 600; color: var(--text-light);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid #F0F0F0;
}
.search-result-group:first-child { border-top: none; }
.search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; cursor: pointer; transition: background 0.15s;
    border-bottom: 1px solid #F8F8F8;
}
.search-result-item:hover { background: #F8F6FF; }
.search-result-item:last-child { border-bottom: none; }
.search-result-icon {
    width: 32px; height: 32px; min-width: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700;
}
.search-result-icon.conversation { background: #E8F5E9; color: #2E7D32; }
.search-result-icon.diagnosis { background: #E3F2FD; color: #1565C0; }
.search-result-icon.knowledge { background: #F3E5F5; color: #7B1FA2; }
.search-result-icon.script { background: #FFF3E0; color: #E65100; }
.search-result-icon.practice { background: #E0F7FA; color: #00695C; }
.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
    font-size: 13px; font-weight: 600; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-result-subtitle {
    font-size: 11px; color: var(--text-light);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-result-snippet {
    font-size: 11px; color: #777; margin-top: 2px;
    line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-empty {
    padding: 24px; text-align: center; color: var(--text-light);
    font-size: 13px;
}
.search-loading {
    padding: 16px; text-align: center; color: var(--text-light);
    font-size: 13px;
}
.conv-item {
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    transition: all 0.2s; position: relative; margin-bottom: 2px;
}
.conv-item:hover { background: rgba(255,255,255,0.06); }
.conv-item.active { background: rgba(108,92,231,0.25); border-left: 3px solid var(--primary-light); }
.conv-item:has(.conv-pin-badge) { border-left: 3px solid rgba(255,200,50,0.5); background: rgba(255,200,50,0.06); }
.conv-item:has(.conv-pin-badge):hover { background: rgba(255,200,50,0.12); }
.conv-item:has(.conv-pin-badge).active { border-left: 3px solid var(--primary-light); background: rgba(108,92,231,0.25); }
.conv-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 20px; }
.conv-item:has(.conv-pin-badge) .conv-title { padding-left: 14px; }
.conv-meta { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 3px; }
.conv-del {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: rgba(255,255,255,0.2);
    font-size: 18px; cursor: pointer; display: none; line-height: 1; padding: 2px 5px;
}
.conv-item:hover .conv-del { display: block; }
.conv-del:hover { color: #E17055; }
.conv-rename-btn {
    position: absolute; right: 50px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: rgba(255,255,255,0.15);
    font-size: 13px; cursor: pointer; display: none; padding: 2px 4px;
    border-radius: 4px; line-height: 1;
}
.conv-item:hover .conv-rename-btn { display: block; }
.conv-rename-btn:hover { color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.1); }
.conv-empty { text-align: center; color: rgba(255,255,255,0.25); padding: 40px 0; font-size: 13px; }
.sidebar-footer {
    padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: space-between;
}
.user-badge { display: flex; align-items: center; gap: 8px; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: #fff; cursor: pointer; overflow: hidden;
}
.user-name { font-size: 13px; color: rgba(255,255,255,0.8); cursor: pointer; }
.logout-btn {
    background: rgba(255,255,255,0.08); border: none; color: rgba(255,255,255,0.5);
    font-size: 12px; cursor: pointer; padding: 6px 12px; border-radius: 6px; transition: all 0.3s; font-family: inherit;
}
.logout-btn:hover { color: #fff; background: rgba(225,112,85,0.5); }

/* Content panel */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.content-header {
    background: var(--white); border-bottom: 1px solid var(--border);
    padding: 12px 20px; display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.menu-toggle { display: block; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); padding: 2px 6px; }
.header-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* Panel visibility */
.panel { display: none; flex: 1; min-height: 0; }
.panel.active { display: flex; flex-direction: column; }

/* Chat area */
.chat-area { flex: 1; overflow-y: auto; padding: 20px 16px; -webkit-overflow-scrolling: touch; }
.chat-inner { max-width: 800px; width: 100%; margin: 0 auto; }
.welcome { text-align: center; padding-top: 8vh; color: var(--text-light); }
.welcome-icon { margin-bottom: 12px; }
.welcome-icon img { width: 64px; height: 64px; object-fit: contain; }
.welcome h3 { font-size: 22px; color: var(--text); margin-bottom: 6px; font-weight: 700; }
.welcome p { font-size: 14px; }
.welcome .welcome-subtitle { font-size: 15px; color: var(--text); font-weight: 500; margin-bottom: 2px; }
.welcome .welcome-desc { font-size: 13px; color: var(--text-light); margin-bottom: 24px; }

.quick-suggestions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 540px;
    margin: 0 auto;
    padding: 0 8px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #E8E5F7;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 1px 3px rgba(108,92,231,0.04);
    min-width: 0;
}
.chip:hover {
    background: #F8F6FF;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108,92,231,0.12);
}
.chip:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(108,92,231,0.08);
}
.chip-icon {
    font-size: 20px;
    flex-shrink: 0;
    line-height: 1;
}
.chip-text {
    font-size: 13px;
    color: #2D3436;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .quick-suggestions {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .chip {
        padding: 10px 12px;
    }
    .chip-text {
        font-size: 12px;
    }
}
.input-area {
    background: var(--white); border-top: 1px solid var(--border);
    padding: 14px 16px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); flex-shrink: 0;
}
.input-row { max-width: 800px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.input-row textarea {
    flex: 1; border: 2px solid var(--border); border-radius: 14px;
    padding: 11px 16px; font-size: 15px; font-family: inherit;
    resize: none; outline: none; transition: border-color 0.3s;
    min-height: 46px; max-height: 200px; line-height: 1.5; background: #F8F9FA;
    overflow-y: auto;
}
.input-row textarea:focus { border-color: var(--primary); background: var(--white); }

/* Prevent placeholder text cutoff on mobile */
input::placeholder, textarea::placeholder { color: #B2BEC3; font-size: 0.95em; }
input, textarea { text-overflow: ellipsis; }
.send-btn {
    background: var(--primary); color: var(--white); border: none;
    border-radius: 14px; padding: 11px 22px; font-size: 15px;
    cursor: pointer; font-weight: 600; transition: all 0.3s;
    white-space: nowrap; min-height: 46px; flex-shrink: 0; font-family: inherit;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.stop-btn {
    background: var(--danger); border: none;
    border-radius: 50%; width: 46px; height: 46px;
    cursor: pointer; transition: all 0.3s;
    white-space: nowrap; flex-shrink: 0; font-family: inherit;
    position: relative; display: flex; align-items: center; justify-content: center;
    animation: pulse-stop 2s infinite;
}
/* White square in the center */
.stop-btn::after {
    content: '';
    display: block;
    width: 14px; height: 14px;
    background: #fff;
    border-radius: 3px;
}
.stop-btn:hover { background: #D63031; transform: scale(1.05); }
@keyframes pulse-stop {
    0%, 100% { box-shadow: 0 0 0 0 rgba(225, 112, 85, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(225, 112, 85, 0); }
}

/* Attachment button (images + files) */
.attach-btn {
    background: #F0F0F5; color: var(--text); border: 2px solid var(--border);
    border-radius: 14px; padding: 10px 14px; font-size: 18px;
    cursor: pointer; transition: all 0.3s; min-height: 46px;
    flex-shrink: 0; font-family: inherit; display: flex; align-items: center; justify-content: center;
}
.attach-btn:hover { background: #E8E8F0; border-color: var(--primary); }
.image-preview-row {
    max-width: 800px; margin: 0 auto 8px auto;
}
.image-previews-container {
    display: flex; flex-wrap: wrap; gap: 8px;
}
.image-preview-wrapper {
    display: inline-block; position: relative;
}
.image-preview-wrapper img {
    max-width: 120px; max-height: 100px; border-radius: 10px; border: 1px solid var(--border); display: block; object-fit: cover;
}
.image-preview-remove {
    position: absolute; top: -8px; right: -8px;
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--danger); color: #fff; border: 2px solid #fff;
    font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    line-height: 1; padding: 0;
}
.image-preview-remove:hover { background: #d63031; }

.file-preview-row { max-width: 800px; margin: 0 auto 8px auto; }
.file-previews-container { display: flex; flex-wrap: wrap; gap: 8px; }
.file-preview-wrapper {
    display: inline-flex; align-items: center; gap: 6px;
    background: #F8F6FF; border: 1px solid #D8D0F0;
    border-radius: 20px; padding: 4px 12px 4px 8px;
    position: relative; font-size: 13px;
}
.file-preview-icon { font-size: 16px; }
.file-preview-name {
    max-width: 140px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; color: var(--text); font-weight: 500;
}
.file-preview-remove {
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--danger); color: #fff; border: none;
    font-size: 12px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    line-height: 1; padding: 0; flex-shrink: 0;
}
.file-preview-remove:hover { background: #d63031; }

/* File badge in chat messages */
.file-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.35);
    border-radius: 14px; padding: 2px 10px 2px 6px;
    font-size: 12px; color: #fff; font-weight: 500;
    margin-right: 4px; margin-bottom: 2px;
}

/* Messages */
.msg { margin-bottom: 20px; display: flex; gap: 10px; align-items: flex-start; animation: fadeUp 0.3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; min-width: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; overflow: hidden; }
.msg.bot .msg-avatar { background: linear-gradient(135deg, #6C5CE7, #A29BFE); color: #fff; }
.msg.user .msg-avatar { background: linear-gradient(135deg, #00B894, #55EFC4); color: #fff; }
.msg-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.msg-bubble { max-width: 75%; min-width: 0; padding: 12px 16px; border-radius: 16px; line-height: 1.7; font-size: 15px; word-wrap: break-word; overflow: hidden; }
.msg.bot .msg-bubble { background: var(--white); color: var(--text); border-bottom-left-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.msg.user .msg-bubble { background: linear-gradient(135deg, #6C5CE7, #A29BFE); color: #fff; border-bottom-right-radius: 4px; }
.msg-bubble p { margin: 0 0 8px; } .msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble pre { background: #1E1E1E; color: #D4D4D4; padding: 12px; border-radius: 10px; overflow-x: auto; margin: 8px 0; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
.msg-bubble code { background: #F0F0F0; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.msg-bubble th, .msg-bubble td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
.msg-bubble th { background: #f5f5f5; }
.msg-bubble img { max-width: 100%; height: auto; border-radius: 8px; }
.msg-bubble a { color: var(--primary); word-break: break-all; }
.msg.user .msg-bubble a { color: #E0E0FF; }
.msg-bubble blockquote { border-left: 3px solid var(--primary); padding-left: 12px; margin: 8px 0; color: #666; }
.msg-bubble h1 { font-size: 18px; } .msg-bubble h2 { font-size: 16px; } .msg-bubble h3 { font-size: 15px; }

/* Message action buttons — always subtly visible, full on hover */
.msg-actions {
    display: flex; gap: 2px; margin-top: 6px; padding-top: 4px;
    border-top: 1px solid rgba(0,0,0,0.06); opacity: 0.45;
    transition: opacity 0.2s; justify-content: flex-end;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action-btn {
    background: none; border: none; cursor: pointer;
    padding: 6px 8px; border-radius: 4px; color: #999;
    transition: all 0.15s; display: inline-flex; align-items: center;
    line-height: 1; touch-action: manipulation; -webkit-touch-callout: none;
    min-width: 32px; min-height: 32px; justify-content: center;
}
.msg-action-btn:hover { background: #F0F0F0; color: #555; }
.msg-action-delete:hover { background: #FEE2E2; color: #E17055; }
.msg.user .msg-actions { border-top-color: rgba(255,255,255,0.15); }
.msg.user .msg-action-btn { color: rgba(255,255,255,0.5); }
.msg.user .msg-action-btn:hover { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.9); }
.msg.user .msg-action-delete:hover { background: rgba(225,112,85,0.4); color: #fff; }

/* Show actions always on touch devices, with larger touch targets */
@media (hover: none) {
    .msg-actions { opacity: 0.6; }
    .msg-action-btn { padding: 8px 10px; min-width: 38px; min-height: 38px; }
    .msg-action-btn svg { width: 16px; height: 16px; }
}

/* Toast */
.toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: rgba(45,52,54,0.92); color: #fff; padding: 10px 24px; border-radius: 24px;
    font-size: 14px; z-index: 9999; pointer-events: none; opacity: 0;
    transition: all 0.3s ease; white-space: nowrap;
    backdrop-filter: blur(8px); box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Quote preview bar */
.quote-preview {
    max-width: 800px; margin: 0 auto 10px auto;
    background: linear-gradient(135deg, #F8F6FF, #EDE9FE);
    border: 1px solid #C4B5FD; border-radius: 10px; padding: 8px 12px;
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; animation: fadeUp 0.25s ease;
}
.quote-preview-inner { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; }
.quote-preview-label { color: #7C3AED; font-weight: 600; white-space: nowrap; font-size: 12px; }
.quote-preview-text { color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-preview-cancel {
    background: none; border: none; color: #999; font-size: 16px;
    cursor: pointer; padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
    line-height: 1; transition: all 0.15s;
}
.quote-preview-cancel:hover { color: #E17055; background: rgba(225,112,85,0.1); }

/* Mobile adjustments */
@media (max-width: 768px) {
    .quote-preview { padding: 6px 10px; font-size: 12px; }
    .quote-preview-label { font-size: 11px; }
    .toast { bottom: 100px; font-size: 13px; padding: 8px 18px; }
}

/* Conversation pin in sidebar */
.conv-pin-badge {
    position: absolute; left: 6px; top: 10px; font-size: 10px;
    line-height: 1; opacity: 0.7;
}
.conv-pin-btn {
    position: absolute; right: 28px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: rgba(255,255,255,0.15);
    font-size: 13px; cursor: pointer; display: none; padding: 2px 4px;
    border-radius: 4px; line-height: 1;
}
.conv-item:hover .conv-pin-btn { display: block; }
.conv-pin-btn:hover { color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.1); }
.conv-pin-btn.pinned { color: rgba(255,200,50,0.7); display: block; }
.conv-pin-btn.pinned:hover { color: rgba(255,200,50,1); }


.typing-indicator { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing-indicator span { width: 8px; height: 8px; background: var(--primary-light); border-radius: 50%; animation: typeBounce 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typeBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-10px); } }

/* Diagnosis panel */
.diag-panel { flex: 1; overflow-y: auto; padding: 0 16px 24px; -webkit-overflow-scrolling: touch; }
.diag-wrap { max-width: 800px; margin: 0 auto; padding-top: 24px; }
.diag-card { background: var(--white); border-radius: 16px; padding: 28px; margin-bottom: 24px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
.diag-card h2 { font-size: 18px; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; }

/* Talk sub-tab bar */
.talk-subtab-bar {
    display: flex; gap: 6px; margin-bottom: 20px;
    background: #F0F0F5; border-radius: 10px; padding: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    position: sticky; top: 0; z-index: 5;
}
.talk-subtab-bar::-webkit-scrollbar { height: 0; }
.talk-subtab {
    padding: 9px 22px; border-radius: 8px; cursor: pointer;
    font-size: 14px; font-weight: 500; color: var(--text-light);
    transition: all 0.2s; white-space: nowrap; flex-shrink: 0;
    user-select: none;
}
.talk-subtab.active { background: var(--white); color: var(--primary); font-weight: 700; box-shadow: 0 2px 6px rgba(108,92,231,0.15); }
.talk-subtab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.5); }

/* Talk sub-panel visibility */
.talk-subpanel { display: none; }
.talk-subpanel.active { display: block; }
.form-row { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 180px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-light); }
.form-group input, .form-group select, .form-group textarea {
    padding: 10px 14px; border: 2px solid var(--border); border-radius: 10px;
    font-size: 14px; outline: none; font-family: inherit; transition: border-color 0.3s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }
.diag-btn {
    padding: 12px 32px; background: var(--primary); color: #fff; border: none;
    border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
    transition: all 0.3s; font-family: inherit;
}
.diag-btn:hover { background: var(--primary-dark); }
.diag-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.diag-btn.secondary { background: var(--white); color: var(--primary); border: 2px solid var(--primary); }
.diag-btn.secondary:hover { background: #F8F6FF; }

/* Results */
.score-big { text-align: center; padding: 20px 0; }
.score-num { font-size: 64px; font-weight: 800; color: var(--primary); }
.score-label { font-size: 14px; color: var(--text-light); margin-top: 4px; }
.score-bottleneck { text-align: center; color: var(--danger); font-size: 14px; margin-bottom: 20px; padding: 8px 16px; background: #FFF0EE; border-radius: 8px; display: inline-block; }

/* Radar chart placeholder */
.radar-placeholder { width: 100%; max-width: 360px; margin: 0 auto 20px; display: block; }

.dim-list { margin-bottom: 20px; }
.dim-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #F0F0F0; }
.dim-row:last-child { border-bottom: none; }
.dim-icon { font-size: 20px; width: 32px; text-align: center; flex-shrink: 0; }
.dim-name { width: 100px; font-size: 14px; font-weight: 500; flex-shrink: 0; }
.dim-bar-bg { flex: 1; height: 8px; background: #F0F0F0; border-radius: 4px; overflow: hidden; }
.dim-bar-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.dim-bar-fill.high { background: var(--success); }
.dim-bar-fill.medium { background: var(--warning); }
.dim-bar-fill.low { background: var(--danger); }
.dim-score { width: 52px; text-align: right; font-weight: 700; font-size: 15px; }
.dim-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.dim-tag.high { background: #F0FFF4; color: #00B894; }
.dim-tag.medium { background: #FFF7E6; color: #FA8C16; }
.dim-tag.low { background: #FFF0EE; color: #E17055; }

.advice-block { margin-bottom: 14px; }
.advice-block h4 { font-size: 14px; margin-bottom: 8px; color: var(--primary); }
.advice-block pre { background: #F8F9FA; padding: 14px; border-radius: 8px; font-size: 13px; line-height: 1.7; white-space: pre-wrap; font-family: inherit; }
.conclusion-text { font-size: 14px; line-height: 1.8; color: var(--text-light); }
.history-item { padding: 12px 16px; border-bottom: 1px solid #F0F0F0; cursor: pointer; transition: background 0.2s; display: flex; justify-content: space-between; align-items: center; }
.history-item:hover { background: #FAFBFF; }
.history-item .org { font-weight: 600; }
.history-item .meta { font-size: 12px; color: var(--text-light); }

/* ===== Talk / Conversation Session UI ===== */
/* Chat area */
.talk-chat-area {
    background: #FAFBFC; border: 1px solid var(--border);
    border-radius: 12px; padding: 16px; margin-bottom: 12px;
    max-height: 400px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 12px;
}

/* Conversation messages */
.talk-msg {
    display: flex; gap: 10px; align-items: flex-start;
    animation: fadeUp 0.3s ease;
}
.talk-msg.customer { flex-direction: row; }
.talk-msg.consultant { flex-direction: row-reverse; }
.talk-msg.system { justify-content: center; }

.talk-msg-avatar {
    width: 34px; height: 34px; min-width: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.talk-msg.customer .talk-msg-avatar { background: #E2E8F0; color: #475569; }
.talk-msg.consultant .talk-msg-avatar { background: var(--primary); color: #fff; }

.talk-msg-bubble {
    max-width: 80%; padding: 12px 16px; border-radius: 12px;
    font-size: 14px; line-height: 1.65;
    word-break: break-word;
}
.talk-msg.customer .talk-msg-bubble {
    background: var(--white); border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.talk-msg.consultant .talk-msg-bubble {
    background: linear-gradient(135deg, #6C5CE7, #A29BFE); color: #fff;
    border-bottom-right-radius: 4px;
}
.talk-msg.system .talk-msg-bubble {
    background: #F1F5F9; color: var(--text-light);
    font-size: 12px; padding: 8px 16px; border-radius: 12px;
}
.talk-msg-label {
    font-size: 12px; margin-bottom: 4px; font-weight: 600;
}
.talk-msg.customer .talk-msg-label { color: var(--primary); }
.talk-msg.consultant .talk-msg-label { display: none; }

/* Stage indicator */
.talk-stage-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    overflow-x: auto; padding: 8px 0; gap: 0;
}
.talk-stage {
    display: flex; flex-direction: column; align-items: center;
    flex: 1; min-width: 56px; text-align: center; flex-shrink: 0;
}
.talk-stage-circle {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; margin-bottom: 4px;
    transition: all 0.3s;
}
.talk-stage .talk-stage-circle { background: #E2E8F0; color: #94A3B8; }
.talk-stage.active .talk-stage-circle { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(108,92,231,0.15); }
.talk-stage.done .talk-stage-circle { background: var(--success); color: #fff; }
.talk-stage-name {
    font-size: 10px; color: var(--text-light); white-space: nowrap;
}
.talk-stage.active .talk-stage-name { color: var(--text); font-weight: 600; }
.talk-stage.done .talk-stage-name { color: var(--success); }

/* Score feedback */
.score-fb {
    background: var(--white); border-radius: 8px; padding: 12px 14px;
    margin: 4px 0; font-size: 13px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    border-left: 4px solid #6B7280;
}
.score-fb-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px;
}
.score-fb-score { font-weight: 700; font-size: 14px; }
.score-fb-level { font-size: 13px; }
.score-fb-bar {
    width: 100%; height: 4px; background: #F1F5F9;
    border-radius: 2px; overflow: hidden; margin-bottom: 8px;
}
.score-fb-bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }
.score-fb-detail { color: #374151; padding: 1px 0; }
.score-fb-kp {
    margin-top: 6px; margin-bottom: 4px; padding: 8px 10px;
    background: linear-gradient(135deg, #EDE9FE, #F5F3FF);
    border-radius: 8px; border-left: 3px solid #7C3AED;
    font-size: 13px; color: #4C1D95;
}
.score-fb-kp .kp-label {
    font-weight: 700; font-size: 11px; text-transform: uppercase;
    letter-spacing: 1px; color: #7C3AED; margin-bottom: 6px;
}
.score-fb-kp-tag {
    display: inline-block; background: #6C5CE7; color: #fff;
    padding: 3px 10px; border-radius: 12px; margin-right: 6px; margin-bottom: 4px;
    font-weight: 700; font-size: 12px;
}
.score-fb-tips {
    margin-top: 6px; padding-top: 6px; border-top: 1px dashed #E5E7EB;
}
.score-fb-tip { color: #6B7280; padding: 1px 0; }
.score-fb-compare {
    margin-top: 8px; padding-top: 8px; border-top: 1px dashed #E5E7EB;
    font-size: 13px;
}
.talk-score-details summary { cursor: pointer; color: #6366F1; font-weight: 600; margin-bottom: 4px; }
.talk-answer-compare { display: flex; gap: 8px; margin-top: 8px; }
.talk-answer-bad {
    background: #FEF2F2; border-radius: 6px; padding: 8px 12px;
    border-left: 3px solid #EF4444; flex: 1; font-size: 13px; color: #374151;
}
.talk-answer-good {
    background: #ECFDF5; border-radius: 6px; padding: 8px 12px;
    border-left: 3px solid #10B981; flex: 1; font-size: 13px; color: #374151;
}

/* ===== Script Template Library ===== */
.script-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.script-toolbar h2 { margin: 0; }
.script-filter-bar {
    display: flex; gap: 12px; margin-bottom: 16px;
    padding: 10px 14px; background: #F8F6FF; border-radius: 10px;
    align-items: center; flex-wrap: wrap;
}
.script-filter-item { display: flex; align-items: center; gap: 6px; }
.script-filter-item label { font-size: 13px; font-weight: 600; color: #6C5CE7; white-space: nowrap; }
.script-filter-item select {
    padding: 6px 10px; border: 1px solid #D8D0F0; border-radius: 6px;
    font-size: 13px; background: #fff; color: #333; min-width: 110px;
}

/* Edit form */
.script-edit-form {
    background: #fff; border: 2px solid #6C5CE7; border-radius: 12px;
    padding: 20px; margin-bottom: 16px; box-shadow: 0 4px 20px rgba(108,92,231,0.1);
}
.script-form-header {
    display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
    font-weight: 700; font-size: 15px; color: #4C1D95;
}
.script-form-icon { font-size: 20px; }
.script-answer-row { display: flex; gap: 12px; }
.script-answer-row .form-group { flex: 1; min-width: 0; }
.script-answer-row textarea { min-height: 90px; }
.script-form-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 14px; border-top: 1px solid #F0ECFF; }

/* Script card */
.script-card {
    background: #fff; border: 1px solid #E8E3F0; border-radius: 10px;
    margin-bottom: 10px; overflow: hidden; transition: all 0.15s;
}
.script-card:hover { border-color: #C4B5FD; box-shadow: 0 2px 12px rgba(108,92,231,0.06); }
.script-card-header {
    padding: 14px 16px; cursor: pointer; display: flex; align-items: flex-start; gap: 12px;
}
.script-card-header:hover { background: #FAF9FF; }
.script-card-icon {
    width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: #fff;
}
.script-card-icon.ice-break { background: #3B82F6; }
.script-card-icon.need-discovery { background: #8B5CF6; }
.script-card-icon.solution-present { background: #F59E0B; }
.script-card-icon.objection-handling { background: #EF4444; }
.script-card-icon.closing { background: #10B981; }
.script-card-body { flex: 1; min-width: 0; }
.script-card-title {
    font-weight: 600; font-size: 14px; color: #1F2937; margin-bottom: 4px;
    line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.script-card-meta {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.script-card-stage {
    font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px;
}
.script-card-stage.ice-break { background: #DBEAFE; color: #1D4ED8; }
.script-card-stage.need-discovery { background: #EDE9FE; color: #6D28D9; }
.script-card-stage.solution-present { background: #FEF3C7; color: #B45309; }
.script-card-stage.objection-handling { background: #FEE2E2; color: #B91C1C; }
.script-card-stage.closing { background: #D1FAE5; color: #047857; }
.script-card-industry {
    font-size: 11px; color: #6B7280; background: #F3F4F6; padding: 2px 8px; border-radius: 4px;
}
.script-card-badge {
    font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px;
}
.script-card-badge.public { background: #D1FAE5; color: #047857; }
.script-card-badge.mine { background: #EDE9FE; color: #6D28D9; }
.script-card-kps {
    display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
}
.script-card-kp {
    font-size: 11px; font-weight: 600; color: #6C5CE7;
    background: #EDE9FE; padding: 1px 8px; border-radius: 10px;
}
.script-card-arrow {
    color: #9CA3AF; font-size: 14px; flex-shrink: 0;
    transition: transform 0.2s; margin-top: 4px;
}
.script-card-detail {
    display: none; padding: 0 16px 16px; border-top: 1px solid #F3F0FF;
}
.script-detail-section { margin-top: 14px; }
.script-detail-label {
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 6px;
}
.script-detail-label.good { color: #047857; }
.script-detail-label.bad { color: #B91C1C; }
.script-detail-label.tips { color: #6D28D9; }
.script-detail-content {
    font-size: 13px; color: #374151; line-height: 1.7;
    padding: 10px 14px; border-radius: 8px; white-space: pre-wrap;
}
.script-detail-content.good { background: #ECFDF5; border-left: 3px solid #10B981; }
.script-detail-content.bad { background: #FEF2F2; border-left: 3px solid #EF4444; }
.script-detail-content.tips { background: #F5F3FF; border-left: 3px solid #8B5CF6; }
.script-card-actions {
    display: flex; gap: 6px; margin-top: 12px;
}
.script-card-actions button {
    font-size: 12px; padding: 4px 12px; border-radius: 6px; border: 1px solid #D1D5DB;
    background: #fff; color: #6B7280; cursor: pointer; transition: all 0.15s;
}
.script-card-actions button:hover { background: #F9FAFB; border-color: #9CA3AF; }
.script-card-actions button.danger { color: #EF4444; border-color: #FECACA; }
.script-card-actions button.danger:hover { background: #FEF2F2; }
.script-empty {
    text-align: center; padding: 40px 20px; color: #9CA3AF;
}
.script-empty-icon { font-size: 40px; margin-bottom: 12px; }

/* AI assist messages */
.ai-assist-msg {
    display: flex; gap: 8px; margin-bottom: 12px; align-items: flex-start;
}
.ai-assist-avatar {
    width: 32px; height: 32px; min-width: 32px; border-radius: 50%;
    background: linear-gradient(135deg, #6C5CE7, #A29BFE);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #fff; font-weight: 700;
}
.ai-assist-bubble {
    padding: 10px 14px; border-radius: 12px; font-size: 14px;
    max-width: 80%; line-height: 1.65;
}
.ai-assist-help .ai-assist-bubble {
    background: #F5F3FF; border: 2px dashed #A29BFE;
}
.ai-assist-label { font-size: 11px; color: var(--primary); margin-bottom: 4px; font-weight: 600; }
.ai-coach-msg {
    margin: 8px 0;
}
.ai-coach-bubble {
    background: #FFF7E6; border: 2px dashed #F59E0B;
    padding: 10px 14px; border-radius: 12px; font-size: 13px;
    line-height: 1.7; box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.ai-coach-label { font-size: 12px; color: #92400E; font-weight: 700; margin-bottom: 6px; }

/* Input row */
.talk-input-row {
    display: flex; gap: 10px; align-items: flex-end;
}
.talk-input-row textarea {
    flex: 1; border: 2px solid var(--border); border-radius: 12px;
    padding: 10px 14px; font-size: 14px; font-family: inherit;
    resize: none; outline: none; transition: border-color 0.3s;
    min-height: 46px; max-height: 200px; line-height: 1.5;
    background: #F8F9FA; overflow-y: auto;
}
.talk-input-row textarea:focus { border-color: var(--primary); background: var(--white); }
.talk-send-btn {
    background: var(--primary); color: #fff; border: none;
    border-radius: 12px; padding: 10px 20px; font-size: 14px;
    font-weight: 600; cursor: pointer; transition: background 0.3s;
    white-space: nowrap; min-height: 46px; flex-shrink: 0;
    font-family: inherit;
}
.talk-send-btn:hover { background: var(--primary-dark); }
.talk-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* AI assist bar */
.ai-assist-bar {
    display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
    align-items: center;
}
.ai-assist-bar button {
    font-size: 13px; padding: 6px 14px; cursor: pointer;
    font-family: inherit; border-radius: 6px; border: 1px solid var(--border);
    transition: all 0.2s; font-weight: 500; background: var(--white);
}
.ai-assist-bar .ai-help-btn { color: var(--primary); border-color: var(--primary); }
.ai-assist-bar .ai-help-btn:hover { background: #F8F6FF; }
.ai-assist-bar .ai-rate-btn { color: var(--success); border-color: var(--success); }
.ai-assist-bar .ai-rate-btn:hover { background: #F0FFF4; }
.ai-loading { font-size: 12px; color: var(--text-light); align-self: center; }

/* Conversation hint */
.talk-hint {
    font-size: 13px; margin-bottom: 10px;
    padding: 10px 14px; background: linear-gradient(135deg, #EDE9FE, #F5F3FF);
    border-radius: 8px; border-left: 4px solid #6C5CE7;
    color: #4C1D95; font-weight: 600;
    line-height: 1.6;
}
.talk-hint .hint-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: #7C3AED; margin-bottom: 4px;
}
.talk-hint .hint-item {
    display: inline-block; background: #6C5CE7; color: #fff;
    padding: 3px 10px; border-radius: 12px; margin: 2px 4px 2px 0;
    font-size: 12px; font-weight: 700;
}

/* Result summary */
.talk-result-score {
    text-align: center; padding: 16px 0;
}
.talk-result-num { font-size: 56px; font-weight: 800; color: var(--primary); }
.talk-result-label { font-size: 16px; color: var(--text); font-weight: 600; margin-top: 4px; }
.talk-result-meta { font-size: 13px; color: var(--text-light); margin: 8px 0 0; }
.talk-stage-score {
    background: #fef2f2; border-radius: 6px; padding: 8px 12px;
    margin-bottom: 6px; display: flex; justify-content: space-between;
}
.talk-stage-score.strong { background: #ECFDF5; }

/* Button row */
.talk-btn-row {
    display: flex; gap: 10px; margin-top: 12px;
}

/* ===== Mobile overlay ===== */
.mobile-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 90; }
.mobile-overlay.show { display: block; }

@media (max-width: 768px) {
    /* Top bar */
    .topbar { padding: 0 12px; height: 44px; padding-top: env(safe-area-inset-top, 0px); min-height: 44px; }
    .topbar-brand { font-size: 14px; }
    .topbar-brand span { display: none; }
    .topbar-user { display: none; }
    .topbar-btn { padding: 4px 10px; font-size: 11px; }

    /* Tab bar - scrollable */
    .tabbar { padding: 0 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tabbar::-webkit-scrollbar { height: 0; }
    .tab-item { padding: 10px 14px; font-size: 13px; white-space: nowrap; flex-shrink: 0; }

    /* Chat */
    .msg-bubble { max-width: 85%; font-size: 14px; }
    .chat-area { padding: 12px 10px; }
    .input-area { padding: 10px 12px; }
    .input-row textarea { font-size: 14px; padding: 10px 12px; }
    .send-btn { padding: 10px 16px; font-size: 14px; min-height: 42px; }
    .attach-btn { padding: 8px 10px; font-size: 16px; min-height: 42px; }
    .file-preview-wrapper { font-size: 12px; padding: 3px 10px 3px 6px; }
    .file-preview-name { max-width: 100px; }
    .welcome { padding-top: 4vh; }
    .welcome-icon img { width: 48px; height: 48px; }
    .welcome h3 { font-size: 18px; }
    .welcome .welcome-subtitle { font-size: 14px; }
    .welcome .welcome-desc { font-size: 12px; margin-bottom: 16px; }

    /* Messages */
    .msg { margin-bottom: 14px; gap: 6px; }
    .msg-avatar { width: 30px; height: 30px; min-width: 30px; font-size: 12px; }

    /* Diagnosis panel */
    .diag-panel { padding: 0 8px 12px; }
    .diag-wrap { padding-top: 12px; }
    .diag-card { padding: 16px 12px; margin-bottom: 16px; border-radius: 12px; }
    .diag-card h2 { font-size: 16px; margin-bottom: 14px; }
    .form-row { flex-direction: column; gap: 10px; }
    .form-group { min-width: auto; }
    .form-group label { font-size: 12px; }
    .form-group input, .form-group select, .form-group textarea { padding: 10px 12px; font-size: 14px; }
    .diag-btn { padding: 10px 24px; font-size: 14px; width: 100%; text-align: center; }
    .diag-btn.secondary { width: auto; }

    /* Score */
    .score-num { font-size: 48px; }
    .score-bottleneck { font-size: 12px; padding: 6px 12px; }

    /* Dimension rows */
    .dim-row { gap: 6px; padding: 8px 0; flex-wrap: wrap; }
    .dim-icon { font-size: 16px; width: 24px; }
    .dim-name { width: 80px; font-size: 12px; }
    .dim-bar-bg { height: 6px; min-width: 40px; }
    .dim-score { width: 36px; font-size: 13px; }
    .dim-tag { font-size: 10px; padding: 1px 6px; }

    /* Radar */
    .radar-placeholder { max-width: 280px; }

    /* History */
    .history-item { padding: 10px 12px; flex-wrap: wrap; gap: 4px; }
    .history-item .org { font-size: 13px; }
    .history-item .meta { font-size: 11px; }

    /* Whitepaper */
    .advice-block pre { font-size: 12px; padding: 10px; }
    .conclusion-text { font-size: 13px; }

    /* Talk stages */
    #talkStageIndicator { gap: 2px; }
    #talkStageIndicator > div { min-width: 48px; }

    /* Conversation section */
    .talk-chat-area { max-height: 340px; padding: 12px; }
    .talk-msg-bubble { max-width: 85%; font-size: 13px; }
    .talk-msg-avatar { width: 28px; height: 28px; min-width: 28px; font-size: 10px; }
    .talk-stage { min-width: 46px; }
    .talk-stage-circle { width: 28px; height: 28px; font-size: 12px; }
    .talk-stage-name { font-size: 9px; }
    .talk-input-row textarea { font-size: 13px; padding: 8px 10px; }
    .talk-send-btn { padding: 8px 14px; font-size: 13px; min-height: 42px; }
    .ai-assist-bar button { font-size: 11px; padding: 5px 10px; }
    .score-fb { font-size: 12px; padding: 10px 12px; }
    .talk-result-num { font-size: 44px; }

    /* AI assist bar */
    #aiAssistBar { flex-wrap: wrap; }
    #aiAssistBar button { font-size: 11px; padding: 5px 10px; }

    /* Practice dashboard */
    #practiceDashboard .form-row { flex-direction: row; flex-wrap: wrap; }
    #practiceDashboard .form-group { min-width: 40%; flex: 1 1 40%; }
    #practiceDashboard .form-group > div:first-child { font-size: 24px; }

    /* Script library */
    .script-edit-form { padding: 14px; }
    .script-answer-row { flex-direction: column; }
    .script-toolbar { flex-direction: column; align-items: stretch; }
    .script-filter-bar { flex-direction: column; gap: 8px; }
    .script-card-header { padding: 12px; }
    .script-card-icon { width: 30px; height: 30px; font-size: 14px; }
    .script-card-title { font-size: 13px; }
    .script-card-detail { padding: 0 12px 12px; }

    /* Talk setup */
    #talkSetup .form-row { flex-direction: column; }
    #talkSetup .form-group { min-width: auto; }

    /* Dashboard trend bars */
    #dashboardContent .form-group > div:first-child { font-size: 24px; }
    #dashboardContent .form-group > div:last-child { font-size: 10px; }

    /* Buttons in result section */
    #convResultSection .diag-btn,
    #convResultSection .diag-btn.secondary { width: auto; flex: 1; }

    /* General touch optimization */
    button, .diag-btn, .topbar-btn, .tab-item, .conv-item, .history-item {
        min-height: 40px;
        -webkit-tap-highlight-color: transparent;
    }
    textarea, input, select { font-size: 16px; } /* prevent iOS zoom on focus */
    .topbar-btn.primary { display: none; } /* hide admin btn on mobile */
    .msg-actions { opacity: 0.6; } /* always show action buttons on mobile */
    .header-title { font-size: 13px; }

    /* Fix placeholder text cutoff on mobile */
    .input-row textarea { min-height: 50px; }
    input::placeholder, textarea::placeholder { white-space: normal; }
    .sidebar-search input::placeholder { font-size: 12px; }
    #searchInput { font-size: 14px; }

    /* Longer input area for tags */
    .form-group input, .form-group textarea { min-height: 42px; }
}

@media (max-width: 400px) {
    /* Extra small screens */
    .topbar-brand { font-size: 12px; }
    .topbar-brand img { width: 20px; height: 20px; }
    .tab-item { padding: 8px 10px; font-size: 12px; }
    .msg-bubble { max-width: 90%; font-size: 13px; }
    .diag-card { padding: 14px 10px; }
    .dim-name { width: 65px; font-size: 11px; }
    .dim-score { width: 30px; font-size: 11px; }
    .score-num { font-size: 40px; }
    #talkStageIndicator > div { min-width: 40px; }
    #talkStageIndicator > div > div:first-child { width: 26px; height: 26px; font-size: 12px; }
    #talkStageIndicator > div > div:last-child { font-size: 9px; }
    .input-row { gap: 6px; }
    .attach-btn { padding: 6px 8px; font-size: 14px; min-height: 38px; }
    .talk-subtab { padding: 6px 14px; font-size: 12px; }
}
