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

/*
 * CoLA 前端共享样式
 * 包含主题变量、通用布局、组件样式
 */

/* ========== 主题变量 ========== */
:root {
    color-scheme: dark;
    --bg-primary: #050508;
    --bg-secondary: #0f0f17;
    --bg-tertiary: #14141d;
    --bg-panel: #1a1a24;
    --bg-panel-glass: rgba(26, 26, 36, 0.65);
    --bg-elevated: #282836;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-blue: #3b82f6;
    --accent-orange: #f97316;
    --accent-purple: #8b5cf6;
    --accent-red: #ef4444;
    --logo-blue: #38bdf8;
    --logo-green: #4ade80;
    --border-color: rgba(255, 255, 255, 0.08);
    --chart-text: rgba(255, 255, 255, 0.7);
    --chart-grid: rgba(255, 255, 255, 0.05);
    --glass-blur: blur(20px);
}

/* 浅色主题 */
[data-theme="light"] {
    color-scheme: light;
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-tertiary: #e2e8f0;
    --bg-panel: #ffffff;
    --bg-panel-glass: rgba(255, 255, 255, 0.75);
    --bg-elevated: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-green: #059669;
    --accent-yellow: #d97706;
    --accent-blue: #2563eb;
    --accent-orange: #ea580c;
    --accent-purple: #7c3aed;
    --accent-red: #dc2626;
    --logo-blue: #38bdf8;
    --logo-green: #4ade80;
    --border-color: rgba(0, 0, 0, 0.1);
    --chart-text: rgba(0, 0, 0, 0.7);
    --chart-grid: rgba(0, 0, 0, 0.05);
    --glass-blur: blur(24px);
}

button {
    font-family: inherit;
}

/* 主题切换按钮 */
.theme-toggle {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    height: 32px;
    width: 32px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-primary);
}

.theme-toggle-float {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.theme-toggle:hover {
    border-color: var(--accent-purple);
}

.theme-toggle svg {
    stroke: var(--text-primary);
}

.theme-toggle span {
    color: var(--text-primary);
    line-height: 1;
}

/* ========== 基础重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

input, select, textarea {
    max-width: 100%;
    min-width: 0;
    font-family: inherit;
}

/* ========== 通用组件 ========== */

/* 按钮 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--accent-blue);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

/* 加载状态 */
.loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 状态指示器 */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-red);
}

.status-dot.connected {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.waiting {
    background: var(--accent-yellow);
    box-shadow: 0 0 8px var(--accent-yellow);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 卡片 */
.card {
    background: var(--bg-panel-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="light"] .card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
    border-top: 1px solid rgba(255, 255, 255, 0.6);
}

/* 表单输入 */
/* 表单输入 (Minimalist & Global) */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea,
.input {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="password"],
[data-theme="light"] input[type="number"],
[data-theme="light"] input[type="datetime-local"],
[data-theme="light"] select,
[data-theme="light"] textarea,
[data-theme="light"] .input {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.15);
}

input:focus, select:focus, textarea:focus, .input:focus {
    outline: none;
    border-color: var(--accent-blue);
    background: transparent !important;
    box-shadow: 0 0 0 1px var(--accent-blue) inset;
}

input::placeholder, textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* 确认弹窗 */
.confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.confirm-overlay.hidden {
    display: none;
}

.confirm-dialog {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 420px;
    padding: 16px;
}

.confirm-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.confirm-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

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

/* 文本区域 */
.textarea {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: 'SF Mono', monospace;
    width: 100%;
    resize: vertical;
}

.textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* ========== 调试面板 ========== */
.debug-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 150px;
    overflow-y: auto;
    background: rgba(0,0,0,0.9);
    color: #0f0;
    font-family: monospace;
    font-size: 11px;
    padding: 8px;
    z-index: 9999;
    display: none;
}

.debug-panel.visible {
    display: block;
}

.debug-panel-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.debug-panel-close {
    background: #333;
    color: #fff;
    border: none;
    padding: 2px 8px;
    cursor: pointer;
}

/* ========== Markdown 渲染样式 ========== */
.md-heading {
    margin: 8px 0 4px 0;
}

.md-heading:first-child {
    margin-top: 0;
}

.md-list {
    margin: 4px 0;
    padding-left: 20px;
}

.md-list li {
    margin: 2px 0;
    line-height: 1.5;
}

.md-list code,
.md-heading code {
    background: rgba(0, 0, 0, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', monospace;
    font-size: 0.85em;
}

[data-theme="light"] .md-list code,
[data-theme="light"] .md-heading code {
    background: rgba(0, 0, 0, 0.08);
}

/* Markdown rendered content styles (for marked.js output) */
.chat-message-content > *:first-child {
    margin-top: 0;
}

.chat-message-content > *:last-child {
    margin-bottom: 0;
}

.chat-message-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

.chat-message-content blockquote {
    border-left: 3px solid var(--accent-purple);
    margin: 12px 0;
    padding: 8px 12px;
    background: rgba(139, 92, 246, 0.1);
    border-radius: 0 4px 4px 0;
}

.chat-message-content blockquote p {
    margin: 4px 0;
    line-height: 1.5;
    color: var(--text-secondary);
}

.chat-message-content blockquote p:first-child {
    margin-top: 0;
}

.chat-message-content blockquote p:last-child {
    margin-bottom: 0;
}

[data-theme="light"] .chat-message-content blockquote {
    background: rgba(139, 92, 246, 0.08);
}

.chat-message-content h1,
.chat-message-content h2,
.chat-message-content h3,
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message-content h1 { font-size: 1.3em; }
.chat-message-content h2 { font-size: 1.2em; }
.chat-message-content h3 { font-size: 1.1em; }
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 { font-size: 1em; }

.chat-message-content p {
    margin: 6px 0;
    line-height: 1.5;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-message-content li {
    margin: 4px 0;
    line-height: 1.5;
}

.chat-message-content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: max-content;
    min-width: 100%;
    max-width: none;
    font-size: 0.9em;
    display: table;
}

.chat-message-content th,
.chat-message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-message-content th {
    background: var(--bg-elevated);
    font-weight: 600;
}

.chat-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', monospace;
    font-size: 0.85em;
}

.chat-message-content pre {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-message-content pre code {
    background: none;
    padding: 0;
}

[data-theme="light"] .chat-message-content code {
    background: rgba(0, 0, 0, 0.08);
}

/* ========== Floating Chat Panel ========== */
.floating-chat-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: min(380px, calc(100vw - 40px));
    height: min(520px, calc(100vh - 40px));
    min-width: 320px;
    min-height: 280px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.floating-chat-panel.collapsed {
    width: var(--chat-collapsed-width, auto) !important;
    height: 44px !important;
    min-width: 100px !important;
    min-height: 44px;
    max-width: none !important;
    max-height: 44px;
}

.floating-chat-panel.collapsed .floating-chat-body {
    display: none;
}

.floating-chat-panel.collapsed .chat-resize-handle {
    display: none;
}

.floating-chat-panel.collapsed .floating-chat-header {
    padding: 0 8px;
    height: 44px;
}

.floating-chat-panel.collapsed .floating-chat-tab {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.floating-chat-panel.collapsed .floating-chat-tab:not(.active) {
    display: none;
}

.floating-chat-panel.dragging {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    cursor: grabbing;
}

.floating-chat-panel.resizing {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    transition: none;
}

.floating-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    min-height: 48px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.floating-chat-header:active {
    cursor: grabbing;
}

.floating-chat-tabs {
    display: flex;
    gap: 4px;
}

.floating-chat-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.floating-chat-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.floating-chat-tab.active {
    background: var(--accent-purple);
    color: #fff;
}

.floating-chat-tab.active svg {
    stroke: #fff;
}

.floating-chat-tab svg {
    stroke: currentColor;
}

.floating-chat-tab .badge {
    background: var(--accent-orange);
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
}

.floating-chat-tab .badge.hidden {
    display: none;
}

.floating-chat-controls {
    display: flex;
    gap: 4px;
}

.floating-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.floating-chat-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.floating-chat-btn.collapse-btn svg {
    transition: transform 0.3s;
}

.floating-chat-panel.collapsed .floating-chat-btn.collapse-btn svg {
    transform: rotate(180deg);
}

.floating-chat-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-resize-handle {
    position: absolute;
    z-index: 3;
    touch-action: none;
}

.chat-resize-corner {
    top: 0;
    left: 0;
    width: 24px;
    height: 24px;
    cursor: nwse-resize;
}

.chat-resize-corner::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    width: 10px;
    height: 10px;
    border-top: 2px solid rgba(168, 85, 247, 0.7);
    border-left: 2px solid rgba(168, 85, 247, 0.7);
    border-top-left-radius: 4px;
}

.chat-resize-top {
    display: none;
    top: 0;
    left: 50%;
    width: 96px;
    height: 18px;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.chat-resize-top::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 44px;
    height: 4px;
    transform: translateX(-50%);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.28);
}

.floating-chat-content {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.floating-chat-content.active {
    display: flex;
}

/* Chat Options Bar (Role, Learner, Session selectors) */
.chat-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 12px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.chat-option-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-option-group label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.chat-option-group select {
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

.chat-option-group select:focus {
    border-color: var(--accent-purple);
}

/* Session Multi-select */
.chat-session-selector {
    position: relative;
}

.chat-session-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 120px;
    justify-content: space-between;
}

.chat-session-btn:hover {
    border-color: var(--accent-purple);
}

.chat-session-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 100;
    display: none;
}

.chat-session-dropdown.open {
    display: block;
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-session-item.selected {
    background: rgba(168, 85, 247, 0.15);
}

.chat-session-item.selected:hover {
    background: rgba(168, 85, 247, 0.2);
}

.chat-session-item:hover:not(.selected) {
    background: var(--bg-secondary);
}

.chat-session-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--accent-purple);
}

.chat-session-item span {
    font-size: 0.8rem;
    color: var(--text-primary);
}

/* Session Quick Options */
.chat-session-quick-options {
    padding: 0;
}

.chat-session-quick-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chat-session-quick-option.selected {
    background: rgba(168, 85, 247, 0.15);
    color: var(--accent-purple);
}

.chat-session-quick-option.selected:hover {
    background: rgba(168, 85, 247, 0.2);
}

.chat-session-quick-option input[type="checkbox"],
.chat-session-quick-option input[type="radio"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--accent-purple);
}

.chat-session-quick-option:hover:not([disabled]):not(.selected) {
    background: var(--bg-secondary);
}

.chat-session-quick-option[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-session-divider {
    display: none;
    margin: 4px 0;
}

/* Active session indicator (green dot) */
.active-indicator,
.session-active-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent-green, #22c55e);
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Learner Multi-select */
.chat-learner-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 120px;
    justify-content: space-between;
}

.chat-learner-btn:hover {
    border-color: var(--accent-purple);
}

.chat-learner-selector,
.chat-session-selector {
    position: relative;
}

.chat-learner-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 100;
    display: none;
}

.chat-learner-dropdown.open {
    display: block;
}

.chat-learner-item,
.chat-learner-quick-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-learner-item:hover,
.chat-learner-quick-option:hover {
    background: var(--bg-secondary);
}

.chat-learner-item input[type="checkbox"],
.chat-learner-quick-option input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.chat-learner-item span,
.chat-learner-quick-option span {
    font-size: 0.8rem;
    color: var(--text-primary);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.chat-message {
    max-width: 85%;
    font-size: 0.9rem;
    line-height: 1.5;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    min-width: 0;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.agent {
    align-self: flex-start;
}

.chat-message.pending .chat-message-body {
    border: 1px solid rgba(168, 85, 247, 0.28);
}

.chat-message.error .chat-message-body {
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(127, 29, 29, 0.2);
}

.chat-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    max-width: 32px;
    max-height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.chat-message-body {
    padding: 10px 14px;
    border-radius: 12px;
    min-width: 0;
}

.chat-message.user .chat-message-body {
    background: var(--accent-purple);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.agent .chat-message-body {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-message-body .time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
}

.chat-message-body .content strong {
    font-weight: 600;
}

.chat-message-body .content em {
    font-style: italic;
}

.chat-message-body .content {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-message-content {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chat-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 18px;
}

.chat-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
    animation: chat-typing-pulse 1.1s infinite ease-in-out;
}

.chat-typing-indicator span:nth-child(2) {
    animation-delay: 0.16s;
}

.chat-typing-indicator span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes chat-typing-pulse {
    0%, 80%, 100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    40% {
        opacity: 0.85;
        transform: translateY(-2px);
    }
}

.chat-message-body .content code {
    background: rgba(0, 0, 0, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', monospace;
    font-size: 0.85em;
}

.chat-message.agent .chat-message-body .content code {
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Input */
.chat-input-area {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    background: var(--bg-secondary);
}

.chat-input-area input,
.chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-area textarea {
    resize: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.4;
    overflow-y: auto;
}

.chat-input-area input:focus,
.chat-input-area textarea:focus {
    border-color: var(--accent-purple);
}

.chat-input-area input::placeholder,
.chat-input-area textarea::placeholder {
    color: var(--text-secondary);
}

.chat-input-area button {
    padding: 10px 18px;
    border-radius: 20px;
    border: none;
    background: var(--accent-green);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-input-area button:hover {
    opacity: 0.9;
}

/* Notification Styles (for Live page) */
.notification-settings {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.notification-settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-settings label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.threshold-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.threshold-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
}

.threshold-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-purple);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
}

.threshold-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.threshold-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent-purple);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.threshold-value {
    min-width: 42px;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-primary);
    text-align: center;
    font-weight: 500;
}

.notification-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.notification-item {
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--accent-orange);
}

.notification-item .notification-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.notification-item .notification-message {
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 480px) {
    .floating-chat-panel:not(.collapsed) {
        right: auto !important;
        bottom: var(--chat-mobile-bottom, 12px) !important;
        width: var(--chat-mobile-width, min(420px, calc(100vw - 24px))) !important;
        min-width: min(320px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
        border-radius: 16px;
        height: var(--chat-mobile-height, min(60vh, calc(100vh - env(safe-area-inset-top, 0px)))) !important;
        min-height: 240px;
        max-height: calc(100vh - env(safe-area-inset-top, 0px));
    }

    .chat-resize-corner {
        display: none;
    }

    .chat-resize-top {
        display: block;
    }
}

/* ========== User Info (Auth) ========== */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-right: 12px;
}

.user-info .user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.user-info .user-role {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: capitalize;
}

.user-info .user-role[data-role="admin"] {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

.user-info .user-role[data-role="teacher"] {
    background: rgba(96, 165, 250, 0.15);
    color: var(--accent-blue);
}

.user-info .user-role[data-role="student"] {
    background: rgba(74, 222, 128, 0.15);
    color: var(--accent-green);
}

.user-info .logout-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.user-info .logout-btn:hover {
    background: var(--bg-panel);
}

.user-info .logout-btn svg {
    stroke: var(--text-secondary);
}

.user-info .logout-btn:hover svg {
    stroke: var(--accent-red);
}

/* User info in fixed position (for pages without header) */
.user-info-float {
    position: fixed;
    top: 20px;
    right: 80px;
    z-index: 100;
}

@media (max-width: 640px) {
    .user-info-float {
        position: static;
        margin: 12px 16px 0;
    }

    .chat-options {
        gap: 10px;
    }

    .chat-option-group {
        width: 100%;
        min-width: 0;
        flex-wrap: wrap;
    }

    .chat-option-group label {
        width: 100%;
    }

    .chat-session-btn,
    .chat-option-group select,
    .chat-learner-btn {
        width: 100%;
        min-width: 0;
    }

    .chat-input-area {
        align-items: flex-end;
    }

    .chat-input-area button {
        min-width: 72px;
        min-height: 44px;
    }
}

/* =========================================
   Unified Page Headers (Logo and Return Link)
   ========================================= */
header a[href="/"] {
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

header a[href="/"]:hover {
    transform: translateY(-2px) scale(1.02);
    filter: drop-shadow(0 0 12px rgba(96, 165, 250, 0.4));
    opacity: 0.95;
}

[data-theme="light"] header a[href="/"]:hover {
    filter: drop-shadow(0 0 12px rgba(37, 99, 235, 0.2));
}

header a[href="/"] h1 {
    font-size: 1.4rem !important;
    font-weight: 800 !important;
    background: linear-gradient(90deg, var(--logo-blue), var(--logo-green)) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    letter-spacing: -0.01em !important;
    margin: 0 !important;
    transition: all 0.3s ease;
}

/* =========================================
   User Info Action Buttons
   ========================================= */
.user-info .top-action-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: inline-flex;
    align-items: center;
}

[data-theme="light"] .user-info .top-action-btn {
    color: var(--text-secondary);
}

.user-info .top-action-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .user-info .top-action-btn:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.04);
}
