/**
 * Table Fix - 智能表格移动适配样式表
 * Version: 1.0.0
 */

/* ========================================
   基础表格容器包装
   ======================================== */

.table-fix-wrapper {
    position: relative;
    width: 100%;
    margin: 1.5em 0;
    overflow: hidden;
}

.table-fix-scroll-container {
    position: relative;
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    -moz-overflow-scrolling: touch;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.table-fix-scroll-container::-webkit-scrollbar {
    display: none;
}

.table-fix-scroll-container::-moz-scrollbar {
    display: none;
}

/* 滚动提示条 */
.table-fix-scroll-indicator {
    position: relative;
    display: none;
    padding: 8px 16px;
    font-size: 12px;
    color: #666;
    background: linear-gradient(90deg, transparent, rgba(0,0,0,0.03), transparent);
    text-align: center;
    pointer-events: none;
    user-select: none;
}

.table-fix-scroll-indicator::before,
.table-fix-scroll-indicator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 0;
    height: 0;
    margin-top: -4px;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    opacity: 0.3;
}

.table-fix-scroll-indicator::before {
    left: 30px;
    border-right: 8px solid #999;
}

.table-fix-scroll-indicator::after {
    right: 30px;
    border-left: 8px solid #999;
}

.table-fix-scroll-container.is-scrolling ~ .table-fix-scroll-indicator {
    display: block;
}

/* ========================================
   浅色主题 (默认)
   ======================================== */

.table-fix-wrapper.theme-light {
    --tf-primary: #3b82f6;
    --tf-secondary: #60a5fa;
    --tf-bg: #ffffff;
    --tf-bg-alt: #f8fafc;
    --tf-bg-hover: #f1f5f9;
    --tf-text: #1e293b;
    --tf-text-muted: #64748b;
    --tf-border: #e2e8f0;
    --tf-header-bg: #f1f5f9;
    --tf-shadow: rgba(0, 0, 0, 0.08);
}

/* ========================================
   深色主题
   ======================================== */

.table-fix-wrapper.theme-dark {
    --tf-primary: #60a5fa;
    --tf-secondary: #93c5fd;
    --tf-bg: #1e293b;
    --tf-bg-alt: #334155;
    --tf-bg-hover: #475569;
    --tf-text: #f1f5f9;
    --tf-text-muted: #94a3b8;
    --tf-border: #475569;
    --tf-header-bg: #334155;
    --tf-shadow: rgba(0, 0, 0, 0.3);
}

/* ========================================
   蓝色主题
   ======================================== */

.table-fix-wrapper.theme-blue {
    --tf-primary: #2563eb;
    --tf-secondary: #3b82f6;
    --tf-bg: #ffffff;
    --tf-bg-alt: #eff6ff;
    --tf-bg-hover: #dbeafe;
    --tf-text: #1e40af;
    --tf-text-muted: #3b82f6;
    --tf-border: #bfdbfe;
    --tf-header-bg: #dbeafe;
    --tf-shadow: rgba(37, 99, 235, 0.1);
}

/* ========================================
   绿色主题
   ======================================== */

.table-fix-wrapper.theme-green {
    --tf-primary: #059669;
    --tf-secondary: #10b981;
    --tf-bg: #ffffff;
    --tf-bg-alt: #ecfdf5;
    --tf-bg-hover: #d1fae5;
    --tf-text: #047857;
    --tf-text-muted: #059669;
    --tf-border: #a7f3d0;
    --tf-header-bg: #d1fae5;
    --tf-shadow: rgba(5, 150, 105, 0.1);
}

/* ========================================
   通用表格样式
   ======================================== */

.table-fix-wrapper table {
    width: 100%;
    min-width: 300px;
    margin: 0;
    border-collapse: collapse;
    background-color: var(--tf-bg);
    color: var(--tf-text);
    font-size: 14px;
    line-height: 1.6;
    box-shadow: 0 2px 8px var(--tf-shadow);
    border-radius: var(--tf-radius, 8px);
    overflow: hidden;
}

.table-fix-wrapper table.tf-no-radius {
    border-radius: 0;
}

/* 表头样式 */
.table-fix-wrapper thead th {
    padding: 12px 16px;
    font-weight: 600;
    text-align: left;
    background-color: var(--tf-header-bg);
    color: var(--tf-text);
    border-bottom: 2px solid var(--tf-primary);
    white-space: nowrap;
    position: relative;
}

/* 固定表头效果 */
.table-fix-wrapper.table-fix-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-fix-wrapper.table-fix-sticky-header table {
    overflow: visible;
}

.table-fix-wrapper.table-fix-sticky-header .table-fix-scroll-container {
    overflow-x: auto;
    overflow-y: visible;
}

/* 单元格样式 */
.table-fix-wrapper tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--tf-border);
    vertical-align: top;
}

/* ========================================
   边框样式
   ======================================== */

.table-fix-wrapper.tf-border-enable table {
    border: 1px solid var(--tf-border);
}

.table-fix-wrapper.tf-border-enable thead th {
    border-right: 1px solid var(--tf-border);
}

.table-fix-wrapper.tf-border-enable tbody td {
    border-right: 1px solid var(--tf-border);
}

.table-fix-wrapper.tf-border-enable thead th:last-child,
.table-fix-wrapper.tf-border-enable tbody td:last-child {
    border-right: none;
}

/* ========================================
   斑马纹样式
   ======================================== */

.table-fix-wrapper.tf-zebra tbody tr:nth-child(odd) {
    background-color: var(--tf-bg-alt);
}

.table-fix-wrapper.tf-zebra tbody tr:nth-child(even) {
    background-color: var(--tf-bg);
}

/* ========================================
   悬停高亮样式
   ======================================== */

.table-fix-wrapper.tf-hover tbody tr {
    transition: background-color 0.2s ease;
}

.table-fix-wrapper.tf-hover tbody tr:hover {
    background-color: var(--tf-bg-hover) !important;
}

/* ========================================
   移动端响应式优化
   ======================================== */

@media screen and (max-width: 768px) {
    .table-fix-wrapper {
        margin: 1em 0;
    }

    .table-fix-wrapper table {
        font-size: 13px;
    }

    .table-fix-wrapper thead th {
        padding: 10px 12px;
        font-size: 13px;
    }

    .table-fix-wrapper tbody td {
        padding: 8px 12px;
    }

    /* 移动端特殊滚动效果 */
    .table-fix-scroll-container {
        position: relative;
        margin: 0 -15px;
        padding: 0 15px;
    }

    /* 触摸滑动提示动画 */
    .table-fix-wrapper.touch-active .table-fix-scroll-indicator {
        opacity: 1;
        animation: tf-pulse 2s infinite;
    }

    @keyframes tf-pulse {
        0%, 100% { opacity: 0.6; }
        50% { opacity: 1; }
    }
}

/* ========================================
   桌面端滚动条美化
   ======================================== */

@media screen and (min-width: 769px) {
    .table-fix-scroll-container {
        scrollbar-width: thin;
        scrollbar-color: var(--tf-primary) var(--tf-bg-alt);
    }

    .table-fix-scroll-container::-webkit-scrollbar {
        display: block;
        height: 6px;
    }

    .table-fix-scroll-container::-webkit-scrollbar-track {
        background: var(--tf-bg-alt);
        border-radius: 3px;
    }

    .table-fix-scroll-container::-webkit-scrollbar-thumb {
        background: var(--tf-primary);
        border-radius: 3px;
        opacity: 0.5;
    }

    .table-fix-scroll-container::-webkit-scrollbar-thumb:hover {
        background: var(--tf-secondary);
        opacity: 1;
    }
}

/* ========================================
   首列/末列特殊样式
   ======================================== */

.table-fix-wrapper table td:first-child,
.table-fix-wrapper table th:first-child {
    border-left: none;
}

.table-fix-wrapper table td:last-child,
.table-fix-wrapper table th:last-child {
    border-right: none;
}

/* ========================================
   最后一行特殊处理
   ======================================== */

.table-fix-wrapper tbody tr:last-child td {
    border-bottom: none;
}

.table-fix-wrapper tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--tf-radius, 8px);
}

.table-fix-wrapper tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--tf-radius, 8px);
}

/* 首行表头圆角 */
.table-fix-wrapper thead tr:first-child th:first-child {
    border-top-left-radius: var(--tf-radius, 8px);
}

.table-fix-wrapper thead tr:first-child th:last-child {
    border-top-right-radius: var(--tf-radius, 8px);
}

/* ========================================
   圆角控制类
   ======================================== */

.table-fix-wrapper.tf-radius-0 table,
.tf-radius-0 {
    --tf-radius: 0 !important;
}

.tf-radius-4 {
    --tf-radius: 4px !important;
}

.tf-radius-8 {
    --tf-radius: 8px !important;
}

.tf-radius-12 {
    --tf-radius: 12px !important;
}

.tf-radius-16 {
    --tf-radius: 16px !important;
}

/* ========================================
   加载动画
   ======================================== */

.table-fix-wrapper.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

.table-fix-wrapper.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--tf-border);
    border-top-color: var(--tf-primary);
    border-radius: 50%;
    animation: tf-spin 0.8s linear infinite;
}

@keyframes tf-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   打印样式优化
   ======================================== */

@media print {
    .table-fix-wrapper {
        overflow: visible !important;
    }

    .table-fix-scroll-container {
        overflow: visible !important;
        -webkit-overflow-scrolling: auto;
    }

    .table-fix-wrapper table {
        box-shadow: none;
        border: 1px solid #000;
    }

    .table-fix-wrapper thead th {
        position: static !important;
        background: #f0f0f0 !important;
    }
}

/* ========================================
   聚焦/无障碍样式
   ======================================== */

.table-fix-wrapper table:focus-within {
    outline: 2px solid var(--tf-primary);
    outline-offset: 2px;
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .table-fix-wrapper table {
        border: 2px solid #000;
    }

    .table-fix-wrapper thead th {
        background: #000 !important;
        color: #fff !important;
    }

    .table-fix-wrapper tbody td {
        border: 1px solid #000;
    }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    .table-fix-wrapper.tf-hover tbody tr,
    .table-fix-scroll-indicator,
    .table-fix-wrapper.is-loading::after {
        animation: none !important;
        transition: none !important;
    }
}
