/* ===================== 表格卡片 ===================== */
.message-content .table-block {
    position: relative;
    margin: 0.9rem 0;
    width: fit-content;   /* 外框跟随表格内容宽度,不再随容器/正文撑满 */
    max-width: 100%;      /* 内容过宽时封顶到容器宽度,超出部分由 table-scroll 横向滚动 */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.message-content .table-scroll {
    width: 100%;
    overflow-x: auto;
    background: linear-gradient(90deg, var(--color-surface), transparent) left center / 18px 100% no-repeat,
                linear-gradient(270deg, var(--color-surface), transparent) right center / 18px 100% no-repeat,
                var(--color-surface);
    -webkit-overflow-scrolling: touch;
}
.message-content .table-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--color-sidebar-bg);
    border-bottom: 1px solid var(--color-border);
}
.message-content .table-header-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-right: auto;   /* 标题占左,开关与工具栏靠右成组 */
}
.message-content .table-toolbar {
    display: flex;
    gap: 2px;
}
.message-content .table-tool-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
}
.message-content .table-tool-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}
.message-content .table-tool-btn.is-done { color: #16a34a; }
.message-content .table-tool-btn .lucide.spin { animation: spin 0.8s linear infinite; }

/* 下载下拉菜单:一个下载按钮,点击后选择 Excel / PDF。无前缀,正文与全屏模态框共用。 */
.table-download {
    position: relative;
    display: inline-flex;
}
.table-download-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    min-width: 140px;
    padding: 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md, 0 6px 20px rgba(0, 0, 0, 0.12));
    display: none;
}
.table-download.is-open .table-download-menu { display: block; }
.table-download-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font-size: 0.82rem;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease);
}
.table-download-item:hover { background: var(--color-surface-hover); }
.table-download-item .lucide { flex: 0 0 auto; color: var(--color-text-secondary); }

.message-content .table-scroll > table {
    display: table;
    width: auto;        /* 宽度由表格内容决定,不再强制撑满容器 */
    min-width: 0;       /* 取消"最小撑满容器"的约束,改由内容自适应 */
    max-width: none;
    overflow: visible;
    margin: 0;
    border-collapse: collapse !important;
    border-spacing: 0;
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: nowrap;
}
.message-content.markdown-body table th,
.message-content.markdown-body table td {
    border: 1px solid var(--color-border) !important;
}
.message-content thead { background: var(--color-sidebar-bg); }
.message-content th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--color-sidebar-bg);
    font-weight: 600;
    color: var(--color-text);
    box-shadow: inset 0 -1px 0 var(--color-border-strong);
}
.message-content tbody tr { background: var(--color-surface); }
.message-content tbody tr:nth-child(even) { background: var(--color-bg); }
.message-content tbody tr:hover { background: var(--color-primary-soft); }
.message-content tbody td { background-color: inherit; }
.message-content th,
.message-content td {
    padding: 0.65rem 0.8rem;
    vertical-align: middle;
}
.message-content th:last-child,
.message-content td:last-child { width: auto; max-width: none; }
.message-content td {
    max-width: 420px;
    white-space: normal;
    word-break: break-word;
    color: var(--color-text-secondary);
}
.message-content td strong { color: var(--color-text); }
.message-content td img {
    box-sizing: border-box !important;
    width: 76px !important;
    height: 76px !important;
    max-width: 76px !important;
    max-height: 76px !important;
    object-fit: contain !important;
    padding: 4px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    cursor: zoom-in;
    transition: transform var(--duration-fast) var(--ease),
        box-shadow var(--duration-fast) var(--ease);
}
.message-content td img:hover {
    transform: scale(1.04);
    box-shadow: var(--shadow-md);
}
@media (min-width: 768px) {
    .message-content td img {
        width: 100px !important;
        height: 100px !important;
        max-width: 100px !important;
        max-height: 100px !important;
    }
}
.message.assistant.is-streaming .message-content,
.message.assistant.is-streaming .message-content * {
    transition: none !important;
}

/* 表格全屏预览模态层 */
.table-modal-overlay[hidden] { display: none !important; }
.table-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 25, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    padding: 3vh 3vw;
    animation: fadeIn 0.18s ease;
}
.table-modal-panel {
    position: relative;
    /* 宽度跟随表格内容自适应:小表格窄、大表格到上限后横向滚动,避免固定宽度导致的留白 */
    width: fit-content;
    min-width: min(360px, 100%);
    max-width: min(1200px, 94vw);
    max-height: 94vh;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.table-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    z-index: 3;
}
.table-modal-header-left { display: flex; align-items: center; }
.table-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}
.table-modal-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.table-modal-header-right .table-toolbar {
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    display: flex;
    gap: 6px;
}
.table-modal-header-right .table-tool-btn {
    width: 34px;
    height: 34px;
    font-size: 1.15rem;
    color: var(--color-text-secondary);
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
}
.table-modal-header-right .table-tool-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}
.table-modal-header-right .table-tool-btn .lucide.spin { animation: spin 0.8s linear infinite; }
.table-modal-body {
    padding: 18px;
    overflow: auto;
    flex: 1;
}
.table-modal-body .table-scroll { overflow-x: auto; }
.table-modal-close {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
}
.table-modal-close:hover {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

/* 图片放大查看 lightbox */
.lightbox-overlay[hidden] { display: none !important; }
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.18s ease;
    cursor: zoom-out;
}
.lightbox-img {
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    background: #fff;
    padding: 6px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    cursor: default;
}
.lightbox-close {
    position: fixed;
    top: 18px;
    right: 22px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-pill);
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) var(--ease);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.32); }

