* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f7f8fa;
    overflow: hidden;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
}

button,textarea {
    outline: none;
}

.app-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-container {
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

@media (min-width: 768px) {
    body {
        background: #f0f2f5;
        padding: 24px;
    }
    .chat-container {
        max-width: 860px;
        height: 92vh;
        max-height: 920px;
        border-radius: 5px;
        box-shadow: 0 4px 32px -8px rgba(0, 0, 0, 0.12);
        border: 1px solid #e8ecf2;
    }
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: #fff;
    border-bottom: 1px solid #eef1f6;
    flex-shrink: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: #2563eb;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    margin-right: 10px;
    flex-shrink: 0;
}

.brand-info h1 {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.header-btn {
    width: 32px;
    height: 32px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    color: #6b7280;
    margin-left: 6px;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.header-btn:hover {
    background: #e5e7eb;
    color: #111827;
    border-color: #d1d5db;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 12px 14px 6px;
    background: #fff;
    display: flex;
    flex-direction: column;
    background-image: url("../assets/cai.jpg");
    background-size: 100% 100%;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.message-row {
    display: flex;
    margin-bottom: 10px;
    width: 100%;
}

.message-row:last-child {
    margin-bottom: 0;
}

.message-row.ai {
    justify-content: flex-start;
}

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

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

.ai .message-content {
    align-items: flex-start;
}

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

.bubble {
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    max-width: 100%;
}

.ai .bubble {
    background: #f7f8fa;
    color: #111827;
    border: 1px solid #eef1f6;
}

.user .bubble {
    background: #2563eb;
    color: #fff;
    border: 1px solid #2563eb;
}

.bubble p {
    margin-bottom: 4px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble ul,
.bubble ol {
    margin: 4px 0;
    padding-left: 16px;
}

.bubble li {
    margin-bottom: 2px;
}

.bubble code {
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 4px;
    border-radius: 2px;
    font-family: "SF Mono", Monaco, monospace;
    font-size: 12px;
}

.user .bubble code {
    background: rgba(255, 255, 255, 0.15);
}

.bubble pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.45;
}

.bubble pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.message-actions {
    display: flex;
    margin-top: 4px;
    background: #f7f8fa;
    border: 1px solid #eef1f6;
    border-radius: 5px;
    padding: 2px 4px;
    align-self: flex-start;
}

.user .message-actions {
    background: #2563eb;
    border-color: #2563eb;
    align-self: flex-end;
}

.action-btn {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 12px;
    margin-right: 1px;
    transition: background 0.15s, color 0.15s;
}

.action-btn:last-child {
    margin-right: 0;
}

.action-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #374151;
}

.user .action-btn {
    color: rgba(255, 255, 255, 0.7);
}

.user .action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.chat-input-area {
    background: #fff;
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid #eef1f6;
    flex-shrink: 0;
    z-index: 10;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.suggestion-chip {
    padding: 5px 10px;
    background: #f7f8fa;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 11px;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
    margin: 3px;
}

.suggestion-chip:hover {
    background: #eef1f6;
    border-color: #d1d5db;
}

.pending-attachment {
    display: flex;
    align-items: center;
    background: #f7f8fa;
    border: 1px solid #e5e7eb;
    border-radius: 5px;
    padding: 4px 6px;
    margin-bottom: 6px;
    position: relative;
}

.pending-attachment img {
    max-width: 60px;
    max-height: 60px;
    border-radius: 4px;
    margin-right: 8px;
    display: block;
}

.pending-attachment .pending-info {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pending-attachment .pending-remove {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    margin-left: 6px;
    flex-shrink: 0;
}

body.dark .pending-attachment {
    background: #21262d;
    border-color: #30363d;
}

body.dark .pending-attachment .pending-info {
    color: #c9d1d9;
}

.input-container {
    display: flex;
    align-items: flex-end;
    background: #f7f8fa;
    border: 1px solid #e5e7eb;
    border-radius: 5px;
    padding: 3px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-container:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: #fff;
}

.input-container textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    padding: 7px 9px;
    outline: none;
    color: #111827;
    resize: none;
    font-family: inherit;
    min-height: 38px;
    max-height: 140px;
    overflow-y: auto;
}

.input-container textarea::placeholder {
    color: #9ca3af;
}

.input-actions {
    display: flex;
    align-items: center;
    padding: 3px;
    flex-shrink: 0;
}

.input-action-btn {
    width: 30px;
    height: 30px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #6b7280;
    margin-right: 1px;
    transition: background 0.15s;
}

.input-action-btn:hover {
    background: #eef1f6;
    color: #111827;
}

.send-btn {
    background: #2563eb;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.send-btn:hover {
    background: #1d4ed8;
}

.send-btn:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
}

.send-btn svg {
    width: 15px;
    height: 15px;
    display: block;
}

.input-footer {
    display: flex;
    justify-content: center;
    margin-top: 6px;
}

.input-footer span {
    font-size: 10px;
    color: #9ca3af;
}

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.2s infinite;
}

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

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

@keyframes typing {
    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

body.dark {
    background: #0d1117;
}

body.dark .chat-container {
    background: #161b22;
    border-color: #21262d;
}

body.dark .chat-header {
    background: #161b22;
    border-bottom-color: #21262d;
}

body.dark .brand-info h1 {
    color: #e6edf3;
}

body.dark .header-btn {
    background: #21262d;
    border-color: #30363d;
    color: #8b949e;
}

body.dark .header-btn:hover {
    background: #30363d;
    color: #e6edf3;
    border-color: #484f58;
}

body.dark .chat-messages {
    background: #161b22;
    background-image: url("../assets/cai.jpg");
    background-size: 100% 100%;
}

body.dark .ai .bubble {
    background: #21262d;
    color: #e6edf3;
    border-color: #30363d;
}

body.dark .user .bubble {
    background: #1f6feb;
    border-color: #1f6feb;
}

body.dark .message-actions {
    background: #21262d;
    border-color: #30363d;
}

body.dark .user .message-actions {
    background: #1f6feb;
    border-color: #1f6feb;
}

body.dark .action-btn {
    color: #6e7681;
}

body.dark .action-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #c9d1d9;
}

body.dark .user .action-btn {
    color: rgba(255, 255, 255, 0.7);
}

body.dark .user .action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

body.dark .chat-input-area {
    background: #161b22;
    border-top-color: #21262d;
}

body.dark .input-container {
    background: #0d1117;
    border-color: #30363d;
}

body.dark .input-container:focus-within {
    background: #0d1117;
    border-color: #1f6feb;
}

body.dark .input-container textarea {
    color: #e6edf3;
}

body.dark .input-container textarea::placeholder {
    color: #6e7681;
}

body.dark .input-action-btn {
    color: #8b949e;
}

body.dark .input-action-btn:hover {
    background: #21262d;
    color: #e6edf3;
}

body.dark .send-btn {
    background: #1f6feb;
}

body.dark .send-btn:hover {
    background: #388bfd;
}

body.dark .suggestion-chip {
    background: #21262d;
    border-color: #30363d;
    color: #c9d1d9;
}

body.dark .suggestion-chip:hover {
    background: #30363d;
}

body.dark .input-footer span {
    color: #6e7681;
}

body.dark .bubble code {
    background: rgba(255, 255, 255, 0.08);
}

body.dark .bubble pre {
    background: #0d1117;
}

@media (max-width: 480px) {
    .chat-header {
        padding: 10px 14px;
        padding-top: max(10px, env(safe-area-inset-top));
    }
    .chat-messages {
        padding: 10px 12px 4px;
        background-image: url("../assets/cai.jpg");
        background-size: 100% 100%;
    }
    .chat-input-area {
        padding: 8px 12px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .bubble {
        font-size: 13px;
        padding: 7px 11px;
    }
    .message-content {
        max-width: 85%;
    }
}