/* =========================================================
   AI 助手 chat.css - iOS 现代化风格 (叠加 common 设计系统)
   ========================================================= */

/* AI对话页：app 铺满 + 内部分区，与 common .app 兼容（不覆盖max-width等） */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    padding-bottom: 0; /* chat自有输入条 + 底部tab */
}

.header {
    position: sticky;
    top: 0;
    z-index: 300;
    flex-shrink: 0;
}
.clear-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.clear-btn:active {
    background: transparent;
}
.clear-btn .clear-icon {
    width: 22px;
    height: 22px;
    display: block;
    object-fit: contain;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

/* 功能模式切换 */
.ai-mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255,255,255,0.9);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.mode-tab {
    height: 36px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-pill);
    background: #fff;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.mode-tab.active {
    border-color: transparent;
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 8px 18px rgba(102,126,234,0.28);
}
.mode-tab.disabled {
    opacity: 0.45;
    background: #f8fafc;
    box-shadow: none;
}
.mode-tab.hidden {
    display: none;
}

/* 对话区域 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px 16px calc(84px + var(--h-nav) + env(safe-area-inset-bottom, 0px));
    background:
        radial-gradient(1200px 300px at 50% -120px, rgba(102,126,234,0.07), transparent 60%),
        var(--bg-app);
}
.chat-messages {
    display: flex; flex-direction: column; gap: 14px;
    padding-bottom: 8px;
}

/* 空状态 (AI对话欢迎) */
.empty-state {
    margin: 40px auto 20px;
    padding: 40px 24px;
    text-align: center;
    max-width: 320px;
}
.empty-state svg {
    width: 68px; height: 68px;
    padding: 14px; margin: 0 auto 16px;
    background: var(--primary-gradient-soft);
    color: var(--primary);
    border-radius: 22px;
    box-shadow: 0 10px 26px rgba(102,126,234,0.16);
    box-sizing: content-box;
    opacity: 1;
}
.empty-state p { color: var(--text-2); font-size: 15px; margin-bottom: 6px; }
.empty-state p:first-of-type { color: var(--text-1); font-weight: 600; font-size: 17px; }
.empty-hint { font-size: 12.5px !important; color: var(--text-3) !important; }

/* 消息气泡 */
.msg-wrapper {
    display: flex; gap: 10px; max-width: 88%;
    animation: fadeInUp .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }
.msg-ai   { align-self: flex-start; }

.msg-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.msg-ai .msg-avatar {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 6px 16px rgba(102,126,234,0.35);
}
.msg-user .msg-avatar {
    background: linear-gradient(135deg,#334155,#0f172a);
    color: #fff;
    box-shadow: 0 6px 14px rgba(15,23,42,0.28);
}

.msg-bubble {
    padding: 11px 14px;
    font-size: 14.5px; line-height: 1.65;
    word-break: break-word;
    max-width: 100%;
}
.msg-ai .msg-bubble {
    background: #fff;
    color: var(--text-1);
    border-radius: 6px 18px 18px 18px;
    box-shadow: 0 4px 14px rgba(15,23,42,0.06), 0 1px 3px rgba(15,23,42,0.04);
    border: 1px solid var(--border-light);
}
.msg-user .msg-bubble {
    background: var(--primary-gradient);
    color: #fff;
    border-radius: 18px 6px 18px 18px;
    box-shadow: 0 8px 20px rgba(102,126,234,0.32);
}
.msg-image {
    display: block;
    width: 100%;
    max-width: 260px;
    margin-top: 8px;
    border-radius: 12px;
    border: 1px solid rgba(226, 232, 240, 0.8);
}
.generated-image {
    max-width: 280px;
    background: #f8fafc;
}
.msg-attachment-name {
    margin-top: 8px;
    font-size: 12px;
    opacity: 0.78;
}

/* 打字机 */
.typing-dots {
    display: inline-flex; gap: 5px; padding: 4px 2px;
}
.typing-dots span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-3);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(1){ animation-delay: 0s;   background: var(--primary); }
.typing-dots span:nth-child(2){ animation-delay: .18s; background: var(--primary-deep); }
.typing-dots span:nth-child(3){ animation-delay: .36s; background: var(--info); }
@keyframes typingBounce {
    0%,80%,100% { transform: scale(1); opacity: .6; }
    40%         { transform: scale(1.35); opacity: 1; }
}

/* 富文本 */
.msg-bubble p  { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble ul, .msg-bubble ol { margin: 8px 0; padding-left: 20px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble code {
    font-family: 'SF Mono','JetBrains Mono',Menlo,Consolas,monospace;
    font-size: 12.5px;
    padding: 1px 6px; border-radius: 6px;
    background: rgba(15,23,42,0.06); color: var(--primary-deep);
}
.msg-user .msg-bubble code { background: rgba(255,255,255,0.2); color: #fff; }

/* 输入条 */
.chat-input-stack {
    position: fixed;
    left: 50%;
    bottom: calc(var(--h-nav) + env(safe-area-inset-bottom, 0px));
    z-index: 120;
    width: 100%;
    max-width: 480px;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.9);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    box-shadow: 0 -10px 28px rgba(15,23,42,0.08);
}
.chat-mode-hint {
    display: none;
    padding: 8px 16px 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-3);
    background: rgba(255,255,255,0.85);
    border-top: 1px solid var(--border-light);
}
.chat-mode-hint.active {
    display: block;
}
.attachment-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px 0;
    font-size: 12px;
    color: var(--text-2);
    background: rgba(255,255,255,0.85);
}
.attachment-preview.hidden {
    display: none;
}
.remove-attachment {
    border: 0;
    border-radius: var(--radius-pill);
    padding: 4px 10px;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-size: 12px;
}
.chat-input-bar {
    display: flex; align-items: flex-end; gap: 10px;
    padding: 12px 16px;
    padding-bottom: 12px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    position: relative;
}
.image-input {
    display: none;
}
.attach-btn {
    display: none;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-light);
    background: #fff;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
.attach-btn.visible {
    display: flex;
}
.attach-btn svg {
    width: 19px;
    height: 19px;
    color: var(--primary);
}
.thinking-inline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 42px;
    padding: 0 9px;
    border: 1px solid rgba(102,126,234,0.18);
    border-radius: var(--radius-pill);
    background: rgba(102,126,234,0.08);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}
.thinking-inline.hidden {
    display: none;
}
.thinking-inline input {
    display: none;
}
.thinking-inline-switch {
    position: relative;
    width: 24px;
    height: 14px;
    border-radius: 999px;
    background: #cbd5e1;
    transition: background .2s ease;
}
.thinking-inline-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15,23,42,0.22);
    transition: transform .2s ease;
}
.thinking-inline input:checked + .thinking-inline-switch {
    background: var(--primary-gradient);
}
.thinking-inline input:checked + .thinking-inline-switch::after {
    transform: translateX(10px);
}
.thinking-inline:has(input:disabled) {
    opacity: 0.5;
}
.chat-input {
    flex: 1;
    min-height: 42px; max-height: 120px;
    padding: 10px 16px;
    border: 1px solid var(--border-light);
    border-radius: 21px;
    font-size: 14.5px; line-height: 1.55;
    resize: none; outline: 0;
    font-family: inherit;
    background: #fff;
    color: var(--text-1);
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.03);
    transition: all .2s;
}
.chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}
.send-btn {
    width: 44px; height: 44px; border: 0;
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 8px 20px rgba(102,126,234,0.35);
    transition: all .18s;
    cursor: pointer;
}
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 19px; height: 19px; color: #fff; margin-left: 1px; }
.send-btn:disabled {
    background: var(--text-3);
    box-shadow: none;
    cursor: not-allowed;
}

/* error 气泡 (AI 回答出错) */
.error-bubble {
    background: #fff !important;
    border: 1px solid var(--danger-soft) !important;
    color: var(--danger) !important;
}
.error-bubble::before { content: ''; }

/* 本页 Toast：默认隐藏，避免提示文字残留 */
.toast {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -8px);
    transition: opacity .18s ease, transform .18s ease;
}
.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}
.toast-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.16);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

/* 确认弹窗 */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal.active {
    display: flex;
}
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(4px);
}
.modal-content {
    position: relative;
    width: min(320px, 100%);
    overflow: hidden;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 20px 45px rgba(15,23,42,0.22);
}
.confirm-title {
    padding: 18px 20px 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-1);
    text-align: center;
}
.confirm-message {
    padding: 0 20px 18px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-2);
    text-align: center;
}
.confirm-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--border-light);
}
.confirm-btn {
    height: 48px;
    border: 0;
    background: #fff;
    font-size: 15px;
    font-weight: 600;
}
.confirm-btn.cancel {
    color: var(--text-2);
    border-right: 1px solid var(--border-light);
}
.confirm-btn.confirm {
    color: var(--primary);
}

/* 由于chat页面有自有输入条，底部nav固定在输入条下方，留足够空白已在 chat-input-bar 处理 */
