/* 在线访客显示样式 */
.online-visitors-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #2196F3;
    color: white;
    padding: 10px 15px;
    border-radius: 25px;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 9999;
    font-family: Arial, sans-serif;
}

.online-visitors-widget .count {
    font-weight: bold;
    margin-left: 5px;
}

.online-visitors-widget .icon {
    margin-right: 5px;
}

/* 管理页面样式 */
.visitor-stats-card {
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.visitor-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #2196F3;
}

.stat-number {
    font-size: 2em;
    font-weight: bold;
    color: #2196F3;
    display: block;
}

.stat-label {
    color: #666;
    font-size: 0.9em;
    margin-top: 5px;
}


/* 实时更新动画效果 */
.stat-box.updated,
[id$="-panel"].updated {
    transform: scale(1.02);
    transition: transform 0.3s ease;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
}

.stat-box,
[id$="-panel"] {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* 在线状态指示器 */
.live-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #4CAF50;
    border-radius: 50%;
    margin-right: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* 数据加载动画 */
.loading-shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* 活动流动画 */
.activity-item {
    animation: slideInRight 0.5s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 统计数字动画 */
.stat-number {
    transition: all 0.3s ease;
}

.stat-number.updated {
    color: #4CAF50;
    transform: scale(1.1);
}

/* ========== 表格组件专用自适应样式 ========== */

/* Sales Person Management 和 Recent Visitors 表格优化 */
.widefat,
.wp-list-table,
#contacts-table,
#sales-persons-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 0 !important;
    background: #fff !important;
}

.widefat th,
.widefat td,
.wp-list-table th,
.wp-list-table td {
    padding: 12px 8px !important;
    text-align: left !important;
    border-bottom: 1px solid #e1e1e1 !important;
    word-wrap: break-word !important;
    vertical-align: top !important;
}

.widefat th {
    background: #f8f9fa !important;
    font-weight: 600 !important;
    color: #333 !important;
    border-bottom: 2px solid #ddd !important;
}

/* 表格内按钮优化 */
.widefat .button-small,
.wp-list-table .button-small {
    padding: 4px 8px !important;
    font-size: 12px !important;
    margin: 2px !important;
    min-width: 30px !important;
    border-radius: 4px !important;
}

/* 状态标签优化 */
.widefat .status-badge {
    display: inline-block !important;
    padding: 4px 8px !important;
    border-radius: 12px !important;
    font-size: 11px !important;
    font-weight: 500 !important;
    text-transform: uppercase !important;
}

/* ========== 移动端表格自适应 (768px以下) ========== */
@media (max-width: 768px) {
    /* 表格容器优化 */
    .card {
        padding: 15px !important;
        margin: 0 0 15px 0 !important;
        overflow-x: auto !important;
    }
    
    /* 表格水平滚动 */
    .widefat,
    .wp-list-table,
    #contacts-table,
    #sales-persons-table {
        min-width: 600px !important;
        font-size: 13px !important;
        display: block !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }
    
    .widefat thead,
    .widefat tbody,
    .widefat tr,
    .widefat th,
    .widefat td {
        display: table-cell !important;
    }
    
    .widefat th,
    .widefat td {
        padding: 8px 6px !important;
        font-size: 12px !important;
        min-width: 80px !important;
    }
    
    /* 表格标题优化 */
    .card h2 {
        font-size: 16px !important;
        margin-bottom: 15px !important;
        padding: 0 !important;
    }
    
    /* 添加按钮优化 */
    #add-sales-person {
        width: 100% !important;
        margin-bottom: 15px !important;
        padding: 12px !important;
        font-size: 14px !important;
    }
    
    /* 表格内按钮移动端优化 */
    .widefat .button-small {
        padding: 6px 4px !important;
        font-size: 16px !important;
        margin: 1px !important;
        min-width: 35px !important;
        min-height: 35px !important;
    }
    
    /* 状态列优化 */
    .widefat .status-badge {
        padding: 3px 6px !important;
        font-size: 10px !important;
    }
    
    /* 邮箱和电话列优化 */
    .widefat td[data-column="email"],
    .widefat td[data-column="phone"] {
        max-width: 120px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
}

/* ========== 小屏手机优化 (480px以下) ========== */
@media (max-width: 480px) {
    /* 表格进一步压缩 */
    .card {
        padding: 10px !important;
        margin: 0 0 10px 0 !important;
    }
    
    .widefat,
    #contacts-table,
    #sales-persons-table {
        min-width: 500px !important;
        font-size: 11px !important;
    }
    
    .widefat th,
    .widefat td {
        padding: 6px 4px !important;
        font-size: 11px !important;
        min-width: 70px !important;
    }
    
    .card h2 {
        font-size: 14px !important;
        margin-bottom: 10px !important;
    }
    
    #add-sales-person {
        padding: 10px !important;
        font-size: 13px !important;
    }
    
    /* 表格按钮小屏优化 */
    .widefat .button-small {
        padding: 4px 2px !important;
        font-size: 14px !important;
        min-width: 30px !important;
        min-height: 30px !important;
    }
}

/* ========== 表格卡片式布局 (超小屏幕替代方案) ========== */
@media (max-width: 600px) {
    /* 可选：将表格转换为卡片式布局 */
    .table-card-view .widefat,
    .table-card-view .wp-list-table {
        display: block !important;
        min-width: auto !important;
        overflow-x: visible !important;
    }
    
    .table-card-view .widefat thead {
        display: none !important;
    }
    
    .table-card-view .widefat tbody {
        display: block !important;
    }
    
    .table-card-view .widefat tr {
        display: block !important;
        margin-bottom: 15px !important;
        padding: 15px !important;
        background: #f9f9f9 !important;
        border-radius: 8px !important;
        border: 1px solid #e1e1e1 !important;
    }
    
    .table-card-view .widefat td {
        display: block !important;
        padding: 5px 0 !important;
        border: none !important;
        text-align: left !important;
        min-width: auto !important;
    }
    
    .table-card-view .widefat td:before {
        content: attr(data-label) ": " !important;
        font-weight: bold !important;
        color: #666 !important;
        display: inline-block !important;
        width: 100px !important;
    }
}

/* ========== 模态框表格自适应 ========== */
@media (max-width: 768px) {
    /* 模态框容器优化 */
    #sales-person-modal > div,
    #assign-sales-modal > div,
    #modify-sales-modal > div,
    #edit-contact-modal > div {
        width: 95% !important;
        margin: 5% auto !important;
        padding: 15px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    /* 模态框内表格优化 */
    .form-table {
        width: 100% !important;
    }
    
    .form-table th {
        width: 100% !important;
        display: block !important;
        padding: 10px 0 5px 0 !important;
        text-align: left !important;
    }
    
    .form-table td {
        width: 100% !important;
        display: block !important;
        padding: 0 0 15px 0 !important;
    }
    
    .form-table input,
    .form-table select,
    .form-table textarea {
        width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* ========== 表格滚动提示 ========== */
@media (max-width: 768px) {
    .card:before {
        content: "👈 向左滑动查看更多" !important;
        display: block !important;
        text-align: center !important;
        padding: 8px !important;
        background: #e3f2fd !important;
        color: #1976d2 !important;
        font-size: 12px !important;
        border-radius: 4px !important;
        margin-bottom: 10px !important;
    }
    
    .card:after {
        content: "" !important;
        display: block !important;
        clear: both !important;
    }
}

/* ========== 表格加载状态优化 ========== */
.widefat.loading {
    opacity: 0.6 !important;
    pointer-events: none !important;
}

.widefat.loading:after {
    content: "加载中..." !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: rgba(255,255,255,0.9) !important;
    padding: 10px 20px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    color: #666 !important;
}

/* 模态框和弹窗自适应 */
.modal,
.dialog,
.popup {
    width: 95% !important;
    max-width: 600px !important;
    margin: 0 auto !important;
    padding: 20px !important;
    box-sizing: border-box !important;
}

/* ========== 平板设备优化 (768px - 1024px) ========== */
@media (min-width: 769px) and (max-width: 1024px) {
    .visitor-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    .visitor-stats-card {
        padding: 25px !important;
    }
    
    .stat-item {
        min-height: 140px !important;
        padding: 25px !important;
    }
    
    .form-table th {
        width: 30% !important;
        display: table-cell !important;
        vertical-align: top !important;
        padding: 15px 10px 15px 0 !important;
    }
    
    .form-table td {
        width: 70% !important;
        display: table-cell !important;
        padding: 15px 0 !important;
    }
}

/* ========== 移动设备优化 (最大768px) ========== */
@media (max-width: 768px) {
    /* 主容器强制单列布局 */
    .visitor-stats-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* 所有卡片容器优化 */
    .visitor-stats-card,
    .postbox,
    .card,
    .metabox-holder .postbox {
        margin: 0 0 15px 0 !important;
        padding: 15px !important;
        border-radius: 8px !important;
    }
    
    /* 统计项目移动端优化 */
    .stat-item,
    .stat-box {
        min-height: 100px !important;
        padding: 15px !important;
        text-align: center !important;
    }
    
    .stat-number {
        font-size: 1.8em !important;
        margin-bottom: 5px !important;
    }
    
    .stat-label {
        font-size: 0.85em !important;
    }
    
    /* 在线访客小部件移动端 */
    .online-visitors-widget {
        bottom: 15px !important;
        right: 15px !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        border-radius: 20px !important;
    }
    
    /* 表格移动端优化 */
    .wp-list-table {
        font-size: 14px !important;
    }
    
    .wp-list-table th,
    .wp-list-table td {
        padding: 8px 4px !important;
        word-wrap: break-word !important;
    }
    
    /* 导航标签移动端 */
    .nav-tab {
        display: block !important;
        width: 100% !important;
        margin: 0 0 5px 0 !important;
        text-align: center !important;
    }
    
    /* 模态框移动端 */
    .modal,
    .dialog {
        width: 95% !important;
        padding: 15px !important;
        margin: 10px auto !important;
    }
}

/* ========== 小屏手机优化 (最大480px) ========== */
@media (max-width: 480px) {
    /* 容器进一步压缩 */
    .visitor-stats-card,
    .postbox,
    .card {
        padding: 12px !important;
        margin: 0 0 12px !important;
    }
    
    /* 统计项目小屏优化 */
    .stat-item {
        min-height: 80px !important;
        padding: 12px !important;
    }
    
    .stat-number {
        font-size: 1.5em !important;
    }
    
    .stat-label {
        font-size: 0.8em !important;
    }
    
    /* 在线访客小部件小屏 */
    .online-visitors-widget {
        bottom: 10px !important;
        right: 10px !important;
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    
    /* 表格小屏优化 */
    .wp-list-table {
        font-size: 12px !important;
    }
    
    .wp-list-table th,
    .wp-list-table td {
        padding: 6px 2px !important;
    }
}

/* ========== 横屏模式优化 ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .visitor-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .stat-item {
        min-height: 90px !important;
        padding: 10px !important;
    }
    
    .online-visitors-widget {
        bottom: 10px !important;
        right: 10px !important;
    }
}

/* ========== 触摸设备优化 ========== */
@media (hover: none) and (pointer: coarse) {
    /* 增大可点击区域 */
    .button,
    .nav-tab,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* 优化触摸交互 */
    .stat-item:hover,
    .button:hover {
        transform: scale(1.02) !important;
        transition: transform 0.2s ease !important;
    }
}

/* ========== 高分辨率屏幕优化 ========== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .online-visitors-widget {
        border: 0.5px solid rgba(255,255,255,0.2) !important;
    }
    
    .stat-item {
        border: 0.5px solid #e1e1e1 !important;
    }
}

/* ========== 打印样式优化 ========== */
@media print {
    .online-visitors-widget {
        display: none !important;
    }
    
    .visitor-stats-card,
    .stat-item {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
}

/* ========== 可访问性优化 ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== 强制覆盖WordPress默认样式 ========== */
@media (max-width: 768px) {
    .wp-admin {
        min-width: 0 !important;
    }
    
    #wpcontent,
    #wpbody,
    #wpbody-content {
        margin: 0 !important;
        padding: 0 10px !important;
        min-width: 0 !important;
    }
    
    .wrap {
        margin: 10px 0 !important;
        padding: 0 !important;
    }
    
    /* 强制移除所有固定宽度 */
    .postbox,
    .card,
    .visitor-stats-card,
    .form-table,
    .widefat {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
}

/* Page Performance 和 Popular Pages 样式优化 */
.page-performance-item {
    transition: all 0.3s ease;
    cursor: pointer;
}

.page-performance-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.page-performance-item a {
    transition: color 0.3s ease;
}

.page-performance-item a:hover {
    color: #667eea !important;
    text-decoration: none;
}

.page-url-display {
    font-family: 'Courier New', monospace;
    background: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #e1e5e9;
    word-break: break-all;
    font-size: 12px;
    color: #666;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .page-performance-item {
        padding: 10px !important;
        margin-bottom: 10px !important;
    }
    
    .page-performance-item a {
        font-size: 13px !important;
    }
    
    .page-url-display {
        font-size: 11px !important;
        padding: 3px 6px !important;
    }
}

/* ========== Popular Pages 和 Page Performance 高度限制优化 ========== */

/* Popular Pages 容器高度限制 - 只显示2个卡片 */
#pages-panel {
    max-height: 80px !important;
    overflow-y: auto !important;
    scrollbar-width: thin !important;
    scrollbar-color: #ccc #f1f1f1 !important;
}

#pages-panel::-webkit-scrollbar {
    width: 8px !important;
}

#pages-panel::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 4px !important;
}

#pages-panel::-webkit-scrollbar-thumb {
    background: #ccc !important;
    border-radius: 4px !important;
}

#pages-panel::-webkit-scrollbar-thumb:hover {
    background: #999 !important;
}

#pages-list {
    max-height: 200px !important;
    overflow-y: auto !important;
    padding-right: 5px !important;
}

/* Page Performance 容器高度限制 - 显示更多内容 */
div[style*="📊"] {
    max-height: 200px !important;
    overflow-y: auto !important;
}

/* 更精确的Page Performance选择器 */
div:has(h4:contains("Page Performance (7 Days)")) {
    max-height: 200px !important;
    overflow-y: auto !important;
    scrollbar-width: thin !important;
    scrollbar-color: #ccc #f1f1f1 !important;
}

/* 通用的页面性能容器样式 */
.page-performance-container {
    max-height: 200px !important;
    overflow-y: auto !important;
    scrollbar-width: thin !important;
    scrollbar-color: #ccc #f1f1f1 !important;
}

.page-performance-container::-webkit-scrollbar {
    width: 8px !important;
}

.page-performance-container::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 4px !important;
}

.page-performance-container::-webkit-scrollbar-thumb {
    background: #ccc !important;
    border-radius: 4px !important;
}

.page-performance-container::-webkit-scrollbar-thumb:hover {
    background: #999 !important;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .page-performance-item {
        padding: 10px !important;
        margin-bottom: 10px !important;
    }
    
    .page-performance-item a {
        font-size: 13px !important;
    }
    
    .page-url-display {
        font-size: 11px !important;
        padding: 3px 6px !important;
    }
}

/* 滚动渐变效果 */
#pages-panel::before,
.page-performance-container::before {
    content: "" !important;
    position: sticky !important;
    top: 0 !important;
    height: 8px !important;
    background: linear-gradient(to bottom, rgba(255,255,255,1), rgba(255,255,255,0)) !important;
    z-index: 1 !important;
    pointer-events: none !important;
}

#pages-panel::after,
.page-performance-container::after {
    content: "" !important;
    position: sticky !important;
    bottom: 0 !important;
    height: 8px !important;
    background: linear-gradient(to top, rgba(255,255,255,1), rgba(255,255,255,0)) !important;
    z-index: 1 !important;
    pointer-events: none !important;
}

/* 在线状态样式 */
.online-status.online {
    color: #4caf50;
    font-weight: bold;
}

.online-status.offline {
    color: #757575;
}

/* 状态徽章样式 */
.status-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

.status-new {
    background: #e3f2fd;
    color: #1976d2;
}

.status-assigned {
    background: #f3e5f5;
    color: #7b1fa2;
}

.status-completed {
    background: #e8f5e8;
    color: #388e3c;
}

/* 优先级徽章样式 */
.priority-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.priority-high {
    background: #ffebee;
    color: #d32f2f;
}

.priority-medium {
    background: #fff3e0;
    color: #f57c00;
}

.priority-low {
    background: #e8f5e8;
    color: #388e3c;
}

/* WhatsApp链接样式 */
a[href*="wa.me"]:hover {
    color: #128c7e !important;
    text-decoration: underline !important;
}