/* ============================================================
   易学智能体 - 全局样式
   ============================================================ */

:root {
    --primary: #8B0000;
    --primary-hover: #6B0000;
    --gold: #C5A028;
    --gold-light: #D4B44A;
    --bg-light: #FFF8DC;
    --bg-dark: #1a1a2e;
    --text: #333;
    --text-light: #666;
    --border: #ddd;
    --white: #fff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --sidebar-width: 240px;
    --topbar-height: 60px;
    --transition: all 0.3s ease;
}

[hidden] { display: none !important; }
#identity-entry, #identity-logout { margin-left: auto; flex-shrink: 0; }
#identity-dialog { margin: auto; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; color: var(--text); background: var(--white); }
#identity-dialog::backdrop { background: rgba(0, 0, 0, .45); }
#identity-form { display: grid; gap: 12px; }
#identity-form input, #identity-form select { width: 100%; min-height: 44px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
#identity-form p, #identity-form small { color: var(--text-light); }
#identity-status { min-height: 24px; }
.identity-actions { display: flex; gap: 12px; flex-wrap: wrap; }
@media (max-width: 600px) { .top-bar-desc { display: none; } #identity-entry, #identity-logout { font-size: 13px; padding: 8px; } }

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg-light);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================================
   布局
   ============================================================ */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary) 0%, #5a0000 100%);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: var(--transition);
}

.sidebar-header {
    padding: 24px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.sidebar-header h2 {
    font-size: 1.3rem;
    color: var(--gold);
    margin-bottom: 4px;
}

.sidebar-subtitle {
    font-size: 0.75rem;
    opacity: 0.7;
}

.sidebar-nav {
    padding: 16px 0;
}

.nav-group {
    margin-bottom: 8px;
}

.nav-group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 20px;
    opacity: 0.6;
    color: var(--gold-light);
}

.nav-list {
    list-style: none;
}

.nav-list li {
    padding: 0;
}

.nav-list li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
    cursor: pointer;
}

.nav-list li a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--gold);
}

.nav-list li a.active {
    background: rgba(197, 160, 40, 0.2);
    color: var(--gold);
    border-right: 3px solid var(--gold);
}

.nav-list li a .nav-icon {
    font-size: 1.1rem;
}

/* 主内容区 */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部栏 */
.top-bar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-title {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 700;
}

.top-bar-desc {
    font-size: 0.85rem;
    color: var(--text-light);
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--primary);
    transition: var(--transition);
}

/* 内容区域 */
.content-body {
    flex: 1;
    padding: 24px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
   表单样式
   ============================================================ */

.form-area {
    margin-bottom: 24px;
}

.form-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.form-card h3 {
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--gold);
    font-size: 1.1rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 120px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--white);
    transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.1);
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

.btn-secondary {
    background: var(--white);
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-secondary:hover {
    background: rgba(139, 0, 0, 0.05);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ============================================================
   结果展示
   ============================================================ */

.result-area {
    min-height: 200px;
}

.result-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.result-card h3 {
    color: var(--primary);
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.result-card h4 {
    color: var(--gold);
    margin: 12px 0 8px;
    font-size: 0.95rem;
}

/* 表格 */
.result-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.result-table th,
.result-table td {
    padding: 10px 12px;
    text-align: center;
    border: 1px solid var(--border);
    font-size: 0.9rem;
}

.result-table th {
    background: var(--primary);
    color: var(--white);
    font-weight: 600;
}

.result-table tr:nth-child(even) {
    background: rgba(255, 248, 220, 0.5);
}

.result-table tr:hover {
    background: rgba(197, 160, 40, 0.1);
}

/* 四柱表格 */
.pillar-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.pillar-table th,
.pillar-table td {
    width: 25%;
    padding: 12px;
    text-align: center;
    border: 1px solid var(--border);
    font-size: 1rem;
}

.pillar-table th {
    background: var(--primary);
    color: var(--gold);
    font-weight: 700;
}

.pillar-table td {
    font-size: 1.2rem;
    font-weight: 600;
}

/* 九宫格 */
.grid-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    border: 2px solid var(--primary);
    background: var(--primary);
    margin: 12px 0;
    max-width: 480px;
}

.grid-3x3 .grid-cell {
    background: var(--white);
    padding: 16px 8px;
    text-align: center;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    line-height: 1.4;
}

.grid-3x3 .grid-cell .cell-title {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.grid-3x3 .grid-cell .cell-content {
    color: var(--text-light);
    font-size: 0.8rem;
}

/* ============================================================
   加载动画
   ============================================================ */

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 12px;
}

.loading-spinner::before {
    content: '';
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-spinner::after {
    content: '推算中...';
    font-size: 0.9rem;
    color: var(--text-light);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Toast 提示
   ============================================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 6px;
    color: var(--white);
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast-error {
    background: #c0392b;
}

.toast-success {
    background: #27ae60;
}

.toast-info {
    background: var(--primary);
}

.toast-warning {
    background: #e67e22;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ============================================================
   欢迎页
   ============================================================ */

.welcome-page {
    text-align: center;
    padding: 40px 20px;
}

.welcome-page h2 {
    font-size: 1.8rem;
    color: var(--primary);
    margin-bottom: 8px;
}

.welcome-page p {
    color: var(--text-light);
    margin-bottom: 32px;
    font-size: 1rem;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    max-width: 900px;
    margin: 0 auto;
}

.module-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--gold);
}

.module-card .card-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.module-card .card-name {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.module-card .card-desc {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* ============================================================
   页脚
   ============================================================ */

.footer {
    text-align: center;
    padding: 16px;
    font-size: 0.8rem;
    color: var(--text-light);
    border-top: 1px solid var(--border);
    background: var(--white);
}

/* ============================================================
   响应式布局
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .hamburger {
        display: flex;
    }

    .content-body {
        padding: 16px;
    }

    .form-row {
        flex-direction: column;
    }

    .module-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .grid-3x3 {
        max-width: 100%;
    }

    .pillar-table th,
    .pillar-table td {
        padding: 8px 4px;
        font-size: 0.85rem;
    }
}

/* 侧边栏遮罩层（移动端） */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================================
   历史记录模块
   ============================================================ */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.history-item:hover {
    border-color: var(--gold);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.history-item-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-module-icon {
    font-size: 1.2rem;
}

.history-module-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.9rem;
}

.history-time {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-left: auto;
}

.history-question {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.4;
}

/* 历史详情展开 */
.history-detail {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    animation: historySlideDown 0.3s ease;
}

.history-detail-show {
    animation: historySlideDown 0.3s ease;
}

@keyframes historySlideDown {
    from {
        opacity: 0;
        max-height: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        max-height: 1000px;
        transform: translateY(0);
    }
}

.history-detail-section {
    margin-bottom: 12px;
}

.history-detail-section strong {
    display: block;
    color: var(--primary);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.history-detail-section p {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}

/* 反馈评分 */
.history-feedback-area {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.feedback-label {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 600;
}

.star-rating {
    display: inline-flex;
    gap: 4px;
}

.star {
    font-size: 1.4rem;
    cursor: pointer;
    transition: transform 0.2s ease, color 0.2s ease;
    user-select: none;
}

.star:hover {
    transform: scale(1.3);
}

.star-filled {
    color: var(--gold);
}

.star-empty {
    color: var(--border);
}

.star-empty:hover {
    color: var(--gold-light);
}

.feedback-comment-area {
    width: 100%;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.feedback-comment-area textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    resize: vertical;
    min-height: 60px;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
    align-self: flex-start;
}

.feedback-done {
    color: #27ae60;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 0;
}

/* ============================================================
   按钮状态
   ============================================================ */

.btn-loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================================
   复制按钮
   ============================================================ */

.result-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.copy-btn {
    background: var(--white);
    color: var(--primary);
    border: 1px solid var(--primary);
    font-size: 0.85rem;
    padding: 6px 14px;
    border-radius: 6px;
}

.copy-btn:hover {
    background: rgba(139, 0, 0, 0.06);
    box-shadow: var(--shadow);
}

/* ============================================================
   重试按钮
   ============================================================ */

.retry-btn {
    margin-top: 16px;
    background: var(--gold);
    color: var(--white);
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 0.9rem;
}

.retry-btn:hover {
    background: var(--gold-light);
    box-shadow: var(--shadow);
}

/* ==================== 移动端适配 ==================== */

/* 超小屏幕 (手机竖屏 < 480px) */
@media (max-width: 480px) {
    .content-body {
        padding: 12px 8px;
    }
    
    .form-card {
        padding: 16px 12px;
        margin-bottom: 12px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .form-row .form-group {
        width: 100%;
    }
    
    .form-group label {
        font-size: 0.85rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* 防止 iOS 自动缩放 */
        padding: 10px 12px;
        min-height: 44px; /* 触摸友好 */
    }
    
    .btn {
        width: 100%;
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px;
    }
    
    /* 结果表格横向滚动 */
    .result-table-wrapper,
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .result-table th,
    .result-table td {
        font-size: 0.75rem;
        padding: 6px 8px;
        white-space: nowrap;
    }
    
    /* 九宫格缩小间距 */
    .grid-3x3 {
        gap: 3px;
        font-size: 0.7rem;
    }
    
    .grid-3x3 .palace {
        padding: 6px 4px;
    }
    
    /* 模块卡片网格 */
    .module-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .module-card {
        padding: 12px 8px;
    }
    
    .module-card .icon {
        font-size: 1.5rem;
    }
    
    .module-card .name {
        font-size: 0.8rem;
    }
    
    /* 四柱表格特殊处理 */
    .bazi-table {
        font-size: 0.75rem;
    }
    
    .bazi-table th,
    .bazi-table td {
        padding: 4px 6px;
    }
    
    /* 复制按钮和操作区 */
    .result-actions {
        flex-wrap: wrap;
    }
    
    .copy-btn {
        width: 100%;
        margin-top: 8px;
    }
    
    /* 侧边栏全屏 */
    .sidebar.active {
        width: 85%;
    }
}

/* 平板竖屏 (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .content-body {
        padding: 16px;
    }
    
    .form-row {
        gap: 12px;
    }
    
    .module-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-3x3 {
        gap: 4px;
        font-size: 0.8rem;
    }
}

/* 桌面端宽屏 (> 1200px) */
@media (min-width: 1200px) {
    .module-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 触摸交互优化 */
@media (hover: none) and (pointer: coarse) {
    /* 触屏设备 - 增大点击区域 */
    .btn, button, a, .nav-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 移除hover效果，改用active */
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.96);
        opacity: 0.8;
    }
    
    .nav-item:hover {
        background: transparent;
    }
    
    .nav-item:active {
        background: rgba(197, 160, 40, 0.1);
    }
}

/* ==================== AI 对话样式 ==================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 400px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #fafafa;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    margin-bottom: 12px;
}

.chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.chat-welcome-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.chat-welcome h3 {
    color: var(--primary, #8B0000);
    margin-bottom: 8px;
}

.chat-suggestions {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.suggestion-btn {
    background: var(--bg-light, #FFF8DC);
    border: 1px solid var(--gold, #C5A028);
    color: var(--primary, #8B0000);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: var(--gold, #C5A028);
    color: white;
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 10px;
    line-height: 1.5;
    animation: bubbleFadeIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes bubbleFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-user {
    background: var(--gold, #C5A028);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-assistant {
    background: white;
    border: 1px solid #e8e8e8;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-loading .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    margin: 0 3px;
    animation: dotBounce 1.4s ease-in-out infinite;
}

.chat-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

.chat-input-area {
    padding: 0;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
}

.chat-input-wrapper input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-wrapper input:focus {
    border-color: var(--gold, #C5A028);
}

.chat-send-btn {
    padding: 12px 24px;
    background: var(--primary, #8B0000);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 15px;
    transition: opacity 0.2s;
    min-width: 70px;
}

.chat-send-btn:hover {
    opacity: 0.85;
}

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

.chat-module-tag {
    display: inline-block;
    background: var(--primary, #8B0000);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-bottom: 6px;
}

.chat-interpretation {
    margin-bottom: 8px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.chat-data-json {
    font-size: 0.75rem;
    background: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    max-height: 200px;
}

/* ============================================================
   数字奇门 / 归藏古易 - 宫格与详情展示
   ============================================================ */

/* 九宫排盘格（多行内容版，区别于 grid-3x3） */
.palace-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    border: 2px solid var(--primary);
    background: var(--primary);
    margin: 12px 0;
    max-width: 640px;
}

.palace-cell {
    background: var(--white);
    padding: 10px 8px;
    text-align: center;
    min-height: 110px;
    font-size: 0.82rem;
    line-height: 1.5;
}

.palace-cell-title {
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.palace-cell-line {
    color: var(--text-light);
    font-size: 0.78rem;
}

.palace-cell-marker {
    color: var(--primary);
    font-weight: 600;
}

.palace-cell-score {
    color: var(--gold);
    font-weight: 600;
    margin-top: 4px;
}

/* 标签-内容定义列表 */
.label-value-list {
    margin: 8px 0;
}

.label-value-list dt {
    font-weight: 600;
    color: var(--primary);
    margin-top: 8px;
}

.label-value-list dd {
    margin-left: 16px;
    color: var(--text);
}

/* 可折叠详情块（summary + detail_lines） */
.detail-block {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 8px 0;
    padding: 0;
    background: var(--white);
}

.detail-block summary {
    cursor: pointer;
    padding: 10px 12px;
    font-size: 0.9rem;
    color: var(--text);
    list-style-position: inside;
}

.detail-block summary:hover {
    background: rgba(197, 160, 40, 0.1);
}

.detail-block[open] summary {
    border-bottom: 1px solid var(--border);
}

.detail-block .label-value-list,
.detail-block p {
    padding: 4px 16px 12px;
    margin: 0;
}

/* 因果链列表 */
.chain-list {
    margin: 8px 0 8px 20px;
}

.chain-list li {
    margin-bottom: 8px;
}

.chain-list .chain-pair {
    font-weight: 600;
    color: var(--primary);
}

.chain-list p {
    color: var(--text-light);
    font-size: 0.88rem;
}

/* 宽表格横向滚动容器 */
.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-scroll .result-table {
    min-width: 640px;
}

/* 移动端：宫格降级为单列 */
@media (max-width: 768px) {
    .palace-grid {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .palace-cell {
        min-height: auto;
    }
}

/* ============================================================
   命盘可视化响应式
   ============================================================ */

.chart-container {
    max-width: 600px;
    margin: 0 auto;
}

.chart-container svg {
    width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .chart-container {
        max-width: 100%;
    }

    .chart-container svg text {
        font-size: clamp(8px, 2vw, 14px);
    }
}

/* 图形/列表切换按钮 */
.view-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.view-toggle button {
    padding: 6px 16px;
    border: 1px solid var(--border, #ddd);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    font-size: 0.9rem;
    color: var(--text, #333);
    transition: all 0.2s ease;
}

.view-toggle button:hover {
    border-color: var(--primary, #8B0000);
    color: var(--primary, #8B0000);
}

.view-toggle button.active {
    background: var(--primary, #8B0000);
    color: white;
    border-color: var(--primary, #8B0000);
}

/* 视图隐藏控制 */
.chart-hidden {
    display: none !important;
}
