/* ============================================================
   AI 聊天页样式（依赖 css/style.css 的主题变量）
   ============================================================ */

.chat-page {
    padding-top: 64px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.chat-shell {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 64px);
}

/* ---------- 顶栏 ---------- */
.chat-top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--glass-border);
    flex-wrap: wrap;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--on-surface);
    margin: 0;
    flex: 1;
    min-width: 0;
}

.chat-title .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.16);
    flex-shrink: 0;
}

.chat-title .dot.off {
    background: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.16);
}

.chat-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-select {
    height: 38px;
    padding: 0 32px 0 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    color: var(--on-surface);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    max-width: 210px;
    transition: var(--transition);
}

.chat-select:hover,
.chat-select:focus {
    border-color: var(--on-surface);
}

.chat-tool-btn {
    height: 38px;
    padding: 0 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    color: var(--on-surface-variant);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.chat-tool-btn:hover {
    color: var(--on-surface);
    border-color: var(--on-surface);
}

.chat-tool-btn .material-icons-round {
    font-size: 17px;
}

.chat-quota {
    font-size: 12px;
    color: var(--on-surface-variant);
    font-weight: 600;
    padding: 0 4px;
    white-space: nowrap;
}

/* ---------- 消息区 ---------- */
.chat-log {
    flex: 1;
    padding: 26px 2px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 64px - 190px);
    scroll-behavior: smooth;
}

.chat-empty {
    margin: auto;
    text-align: center;
    max-width: 520px;
    padding: 20px 0;
}

.chat-empty .orb {
    width: 74px;
    height: 74px;
    margin: 0 auto 20px;
    border-radius: 24px;
    background: var(--on-surface);
    color: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: orbFloat 4s ease-in-out infinite;
}

.chat-empty .orb .material-icons-round {
    font-size: 38px;
}

@keyframes orbFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(-4deg); }
}

.chat-empty h2 {
    font-size: clamp(24px, 4vw, 32px);
    font-weight: 800;
    letter-spacing: -1px;
    margin: 0 0 10px;
    color: var(--on-surface);
}

.chat-empty p {
    font-size: 14px;
    color: var(--on-surface-variant);
    margin: 0 0 26px;
    line-height: 1.7;
}

.chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 10px;
    text-align: left;
}

.chip {
    padding: 13px 15px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    color: var(--on-surface);
    font-size: 13px;
    line-height: 1.5;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: var(--transition);
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.chip:hover {
    border-color: var(--on-surface);
    transform: translateY(-2px);
}

.chip .material-icons-round {
    font-size: 17px;
    color: var(--on-surface-variant);
    flex-shrink: 0;
    margin-top: 1px;
}

/* ---------- 消息气泡 ---------- */
.msg {
    display: flex;
    gap: 12px;
    animation: msgIn 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    scroll-margin: 12px;
}

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

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    margin-top: 2px;
}

.msg.user .msg-avatar {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--on-surface);
}

.msg.assistant .msg-avatar {
    background: var(--on-surface);
    color: var(--background);
}

.msg-body {
    min-width: 0;
    flex: 1;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--on-surface-variant);
    margin-bottom: 6px;
}

.msg-meta .time {
    font-weight: 500;
    opacity: 0.7;
}

.msg-bubble {
    font-size: 15px;
    line-height: 1.75;
    color: var(--on-surface);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.msg.user .msg-bubble {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 4px 16px 16px 16px;
    padding: 12px 16px;
}

.msg.assistant .msg-bubble {
    padding: 2px 0;
}

.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
    margin: 18px 0 8px;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.3px;
}
.msg-bubble ul, .msg-bubble ol { margin: 0 0 10px; padding-left: 22px; }
.msg-bubble li { margin-bottom: 5px; }
.msg-bubble a { color: var(--on-surface); text-decoration: underline; text-underline-offset: 3px; }
.msg-bubble strong { font-weight: 800; }
.msg-bubble hr { border: none; border-top: 1px solid var(--glass-border); margin: 16px 0; }

.msg-bubble code.inline {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    padding: 1px 6px;
    border-radius: 6px;
}

.code-block {
    position: relative;
    margin: 12px 0;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: #08080a;
}

[data-theme="light"] .code-block {
    background: #1c1c1e;
}

.code-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: #8b8b93;
}

.code-block-head button {
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #d0d0d6;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
}

.code-block-head button:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.code-block pre {
    margin: 0;
    padding: 15px 16px;
    overflow-x: auto;
    background: transparent !important;
    border: none !important;
}

.code-block code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13.5px;
    line-height: 1.65;
    color: #e6e6ea;
    white-space: pre;
    background: none !important;
    padding: 0 !important;
    text-shadow: none !important;
}

.msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.msg:hover .msg-actions,
.msg-actions:focus-within {
    opacity: 1;
}

.msg-act {
    border: none;
    background: var(--surface);
    color: var(--on-surface-variant);
    width: 28px;
    height: 28px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.msg-act:hover {
    background: var(--glass-border);
    color: var(--on-surface);
}

.msg-act .material-icons-round {
    font-size: 15px;
}

.typing {
    display: inline-flex;
    gap: 5px;
    padding: 6px 0;
}

.typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--on-surface-variant);
    animation: bounce 1.3s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }

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

.stream-cursor::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--on-surface);
    margin-left: 2px;
    vertical-align: -3px;
    animation: blink 0.9s steps(1) infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

.msg-error {
    font-size: 13.5px;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.28);
    padding: 10px 14px;
    border-radius: 12px;
}

/* ---------- 输入区 ---------- */
.chat-composer {
    position: sticky;
    bottom: 0;
    padding: 14px 0 22px;
    background: linear-gradient(to top, var(--background) 65%, transparent);
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 10px 10px 10px 18px;
    transition: var(--transition);
}

.composer-box:focus-within {
    border-color: var(--on-surface);
    box-shadow: 0 8px 34px rgba(0, 0, 0, 0.18);
}

.composer-box textarea {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    outline: none;
    color: var(--on-surface);
    font-size: 15px;
    line-height: 1.6;
    font-family: inherit;
    max-height: 180px;
    min-height: 26px;
    padding: 6px 0;
}

.composer-box textarea::placeholder {
    color: var(--on-surface-variant);
    opacity: 0.75;
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: none;
    background: var(--on-surface);
    color: var(--background);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.16);
}

[data-theme="light"] .send-btn:hover:not(:disabled) {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

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

.send-btn .material-icons-round {
    font-size: 20px;
}

.composer-hint {
    text-align: center;
    font-size: 11.5px;
    color: var(--on-surface-variant);
    margin-top: 10px;
    opacity: 0.85;
}

.composer-hint a {
    color: var(--on-surface);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
    .chat-shell { padding: 16px 14px 0; }
    .chat-title { font-size: 17px; width: 100%; }
    .chat-select { max-width: 150px; }
    .chat-quota { display: none; }
    .chat-log { max-height: calc(100vh - 64px - 210px); padding: 18px 0; gap: 16px; }
    .msg-avatar { width: 30px; height: 30px; font-size: 13px; }
    .msg-bubble { font-size: 14.5px; }
    .msg-actions { opacity: 1; }
    .chip-grid { grid-template-columns: 1fr; }
    .chat-tool-btn span { display: none; }
    .chat-tool-btn { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .msg, .chat-empty .orb, .typing i { animation: none; }
    .chat-log { scroll-behavior: auto; }
}
