/* ================================================================
   chat.css — AI 对话页面样式
   Soft Editorial Light · Playfair Display + DM Sans
   ================================================================ */

/* ===== CSS Variables ===== */
:root {
    --chat-bg: #faf9f6;
    --chat-surface: #ffffff;
    --chat-border: #e8edf2;
    --chat-text: #1a2332;
    --chat-text-secondary: #5a6d80;
    --chat-text-muted: #8b97a5;
    --chat-accent: #0ea5e9;
    --chat-accent-hover: #0284c7;
    --chat-accent-soft: rgba(14, 165, 233, 0.06);
    --chat-accent-glow: rgba(14, 165, 233, 0.15);
    --chat-warm-line: #d4c5b2;
    --chat-shadow-sm: 0 1px 3px rgba(26, 35, 50, 0.04);
    --chat-shadow-md: 0 4px 16px rgba(26, 35, 50, 0.06);
    --chat-radius: 18px;
    --chat-radius-sm: 12px;
}

/* ===== Body Override ===== */
body {
    background-color: var(--chat-bg);
    font-family:
        'DM Sans',
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
}

/* ===== Header ===== */
.chat-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--chat-border);
}

.mobile-menu-btn {
    color: var(--chat-text);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.15s;
}

.mobile-menu-btn:hover {
    background: var(--chat-accent-soft);
}

/* ===== Page Container ===== */
.chat-page-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 20px 32px;
    min-height: calc(100vh - 80px);
}

.chat-page-layout {
    display: grid;
    grid-template-columns: 270px 1fr;
    gap: 28px;
    height: calc(100vh - 156px);
    min-height: 600px;
}

/* ===== Sidebar Persona Card ===== */
.chat-sidebar {
    display: flex;
    flex-direction: column;
}

.chat-persona-card {
    background: var(--chat-surface);
    border-radius: var(--chat-radius);
    padding: 28px 24px 24px;
    box-shadow: var(--chat-shadow-sm);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

/* Blue accent line at top */
.chat-persona-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 3px;
    background: linear-gradient(90deg, var(--chat-accent), #38bdf8, var(--chat-accent));
    border-radius: 0 0 3px 3px;
    opacity: 0.7;
}

.persona-avatar {
    position: relative;
    width: 84px;
    height: 84px;
    margin-top: 4px;
}

.persona-photo {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #e0f2fe;
    transition: border-color 0.3s;
}

.chat-persona-card:hover .persona-photo {
    border-color: #bae6fd;
}

.persona-online-dot {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #22c55e;
    border: 3px solid #fff;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
    animation: pulse-dot 2.4s infinite;
}

@keyframes pulse-dot {
    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
    }
    50% {
        box-shadow: 0 0 0 9px rgba(34, 197, 94, 0.03);
    }
}

.persona-name {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--chat-text);
    letter-spacing: -0.01em;
    margin-top: 2px;
}

.persona-role {
    font-size: 13px;
    color: var(--chat-accent);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.persona-bio {
    font-size: 13px;
    color: var(--chat-text-secondary);
    line-height: 1.7;
}

.persona-stats {
    display: flex;
    gap: 20px;
    padding: 14px 0;
    border-top: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
    width: 100%;
    justify-content: center;
}

.persona-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.persona-stat .stat-num {
    font-family: 'DM Sans', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--chat-accent);
    letter-spacing: -0.02em;
}

.persona-stat .stat-lbl {
    font-size: 11px;
    color: var(--chat-text-muted);
    letter-spacing: 0.03em;
}

.persona-capabilities {
    text-align: left;
    width: 100%;
    padding-top: 2px;
}

.persona-capabilities h4 {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.persona-capabilities ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.persona-capabilities li {
    font-size: 13px;
    color: var(--chat-text-secondary);
    padding: 4px 0 4px 18px;
    position: relative;
    transition: color 0.2s;
}

.persona-capabilities li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 11px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--chat-accent);
    opacity: 0.5;
    transition:
        opacity 0.2s,
        transform 0.2s;
}

.persona-capabilities li:hover {
    color: var(--chat-text);
}

.persona-capabilities li:hover::before {
    opacity: 1;
    transform: scale(1.4);
}

/* ===== Chat Main Panel ===== */
.chat-main {
    background: var(--chat-surface);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Subtle top accent line */
.chat-main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--chat-warm-line), transparent);
    opacity: 0.4;
    z-index: 1;
}

/* ===== Chat Header ===== */
.chat-main-header {
    padding: 22px 28px 12px;
    border-bottom: 1px solid var(--chat-border);
}

.chat-main-header h1 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--chat-text);
    letter-spacing: -0.01em;
}

.skill-indicator {
    font-size: 12px;
    color: var(--chat-accent);
    margin-top: 4px;
    min-height: 18px;
    font-weight: 500;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.skill-indicator:not(:empty)::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-accent);
    animation: skill-blink 1.8s infinite;
}

@keyframes skill-blink {
    0%,
    100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

/* ===== Messages Area ===== */
.chat-page-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    background: radial-gradient(ellipse at 50% 0%, rgba(14, 165, 233, 0.015) 0%, transparent 70%), var(--chat-surface);
}

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

.chat-page-messages::-webkit-scrollbar-thumb {
    background: #dde4ec;
    border-radius: 2px;
}

.chat-page-messages::-webkit-scrollbar-thumb:hover {
    background: #c5d0db;
}

/* ===== Message Bubble ===== */
.chat-page-message {
    display: flex;
    gap: 10px;
    max-width: 78%;
    animation: msg-rise 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes msg-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-page-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-page-message.assistant {
    align-self: flex-start;
}

/* Avatar circle */
.chat-page-message .msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.chat-page-message.user .msg-avatar {
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    color: #fff;
    font-family: 'DM Sans', sans-serif;
}

.chat-page-message.assistant .msg-avatar {
    background: #e0f2fe;
    color: var(--chat-accent);
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
}

/* Bubble */
.chat-page-message .msg-bubble {
    padding: 12px 16px;
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
    font-family:
        'DM Sans',
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
}

.chat-page-message.user .msg-bubble {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(14, 165, 233, 0.18);
}

.chat-page-message.assistant .msg-bubble {
    background: #f4f7fa;
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(26, 35, 50, 0.03);
}

/* Source reference tag inside assistant bubble */
.chat-page-message.assistant .msg-bubble .source-ref {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--chat-accent);
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-style: normal;
    background: rgba(14, 165, 233, 0.07);
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.02em;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 2px;
    align-items: center;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-accent);
    opacity: 0.5;
    animation: typing-breathe 1.6s infinite ease-in-out;
}

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

@keyframes typing-breathe {
    0%,
    80%,
    100% {
        transform: scale(0.7);
        opacity: 0.3;
    }
    40% {
        transform: scale(1.15);
        opacity: 0.9;
    }
}

/* ===== Suggestion Chips ===== */
.chat-page-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 28px 12px;
}

.chat-page-suggestion-chip {
    padding: 7px 16px;
    border-radius: 20px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface);
    color: var(--chat-text-secondary);
    font-size: 13px;
    font-family:
        'DM Sans',
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chat-page-suggestion-chip:hover {
    border-color: var(--chat-accent);
    color: var(--chat-accent);
    background: var(--chat-accent-soft);
    box-shadow: 0 2px 8px var(--chat-accent-glow);
    transform: translateY(-1px);
}

/* ===== Input Area ===== */
.chat-page-input-area {
    padding: 14px 28px 22px;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-page-input-area textarea {
    flex: 1;
    resize: none;
    padding: 13px 16px;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    font-family:
        'DM Sans',
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    line-height: 1.5;
    max-height: 120px;
    outline: none;
    color: var(--chat-text);
    background: var(--chat-bg);
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.chat-page-input-area textarea:focus {
    border-color: var(--chat-accent);
    box-shadow:
        inset 0 -2px 0 0 var(--chat-accent),
        0 0 0 4px var(--chat-accent-glow);
}

.chat-page-input-area textarea::placeholder {
    color: var(--chat-text-muted);
    font-weight: 400;
}

/* ===== Send Button ===== */
.chat-page-send-btn {
    width: 46px;
    height: 46px;
    border-radius: var(--chat-radius-sm);
    border: none;
    background: var(--chat-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition:
        background 0.2s,
        transform 0.2s,
        box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.25);
}

.chat-page-send-btn:hover {
    background: var(--chat-accent-hover);
    transform: scale(1.04);
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.35);
}

.chat-page-send-btn:active {
    transform: scale(0.96);
}

.chat-page-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-page-send-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s;
}

.chat-page-send-btn:not(:disabled):hover svg {
    transform: translateX(1px) translateY(-1px);
}

/* ===== Floating Chat Widget (kept for potential reuse) ===== */
.chat-floating-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--chat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(14, 165, 233, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.chat-floating-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(14, 165, 233, 0.45);
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .chat-page-layout {
        grid-template-columns: 1fr;
        height: auto;
        gap: 16px;
    }

    .chat-sidebar {
        display: none;
    }

    .chat-main {
        height: calc(100vh - 120px);
        min-height: 500px;
        border-radius: var(--chat-radius-sm);
    }

    .chat-page-messages {
        padding: 14px 16px;
        gap: 14px;
    }

    .chat-page-message {
        max-width: 88%;
    }

    .chat-page-suggestions {
        padding: 8px 16px 10px;
    }

    .chat-page-input-area {
        padding: 10px 16px 16px;
    }

    .chat-main-header {
        padding: 16px 20px 10px;
    }

    .chat-main-header h1 {
        font-size: 19px;
    }
}

@media (max-width: 480px) {
    .chat-page-container {
        padding: 0;
    }

    .chat-main {
        border-radius: 0;
        height: calc(100vh - 72px);
    }

    .chat-page-message {
        max-width: 92%;
    }

    .chat-page-message .msg-bubble {
        padding: 10px 14px;
        font-size: 13px;
    }
}
