/* TPL Brand Colors */
:root {
    --tpl-blue: #112a87;
    --tpl-blue-light: #193684;
    --tpl-blue-dark: #0a1a5c;
    --tpl-red: #c00922;
    --tpl-red-hover: #a0071c;
    --tpl-secondary: #104392;
    --tpl-gray-bg: #f5f5f5;
    --tpl-border: #e8e8e8;
}

/* 页面整体布局：顶部header + 主内容 + 底部footer */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(135deg, #eff2f7 0%, #ffffff 100%);
}

.auth-top-header,
.tpl-footer {
    flex-shrink: 0;
}

/* 顶部操作区 */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.lang-switch-inline select {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
}

.lang-switch-inline select:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lang-switch-inline select option {
    background: var(--tpl-blue);
    color: #fff;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    color: #fff;
}

.header-user:hover {
    background: rgba(255, 255, 255, 0.2);
}

.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tpl-blue);
    font-weight: 600;
    font-size: 13px;
}

.header-user-name {
    font-size: 14px;
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-chevron {
    opacity: 0.7;
    transition: transform 0.3s;
}

.header-user:hover .header-chevron {
    opacity: 1;
}

.header-user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: white;
    border: 1px solid var(--tpl-border);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    overflow: hidden;
    z-index: 200;
}

.header-user-menu.show {
    display: block;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header-user-menu .user-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: #333;
}

.header-user-menu .user-menu-item:hover {
    background-color: #f0f3ff;
    color: var(--tpl-blue);
}

.header-user-menu .user-menu-item:last-child {
    color: var(--tpl-red);
    font-weight: 500;
}

.header-user-menu .user-menu-item:last-child:hover {
    background-color: #fff2f0;
}

/* 主聊天页面 */
.chat-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow: hidden;
    min-height: 0;
}

.chat-wrapper {
    flex: 1;
    display: flex;
    gap: 10px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    min-height: 0;
    height: 100%;
}

/* 左侧边栏 */
.chat-sidebar {
    width: 320px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--tpl-border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: #F1F2F4;
}

.sidebar-logo {
    height: 40px;
    width: auto;
    flex-shrink: 0;
}

.sidebar-brand-text h2 {
    font-size: 17px;
    color: var(--tpl-blue);
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: 0.3px;
}

.sidebar-brand-text p {
    font-size: 11px;
    color: var(--tpl-blue);
}

.new-chat-btn {
    margin: 8px 16px 8px 16px;
    width: calc(100% - 32px);
    background: var(--tpl-red);
    font-size: 14px;
    padding: 12px 16px;
    border-radius: 10px;
    font-weight: 500;
    transition: all 0.3s;
}

.new-chat-btn:hover {
    background: var(--tpl-red-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(192, 9, 34, 0.25);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.session-empty {
    text-align: center;
    color: #999;
    padding: 32px 16px;
    font-size: 13px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: all 0.2s;
    position: relative;
    border: 1px solid transparent;
}

.session-item:hover {
    background-color: #f5f7ff;
    border-color: #e3e8ff;
}

.session-item.active {
    background: linear-gradient(135deg, #e7ecfb 0%, #f0f3ff 100%);
    border-color: #c2d1ff;
}

.session-item.active .session-name {
    color: var(--tpl-blue);
    font-weight: 600;
}

.session-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f0f3ff;
    color: var(--tpl-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.session-item.active .session-icon {
    background: var(--tpl-blue);
    color: #fff;
}

.session-content {
    flex: 1;
    min-width: 0;
}

.session-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #333;
}

.session-time {
    font-size: 11px;
    color: #999;
}

.session-delete {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background-color: transparent;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

.session-item:hover .session-delete {
    opacity: 1;
}

.session-delete:hover {
    background-color: #fff2f0;
    color: var(--tpl-red);
}

/* 主聊天区域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    border: 1px solid var(--tpl-border);
    min-width: 0;
}

.chat-main-header {
    padding: 16px 24px;
    background: #fff;
    border-bottom: 1px solid var(--tpl-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-main-header h3 {
    font-size: 16px;
    color: var(--tpl-blue);
    font-weight: 600;
}

.chat-header-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #52c41a;
    font-weight: 500;
    padding: 4px 10px;
    background: #f6ffed;
    border-radius: 50px;
    border: 1px solid #b7eb8f;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #52c41a;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    background: linear-gradient(180deg, #fafbfc 0%, #f5f7fa 100%);
}

.message-item {
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.35s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-item.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tpl-blue);
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(17, 42, 135, 0.15);
}

.message-avatar svg {
    stroke: #fff;
}

.message-item.assistant .message-avatar {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.message-bubble {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-content {
    padding: 14px 18px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    line-height: 1.65;
    font-size: 15px;
    color: #333;
    border: 1px solid #f0f0f0;
}

.message-item.user .message-content {
    background: linear-gradient(135deg, var(--tpl-blue) 0%, var(--tpl-secondary) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    border-color: transparent;
}

.message-item.assistant .message-content {
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 11px;
    color: #aaa;
    padding: 0 4px;
}

.message-item.user .message-meta {
    text-align: right;
}

/* 输入区域 */
.chat-input-area {
    padding: 16px 24px 20px;
    background: #fff;
    border-top: 1px solid var(--tpl-border);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #f8f9ff;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid #e7ecfb;
    transition: all 0.3s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--tpl-secondary);
    box-shadow: 0 0 0 4px rgba(16, 67, 146, 0.08);
    background: #fff;
}

.chat-input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    resize: none;
    min-height: 44px;
    max-height: 140px;
    line-height: 1.5;
    background: transparent;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--tpl-blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--tpl-red);
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.98);
}

.input-hint {
    text-align: center;
    margin-top: 10px;
    font-size: 12px;
    color: #aaa;
}

.hint-key {
    display: inline-block;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    color: #666;
    margin: 0 2px;
}

.hint-divider {
    margin: 0 8px;
    color: #ccc;
}

/* 空状态 */
.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    min-height: 100%;
}

.empty-state-card {
    text-align: center;
    background: #fff;
    padding: 40px 48px;
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--tpl-border);
    max-width: 400px;
    animation: fadeInUp 0.5s ease both;
}

.empty-state-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #e7ecfb 0%, #f0f3ff 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: var(--tpl-blue);
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--tpl-blue);
    margin-bottom: 8px;
}

.empty-state-desc {
    font-size: 14px;
    color: #888;
    line-height: 1.5;
}

/* 弹窗 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    display: none;
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal {
    background: white;
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 420px;
    margin: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: scaleIn 0.25s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--tpl-blue);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* 响应式 */
@media (max-width: 992px) {
    .chat-sidebar {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .chat-page {
        padding: 12px;
    }

    .chat-wrapper {
        flex-direction: column;
        gap: 8px;
    }

    .chat-sidebar {
        width: 100%;
        max-height: 32vh;
        min-height: 110px;
    }

    .sidebar-brand {
        display: none;
    }

    .chat-main {
        flex: 1;
    }

    .message-bubble {
        max-width: 88%;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-main-header {
        padding: 12px 16px;
    }

    .chat-input-area {
        padding: 10px 16px 12px;
    }

    .chat-input-wrapper {
        padding: 8px 10px;
    }

    .chat-input {
        padding: 8px 10px;
        min-height: 38px;
        font-size: 15px;
    }

    .send-btn {
        width: 38px;
        height: 38px;
    }

    .input-hint {
        display: none;
    }

    .auth-menu-nav .metitle p {
        display: none;
    }

    .header-user-name {
        display: none;
    }

    .header-chevron {
        display: none;
    }

    .header-user {
        padding: 2px;
        border-radius: 50%;
    }

    .session-delete {
        opacity: 1;
    }

    .lang-switch-inline select {
        padding: 6px 10px;
        font-size: 13px;
    }

    .modal {
        padding: 24px;
    }

    .empty-state {
        padding: 20px;
    }

    .empty-state-card {
        padding: 28px 24px;
    }
}

@media (max-width: 480px) {
    .chat-page {
        padding: 0;
    }

    .chat-wrapper {
        gap: 0;
    }

    .chat-sidebar {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        max-height: 28vh;
        min-height: 100px;
    }

    .chat-main {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }

    .chat-messages {
        padding: 12px;
    }

    .message-bubble {
        max-width: 95%;
    }

    .message-avatar {
        width: 34px;
        height: 34px;
        font-size: 12px;
    }

    .chat-main-header {
        padding: 10px 12px;
    }

    .chat-main-header h3 {
        font-size: 15px;
    }

    .chat-input-area {
        padding: 8px 12px 10px;
    }

    .chat-input-wrapper {
        padding: 6px 8px;
    }

    .chat-input {
        padding: 6px 8px;
        font-size: 15px;
        min-height: 36px;
    }

    .send-btn {
        width: 36px;
        height: 36px;
    }

    .input-hint {
        display: none;
    }

    .lang-switch-inline select {
        padding: 5px 8px;
        font-size: 12px;
        border-radius: 6px;
    }

    .new-chat-btn {
        margin: 12px 12px 4px 12px;
        width: calc(100% - 24px);
        padding: 10px 14px;
        font-size: 13px;
    }

    .session-list {
        padding: 0px 10px;
    }

    .session-item {
        padding: 10px;
    }

    .session-delete {
        opacity: 1;
    }

    .session-name {
        font-size: 13px;
    }

    .modal {
        padding: 20px;
        margin: 16px;
    }

    .modal-header {
        font-size: 16px;
    }

    .empty-state-card {
        padding: 24px 20px;
    }

    .empty-state-title {
        font-size: 16px;
    }

    .empty-state-desc {
        font-size: 13px;
    }
}

/* 思考动画 */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--tpl-secondary);
    animation: thinking-bounce 1.4s infinite ease-in-out both;
}

.thinking-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dot:nth-child(2) {
    animation-delay: -0.16s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0s;
}

.thinking-text {
    margin-left: 8px;
    color: #888;
    font-size: 14px;
}

@keyframes thinking-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Markdown 样式 */
.message-content pre {
    background-color: #f6f8fa;
    border-radius: 10px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
    border: 1px solid #f0f0f0;
}

.message-content code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
}

.message-item.user .message-content pre {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.15);
}

.message-item.user .message-content code {
    color: rgba(255, 255, 255, 0.95);
}

.message-content p code {
    background-color: rgba(27, 31, 35, 0.05);
    border-radius: 5px;
    font-size: 85%;
    margin: 0;
    padding: 0.2em 0.4em;
}

.message-item.user .message-content p code {
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 14px;
    margin-bottom: 10px;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 {
    font-size: 1.4em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

.message-content h2 {
    font-size: 1.2em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content p {
    margin: 8px 0;
    line-height: 1.7;
}

.message-content ul,
.message-content ol {
    padding-left: 1.8em;
    margin: 8px 0;
}

.message-content li {
    margin: 5px 0;
}

.message-content blockquote {
    border-left: 4px solid #dfe2e5;
    padding-left: 14px;
    margin: 10px 0;
    color: #6a737d;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 14px;
}

.message-content table th,
.message-content table td {
    border: 1px solid #dfe2e5;
    padding: 8px 12px;
}

.message-content table th {
    background-color: #f6f8fa;
    font-weight: 600;
}

.message-content table tr:nth-child(2n) {
    background-color: #f6f8fa;
}

.message-content a {
    color: var(--tpl-secondary);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-item.user .message-content a {
    color: #b3d4ff;
}

.message-content hr {
    border: 0;
    border-top: 1px solid #eaecef;
    margin: 14px 0;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}
