/* ============================================
   Chat Layout — 聊天类页面共享布局与组件样式
   用于 main_qa.html 和 main_qa_hexagram.html
   ============================================ */

/* ============================================
   页面布局骨架
   ============================================ */
body {
    height: 100vh;
    display: flex;
    background: var(--bg-page);
    font-family: var(--font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif);
    color: var(--text-primary);
    overflow: hidden;
}

.page-layout {
    display: flex;
    width: 100%;
    height: 100vh;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 0;
    min-height: 0;
    position: relative;
}

/* ============================================
   聊天区域
   ============================================ */
.chat-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 60px 24px 24px;
    min-height: 0;
}

.chat-content {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 400px;
    padding-bottom: 8px;
}

/* ============================================
   空状态基础
   ============================================ */
.empty-state {
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 80px 20px 40px;
    text-align: center;
}

.empty-state h2 {
    font-size: 22px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 32px;
    line-height: 1.5;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   输入区域
   ============================================ */
.input-area {
    /* padding: 20px 24px; */
    padding: 2px 24px 12px 24px;
    /* 顶部 24px，底部 12px，左右 24px */
    display: flex;
    /* gap: 12px; */
    justify-content: center;
    align-items: center;
    background-color: transparent;
    flex-shrink: 0;
}

.input-container {
    /* width: 75%; */
    width: 70%;
    display: flex;
    flex-direction: column;
    /* gap: 12px; */
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    background-color: transparent;
    box-shadow: 0 0 0 1px rgba(30, 159, 255, 0.1);
    transition: all var(--transition-normal);
}

.input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgba(30, 159, 255, 0.15);
}

#input,
.message-input {
    border: none;
    outline: none;
    padding: 8px 0;
    font-size: 14px;
    font-family: var(--font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif);
    line-height: 1.6;
    background: transparent;
    color: var(--text-primary);
    width: 100%;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    caret-color: var(--text-primary);
    overflow-y: auto;
}

#input::placeholder,
.message-input::placeholder {
    color: #adb5bd;
}

.input-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tools-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(30, 159, 255, 0.3);
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(30, 159, 255, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn svg {
    width: 18px;
    height: 18px;
    stroke: white;
}

.send-btn:disabled {
    background: #dee2e6;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 0.7;
}

.send-btn:disabled:hover {
    background: #dee2e6;
    transform: none;
}

.send-btn:disabled svg {
    stroke: #adb5bd;
}

/* ============================================
   回到顶部按钮
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-normal);
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.back-to-top svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 2;
}

/* ============================================
   思维链折叠组件（千问风格）
   ============================================ */
.thinking-details {
    margin-bottom: 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    box-shadow: none;
    transition: none;
}

.thinking-details:hover {
    box-shadow: none;
}

.thinking-summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    cursor: pointer;
    user-select: none;
    /* C-16: 思维链标题采用设计令牌正文文字样式 */
    font-family: var(--font-family);
    font-size: var(--text-base);
    color: var(--text-secondary);
    list-style: none;
    border: 1px solid #e8e8e8;
    border-radius: 20px;
    background: #fafafa;
    transition: all 0.2s ease;
    width: fit-content;
}

.thinking-summary::-webkit-details-marker {
    display: none;
}

.thinking-summary:hover {
    background: #f0f0f0;
    border-color: #d9d9d9;
}

.thinking-icon {
    font-size: 14px;
    filter: none;
}

.thinking-label {
    font-weight: 500;
    letter-spacing: 0;
}

.thinking-duration {
    margin-left: 4px;
    /* C-16: 时长采用设计令牌辅助文字样式 */
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    opacity: 1;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.thinking-content-streaming {
    padding: 12px 0 0 0;
    /* C-16: 思维链内容采用设计令牌正文文字样式 */
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: 1.7;
    color: var(--text-secondary);
    max-height: 400px;
    overflow-y: auto;
    background: transparent;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.thinking-content-streaming ul,
.thinking-content-streaming ol {
    margin: 4px 0;
    padding-left: 0;
    list-style-position: inside;
}

.thinking-content-streaming li {
    margin: 2px 0;
    line-height: 1.6;
}

.thinking-content-streaming li+li {
    margin-top: 4px;
}

.thinking-answer-content {
    margin-top: 8px;
}

/* 折叠状态 */
.thinking-details:not([open]) .thinking-content-streaming {
    display: none;
}

.thinking-details:not([open]) .thinking-summary {
    color: #6b7280;
    border-color: #e8e8e8;
    background: #fafafa;
}

.thinking-details:not([open]) .thinking-summary:hover {
    background: #f0f0f0;
    border-color: #d9d9d9;
}

.thinking-details:not([open]) .thinking-summary::after {
    content: '\25BE';
    font-size: 12px;
    margin-left: auto;
    padding-left: 8px;
    color: #bfbfbf;
    flex-shrink: 0;
}

.thinking-details[open] .thinking-summary::after {
    content: '\25B4';
    font-size: 12px;
    margin-left: auto;
    padding-left: 8px;
    color: #bfbfbf;
    flex-shrink: 0;
}

/* 思考中动画指示器 */
.thinking-details[open].thinking-active .thinking-summary {
    color: #595959;
    border-color: #d9d9d9;
    background: #f5f5f5;
}

.thinking-details[open].thinking-active .thinking-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking-details[open].thinking-active .thinking-summary::before {
    content: '';
    width: 10px;
    height: 10px;
    border: 2px solid #d9d9d9;
    border-top-color: #595959;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
}

/* ============================================
   等待动画占位符
   ============================================ */
.thinking-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 12px;
    margin-bottom: 16px;
    min-height: 120px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease;
}

.spinner-container {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
}

.spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.spinner-ring:nth-child(2) {
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
    border-top-color: var(--primary-dark);
    animation-duration: 0.8s;
    animation-direction: reverse;
}

.spinner-ring:nth-child(3) {
    width: 60%;
    height: 60%;
    top: 20%;
    left: 20%;
    border-top-color: rgba(30, 159, 255, 0.5);
    animation-duration: 0.5s;
}

.placeholder-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 8px;
}

.placeholder-hint {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ============================================
   关键帧动画
   ============================================ */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(0.95);
    }
}

/* ============================================
   响应式设计（共享部分）
   ============================================ */
/* 平板设备 */
@media (min-width: 768px) and (max-width: 1023px) {
    .chat-scroll {
        padding: 20px;
    }

    .input-area {
        /* padding: 16px; */
        padding: 2px 16px 12px 16px;
        /* 顶部 2px，底部 12px，左右 16px */
    }

    .input-container {
        width: 85%;
    }
}

/* 手机设备 */
@media (max-width: 767px) {
    .chat-scroll {
        padding: 56px 12px 12px;
    }

    .empty-state {
        padding: 76px 12px 20px;
    }

    .input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .input-container {
        width: 100%;
        padding: 10px 12px;
    }

    .thinking-content-streaming {
        max-height: 200px;
        /* C-16: 响应式沿用令牌，手机端用 text-sm 缩小 */
        font-size: var(--text-sm);
        padding: 12px 14px;
        line-height: 1.5;
    }

    .thinking-content-streaming ul,
    .thinking-content-streaming ol {
        margin: 3px 0;
        padding-left: 0;
        list-style-position: inside;
    }

    .thinking-content-streaming li {
        margin: 1px 0;
        line-height: 1.5;
    }

    .thinking-content-streaming li+li {
        margin-top: 3px;
    }

    .thinking-summary {
        padding: 8px 12px;
        font-size: 12px;
    }

    .thinking-placeholder {
        padding: 30px 16px;
        min-height: 100px;
    }

    .spinner-container {
        width: 50px;
        height: 50px;
    }

    .placeholder-text {
        font-size: 13px;
    }
}

/* iPhone 刘海屏安全区域适配 */
@supports (padding-top: env(safe-area-inset-top)) {
    .input-area {
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
}