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

:root {
    --primary-color: #007AFF;
    --secondary-color: #5856D6;
    --background: #000000;
    --surface: #1C1C1E;
    --surface-light: #2C2C2E;
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --border-color: #38383A;
    --user-bubble: #007AFF;
    --assistant-bubble: #2C2C2E;
    --success: #34C759;
    --error: #FF3B30;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
}

/* 顶部栏 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
    animation: pulse 2s infinite;
}

.status-indicator.connected .status-dot {
    background: var(--success);
}

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

.status-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.refresh-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.refresh-btn:active {
    transform: rotate(180deg);
}

.settings-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

/* 对话区域 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 24px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.message {
    display: flex;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

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

.message.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 75%;
    max-width: min(75%, calc(100vw - 96px));
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 8px 0 4px 0;
    font-weight: 600;
}

.message-bubble h1 {
    font-size: 18px;
}

.message-bubble h2 {
    font-size: 16px;
}

.message-bubble h3 {
    font-size: 14px;
}

.message-bubble ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style: none;
}

.message-bubble li {
    margin: 4px 0;
    position: relative;
}

.message-bubble li::before {
    content: '•';
    position: absolute;
    left: -15px;
}

.message-bubble li.check::before,
.message-bubble li.cross::before {
    content: '';
}

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

.message-bubble code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
}

.message-bubble a {
    color: #8ec5ff;
    text-decoration: underline;
    overflow-wrap: anywhere;
    word-break: break-all;
}

.message.user .message-bubble a {
    color: #dcecff;
}

.message-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.message.user .message-content {
    align-items: flex-end;
}

.message-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
    gap: 6px;
    padding: 0 4px;
}

.copy-btn {
    border: 1px solid var(--border-color);
    background: var(--surface-light);
    color: var(--text-secondary);
    border-radius: 8px;
    font-size: 11px;
    padding: 2px 8px;
    cursor: pointer;
}

.copy-btn:active {
    opacity: 0.7;
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
}

.message-bubble strong {
    font-weight: 600;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--assistant-bubble);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* 输入区域 */
.input-container {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 100;
}

.attach-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.attach-btn:active {
    transform: scale(0.9);
}

.attachments-preview {
    padding: 8px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    max-height: 120px;
    overflow-y: auto;
}

.attachment-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface-light);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.attachment-item img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-info {
    flex: 1;
    min-width: 0;
}

.attachment-name {
    font-size: 12px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.attachment-size {
    font-size: 10px;
    color: var(--text-secondary);
}

.attachment-remove {
    background: var(--error);
    border: none;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-input {
    flex: 1;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 16px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.send-btn {
    background: #0051a8;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    position: relative;
}

.send-btn.has-input {
    background: #003d7a;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn.has-input:not(:disabled):hover {
    background: #002952;
    transform: scale(1.05);
}

.send-btn.has-input:active:not(:disabled) {
    transform: scale(0.9);
    background: #001a33;
}

.send-btn.sending {
    background: #28a745;
    pointer-events: none;
}

.send-btn.sending::after {
    content: '✓';
    position: absolute;
    font-size: 20px;
    color: white;
    animation: checkmark 0.3s ease;
}

@keyframes checkmark {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* 设置面板 */
.settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: flex-end;
    z-index: 1000;
}

.settings-panel.active {
    display: flex;
}

.settings-content {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

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

.settings-header h3 {
    font-size: 20px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
}

.settings-body {
    padding: 20px;
}

.setting-item {
    margin-bottom: 24px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.setting-item input[type="text"],
.setting-item input[type="password"] {
    width: 100%;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 16px;
}

.setting-item input[type="text"]:focus,
.setting-item input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-item small {
    display: block;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 12px;
}

.setting-item input[type="checkbox"] {
    margin-right: 8px;
}

.save-btn {
    width: 100%;
    background: var(--primary-color);
    border: none;
    border-radius: 12px;
    padding: 14px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}

.save-btn:active {
    opacity: 0.8;
}
