/**
 * opti-behavior Heatmap Modern Dashboard Styles
 *
 * @package opti-behavior-heatmap
 * @version 1.0.0
 */

/* Reset and base styles */
.opti-behavior-dashboard,
.opti-behavior-sessions,
.opti-behavior-heatmaps,
.opti-behavior-analytics {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: #f1f1f1;
    margin: 0;
    padding: 0;
}

.opti-behavior-dashboard .wrap,
.opti-behavior-sessions .wrap,
.opti-behavior-heatmaps .wrap,
.opti-behavior-analytics .wrap {
    background: transparent;
    margin: 20px 0 0 0;
    padding: 0;
}

/* Dashboard header */
.opti-behavior-dashboard h1 {
    color: #1e293b;
    font-size: 2rem;
    font-weight: 600;
    margin: 0 0 2rem 0;
    padding: 0;
}

/* Dashboard grid layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Stats cards */
.stats-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.stats-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.stats-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.stats-card-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-card-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.stats-card-icon.sessions {
    background: #dbeafe;
    color: #2563eb;
}

.stats-card-icon.visitors {
    background: #dcfce7;
    color: #16a34a;
}

.stats-card-icon.pageviews {
    background: #fef3c7;
    color: #d97706;
}

.stats-card-icon.bounce {
    background: #fee2e2;
    color: #dc2626;
}

.stats-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.stats-card-change {
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stats-card-change.positive {
    color: #16a34a;
}

.stats-card-change.negative {
    color: #dc2626;
}

.stats-card-change.neutral {
    color: #64748b;
}

/* Chart containers */
.chart-container {
    background: #ffffff;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    margin-bottom: 1.5rem;
    height: 400px; /* Fixed height to prevent huge charts */
    max-height: 400px;
    overflow: hidden;
}

/* Chart canvas sizing */
.chart-container canvas {
    max-height: 300px !important;
    height: 300px !important;
    width: 100% !important;
}

/* Specific chart containers */
#sessions-chart {
    max-height: 300px !important;
    height: 300px !important;
    width: 100% !important;
}

/* Chart wrapper for better control */
.chart-wrapper {
    position: relative;
    height: 300px;
    max-height: 300px;
    width: 100%;
    overflow: hidden;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.chart-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
}

.chart-filters {
    display: flex;
    gap: 0.5rem;
}

.chart-filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-filter-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.chart-filter-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

/* Session recordings table */
.sessions-table {
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.sessions-table-header {
    background: #f8fafc;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sessions-table-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
}

.sessions-table-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.sessions-table-search {
    padding: 0.5rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.875rem;
    width: 200px;
}

.sessions-table-body {
    overflow-x: auto;
}

.sessions-table table {
    width: 100%;
    border-collapse: collapse;
}

.sessions-table th,
.sessions-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}

.sessions-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #374151;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sessions-table td {
    color: #1e293b;
    font-size: 0.875rem;
}

.sessions-table tr:hover {
    background: #f8fafc;
}

/* Session row elements */
.session-id {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.75rem;
    color: #6b7280;
}

.session-duration {
    font-weight: 600;
    color: #1e293b;
}

.session-pages {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.session-device {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.device-icon {
    width: 1rem;
    height: 1rem;
    opacity: 0.7;
}

.session-country {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.country-flag {
    width: 1rem;
    height: 1rem;
    border-radius: 2px;
}

.visitor-flag-icon {
    width: 1rem;
    height: 0.75rem;
    object-fit: cover;
    border-radius: 2px;
    margin-right: 0.5rem;
    display: inline-block;
    vertical-align: middle;
}

.session-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.25rem 0.75rem;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.action-btn.primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.action-btn.primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* Loading states */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: #64748b;
}

.loading-spinner {
    width: 2rem;
    height: 2rem;
    border: 2px solid #e2e8f0;
    border-top: 2px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.75rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Widget Empty State Fixes */
/* Fix Real-time Visitors widget container to prevent scrollbars */
.realtime-widget .widget-content {
    overflow: auto !important;
    height: 400px !important;
    max-height: 400px !important;
}

.realtime-widget .realtime-visitors {
    height: 100% !important;
    max-height: 400px !important;
    overflow: auto !important;
}

/* Fix Real-time Visitors widget empty state to fill widget properly */
.realtime-widget .optibehavior-empty-state {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 400px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 20px !important;
    box-sizing: border-box !important;
}

/* Ensure the container has relative positioning for absolute positioning to work */
.realtime-widget .realtime-visitors {
    position: relative !important;
}

/* Fix Real-time Visitors widget no-visitors state (JavaScript generated) */
.dashboard-widget.realtime-widget .no-visitors {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    max-height: 400px !important;
    width: 100% !important;
    text-align: center !important;
    color: #6b7280 !important;
    padding: 20px !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

.dashboard-widget.realtime-widget .no-visitors p {
    margin: 0 !important;
    font-size: 14px !important;
    color: #6b7280 !important;
}

/* Responsive design */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .sessions-table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .sessions-table-filters {
        width: 100%;
        justify-content: space-between;
    }

    .sessions-table-search {
        width: 100%;
    }
}

/* 3-Column Analytics Layout - Modern Professional Design */
.optibehavior-analytics-container {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: none;
    border-radius: 20px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    position: relative;
}

.optibehavior-analytics-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6 0%, #10b981 50%, #ef4444 100%);
}

.optibehavior-analytics-grid {
    display: flex !important;
    flex-direction: row !important;
    gap: 16px;
    min-height: 350px;
    width: 100% !important;
    align-items: stretch;
}

.optibehavior-analytics-column {
    padding: 24px;
    background: #ffffff;
    display: flex !important;
    flex-direction: column !important;
    position: relative;
    transition: all 0.3s ease;
    flex: 1 1 33.333% !important;
    width: 33.333% !important;
    min-width: 0 !important;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.optibehavior-analytics-column:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}


.optibehavior-column-header {
    display: flex !important;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    text-align: left;
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid #e5e7eb;
}

.optibehavior-column-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.1;
    background: radial-gradient(circle at center, currentColor 0%, transparent 70%);
}

.optibehavior-column-icon {
    font-size: 20px;
    margin: 0;
    display: inline-block;
    align-self: center;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.optibehavior-column-title {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.025em;
}

.optibehavior-column-subtitle {
    font-size: 13px;
    color: #64748b;
    margin: 0;
    font-weight: 500;
    flex-basis: 100%;
    padding-left: 42px; /* 32px icon + 10px gap */
}

.optibehavior-column-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Entry Column Styles - Blue Theme */
.optibehavior-entry-column .optibehavior-column-header {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border: 1px solid #93c5fd;
}

.optibehavior-entry-column .optibehavior-column-icon {
    color: #1d4ed8;
}

.optibehavior-entry-column .optibehavior-column-title {
    color: #1e40af;
}

/* Behavior Column Styles - Green Theme */
.optibehavior-behavior-column .optibehavior-column-header {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border: 1px solid #86efac;
}

.optibehavior-behavior-column .optibehavior-column-icon {
    color: #15803d;
}

.optibehavior-behavior-column .optibehavior-column-title {
    color: #166534;
}

.optibehavior-behavior-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.optibehavior-behavior-stat {
    text-align: center;
    padding: 16px 12px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.optibehavior-behavior-stat::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #10b981, #059669);
}

.optibehavior-behavior-stat:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.optibehavior-behavior-label {
    font-size: 10px;
    color: #64748b;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.optibehavior-behavior-value {
    font-size: 16px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
}

/* Exit Column Styles - Red Theme */
.optibehavior-exit-column .optibehavior-column-header {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border: 1px solid #fca5a5;
}

.optibehavior-exit-column .optibehavior-column-icon {
    color: #dc2626;
}

.optibehavior-exit-column .optibehavior-column-title {
    color: #991b1b;
}

/* Referrer and Outbound Click Item Styles */
#optibehavior-referrers-content,
#optibehavior-outbound-content {
    min-height: 60px;
}

#optibehavior-referrers-list > div,
#optibehavior-outbound-list > div {
    display: grid;
    gap: 8px;
}

#optibehavior-referrers-list > div > div,
#optibehavior-outbound-list > div > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 12px;
    margin-bottom: 10px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#optibehavior-referrers-list > div > div::before,
#optibehavior-outbound-list > div > div::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 4px;
    transition: all 0.3s ease;
}

#optibehavior-referrers-list > div > div::before {
    background: linear-gradient(180deg, #3b82f6 0%, #1d4ed8 100%);
}

#optibehavior-outbound-list > div > div::before {
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
}

#optibehavior-referrers-list > div > div:hover,
#optibehavior-outbound-list > div > div:hover {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#optibehavior-referrers-list > div > div:hover::before,
#optibehavior-outbound-list > div > div:hover::before {
    width: 6px;
}

#optibehavior-referrers-list > div > div:last-child,
#optibehavior-outbound-list > div > div:last-child {
    margin-bottom: 0;
}

#optibehavior-referrers-list > div > div > div:first-child,
#optibehavior-outbound-list > div > div > div:first-child {
    flex: 1;
    font-weight: 600;
    color: #1e293b;
    font-size: 14px;
    line-height: 1.4;
}

#optibehavior-referrers-list > div > div > div:last-child,
#optibehavior-outbound-list > div > div > div:last-child {
    font-size: 12px;
    color: #ffffff;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
    min-width: 60px;
    text-align: center;
}

/* Loading and Empty States */
.optibehavior-loading {
    text-align: center;
    padding: 48px 20px;
    color: #64748b;
    font-style: italic;
    font-size: 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    border: 1px dashed #cbd5e1;
}

.optibehavior-empty {
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
    font-size: 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    border: 1px dashed #cbd5e1;
}

/* Controls Row */
.optibehavior-controls-row {
    border-top: 1px solid #e5e7eb;
    padding: 16px 24px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 0 0 20px 20px;
}

.optibehavior-heatmap-controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px 18px;
}

.optibehavior-heatmap-links {
    display: inline-flex;
    gap: 12px;
    white-space: nowrap;
}

.optibehavior-heatmap-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.optibehavior-heatmap-link:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

.optibehavior-time-filters {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
    background: #ffffff;
    padding: 6px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    white-space: nowrap;
}

.optibehavior-time-filter {
    padding: 8px 16px;
    background: transparent;
    color: #64748b;
    text-decoration: none;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    white-space: nowrap;
}

.optibehavior-time-filter:hover {
    background: #f1f5f9;
    color: #475569;
    transform: translateY(-1px);
}

.optibehavior-time-filter.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

/* Responsive Design - Only stack on very small phones */
@media (max-width: 480px) {
    .optibehavior-analytics-grid {
        flex-direction: column !important;
        gap: 1px;
    }

    .optibehavior-analytics-column {
        padding: 20px;
        background: #ffffff;
        width: 100% !important;
        flex: none !important;
    }

    .optibehavior-analytics-column:first-child {
        border-radius: 20px 20px 0 0;
    }

    .optibehavior-analytics-column:last-child {
        border-radius: 0 0 20px 20px;
    }

    .optibehavior-analytics-column:only-child {
        border-radius: 20px;
    }

    .optibehavior-behavior-stats {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .optibehavior-heatmap-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .optibehavior-heatmap-links {
        justify-content: center;
    }

    .optibehavior-time-filters {
        justify-content: center;
    }
}

@media (max-width: 400px) {
    .optibehavior-analytics-column {
        padding: 16px;
    }

    .optibehavior-column-header {
        padding: 16px 12px;
        margin-bottom: 20px;
    }

    .optibehavior-column-icon {
        font-size: 28px;
        margin-bottom: 10px;
    }

    .optibehavior-column-title {
        font-size: 16px;
    }

    .optibehavior-behavior-stats {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .optibehavior-behavior-stat {
        padding: 12px 10px;
    }

    .optibehavior-behavior-value {
        font-size: 14px;
    }

    #optibehavior-referrers-list > div > div,
    #optibehavior-outbound-list > div > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px;
    }

    #optibehavior-referrers-list > div > div > div:last-child,
    #optibehavior-outbound-list > div > div > div:last-child {
        align-self: flex-end;
    }

    .optibehavior-heatmap-link {
        padding: 10px 16px;
        font-size: 13px;
    }

    .optibehavior-time-filters {
        gap: 4px;
        padding: 4px;
    }

    .optibehavior-time-filter {
        padding: 6px 12px;
        font-size: 11px;
    }
}

/* ========================================================================
   Additional Dashboard Styles (Previously in dashboard-custom.css)
   ======================================================================== */

/* Realtime Map Styles */
/* Vertical tooltips on the real-time map (avoid horizontal cropping) */
#realtime-map .leaflet-tooltip,
.realtime-map .leaflet-tooltip {
    font-size: 11px !important;
    line-height: 1.2;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #cbd5e1;
}

#realtime-map .leaflet-tooltip .leaflet-tooltip-content {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: normal;
}

/* Pulsing blue live marker */
.leaflet-div-icon.realtime-pulse-icon,
.leaflet-marker-icon.realtime-pulse-icon {
    position: absolute !important;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
}

/* Realtime pulse marker - larger and more visible */
.leaflet-div-icon.realtime-pulse-icon::before,
.leaflet-marker-icon.realtime-pulse-icon::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin-left: -20px;
    margin-top: -20px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.3);
    animation: rt-pulse 1.5s ease-out infinite;
}

.leaflet-div-icon.realtime-pulse-icon::after,
.leaflet-marker-icon.realtime-pulse-icon::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin-left: -6px;
    margin-top: -6px;
    border-radius: 50%;
    background: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.6), 0 0 10px rgba(59, 130, 246, 0.8);
}

@keyframes rt-pulse {
    0% {
        transform: scale(0.3);
        opacity: 1;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

@keyframes spn {
    to {
        transform: rotate(360deg);
    }
}

/* Heatmap Table Styles */
.heatmaps-panel [data-optibehavior-table] {
    --chip-bg: #3b82f6;
    --chip-ring: #dbeafe;
}

/* Modern compact chips for actions */
.optibehavior-chip {
    --bg: #6757e8;
    --fg: #fff;
    --ring: #dcd7ff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 28px;
    width: 84px;
    padding: 0 8px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
    text-decoration: none;
    box-shadow: 0 0 0 1px var(--ring) inset;
    transition: background 0.2s ease, transform 0.05s ease;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.optibehavior-chip:hover {
    filter: saturate(1.1);
    transform: translateY(-1px);
}

.optibehavior-chip:focus {
    outline: 2px solid #3858e9;
    outline-offset: 2px;
}

.optibehavior-chip .optibehavior-icon {
    width: 14px;
    height: 14px;
    opacity: 0.95;
}

.optibehavior-chip .optibehavior-count {
    min-width: 0;
}

/* Chip Variants */
.optibehavior-chip.is-mixed {
    --bg: #6c5ce7;
    --ring: #dcd7ff;
}

.optibehavior-chip.is-desktop {
    --bg: #10b981;
    --ring: #ccf1e3;
}

.optibehavior-chip.is-mobile {
    --bg: #f472b6;
    --ring: #ffd6e9;
}

/* Actions cell layout */
.heatmaps-panel [data-optibehavior-table] td.actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}

/* Standardize WP admin-sized buttons in the Actions column */
.optibehavior-btn.button {
    height: 28px;
    line-height: 26px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.optibehavior-btn {
    min-width: 118px;
    text-align: center;
}

.optibehavior-btn .optibehavior-btn-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

/* Loading State */
.heatmaps-panel.is-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Table Wrapper */
[data-optibehavior-table-wrapper] {
    margin-top: 20px;
}

/* Simplified Heatmap Table */
.simplified-heatmap-table {
    width: 100%;
    border-collapse: collapse;
}

.simplified-heatmap-table th,
.simplified-heatmap-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.simplified-heatmap-table thead th {
    background: #f9fafb;
    font-weight: 600;
    cursor: pointer;
}

.simplified-heatmap-table thead th:hover {
    background: #f3f4f6;
}

.simplified-heatmap-table tbody tr:hover {
    background: #f9fafb;
}

/* Sortable Column Indicators */
.simplified-heatmap-table thead a[data-sort] {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
}

.simplified-heatmap-table thead a[data-sort]::after {
    content: "↕";
    opacity: 0.3;
}

.simplified-heatmap-table thead a[data-sort][data-active="1"]::after {
    opacity: 1;
}

.simplified-heatmap-table thead a[data-sort][data-current="asc"]::after {
    content: "↑";
}

.simplified-heatmap-table thead a[data-sort][data-current="desc"]::after {
    content: "↓";
}

/* Dashboard Stats Cards */
.dashboard-stats-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.dashboard-stats-card h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.dashboard-stats-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
}

/* Stat Value Loading Spinner */
.stat-value-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 4px solid #e2e8f0;
    border-top-color: #3B82F6;
    border-right-color: #3B82F6;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin: 8px 0;
}

.stat-value.is-loaded .stat-value-spinner {
    display: none;
}

.dashboard-stats-card .stat-label {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
}

/* Chart Containers */
.chart-container {
    position: relative;
    height: 300px;
    margin: 20px 0;
}

.chart-container canvas {
    max-height: 100%;
}

/* Period Selector */
#dashboard-period,
#start-date,
#end-date {
    padding: 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
}

/* Custom Date Range */
.custom-date-range {
    display: none;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.custom-date-range.active {
    display: flex;
}

/* Responsive Design for Additional Styles */
@media (max-width: 782px) {
    .optibehavior-btn {
        min-width: auto;
        padding: 0 8px;
    }

    .heatmaps-panel [data-optibehavior-table] td.actions {
        flex-direction: column;
        gap: 4px;
    }
}

/* Spinner animation */
@keyframes spn {
    to {
        transform: rotate(360deg);
    }
}

/* Force the table to fit the viewport even on small admin screens */
.heatmaps-panel .simplified-heatmap-table {
    overflow-x: hidden !important;
}

.heatmaps-panel .heatmap-table {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: collapse;
}

.heatmaps-panel .heatmap-table th,
.heatmaps-panel .heatmap-table td {
    padding: 10px 8px !important;
    box-sizing: border-box;
}

.heatmaps-panel [data-optibehavior-table] .page-info {
    width: 180px !important;
    max-width: 180px !important;
}

.heatmaps-panel [data-optibehavior-table] .page-title,
.heatmaps-panel [data-optibehavior-table] .page-url {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.heatmaps-panel [data-optibehavior-table] .page-url {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block !important;
}

.heatmaps-panel [data-optibehavior-table] td.actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: flex-end;
}

.heatmaps-panel [data-optibehavior-table] td.actions a {
    white-space: nowrap !important;
    padding: 4px 8px;
    font-size: 12px;
    width: 84px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}


/* Top Pages modern indicators */
.opti-behavior-dashboard .top-pages .page-item {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 4px;
	padding: 10px 12px;
	border-radius: 8px;
	border: 1px solid #e2e8f0;
	background: #ffffff;
	margin-bottom: 8px;
}

.opti-behavior-dashboard .top-pages .page-info {
	flex: 1;
	min-width: 0;
}

.opti-behavior-dashboard .top-pages .page-title-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	margin-bottom: 4px;
}

.opti-behavior-dashboard .top-pages .page-title {
	flex: 1 1 auto;
	min-width: 0;
	font-weight: 500;
	color: #0f172a;
	font-size: 13px;
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
}

.opti-behavior-dashboard .top-pages .page-actions {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	gap: 4px;
}

.opti-behavior-dashboard .top-pages .page-url {
	display: inline-block;
	font-size: 11px;
	color: #64748b;
	text-decoration: none;
	max-width: 100%;
	text-overflow: ellipsis;
	white-space: nowrap;
	overflow: hidden;
}

.opti-behavior-dashboard .top-pages .page-url:hover {
	color: #0f172a;
	text-decoration: underline;
}

.opti-behavior-dashboard .top-pages .page-stats {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 4px;
	min-width: 180px;
}

.opti-behavior-dashboard .top-pages .page-views-wrapper {
	margin-bottom: 2px;
}

.opti-behavior-dashboard .top-pages .page-views {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 11px;
	color: #0f172a;
}

.opti-behavior-dashboard .top-pages .page-views-icon {
	width: 14px;
	height: 14px;
	color: #f97316;
}

.opti-behavior-dashboard .top-pages .page-views-value {
	font-weight: 600;
}


.opti-behavior-dashboard .top-pages .page-views-change {
	margin-left: 6px;
	font-size: 10px;
	font-weight: 500;
}

.opti-behavior-dashboard .top-pages .page-views-change.positive {
	color: #16a34a;
}

.opti-behavior-dashboard .top-pages .page-views-change.negative {
	color: #dc2626;
}

.opti-behavior-dashboard .top-pages .page-views-change.neutral {
	color: #64748b;
}

.opti-behavior-dashboard .top-pages .page-views-label {
	color: #64748b;
}

.opti-behavior-dashboard .top-pages .page-clicks-indicator {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 10px;
}

.opti-behavior-dashboard .top-pages .click-pill {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 1px 6px;
	border-radius: 999px;
	background: #ecfdf5;
	color: #15803d;
	font-weight: 500;
	font-size: 10px;
}

.opti-behavior-dashboard .top-pages .click-pill-icon {
	width: 12px;
	height: 12px;
}

.opti-behavior-dashboard .top-pages .click-percentage-pill {
	padding: 2px 6px;
	border-radius: 999px;
	background: #eff6ff;
	color: #1d4ed8;
	font-weight: 500;
}

.opti-behavior-dashboard .top-pages .click-change {
	font-weight: 500;
}

.opti-behavior-dashboard .top-pages .click-change.positive {
	color: #16a34a;
}

.opti-behavior-dashboard .top-pages .click-change.negative {
	color: #dc2626;
}

.opti-behavior-dashboard .top-pages .click-change.neutral {
	color: #64748b;
}

.opti-behavior-dashboard .top-pages .page-item {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: flex-start;
	gap: 16px;
}

.opti-behavior-dashboard .top-pages .page-left {
	flex: 0 0 auto;
	min-width: 0;
}

.opti-behavior-dashboard .top-pages .page-right {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 4px;
}

/* Top Pages compact metrics row (Level 2) */
.opti-behavior-dashboard .top-pages .page-metrics {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	justify-content: flex-end;
	gap: 16px;
	margin-top: 2px;
	margin-bottom: 2px;
}

.opti-behavior-dashboard .top-pages .metric {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 11px;
	color: #0f172a;
}

.opti-behavior-dashboard .top-pages .metric-icon {
	width: 14px;
	height: 14px;
}

.opti-behavior-dashboard .top-pages .metric-views .metric-icon {
	color: #f97316; /* flame */
}

.opti-behavior-dashboard .top-pages .metric-clicks .metric-icon {
	color: #0f766e; /* clicks */
}

.opti-behavior-dashboard .top-pages .metric-value {
	font-weight: 600;
}

.opti-behavior-dashboard .top-pages .metric-change {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	font-size: 10px;
	font-weight: 600;
	padding: 2px 6px;
	border-radius: 999px;
}

.opti-behavior-dashboard .top-pages .metric-arrow {
	font-size: 10px;
}

.opti-behavior-dashboard .top-pages .metric-change.positive {
	color: #16a34a; /* green */
	background-color: #dcfce7; /* light green */
}

.opti-behavior-dashboard .top-pages .metric-change.negative {
	color: #dc2626; /* red */
	background-color: #fee2e2; /* light red */
}

.opti-behavior-dashboard .top-pages .metric-change.neutral {
	color: #64748b; /* gray */
	background-color: #e5e7eb; /* light gray */
}


/* Top Pages heatmap buttons alignment and icon sizing */
.opti-behavior-dashboard .top-pages .page-actions {
	align-items: center;
}

.opti-behavior-dashboard .pages-widget .optibehavior-heatmap-btn {
	padding: 4px 10px;
	min-height: 24px;
	font-size: 11px;
}

.opti-behavior-dashboard .pages-widget .optibehavior-heatmap-btn svg {
	width: 14px;
	height: 14px;
}

/* Top Countries Widget - Shared vertical scroll treatment (same as Bot Traffic + Top Referrers) */
.countries-widget .countries-table-container {
    max-height: 290px; /* show ~8 countries before scroll (8 x 36px rows + buffer) */
    overflow-y: auto;   /* show scrollbar when there are many entries */
    margin-right: -24px; /* push scrollbar to widget border */
    padding-right: 24px; /* keep content aligned with other widgets */
}

/* ============================================
   MODERN LOADING INDICATOR
   ============================================ */

/* Loading overlay for widgets */
.widget-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.widget-loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Modern spinner */
.widget-spinner {
    position: relative;
    width: 48px;
    height: 48px;
}

.widget-spinner::before,
.widget-spinner::after {
    content: '';
    position: absolute;
    border-radius: 50%;
}

/* Outer spinning ring */
.widget-spinner::before {
    width: 48px;
    height: 48px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-right-color: #3b82f6;
    animation: widget-spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* Inner pulsing dot */
.widget-spinner::after {
    width: 12px;
    height: 12px;
    background: #3b82f6;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: widget-pulse 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes widget-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes widget-pulse {
    0%, 100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* Widget container needs position relative for overlay */
.dashboard-widget {
    position: relative;
}

.stats-card {
    position: relative;
}
