/* Lucy v4.0 — Stylesheet with Dark Mode */

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-bg: #eef2ff;
    --primary-bg2: rgba(99,102,241,0.12);
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;
    --border: #e2e8f0;
    --border-2: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --user-bubble: #6366f1;
    --user-text: #ffffff;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
    --sidebar-w: 300px;
    --transition: 0.2s ease;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, system-ui, sans-serif;
}

/* ── Dark Mode ─────────────────────────────────────────────────── */
[data-theme="dark"] {
    --primary: #818cf8;
    --primary-light: #a5b4fc;
    --primary-dark: #6366f1;
    --primary-bg: rgba(99,102,241,0.15);
    --primary-bg2: rgba(99,102,241,0.2);
    --surface: #1e1e2e;
    --surface-2: #181825;
    --surface-3: #282840;
    --border: #313244;
    --border-2: #45475a;
    --text: #cdd6f4;
    --text-2: #a6adc8;
    --text-3: #6c7086;
    --success-bg: rgba(16,185,129,0.1);
    --danger-bg: rgba(239,68,68,0.1);
    --user-bubble: #6366f1;
    --shadow: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--surface-2); color: var(--text); line-height: 1.5; height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────────────── */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #6d28d9 100%); padding: 20px; }
.login-card { background: var(--surface); border-radius: 24px; padding: 48px 40px; width: 100%; max-width: 420px; box-shadow: 0 25px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 36px; }
.logo-circle { width: 72px; height: 72px; background: linear-gradient(135deg, #6366f1, #7c3aed); border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; color: white; margin-bottom: 16px; }
.login-logo h1 { font-size: 28px; font-weight: 700; }
.login-logo p { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.login-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.login-switch:hover { color: var(--accent); }
.login-footer { text-align: center; margin-top: 24px; font-size: 12px; color: var(--text-3); }

/* ── Form Elements ──────────────────────────────────────────────── */
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input-group input, .input-group textarea, .input-group select {
    width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-size: 15px; font-family: var(--font); color: var(--text); background: var(--surface); transition: border-color var(--transition);
}
.input-group input:focus, .input-group textarea:focus, .input-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 24px; border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: all var(--transition); }
.btn-primary { background: var(--primary-dark); color: white; }
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.3); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { background: none; border: none; padding: 6px; cursor: pointer; color: var(--text-3); border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: all var(--transition); font-size: 20px; }
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon svg { width: 20px; height: 20px; }
.error-msg { color: var(--danger); font-size: 14px; margin-top: 12px; text-align: center; }
.ml-auto { margin-left: auto; }

/* ── App Layout ─────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.sidebar-header { padding: 16px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.logo-small { width: 36px; height: 36px; background: linear-gradient(135deg, #6366f1, #7c3aed); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: white; flex-shrink: 0; }
.sidebar-header h2 { font-size: 18px; font-weight: 700; }
.version { font-size: 11px; color: var(--text-3); }
.mode-toggle { display: flex; margin: 12px 12px 0; background: var(--bg-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.mode-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 12px; border: none; background: none; border-radius: calc(var(--radius-sm) - 2px); font-size: 13px; font-weight: 600; font-family: var(--font); color: var(--text-3); cursor: pointer; transition: all var(--transition); }
.mode-btn.active[data-mode="work"] { background: var(--bg-1); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.mode-btn.active[data-mode="social"] { background: linear-gradient(135deg, #ec4899, #f97316); color: white; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.mode-btn:hover:not(.active) { color: var(--text-1); }
.btn-new-chat { display: flex; align-items: center; gap: 8px; margin: 12px; padding: 10px 16px; background: var(--primary-bg); color: var(--primary); border: 1px dashed var(--primary-light); border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: all var(--transition); }
.btn-new-chat:hover { background: var(--primary-bg2); border-style: solid; }
.btn-new-chat svg { width: 16px; height: 16px; }
.sidebar-nav { padding: 0 12px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: none; background: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--text-2); cursor: pointer; transition: all var(--transition); text-align: left; font-family: var(--font); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.sidebar-divider { height: 1px; background: var(--border); margin: 8px 16px; }

/* Conversations */
.conversation-list { padding: 8px 12px; overflow-y: auto; max-height: 200px; }
.conversation-list h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-3); margin-bottom: 6px; padding: 0 4px; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; transition: all var(--transition); border: none; background: none; width: 100%; text-align: left; font-family: var(--font); }
.conv-item:hover { background: var(--surface-3); color: var(--text); }
.conv-item.pinned { border-left: 2px solid var(--primary); }
.conv-item .conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-pin { font-size: 11px; flex-shrink: 0; }
.conv-item .conv-pin-toggle { opacity: 0; font-size: 13px; color: var(--text-3); padding: 2px; cursor: pointer; flex-shrink: 0; }
.conv-item .conv-delete { opacity: 0; font-size: 16px; color: var(--text-3); padding: 2px; flex-shrink: 0; }
.conv-item:hover .conv-delete, .conv-item:hover .conv-pin-toggle { opacity: 1; }
.confirm-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 9999; backdrop-filter: blur(4px); }
.confirm-card { background: var(--bg-1); border-radius: 16px; padding: 28px; max-width: 400px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.confirm-card h3 { margin: 0 0 12px; font-size: 18px; font-weight: 700; }
.confirm-card p { margin: 0 0 24px; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.confirm-actions { display: flex; gap: 12px; justify-content: flex-end; }
.confirm-actions .btn { padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; font-family: var(--font); }
.confirm-no { background: var(--bg-2); color: var(--text-2); }
.confirm-no:hover { background: var(--surface-3); }

/* Quick Questions */
.quick-questions { padding: 8px 16px; flex: 1; overflow-y: auto; }
.quick-questions h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-3); margin-bottom: 6px; }
.quick-questions button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; font-size: 12px; color: var(--text-2); cursor: pointer; margin-bottom: 5px; transition: all var(--transition); font-family: var(--font); }
.quick-questions button:hover { border-color: var(--primary-light); color: var(--primary); background: var(--primary-bg); }
.sidebar-user { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar { width: 32px; height: 32px; background: var(--primary-bg); color: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-3); }

/* ── Mobile Header ──────────────────────────────────────────────── */
.mobile-header { display: none; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); align-items: center; gap: 12px; }
.mobile-title { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 700; font-size: 18px; }
.mobile-title .logo-small { width: 32px; height: 32px; font-size: 14px; border-radius: 8px; }

/* ── Main Content ───────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.panel { display: none; flex-direction: column; height: 100%; }
.panel.active { display: flex; }
.panel-header { padding: 24px 32px; background: var(--surface); border-bottom: 1px solid var(--border); }
.panel-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.panel-header p { color: var(--text-2); font-size: 14px; }

/* ── Welcome Screen ─────────────────────────────────────────────── */
.welcome-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 32px; flex: 1; }
.welcome-logo { width: 72px; height: 72px; background: linear-gradient(135deg, #6366f1, #7c3aed); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; color: white; margin-bottom: 20px; }
.welcome-screen h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.welcome-screen p { color: var(--text-2); font-size: 15px; text-align: center; max-width: 480px; margin-bottom: 32px; line-height: 1.6; }
.welcome-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 500px; width: 100%; }
.welcome-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: left; cursor: pointer; transition: all var(--transition); font-family: var(--font); }
.welcome-card:hover { border-color: var(--primary-light); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.welcome-card strong { display: block; font-size: 13px; color: var(--primary); margin-bottom: 4px; }
.welcome-card span { font-size: 13px; color: var(--text-2); line-height: 1.4; }

/* ── Chat ───────────────────────────────────────────────────────── */
#lucy-3d-canvas {
    position: absolute;
    top: 40px; left: 24px;
    width: min(460px, 38vw);
    height: min(600px, calc(100vh - 260px));
    z-index: 2;
    pointer-events: none;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}
#panel-chat { position: relative; }
.chat-area { flex: 1; overflow-y: auto; padding: 24px 32px; scroll-behavior: smooth; position: relative; z-index: 1; }
@media (min-width: 1200px) {
    .chat-area { padding-left: 510px; }
    .welcome-screen { padding-left: 502px; }
}
@media (min-width: 900px) and (max-width: 1199px) {
    #lucy-3d-canvas { width: 360px; height: 480px; }
    .chat-area { padding-left: 400px; }
    .welcome-screen { padding-left: 392px; }
}
@media (max-width: 899px) {
    #lucy-3d-canvas { position: relative; top: 0; left: 0; width: 100%; height: 260px; margin-bottom: 12px; }
    .chat-area { padding-top: 0; }
}
.message { display: flex; gap: 12px; margin-bottom: 20px; max-width: 860px; animation: fadeIn 0.3s ease; }
.message.user-msg { flex-direction: row-reverse; margin-left: auto; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg-avatar { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; margin-top: 2px; }
.lucy-msg .msg-avatar { background: linear-gradient(135deg, #6366f1, #7c3aed); color: white; }
.user-msg .msg-avatar { background: var(--surface-3); color: var(--text); }
.msg-body { flex: 1; min-width: 0; }
.msg-content { padding: 14px 18px; border-radius: 18px; font-size: 14px; line-height: 1.7; word-wrap: break-word; overflow-wrap: break-word; }
.lucy-msg .msg-content { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 4px; }
.user-msg .msg-content { background: var(--user-bubble); color: var(--user-text); border-top-right-radius: 4px; }

/* Markdown in Lucy messages */
.msg-content h1, .msg-content h2, .msg-content h3 { font-weight: 700; margin: 12px 0 6px; }
.msg-content h1 { font-size: 18px; } .msg-content h2 { font-size: 16px; } .msg-content h3 { font-size: 15px; }
.msg-content strong { font-weight: 600; }
.msg-content code { background: var(--surface-3); padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace; }
.user-msg .msg-content code { background: rgba(255,255,255,0.2); }
.msg-content pre { background: var(--surface-3); border-radius: 8px; padding: 12px 16px; overflow-x: auto; margin: 8px 0; }
.msg-content pre code { background: none; padding: 0; }
.msg-content ul, .msg-content ol { margin: 6px 0; padding-left: 20px; }
.msg-content li { margin-bottom: 4px; }
.msg-content blockquote { border-left: 3px solid var(--primary); padding-left: 12px; margin: 8px 0; color: var(--text-2); }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Message footer */
.msg-footer { display: flex; align-items: center; gap: 12px; margin-top: 6px; padding: 0 4px; }
.msg-time { font-size: 11px; color: var(--text-3); }
.msg-copy { font-size: 11px; color: var(--text-3); cursor: pointer; border: none; background: none; font-family: var(--font); padding: 2px 6px; border-radius: 4px; transition: all var(--transition); }
.msg-copy:hover { background: var(--surface-3); color: var(--text); }

/* Streaming cursor */
.streaming .msg-content::after { content: '\25CF'; color: var(--primary); animation: blink 1s step-end infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* Thinking indicator */
.thinking-indicator { display: flex; gap: 5px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; border-top-left-radius: 4px; width: fit-content; }
.thinking-indicator span { width: 8px; height: 8px; background: var(--text-3); border-radius: 50%; animation: bounce 1.4s ease-in-out infinite; }
.thinking-indicator span:nth-child(2) { animation-delay: 0.2s; }
.thinking-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* Chat input */
.chat-input-area { padding: 12px 32px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.chat-input-wrapper { display: flex; align-items: flex-end; gap: 8px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 18px; padding: 8px 8px 8px 18px; transition: border-color var(--transition); }
.chat-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
#chat-input { flex: 1; border: none; background: none; font-size: 15px; font-family: var(--font); color: var(--text); resize: none; max-height: 120px; padding: 6px 0; line-height: 1.5; }
#chat-input:focus { outline: none; }
#chat-input::placeholder { color: var(--text-3); }
.send-btn { width: 40px; height: 40px; background: var(--primary-dark); border: none; border-radius: 12px; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all var(--transition); }
.send-btn:hover { background: #4338ca; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn svg { width: 18px; height: 18px; }
.chat-hint { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 6px; }

/* ── Upload Zone ────────────────────────────────────────────────── */
.upload-zone { border: 2px dashed var(--border-2); border-radius: var(--radius); padding: 48px 24px; text-align: center; transition: all var(--transition); cursor: pointer; }
.upload-zone:hover, .upload-zone.drag-active { border-color: var(--primary); background: var(--primary-bg); }
.upload-zone.drag-active { transform: scale(1.01); }
.upload-icon { width: 48px; height: 48px; color: var(--text-3); margin-bottom: 16px; }
.upload-zone p { font-size: 15px; color: var(--text-2); margin-bottom: 8px; }
.upload-link { color: var(--primary); cursor: pointer; text-decoration: underline; font-weight: 600; }
.upload-types { font-size: 12px; color: var(--text-3); }
.progress-bar { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin: 16px 0 8px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s ease; width: 0%; }

/* ── Tool Panels ────────────────────────────────────────────────── */
.tool-content { flex: 1; padding: 24px 32px; overflow-y: auto; }
.tool-textarea { width: 100%; padding: 16px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: var(--font); color: var(--text); background: var(--surface); resize: vertical; margin-bottom: 16px; line-height: 1.6; }
.tool-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.full-width { grid-column: 1 / -1; }
.result-area { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; font-size: 14px; line-height: 1.7; max-height: 500px; overflow-y: auto; }
.result-area.error { border-color: var(--danger); background: var(--danger-bg); }
.result-area.success { border-color: var(--success); background: var(--success-bg); }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal-card { position: relative; background: var(--surface); border-radius: 20px; width: 90%; max-width: 500px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 18px; }
.modal-body { padding: 24px; }
.modal-body h3 { font-size: 15px; color: var(--text-2); margin-bottom: 12px; }
.system-info { font-size: 13px; color: var(--text-2); line-height: 1.8; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -100%; top: 0; bottom: 0; z-index: 100; transition: left 0.3s ease; box-shadow: var(--shadow-lg); width: 280px; }
    .sidebar.open { left: 0; }
    .mobile-header { display: flex; }
    .main-content { height: calc(100vh - 53px); }
    .panel-header { padding: 16px; }
    .chat-area { padding: 16px; }
    .chat-input-area { padding: 8px 16px 12px; }
    .tool-content { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .message { max-width: 100%; }
    .welcome-cards { grid-template-columns: 1fr; }
    .welcome-screen { padding: 40px 16px; }
}

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Tech Tree ──────────────────────────────────────────────────── */
.tt-card { max-width: 680px; width: 95%; max-height: 90vh; }
.tt-header { text-align: center; padding: 24px 24px 16px; border-bottom: 1px solid var(--border); }
.tt-header h2 { font-size: 22px; margin: 12px 0 4px; }
.tt-header p { color: var(--text-2); font-size: 14px; margin-bottom: 12px; }
.tt-avatar-preview { display: flex; justify-content: center; }
.tt-avatar-circle {
    width: 72px; height: 72px; border-radius: 20px; display: flex; align-items: center; justify-content: center;
    font-size: 30px; font-weight: 700; color: white; transition: all 0.4s ease;
    background: linear-gradient(135deg, var(--primary), #7c3aed); box-shadow: 0 8px 24px rgba(99,102,241,0.3);
}
.tt-tokens { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-3); padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: 600; }
.tt-token-icon { font-size: 18px; }
.tt-branches { padding: 20px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; overflow-y: auto; max-height: 340px; }
.tt-branch { text-align: center; }
.tt-branch-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; padding: 4px 0; border-radius: 6px; }
.tt-node-stack { display: flex; flex-direction: column; align-items: center; gap: 0; }
.tt-connector { width: 2px; height: 12px; background: var(--border); }
.tt-node {
    width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; cursor: pointer; transition: all 0.25s ease;
    border: 3px solid var(--border); background: var(--surface); color: var(--text-3); position: relative;
}
.tt-node:hover { transform: scale(1.15); }
.tt-node.purchased { border-color: currentColor; background: currentColor; color: white !important; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.tt-node.purchased::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid currentColor; opacity: 0.3; }
.tt-node.available { border-color: currentColor; border-style: dashed; color: var(--text); animation: pulse-node 2s ease-in-out infinite; }
@keyframes pulse-node { 0%,100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.3); } 50% { box-shadow: 0 0 0 8px rgba(99,102,241,0); } }
.tt-node.locked { opacity: 0.3; cursor: not-allowed; }
.tt-node.locked:hover { transform: none; }
.tt-node.too_expensive { opacity: 0.5; border-style: dashed; cursor: not-allowed; }
.tt-node-label { font-size: 10px; color: var(--text-3); margin-top: 4px; max-width: 80px; line-height: 1.2; }
.tt-node-cost { font-size: 9px; color: var(--text-3); }
.tt-refund { font-size: 10px; color: var(--danger); cursor: pointer; border: none; background: none; margin-top: 6px; padding: 2px 6px; border-radius: 4px; font-family: var(--font); }
.tt-refund:hover { background: var(--danger-bg); }

/* Avatar grid */
.tt-avatars { padding: 0 20px 12px; }
.tt-avatars h3 { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.tt-avatar-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.tt-avatar-option {
    width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: white; cursor: pointer; border: 3px solid transparent;
    transition: all 0.2s ease; position: relative;
}
.tt-avatar-option:hover { transform: scale(1.1); }
.tt-avatar-option.selected { border-color: var(--text); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.tt-avatar-option .tt-av-name { display: none; position: absolute; bottom: -18px; font-size: 9px; color: var(--text-2); white-space: nowrap; }
.tt-avatar-option:hover .tt-av-name { display: block; }

.tt-footer { padding: 16px 20px; border-top: 1px solid var(--border); text-align: center; }
.tt-earn-hint { font-size: 11px; color: var(--text-3); margin-top: 8px; }

@media (max-width: 768px) {
    .tt-branches { grid-template-columns: repeat(3, 1fr); }
    .tt-card { max-height: 95vh; }
}
@media (max-width: 480px) {
    .tt-branches { grid-template-columns: repeat(2, 1fr); }
}

/* ── Companion & Shop ──────────────────────────────────────────── */

/* Sidebar shop button */
.sidebar-shop { padding: 4px 12px; display: flex; align-items: center; gap: 8px; }
.btn-shop {
    flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 14px;
    background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer;
    font-family: var(--font); transition: all var(--transition);
}
.btn-shop:hover { background: var(--primary-bg); border-color: var(--primary-light); color: var(--primary); }
.shop-icon { font-size: 18px; }
.shop-token-badge {
    margin-left: auto; font-size: 12px; font-weight: 700; color: var(--warning);
    background: rgba(245,158,11,0.12); padding: 2px 8px; border-radius: 10px;
}
.companion-equipped { display: flex; align-items: center; }
.companion-preview { font-size: 22px; min-width: 28px; text-align: center; line-height: 1; }
.companion-preview.empty { opacity: 0; }

/* Chat companion badge */
.msg-avatar-wrap { position: relative; flex-shrink: 0; }
.companion-badge {
    position: absolute; bottom: -6px; right: -8px;
    font-size: 14px; line-height: 1; z-index: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
    animation: petBounce 2s ease-in-out infinite;
}
@keyframes petBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* Token toast notification */
.pet-toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(60px);
    background: var(--surface); border: 1px solid var(--warning); border-radius: 12px;
    padding: 10px 20px; font-size: 14px; font-weight: 600; color: var(--text);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15); z-index: 9999;
    transition: transform 0.3s ease, opacity 0.3s ease; opacity: 0;
}
.pet-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.pet-toast-icon { font-size: 18px; margin-right: 6px; }

/* Shop modal */
.shop-modal-card { max-width: 580px; width: 95%; max-height: 85vh; display: flex; flex-direction: column; }
.shop-header { padding: 20px 24px 0; border-bottom: 1px solid var(--border); }
.shop-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.shop-header-top h2 { font-size: 20px; }
.shop-token-bar {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-3); padding: 6px 14px; border-radius: 16px;
    font-size: 14px; font-weight: 600; margin-bottom: 14px;
}
.shop-token-icon { font-size: 16px; }
.shop-token-hint { font-size: 11px; color: var(--text-3); margin-left: 8px; font-weight: 400; }

/* Shop tabs */
.shop-tabs { display: flex; gap: 0; }
.shop-tab {
    flex: 1; padding: 10px 0; border: none; background: none; font-size: 13px;
    font-weight: 600; font-family: var(--font); color: var(--text-3); cursor: pointer;
    border-bottom: 3px solid transparent; transition: all var(--transition);
}
.shop-tab:hover { color: var(--text); }
.shop-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Shop body */
.shop-body { flex: 1; overflow-y: auto; padding: 16px 24px 24px; }
.shop-section { display: none; }
.shop-section.active { display: block; }

/* Shop grid */
.shop-grid { display: flex; flex-direction: column; gap: 8px; }
.shop-rarity-label {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 8px 0 4px; display: flex; align-items: center; gap: 6px;
}
.shop-rarity-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Shop card (item row) */
.shop-card {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    border: 1.5px solid var(--border); background: var(--surface);
    transition: all var(--transition);
}
.shop-card:hover { border-color: var(--primary-light); background: var(--primary-bg); }
.shop-card.owned { border-color: var(--success); background: var(--success-bg); }
.shop-card.equipped { border-color: var(--primary); background: var(--primary-bg); box-shadow: 0 0 0 2px var(--primary-bg2); }
.shop-card.locked { opacity: 0.5; }
.shop-card.locked:hover { border-color: var(--border); background: var(--surface); }

.shop-card-emoji { font-size: 28px; width: 40px; text-align: center; flex-shrink: 0; }
.shop-card-info { flex: 1; min-width: 0; }
.shop-card-name { font-size: 14px; font-weight: 600; }
.shop-card-tagline { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Lucy look preview circle */
.shop-lucy-preview {
    width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center;
    justify-content: center; font-size: 18px; color: white; font-weight: 700; flex-shrink: 0;
}

/* Shop buttons */
.shop-btn {
    padding: 6px 14px; border-radius: 8px; font-size: 12px; font-weight: 700;
    font-family: var(--font); cursor: pointer; border: none; transition: all var(--transition);
    white-space: nowrap; flex-shrink: 0;
}
.shop-btn-buy { background: var(--warning); color: #fff; }
.shop-btn-buy:hover { background: #d97706; transform: scale(1.05); }
.shop-btn-equip { background: var(--primary-bg); color: var(--primary); border: 1px solid var(--primary-light); }
.shop-btn-equip:hover { background: var(--primary); color: white; }
.shop-btn-equipped { background: var(--primary); color: white; }
.shop-btn-disabled { opacity: 0.4; cursor: not-allowed; }
.shop-btn-disabled:hover { transform: none; }

.shop-empty-hint { text-align: center; padding: 32px 16px; color: var(--text-3); font-size: 14px; }

/* Pet Upgrades (V4.1: 5 upgrades/pet — house + 3 varieties + interaction) */
.shop-upgrade-group-header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 4px 6px; margin-top: 12px;
    border-top: 1px solid var(--border);
}
.shop-upgrade-group-header:first-child { border-top: none; margin-top: 0; }
.shop-upgrade-group-header.locked-group { opacity: 0.55; }
.shop-upgrade-pet-emoji { font-size: 30px; width: 40px; text-align: center; }
.shop-upgrade-pet-meta { flex: 1; min-width: 0; }
.shop-upgrade-pet-name { font-size: 15px; font-weight: 700; color: var(--text); }
.shop-upgrade-pet-hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.shop-upgrade-card { position: relative; padding-left: 80px; }
.shop-upgrade-slot-tag {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
    padding: 3px 8px; border-radius: 6px;
    background: var(--surface-3); color: var(--text-2);
    min-width: 60px; text-align: center;
}
.shop-upgrade-card.equipped .shop-upgrade-slot-tag { background: var(--primary); color: white; }
.shop-color-dot {
    display: inline-block; width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid var(--border); vertical-align: middle; margin-right: 4px;
}
.shop-active-badge {
    display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: 0.5px;
    padding: 2px 6px; border-radius: 6px;
    background: var(--primary); color: #fff; margin-left: 6px;
    vertical-align: middle;
}
.shop-upgrade-group-header.active-group .shop-upgrade-pet-name { color: var(--primary); }
.shop-upgrade-card.inactive-pet { opacity: 0.72; }
.shop-upgrade-card.inactive-pet:hover { opacity: 1; }

/* Interact button (floats over the 3D canvas) */
#lucy-interact-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 3;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
    display: none;  /* shown when pet equipped */
}
#lucy-interact-btn.visible { display: inline-block; }
#lucy-interact-btn:hover { transform: scale(1.06); box-shadow: 0 6px 18px rgba(99, 102, 241, 0.5); }
#lucy-interact-btn:active { transform: scale(0.96); }
#lucy-interact-btn:disabled { opacity: 0.5; cursor: wait; }
@media (min-width: 900px) {
    #lucy-interact-btn { top: 56px; left: 40px; }   /* inside canvas box at (40,24) */
}
@media (max-width: 899px) {
    #lucy-interact-btn { top: 12px; left: 12px; }
}

@media (max-width: 480px) {
    .shop-modal-card { max-height: 95vh; }
    .shop-tabs { font-size: 12px; }
}

/* ── Print ──────────────────────────────────────────────────────── */
@media print {
    .sidebar, .mobile-header, .chat-input-area, .send-btn, .btn-icon { display: none !important; }
    .main-content { height: auto; overflow: visible; }
    .chat-area { height: auto; overflow: visible; padding: 0; }
    .message { page-break-inside: avoid; }
}

/* ── Documents Container (doc-to-conversation handoff) ─────────── */
.documents-container {
    margin: 12px 0;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}
.documents-container.hidden { display: none; }
@media (min-width: 1200px) {
    .documents-container { margin-left: 510px; margin-right: 32px; }
}
@media (min-width: 900px) and (max-width: 1199px) {
    .documents-container { margin-left: 400px; margin-right: 24px; }
}
.doc-container-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.7;
    margin-bottom: 8px;
}
.doc-card-row {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 6px 0;
}
.doc-card-row:first-of-type { border-top: none; }
.doc-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
}
.doc-card-header:hover { opacity: 0.85; }
.doc-card-filename { font-weight: 600; }
.doc-card-sep { opacity: 0.4; }
.doc-card-summary { opacity: 0.75; flex: 1; }
.doc-card-chevron { opacity: 0.6; font-size: 12px; }
.doc-card-body {
    padding: 10px 0 4px 24px;
    font-size: 14px;
    line-height: 1.5;
    max-height: 45vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.doc-card-body.hidden { display: none; }
.doc-card-analysis pre {
    background: rgba(0, 0, 0, 0.25);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
}
.doc-card-extracted {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}
.doc-card-extracted summary {
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    opacity: 0.75;
    padding: 4px 0;
}
.doc-card-extracted summary:hover { opacity: 1; }
.doc-card-extracted pre {
    margin-top: 8px;
    padding: 8px;
    font-size: 12px;
    line-height: 1.4;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}
.doc-handoff-actions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── Document Handoff Picker ──────────────────────────────────── */
.handoff-card { min-width: 420px; max-width: 560px; }
.handoff-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
    max-height: 320px;
    overflow-y: auto;
}
.handoff-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    cursor: pointer;
}
.handoff-row:hover { background: rgba(255, 255, 255, 0.04); }
.handoff-row input[type="radio"] { margin: 0; }
.handoff-row-title { font-weight: 600; flex-shrink: 0; }
.handoff-row-meta { opacity: 0.65; font-size: 13px; }
.handoff-row-new { border-color: rgba(100, 200, 255, 0.3); }
.handoff-slot-info {
    font-size: 12px;
    opacity: 0.65;
    margin: 8px 0 12px;
    text-align: right;
}

/* Photo generation V1 — inline image rendering */
.lucy-image-container {
    margin-top: 12px;
}
.lucy-generated-image {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid #ddd;
    display: block;
}
.lucy-download-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 13px;
    text-decoration: none;
    color: #333;
}
.lucy-download-btn:hover {
    background: #e8e8e8;
}

/* Expired image placeholder (shown after 30d retention) */
.lucy-image-expired {
    padding: 12px;
    background: #fafafa;
    border: 1px dashed #ccc;
    border-radius: 8px;
    color: #888;
    font-size: 14px;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── Settings v2 ─────────────────────────────────────────────────── */
.settings-section { margin-bottom: 24px; padding: 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.settings-section h3 { margin: 0 0 12px; font-size: 15px; opacity: 0.85; }
.settings-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }

/* ── Trait control ───────────────────────────────────────────────── */
.trait-row { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.trait-title { font-weight: 600; margin-bottom: 6px; }
.trait-pills { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.trait-pill { padding: 4px 10px; border: 1px solid rgba(255,255,255,0.2); border-radius: 12px; background: transparent; cursor: pointer; font-size: 12px; }
.trait-pill.selected { background: rgba(100,200,255,0.2); border-color: rgba(100,200,255,0.5); }
.trait-pill.locked { opacity: 0.5; }
.trait-pill.owned { background: var(--success, #16a34a); color: white; border-color: var(--success, #16a34a); }
.trait-refund-row { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.trait-refund-btn { background: transparent; border: 1px solid var(--border); color: var(--text-2, #aaa); font-size: 11px; padding: 2px 6px; margin-left: 0; border-radius: 4px; cursor: pointer; }
.trait-refund-btn:hover { background: rgba(220,38,38,0.1); color: var(--danger, #dc2626); border-color: var(--danger, #dc2626); }
.trait-slider-disabled-hint { font-size: 12px; color: var(--text-3, #888); font-style: italic; padding: 4px 0; }
.trait-slider-row { display: flex; align-items: center; gap: 10px; }
.trait-slider { flex: 1; }
.trait-strength-label { font-size: 12px; opacity: 0.7; min-width: 40px; }
.trait-desc { font-size: 12px; opacity: 0.65; margin-top: 4px; }
.shop-btn-refund { background: transparent; border: 1px solid var(--border); color: var(--text-2, #aaa); font-size: 12px; padding: 4px 8px; margin-left: 4px; border-radius: 6px; cursor: pointer; }
.shop-btn-refund:hover { background: rgba(220,38,38,0.1); border-color: var(--danger, #dc2626); color: var(--danger, #dc2626); }

/* ── Theme toggle ────────────────────────────────────────────────── */
.theme-toggle label { margin: 0 8px 0 4px; cursor: pointer; }

/* ── Onboarding wizard ──────────────────────────────────────────── */
.onboarding-card { min-width: 480px; max-width: 640px; padding: 24px; position: relative; }
.onboarding-close { position: absolute; top: 8px; right: 12px; background: none; border: none; font-size: 24px; cursor: pointer; opacity: 0.6; }
.onboarding-close:hover { opacity: 1; }
.onboarding-dots { display: flex; gap: 6px; margin-bottom: 8px; }
.onboarding-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.2); cursor: pointer; }
.onboarding-dot.active { background: rgba(100,200,255,0.7); }
.onboarding-counter { font-size: 11px; opacity: 0.6; margin-bottom: 4px; }
.onboarding-body p { margin: 8px 0; }
.onboarding-actions { margin-top: 16px; }

/* ── Chat-point indicator ───────────────────────────────────────── */
#lucy-token-indicator { font-size: 12px; opacity: 0.75; padding: 4px 8px; }
.lucy-points-dots { font-family: monospace; letter-spacing: 1px; }

/* ── Account-delete modal ──────────────────────────────────────── */
.btn-danger { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); color: #fca5a5; }
.confirm-input { padding: 6px 10px; margin-top: 8px; width: 200px; font-family: monospace; }

/* ── Cross-exam offer card ─────────────────────────────────────── */
.cross-exam-offer { padding: 12px 14px; border: 1px dashed rgba(255,255,255,0.15); border-radius: 8px; margin: 8px 0; }
.cross-exam-offer .offer-actions { margin-top: 10px; display: flex; gap: 8px; }

/* ── Same-patient badge ────────────────────────────────────────── */
.same-patient-badge { display: inline-flex; align-items: center; gap: 6px; margin-left: 12px; font-size: 12px; opacity: 0.85; }
.same-patient-badge select { font-size: 11px; padding: 2px 6px; }
