/**
 * 深思1号 - Webchat UI v1.0 样式表
 * 
 * 设计风格：微信风格
 * - 绿色用户消息气泡 (#95EC69)
 * - 微信绿发送按钮 (#07C160)
 * - 深色/浅色主题切换
 * 
 * @author 奥深思（深圳）科技有限公司
 * @license MIT
 */

/* 基础样式 - 参考 OpenClaw Control UI */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* 背景 - 深色有层次 */
    --bg: #12141a;
    --bg-accent: #14161d;
    --bg-elevated: #1a1d25;
    --bg-hover: #262a35;
    --bg-muted: #262a35;

    /* 卡片 */
    --card: #181b22;
    --card-foreground: #f4f4f5;

    /* 文字 */
    --text: #e4e4e7;
    --text-strong: #fafafa;
    --text-muted: #71717a;

    /* 边框 */
    --border: #27272a;
    --border-strong: #3f3f46;

    /* 强调色 - 红色 */
    --accent: #ff5c5c;
    --accent-hover: #ff7070;
    --accent-muted: rgba(255, 92, 92, 0.15);
    --accent-glow: rgba(255, 92, 92, 0.25);

    /* 语义色 */
    --success: #22c55e;
    --success-muted: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-muted: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-muted: rgba(239, 68, 68, 0.12);

    /* 字体 */
    --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* 圆角 */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.03);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03);

    /* 过渡 */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

/* 浅色主题 */
[data-theme="light"] {
    --bg: #f8f9fa;
    --bg-accent: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #f1f3f5;
    --bg-muted: #e9ecef;

    --card: #ffffff;
    --card-foreground: #1a1a2e;

    --text: #1a1a2e;
    --text-strong: #000000;
    --text-muted: #6c757d;

    --border: #dee2e6;
    --border-strong: #ced4da;

    --accent: #e53e3e;
    --accent-hover: #c53030;
    --accent-muted: rgba(229, 62, 62, 0.1);
    --accent-glow: rgba(229, 62, 62, 0.2);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* ===== 连接面板 ===== */
#connect-panel {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg);
}

#connect-panel .panel-header {
    text-align: center;
    margin-bottom: 2rem;
}

#connect-panel .panel-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-strong);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#connect-panel .panel-header p {
    color: var(--text-muted);
    font-size: 1rem;
}

#connect-panel .panel-body {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

/* ===== 聊天面板 ===== */
#chat-panel {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* ===== 头部 ===== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-strong);
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status.connected {
    background: var(--success-muted);
    color: var(--success);
}

.status.connected::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status.disconnected {
    background: var(--danger-muted);
    color: var(--danger);
}

.status.connecting {
    background: var(--warning-muted);
    color: var(--warning);
}

/* 会话信息 */
.session-info {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    background: var(--bg-muted);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.session-info:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.session-info.hidden {
    display: none;
}

.session-label {
    color: var(--text-muted);
}

.session-id {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--accent);
}

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

.header-right {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-body);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 30px var(--accent-glow);
}

/* 微信风格：小按钮 - 圆形、精致 */
.btn-sm {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 1rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-muted);
    border: none;
    transition: all 0.2s ease;
}

.btn-sm:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-sm:active {
    transform: translateY(0);
    box-shadow: none;
}

/* 按钮 SVG 图标 */
.btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

/* 主题按钮图标切换 */
#theme-btn .icon-sun {
    display: none;
}

[data-theme="dark"] #theme-btn .icon-moon {
    display: none;
}

[data-theme="dark"] #theme-btn .icon-sun {
    display: block;
}

[data-theme="dark"] .btn-sm {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

[data-theme="dark"] .btn-sm:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

/* 危险按钮 - 断开连接 */
.btn-danger {
    background: transparent;
    color: var(--text-muted);
    border: none;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
}

/* ===== 消息区域 ===== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

/* 滚动条样式 */
.messages::-webkit-scrollbar {
    width: 8px;
}

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

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

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ===== 欢迎界面 ===== */
.welcome {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

.welcome h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-strong);
}

.welcome p {
    font-size: 1rem;
}

/* ===== 消息气泡 ===== */
.message {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: messageIn 0.2s ease-out;
    position: relative;
}

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

/* 微信风格：用户消息 - 绿色气泡右对齐 */
.message.user {
    align-self: flex-end;
    background: #95EC69;
    color: #000;
    border-radius: 8px 0 8px 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 微信风格：AI消息 - 白色气泡左对齐 */
.message.assistant {
    align-self: flex-start;
    background: #FFFFFF;
    color: #000;
    border-radius: 0 8px 8px 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 微信风格：隐藏头像图标 */
.message .avatar {
    display: none;
}

/* 深色模式下的消息气泡 */
[data-theme="dark"] .message.assistant {
    background: #2E2E2E;
    color: #E5E5E5;
}

.message.system {
    align-self: center;
    background: var(--bg-muted);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    max-width: 90%;
}

.message.error {
    background: var(--danger-muted);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.message-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    opacity: 0.7;
}

.message.user .message-meta {
    color: rgba(255, 255, 255, 0.7);
}

.message .body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* 微信风格：时间戳居中显示 */
.message .time {
    font-size: 0.7rem;
    color: #B2B2B2;
    margin-top: 0.25rem;
    text-align: right;
}

.message.user .time {
    color: rgba(0, 0, 0, 0.45);
}

.message.assistant .time {
    color: #B2B2B2;
    text-align: left;
}

/* 深色模式 */
[data-theme="dark"] .message.assistant .time {
    color: #888;
}

[data-theme="dark"] .message pre {
    background: #1a1a1a;
    border-color: #333;
}

[data-theme="dark"] .message pre .code-lang {
    background: #252525;
    border-color: #333;
}

[data-theme="dark"] .message .inline-code {
    background: #2a2a2a;
}

/* 时间戳容器 - 居中显示 */
.message-time-center {
    align-self: center;
    font-size: 0.7rem;
    color: #B2B2B2;
    margin: 0.5rem 0;
    padding: 0.25rem 0.75rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

[data-theme="dark"] .message-time-center {
    background: rgba(255, 255, 255, 0.1);
    color: #888;
}

/* ===== 输入区域 ===== */
.chat-input {
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-top: none;
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    background: #F5F5F5;
    border: none;
    border-radius: 20px;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: background var(--transition-fast);
}

[data-theme="dark"] .input-wrapper {
    background: #2C2C2C;
}

.input-wrapper:focus-within {
    background: #ECECEC;
}

[data-theme="dark"] .input-wrapper:focus-within {
    background: #333333;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    padding: 0.5rem;
}

.input-wrapper textarea:focus {
    outline: none;
}

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

.input-wrapper .btn {
    height: 40px;
    width: 40px;
    padding: 0;
    flex-shrink: 0;
    border-radius: 50%;
    font-size: 1.1rem;
}

/* 发送按钮 - 微信风格绿色 */
#send-btn {
    background: #07C160;
    color: white;
    box-shadow: 0 2px 8px rgba(7, 193, 96, 0.3);
    transition: all 0.2s ease;
}

#send-btn:hover {
    background: #06AD56;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(7, 193, 96, 0.4);
}

#send-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(7, 193, 96, 0.3);
}

#send-btn svg {
    width: 18px;
    height: 18px;
    transform: rotate(20deg);
}

/* 停止按钮 */
#stop-btn {
    background: #F5F5F5;
    color: #666;
}

#stop-btn:hover {
    background: #E5E5E5;
}

[data-theme="dark"] #stop-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #999;
}

[data-theme="dark"] #stop-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.input-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding: 0 0.25rem;
}

/* ===== 表单元素 ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

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

/* ===== 模态框 ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border);
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
}

/* ===== 错误提示 ===== */
.error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
    padding: 0.5rem;
    background: var(--danger-muted);
    border-radius: var(--radius-sm);
}

/* ===== 加载动画 ===== */
.typing {
    display: inline-flex;
    gap: 4px;
    padding: 0.25rem 0;
}

.typing span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

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

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== Markdown 样式 ===== */
.message h1, .message h2, .message h3 {
    margin: 0.75rem 0 0.5rem;
    color: var(--text-strong);
}

.message h1 { font-size: 1.25rem; }
.message h2 { font-size: 1.1rem; }
.message h3 { font-size: 1rem; }

.message p {
    margin: 0.5rem 0;
}

.message p:first-child { margin-top: 0; }
.message p:last-child { margin-bottom: 0; }

.message code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-muted);
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
}

.message .inline-code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-muted);
    padding: 0.15rem 0.35rem;
    border-radius: var(--radius-sm);
    color: var(--accent);
}

.message pre {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 0.75rem 0;
}

.message pre.code-block {
    position: relative;
}

.message pre .code-lang {
    background: var(--bg-muted);
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
}

.message pre code {
    background: none;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    display: block;
    overflow-x: auto;
    white-space: pre;
}

.message pre .code-content {
    padding: 0.75rem 1rem;
}

.message ul, .message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message li {
    margin: 0.25rem 0;
}

.message a {
    color: var(--accent);
    text-decoration: none;
}

.message a:hover {
    text-decoration: underline;
}

.message blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.5rem 0;
    padding: 0.25rem 0 0.25rem 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.message hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75rem 0;
}

.message strong {
    font-weight: 600;
    color: var(--text-strong);
}

.message em {
    font-style: italic;
}

/* ===== 响应式 ===== */
@media (max-width: 600px) {
    .chat-header {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-left h1 {
        font-size: 1rem;
    }

    .messages {
        padding: 1rem;
    }

    .chat-input {
        padding: 0.75rem 1rem;
    }

    .message {
        max-width: 92%;
    }

    .input-wrapper .btn {
        height: 36px;
        width: 36px;
    }
}

/* ===== 配对提示 ===== */
.pairing-required {
    text-align: center;
    padding: 1rem;
}

.pairing-required p {
    margin: 0.5rem 0;
    color: var(--text);
}

.pairing-required code {
    display: block;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
    margin: 0.75rem 0;
    word-break: break-all;
}

.status.pairing {
    background: var(--warning-muted);
    color: var(--warning);
}

.status.pairing::before {
    content: '⏳';
    margin-right: 0.25rem;
}

/* ===== 隐藏类 ===== */
.hidden {
    display: none !important;
}

/* ===== 打字指示器 ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin: 0 1rem;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    animation: fadeIn 0.2s ease;
}

.typing-indicator.hidden {
    display: none;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-text {
    color: var(--text-muted);
    font-size: 0.875rem;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

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

/* ===== Logo ===== */
.logo-gif {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 0.5rem;
    object-fit: cover;
}

.logo-gif-small {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 0.5rem;
    object-fit: cover;
}

.welcome-icon img {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}
