/* 宸良手纪 · 问答助手 — 与主页 style.css 统一的纸感风格 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@500;600;700&family=Noto+Sans+SC:wght@400;500&display=swap');

:root {
    --paper: #f6f3ed;
    --paper-deep: #ebe6dc;
    --ink: #2c2925;
    --ink-soft: #5c5650;
    --ink-muted: #8a837a;
    --clay: #b86b4b;
    --moss: #5f7a62;
    --water: #5a7f94;
    --line: #d9d3c8;
}

.chat-trigger {
    position: fixed;
    right: 1.5rem;
    bottom: 1.75rem;
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0;
    background: none;
    color: var(--ink);
    border: none;
    border-bottom: 2px solid var(--clay);
    cursor: pointer;
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.chat-trigger:hover {
    color: var(--clay);
}

.chat-trigger .trigger-icon {
    font-size: 0.9rem;
    line-height: 1;
    color: var(--clay);
}

.chat-panel {
    position: fixed;
    right: 1.5rem;
    bottom: 4.5rem;
    z-index: 9999;
    width: 24rem;
    max-width: calc(100vw - 2rem);
    height: 34rem;
    max-height: calc(100vh - 7rem);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: var(--ink);
    line-height: 1.75;
    transform: translateY(10px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chat-panel.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.125rem;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
    flex-shrink: 0;
}

.chat-header h3 {
    font-family: 'Noto Serif SC', 'Songti SC', serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    letter-spacing: 0.04em;
    flex: 1;
}

.chat-header-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-mode-toggle {
    background: none;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--ink-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    transition: all 0.15s;
    white-space: nowrap;
}

.chat-mode-toggle:hover {
    color: var(--ink);
    border-color: var(--ink-muted);
    background: var(--paper-deep);
}

.chat-close {
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 0.95rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}

.chat-close:hover {
    color: var(--ink);
    border-color: var(--ink-muted);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.125rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    background: var(--paper);
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 2px;
}

.chat-msg {
    max-width: 92%;
    font-size: 0.92rem;
    line-height: 1.75;
    word-break: break-word;
    white-space: pre-wrap;
    animation: chatMsgIn 0.2s ease;
}

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.assistant {
    align-self: flex-start;
    color: var(--ink-soft);
    padding-left: 0.85rem;
    border-left: 3px solid var(--moss);
}

.chat-msg.user {
    align-self: flex-end;
    color: var(--ink);
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--clay);
    text-align: right;
}

.chat-msg-header {
    margin-bottom: 0.5rem;
    color: var(--ink);
    font-size: 0.92rem;
}

.chat-result-card {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--line);
}

.chat-result-card:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.chat-result-title {
    display: inline-block;
    font-family: 'Noto Serif SC', serif;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
    text-decoration: none;
    margin-bottom: 0.35rem;
}

.chat-result-title:hover {
    color: var(--clay);
}

.chat-result-snippet {
    font-size: 0.85rem;
    color: var(--ink-soft);
    line-height: 1.65;
}

.chat-result-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.45rem;
}

.chat-source-tag {
    font-size: 0.78rem;
    color: var(--ink-muted);
}

.chat-result-link {
    font-size: 0.78rem;
    color: var(--clay);
    text-decoration: none;
    white-space: nowrap;
}

.chat-result-link:hover {
    color: var(--ink);
}

.chat-status {
    align-self: center;
    color: var(--ink-muted);
    font-size: 0.88rem;
    padding: 1rem 0;
    text-align: center;
}

.chat-typing {
    display: flex;
    gap: 4px;
    padding: 0.25rem 0 0.25rem 0.85rem;
    align-self: flex-start;
    border-left: 3px solid var(--line);
}

.chat-typing span {
    width: 5px;
    height: 5px;
    background: var(--ink-muted);
    border-radius: 50%;
    animation: chatBounce 1.2s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1.125rem;
    border-top: 1px solid var(--line);
    background: var(--paper-deep);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    min-width: 0;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 0.5rem 0;
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--ink);
    background: transparent;
    outline: none;
    transition: border-color 0.15s;
}

.chat-input::placeholder {
    color: var(--ink-muted);
}

.chat-input:focus {
    border-bottom-color: var(--clay);
}

.chat-send {
    flex-shrink: 0;
    background: none;
    color: var(--ink);
    border: none;
    border-bottom: 2px solid var(--clay);
    border-radius: 0;
    padding: 0.35rem 0;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.15s;
}

.chat-send:hover {
    color: var(--clay);
}

.chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .chat-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    .chat-trigger {
        right: 1rem;
        bottom: 1rem;
        font-size: 0.88rem;
    }
}