*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #F0F2F5;
    color: #2D3748;
}

.chat-app {
    max-width: 700px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

.chat-header {
    padding: 16px 24px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-info h1 {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.3;
}

.chat-status {
    font-size: 0.75rem;
    opacity: 0.85;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #F7FAFC;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 4px;
}

.msg {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.925rem;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: msgIn 0.25s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-bot {
    align-self: flex-start;
    background: #fff;
    color: #2D3748;
    border: 1px solid #E2E8F0;
    border-bottom-left-radius: 4px;
}

.msg-bot strong {
    font-weight: 600;
}

.msg-bot ul {
    margin: 6px 0;
    padding-left: 20px;
}

.msg-bot li {
    margin: 2px 0;
}

.msg-bot a {
    color: #2563EB;
    text-decoration: underline;
    word-break: break-word;
}

.msg-bot code {
    background: #EDF2F7;
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

.msg-bot pre {
    background: #1A202C;
    color: #E2E8F0;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}

.msg-bot pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.msg-user {
    align-self: flex-end;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-typing {
    padding: 14px 18px;
}

.typing-dots {
    display: flex;
    gap: 5px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #A0AEC0;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid #E2E8F0;
    background: #fff;
    flex-shrink: 0;
}

.chat-input-area form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    position: relative;
}

.image-upload-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid #E2E8F0;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    color: #718096;
}

.image-upload-btn:hover {
    border-color: #3B82F6;
    color: #3B82F6;
    background: #EBF5FF;
}

.image-upload-btn svg {
    width: 22px;
    height: 22px;
}

.image-upload-btn input[type="file"] {
    display: none;
}

.voice-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid #E2E8F0;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    color: #718096;
    position: relative;
    padding: 0;
}

.voice-btn:hover {
    border-color: #2563EB;
    color: #2563EB;
    background: #EBF5FF;
}

.voice-btn .icon-mic {
    width: 22px;
    height: 22px;
}

.voice-btn .voice-pulse {
    display: none;
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #DC2626;
    animation: voicePulse 1.2s ease-out infinite;
}

.voice-btn.listening {
    border-color: #DC2626;
    color: #DC2626;
    background: #FEF2F2;
}

.voice-btn.listening .voice-pulse {
    display: block;
}

.voice-btn:disabled,
.voice-btn.voice-unsupported {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-input-area.is-listening input {
    border-color: #DC2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.chat-input-area input.voice-listening {
    border-color: #DC2626;
}

@keyframes voicePulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.2); opacity: 0; }
}

.image-preview-bar {
    display: none;
    padding: 8px 24px;
    background: #fff;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
}

.image-preview-bar.active {
    display: flex;
    align-items: center;
    gap: 10px;
}

.image-preview-bar img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #E2E8F0;
}

.image-preview-bar .preview-info {
    flex: 1;
    font-size: 0.8rem;
    color: #718096;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-bar .preview-remove {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: #FED7D7;
    color: #E53E3E;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.image-preview-bar .preview-remove:hover {
    background: #FEB2B2;
}

.msg-user-image {
    max-width: 220px;
    border-radius: 12px;
    margin-bottom: 4px;
    display: block;
}

.msg-image-wrapper {
    align-self: flex-end;
    max-width: 75%;
    animation: msgIn 0.25s ease;
}

.chat-input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #E2E8F0;
    border-radius: 28px;
    font-size: 0.95rem;
    outline: none;
    font-family: inherit;
    color: #2D3748;
    transition: border-color 0.2s;
}

.chat-input-area input:focus {
    border-color: #3B82F6;
}

.chat-input-area input::placeholder {
    color: #A0AEC0;
}

.chat-input-area button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-input-area button:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-security-note {
    text-align: center;
    padding: 8px 16px;
    font-size: 0.72rem;
    line-height: 1.4;
    color: #92400E;
    background: #FFFBEB;
    border-top: 1px solid #FDE68A;
    flex-shrink: 0;
}

.chat-footer {
    text-align: center;
    padding: 8px;
    font-size: 0.7rem;
    color: #A0AEC0;
    border-top: 1px solid #F0F0F0;
    background: #fff;
    flex-shrink: 0;
}

@media (max-width: 700px) {
    .chat-app {
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 14px 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 16px;
    }

    .chat-input-area input {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .voice-btn,
    .image-upload-btn,
    .chat-input-area button.send-btn {
        width: 44px;
        height: 44px;
    }

    .msg {
        max-width: 88%;
        font-size: 0.875rem;
    }
}
