/* ===== Page Insights Styles ===== */

/* ===== Period Selector ===== */
.period-btn {
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary, #aaa);
    transition: all 0.2s;
}
.period-btn:hover {
    border-color: var(--primary, #2d79f3);
    color: var(--primary, #2d79f3);
}
.period-btn.active {
    background: var(--primary, #2d79f3);
    border-color: var(--primary, #2d79f3);
    color: #fff;
}

/* ===== Column Picker ===== */
.insights-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 8px 12px;
    gap: 8px;
}

.col-picker-wrap {
    position: relative;
}

.btn-col-picker {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-col-picker:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.col-picker-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    min-width: 260px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    padding: 8px 0;
}

.col-picker-dropdown.show {
    display: block;
}

.col-picker-dropdown label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-primary);
    transition: background 0.15s;
    user-select: none;
}

.col-picker-dropdown label:hover {
    background: rgba(108, 92, 231, 0.06);
}

.col-picker-dropdown label input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.col-picker-dropdown .col-picker-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    color: #fff;
    font-size: 0.6rem;
    flex-shrink: 0;
}

.col-picker-dropdown .col-picker-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.col-picker-dropdown .col-picker-actions button {
    flex: 1;
    padding: 6px 0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: opacity 0.15s;
}

.col-picker-dropdown .col-picker-actions button:hover {
    opacity: 0.85;
}

.col-picker-dropdown .col-picker-actions .btn-pick-all {
    background: var(--primary);
    color: #fff;
}

.col-picker-dropdown .col-picker-actions .btn-pick-none {
    background: var(--border);
    color: var(--text-secondary);
}

/* ===== Table Wrap — horizontal scroll ===== */
.insights-table-wrap {
    overflow-x: auto !important;
    overflow-y: visible;
    padding: 0;
    position: relative;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.insights-table-wrap::-webkit-scrollbar {
    height: 10px;
}
.insights-table-wrap::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 5px;
}
.insights-table-wrap::-webkit-scrollbar-thumb {
    background: #aaa;
    border-radius: 5px;
}
.insights-table-wrap::-webkit-scrollbar-thumb:hover {
    background: #888;
}

/* ===== Insights Table ===== */
.insights-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.insights-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 12px 14px;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    text-align: center;
}

/* Sticky first column (เพจ) */
.insights-table thead th:first-child {
    text-align: left;
    min-width: 240px;
    position: sticky;
    left: 0;
    z-index: 12;
    background: var(--bg-card);
}

.insights-table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--bg-card);
}

.insights-table tbody tr:hover td:first-child {
    background: #f3f1ff;
}

/* Shadow hint on sticky column */
.insights-table thead th:first-child::after,
.insights-table tbody td:first-child::after {
    content: '';
    position: absolute;
    top: 0;
    right: -6px;
    width: 6px;
    height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.06), transparent);
    pointer-events: none;
}

.insights-table thead th:last-child {
    text-align: center;
    min-width: 100px;
}

.insights-table tbody tr {
    transition: background 0.2s;
}

.insights-table tbody tr:hover {
    background: rgba(108, 92, 231, 0.04);
}

.insights-table tbody tr.selected {
    background: rgba(108, 92, 231, 0.07);
}

.insights-table tbody tr + tr td {
    border-top: 1px solid var(--border);
}

.insights-table td {
    padding: 14px 14px;
    vertical-align: middle;
    white-space: nowrap;
}

/* Page Info Cell */
.insights-table .cell-page {
    display: flex;
    align-items: center;
    gap: 12px;
}

.insights-table .cell-page img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
    flex-shrink: 0;
}

.insights-table .cell-page .page-name {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-primary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.insights-table .cell-page .page-sub {
    font-size: 0.73rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

/* Metric Cell */
.insights-table .cell-metric {
    text-align: center;
    min-width: 100px;
}

.insights-table .cell-metric .metric-val {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.insights-table .cell-metric .metric-change {
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.insights-table .cell-metric .metric-change.up { color: #00B894; }
.insights-table .cell-metric .metric-change.down { color: #E17055; }
.insights-table .cell-metric .metric-change.neutral { color: var(--text-muted); }

/* Metric Header Icon */
.th-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    color: #fff;
    font-size: 0.65rem;
    margin-bottom: 4px;
}

/* Actions Cell */
.insights-table .cell-actions {
    text-align: center;
}

.insights-table .cell-actions button {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin: 0 2px;
}

.insights-table .cell-actions .btn-select {
    background: var(--primary);
    color: #fff;
    opacity: 0.4;
}

.insights-table tbody tr:hover .btn-select,
.insights-table .cell-actions .btn-select.active {
    opacity: 1;
}

.insights-table .cell-actions .btn-select.active {
    background: var(--success);
}

.insights-table .cell-actions .btn-remove {
    background: var(--danger);
    color: #fff;
    opacity: 0.4;
}

.insights-table tbody tr:hover .btn-remove {
    opacity: 1;
}

/* Updated time cell */
.insights-table .cell-updated {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* No Data in Row */
.insights-table .cell-nodata {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

/* Fire animation - 3 ระดับ */
.fire-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.9rem;
    line-height: 1;
}

/* Level 1: 🔥 โดดเล็ก (2x) - เต้นช้า */
.fire-badge.fire-lv1 {
    animation: firePulse1 1.8s ease-in-out infinite alternate;
}

/* Level 2: 🔥🔥 โดดแรง (5x) - เต้นเร็วขึ้น */
.fire-badge.fire-lv2 {
    animation: firePulse2 1.2s ease-in-out infinite alternate;
    font-size: 0.95rem;
}

/* Level 3: 🔥🔥🔥 ไวรัล (10x) - เต้นเร็ว + เรืองแสง */
.fire-badge.fire-lv3 {
    animation: firePulse3 0.8s ease-in-out infinite alternate;
    font-size: 1rem;
    filter: drop-shadow(0 0 4px rgba(255, 100, 0, 0.6));
}

@keyframes firePulse1 {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

@keyframes firePulse2 {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.15); filter: brightness(1.2); }
}

@keyframes firePulse3 {
    0% { transform: scale(1); filter: brightness(1) drop-shadow(0 0 4px rgba(255,100,0,0.4)); }
    50% { transform: scale(1.2); filter: brightness(1.4) drop-shadow(0 0 8px rgba(255,60,0,0.7)); }
    100% { transform: scale(1.05); filter: brightness(1.1) drop-shadow(0 0 4px rgba(255,100,0,0.4)); }
}

/* Percentage bar animation */
.percent-bar-wrap {
    width: 100%;
    height: 4px;
    background: rgba(0,0,0,0.06);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.percent-bar {
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

.percent-bar.hot {
    background: linear-gradient(90deg, #F9A825, #E17055, #E74C3C);
}

/* Counter animation */
.count-up {
    display: inline-block;
}

/* Last Updated */
.insights-last-updated {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Fetched Pages List */
.insights-fetched-page {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.insights-fetched-page:last-child {
    border-bottom: none;
}

.insights-fetched-page:hover {
    background: var(--bg-card-hover);
}

.insights-fetched-page .page-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.insights-fetched-page img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.insights-fetched-page .page-info h4 {
    font-size: 0.88rem;
    font-weight: 600;
}

.insights-fetched-page .page-info span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.insights-fetched-page .btn-track {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.insights-fetched-page .btn-track.track {
    background: var(--primary);
    color: #fff;
}

.insights-fetched-page .btn-track.track:hover {
    background: var(--primary-dark);
}

.insights-fetched-page .btn-track.tracked {
    background: var(--success);
    color: #fff;
}

.insights-fetched-page .btn-track.untrack {
    background: var(--danger);
    color: #fff;
}

/* Token List for Insights */
.insights-token-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

.insights-token-item:last-child {
    border-bottom: none;
}

.insights-token-item .token-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.insights-token-item .token-info .token-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.insights-token-item .token-info .token-name {
    font-weight: 600;
    font-size: 0.88rem;
}

.insights-token-item .token-info .token-meta {
    font-size: 0.73rem;
    color: var(--text-muted);
}

.insights-token-item .token-actions {
    display: flex;
    gap: 6px;
}

.insights-token-item .token-actions button {
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

/* Update progress */
.insights-update-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(108,92,231,0.06);
    border-radius: 10px;
    margin-bottom: 16px;
}

.insights-update-progress .progress-bar-outer {
    flex: 1;
    height: 8px;
    background: rgba(0,0,0,0.08);
    border-radius: 4px;
    overflow: hidden;
}

.insights-update-progress .progress-bar-inner {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.insights-update-progress .progress-text {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Responsive */
@media (max-width: 768px) {
    .insights-table {
        font-size: 0.78rem;
    }
    .insights-table td,
    .insights-table thead th {
        padding: 10px 8px;
    }
    .insights-table .cell-page img {
        width: 34px;
        height: 34px;
    }
    .insights-table .cell-metric .metric-val {
        font-size: 0.88rem;
    }
}

/* Pulse dot for live-updated pages */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.5); }
    70% { box-shadow: 0 0 0 8px rgba(0, 184, 148, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 184, 148, 0); }
}

/* Number count up animation */
@keyframes countFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-count {
    animation: countFadeIn 0.6s ease forwards;
}

/* Sparkle effect for fire items */
.sparkle {
    position: relative;
}

.sparkle::after {
    content: '✨';
    position: absolute;
    top: -4px;
    right: -8px;
    font-size: 0.6rem;
    animation: sparkleFloat 2s ease-in-out infinite;
}

@keyframes sparkleFloat {
    0%, 100% { transform: translateY(0) scale(1); opacity: 1; }
    50% { transform: translateY(-6px) scale(1.2); opacity: 0.6; }
}
