/**
 * Country Analytics Stylesheet
 */

.page-country-analytics {
    padding: 30px 0;
}

.page-country-analytics h1 {
    margin-bottom: 10px;
    color: #333;
}

.page-country-analytics .description {
    color: #666;
    margin-bottom: 30px;
    font-size: 16px;
}

/* Loading Spinner */
.analytics-loading {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Spin animation for refresh icons */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Error Display */
.analytics-error {
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 4px;
    padding: 20px;
    margin: 20px 0;
}

.analytics-error .error-message {
    color: #c33;
    margin: 0;
}

/* Summary Cards */
.obj_article_details .analytics-summary,
.country-analytics-widget .analytics-summary,
.analytics-summary {
    display: flex !important;
    gap: 20px !important;
    margin-bottom: 30px !important;
    flex-wrap: wrap !important;
}

.obj_article_details .summary-card,
.country-analytics-widget .summary-card,
.summary-card {
    flex: 1 !important;
    min-width: 200px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    padding: 25px !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
}

.obj_article_details .summary-card h3,
.country-analytics-widget .summary-card h3,
.summary-card h3 {
    margin: 0 0 10px 0 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    opacity: 0.9 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

.obj_article_details .summary-card .summary-number,
.country-analytics-widget .summary-card .summary-number,
.summary-card .summary-number {
    margin: 0 !important;
    font-size: 36px !important;
    font-weight: 700 !important;
}

/* Table Container */
.analytics-table-container {
    overflow-x: auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin-bottom: 30px;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    border: 1px solid #e8ecef;
}

/* Table Styles */
.analytics-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
    margin: 0;
    border: none;
}

.analytics-table th,
.analytics-table td {
    border: none;
}

.analytics-table tbody td {
    border-right: 1px solid #e8ecef;
}

.analytics-table tbody td:last-child {
    border-right: none;
}

.analytics-table thead tr:first-child {
    background: #fafbfc;
}

.analytics-table th {
    padding: 16px 18px;
    text-align: center;
    font-weight: 600;
    color: #2d3748;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: none;
}

.analytics-table thead tr:first-child th {
    font-size: 14px;
    padding: 18px;
    border-bottom: 1px solid #e0e4e8;
}

.analytics-table tr.sub-header {
    background: #f5f7fa;
}

.analytics-table tr.sub-header th {
    padding: 12px 18px;
    font-size: 12px;
    font-weight: 600;
    color: #4a5568;
    border-bottom: 3px solid #667eea;
}

.analytics-table tbody tr {
    border-bottom: 1px solid #f0f3f5;
    transition: all 0.2s ease;
}

.analytics-table tbody tr:hover {
    background-color: #f8fafe;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.08);
}

.analytics-table tbody tr:last-child {
    border-bottom: none;
}

.analytics-table tbody tr:nth-child(odd) {
    background-color: #fafbfc;
}

.analytics-table td {
    padding: 16px 18px;
    color: #2d3748;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

.analytics-table td.views-cell {
    text-align: center;
    font-weight: 600;
    color: #1a202c;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.analytics-table td.country-cell {
    text-align: left !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
}

/* YoY % Change Cell Styles */
.analytics-table td.yoy-cell {
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

.yoy-change {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
}

.yoy-change.positive {
    color: #059669;
    background-color: #d1fae5;
}

.yoy-change.negative {
    color: #dc2626;
    background-color: #fee2e2;
}

.yoy-change.neutral {
    color: #6b7280;
    background-color: #f3f4f6;
}

.yoy-arrow {
    font-size: 14px;
    font-weight: bold;
}

/* Country Cell with Flag */
.country-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
}

.country-flag {
    width: 32px;
    height: 24px;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.country-cell span {
    font-weight: 500;
    color: #2d3748;
}

/* Percentage Bar */
.percentage-bar-container {
    position: relative;
    width: 100%;
    max-width: 200px;
}

.percentage-bar {
    height: 24px;
    background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.percentage-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 600;
    font-size: 12px;
    color: #333;
    text-shadow: 0 0 3px white;
}

/* Last Updated */
.last-updated {
    text-align: right;
    color: #6c757d;
    font-size: 14px;
    padding: 10px 0;
}

/* Responsive Design */

/* Tablet Landscape (1024px - 768px) */
@media (max-width: 1024px) {
    .analytics-table {
        min-width: 650px;
    }

    .analytics-table th,
    .analytics-table td {
        padding: 14px 12px;
        font-size: 13px;
    }

    .country-flag {
        width: 28px;
        height: 21px;
    }
}

/* Tablet Portrait (768px - 480px) */
@media (max-width: 768px) {
    .page-country-analytics h1 {
        font-size: 1.5rem !important;
    }

    .page-country-analytics h2 {
        font-size: 0.85rem !important;
    }

    .page-country-analytics .description {
        font-size: 0.8rem !important;
        flex-wrap: wrap;
    }

    .analytics-summary {
        flex-direction: column !important;
        gap: 15px !important;
    }

    .summary-card {
        min-width: 100% !important;
    }

    .analytics-table-container {
        border-radius: 8px;
        margin-bottom: 20px;
    }

    .analytics-table {
        min-width: 600px;
    }

    .analytics-table th,
    .analytics-table td {
        padding: 12px 10px;
        font-size: 12px;
    }

    .country-flag {
        width: 24px;
        height: 18px;
    }

    .percentage-bar-container {
        max-width: 120px;
    }

    .yoy-change {
        padding: 3px 8px;
        font-size: 11px;
    }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
    .page-country-analytics {
        padding: 15px 0;
    }

    .page-country-analytics h1 {
        font-size: 1.3rem !important;
        margin-bottom: 6px !important;
    }

    .page-country-analytics h2 {
        font-size: 0.8rem !important;
        margin-bottom: 10px !important;
    }

    .page-country-analytics .description {
        font-size: 0.75rem !important;
        gap: 4px !important;
    }

    .page-country-analytics .description svg {
        width: 12px !important;
        height: 12px !important;
    }

    .summary-card {
        padding: 20px !important;
    }

    .summary-card h3 {
        font-size: 12px !important;
    }

    .summary-card .summary-number {
        font-size: 28px !important;
    }

    .analytics-table {
        min-width: 500px;
        font-size: 11px;
    }

    .analytics-table th {
        padding: 10px 8px;
        font-size: 10px;
        letter-spacing: 0.3px;
    }

    .analytics-table tr.sub-header th {
        padding: 8px;
        font-size: 9px;
    }

    .analytics-table td {
        padding: 10px 8px;
        font-size: 11px;
    }

    .country-flag {
        width: 20px;
        height: 15px;
    }

    .country-cell {
        gap: 8px;
    }

    .country-cell span {
        font-size: 11px;
    }

    .percentage-bar-container {
        max-width: 100px;
    }

    .percentage-bar {
        height: 20px !important;
    }

    .percentage-text {
        font-size: 10px !important;
    }

    .yoy-change {
        padding: 2px 6px;
        font-size: 10px;
        gap: 3px;
    }

    .yoy-arrow {
        font-size: 11px;
    }
}

/* Article Page Widget Styles */
.obj_article_details .country-analytics-widget,
.country-analytics-widget {
    margin-top: 30px !important;
    padding: 20px 25px !important;
    background: #f8f9fa !important;
    border-radius: 8px !important;
    border: 1px solid #dee2e6 !important;
}

.obj_article_details .country-analytics-widget .label,
.country-analytics-widget .label {
    margin-bottom: 20px !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #333 !important;
    padding-bottom: 10px !important;
    border-bottom: 2px solid #dee2e6 !important;
}

.article-country-analytics-container {
    position: relative;
    min-height: 100px;
}

.analytics-loading-small {
    text-align: center;
    padding: 20px;
}

.spinner-small {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

.analytics-error-small {
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 4px;
    padding: 10px;
    margin: 10px 0;
}

.analytics-error-small .error-message {
    color: #c33;
    margin: 0;
    font-size: 14px;
}

/* Article widget uses same table styles as main page - exact match with high specificity */
.obj_article_details .country-analytics-widget .analytics-table-container,
.country-analytics-widget .analytics-table-container {
    overflow-x: auto !important;
    background: white !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    margin-bottom: 20px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    max-width: 100% !important;
}

.obj_article_details .country-analytics-widget .analytics-table,
.country-analytics-widget .analytics-table {
    width: 100% !important;
    border-collapse: collapse !important;
    min-width: 600px !important;
    margin: 0 auto !important;
    border: 1px solid #dee2e6 !important;
}

.obj_article_details .country-analytics-widget .analytics-table th,
.obj_article_details .country-analytics-widget .analytics-table td,
.country-analytics-widget .analytics-table th,
.country-analytics-widget .analytics-table td {
    border: 1px solid #dee2e6 !important;
}

.obj_article_details .country-analytics-widget .analytics-table thead,
.country-analytics-widget .analytics-table thead {
    background-color: #f8f9fa !important;
    border-bottom: 2px solid #dee2e6 !important;
}

.obj_article_details .country-analytics-widget .analytics-table th,
.country-analytics-widget .analytics-table th {
    padding: 15px !important;
    text-align: left !important;
    font-weight: 600 !important;
    color: #495057 !important;
    font-size: 14px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

.obj_article_details .country-analytics-widget .analytics-table th.views-header,
.country-analytics-widget .analytics-table th.views-header {
    text-align: center !important;
}

.obj_article_details .country-analytics-widget .analytics-table tr.sub-header th,
.country-analytics-widget .analytics-table tr.sub-header th {
    font-weight: 500 !important;
    font-size: 11px !important;
    padding: 8px 15px !important;
    text-align: center !important;
    background-color: #f1f3f5 !important;
    border-top: 1px solid #dee2e6 !important;
    border-bottom: 1px solid #dee2e6 !important;
}

.obj_article_details .country-analytics-widget .analytics-table tbody tr,
.country-analytics-widget .analytics-table tbody tr {
    border-bottom: 1px solid #e9ecef !important;
    transition: background-color 0.2s ease !important;
}

.obj_article_details .country-analytics-widget .analytics-table tbody tr:hover,
.country-analytics-widget .analytics-table tbody tr:hover {
    background-color: #f8f9fa !important;
}

.obj_article_details .country-analytics-widget .analytics-table tbody tr:last-child,
.country-analytics-widget .analytics-table tbody tr:last-child {
    border-bottom: none !important;
}

.obj_article_details .country-analytics-widget .analytics-table td,
.country-analytics-widget .analytics-table td {
    padding: 15px !important;
    color: #212529 !important;
    text-align: center !important;
}

.obj_article_details .country-analytics-widget .analytics-table td.views-cell,
.country-analytics-widget .analytics-table td.views-cell {
    text-align: center !important;
    font-weight: 500 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

.obj_article_details .country-analytics-widget .analytics-table td.country-cell,
.country-analytics-widget .analytics-table td.country-cell {
    text-align: center !important;
    justify-content: center !important;
}

.obj_article_details .country-analytics-widget .country-cell,
.country-analytics-widget .country-cell {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
}

.obj_article_details .country-analytics-widget .country-flag,
.country-analytics-widget .country-flag {
    width: 24px !important;
    height: 18px !important;
    border: 1px solid #ddd !important;
    border-radius: 2px !important;
    object-fit: cover !important;
}

.obj_article_details .country-analytics-widget .percentage-bar-container,
.country-analytics-widget .percentage-bar-container {
    position: relative !important;
    width: 100% !important;
    max-width: 200px !important;
}

.obj_article_details .country-analytics-widget .percentage-bar,
.country-analytics-widget .percentage-bar {
    height: 24px !important;
    background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%) !important;
    border-radius: 4px !important;
    transition: width 0.3s ease !important;
}

.obj_article_details .country-analytics-widget .percentage-text,
.country-analytics-widget .percentage-text {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    color: #333 !important;
    text-shadow: 0 0 3px white !important;
}

.country-analytics-widget .last-updated {
    text-align: right;
    color: #6c757d;
    font-size: 14px;
    padding: 10px 0;
}

/* Collapsible header styles */
.country-analytics-header {
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.collapse-icon {
    font-size: 20px;
    font-weight: bold;
    width: 24px;
    text-align: center;
    color: #495057;
}

/* Load more button */
.load-more-container {
    text-align: center;
    margin-top: 20px;
    margin-bottom: 10px;
}

.load-more-btn {
    background-color: #667eea;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.load-more-btn:hover {
    background-color: #5568d3;
}

.load-more-btn:active {
    background-color: #4457b8;
}

/* Refresh Analytics Button - matching Load More button style */
.refresh-analytics-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.refresh-analytics-btn:hover {
    background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.2);
}

.refresh-analytics-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.refresh-analytics-btn i {
    transition: transform 0.3s ease;
}

.refresh-analytics-btn:hover i {
    transform: rotate(180deg);
}

/* Header Refresh Icon */
.refresh-icon-header {
    position: relative;
}

.refresh-icon-header:hover {
    color: #5568d3 !important;
    transform: scale(1.1);
}

.refresh-icon-header:active {
    transform: scale(0.95);
}

.refresh-icon-header i {
    transition: transform 0.5s ease;
}

.refresh-icon-header:hover i {
    transform: rotate(360deg);
}

/* Tooltip styling for header refresh icon */
.refresh-icon-header::after {
    content: attr(title);
    position: absolute;
    bottom: -35px;
    right: 0;
    background: #333;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}

.refresh-icon-header:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Legacy article-analytics-table styles - keeping for backward compatibility */
.article-analytics-table-container {
    overflow-x: auto;
    margin-top: 15px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.article-analytics-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

.article-analytics-table thead {
    background-color: #e9ecef;
    border-bottom: 2px solid #dee2e6;
}

.article-analytics-table th {
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-right: 1px solid #dee2e6;
}

.article-analytics-table th:last-child {
    border-right: none;
}

.article-analytics-table th.views-header {
    text-align: center;
    border-right: none;
}

.article-analytics-table tr.sub-header th {
    font-weight: 500;
    font-size: 11px;
    padding: 8px 15px;
    text-align: center;
    background-color: #f1f3f5;
    border-top: 1px solid #dee2e6;
    border-bottom: 1px solid #dee2e6;
}

.article-analytics-table tr.sub-header th:first-child {
    border-left: none;
}

.article-analytics-table tbody tr {
    border-bottom: 1px solid #e9ecef;
    transition: background-color 0.2s ease;
}

.article-analytics-table tbody tr:hover {
    background-color: #f8f9fa;
}

.article-analytics-table tbody tr:last-child {
    border-bottom: none;
}

.article-analytics-table td {
    padding: 12px 15px;
    color: #212529;
    border-right: 1px solid #f0f0f0;
    vertical-align: middle;
}

.article-analytics-table td:last-child {
    border-right: none;
}

.article-analytics-table td.views-cell {
    text-align: right;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.country-flag-small {
    width: 20px;
    height: 15px;
    border: 1px solid #ddd;
    border-radius: 2px;
    object-fit: cover;
    margin-right: 8px;
    vertical-align: middle;
}

.country-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 150px;
}

.country-cell span {
    vertical-align: middle;
    font-weight: 500;
}

/* Responsive for article widget */
@media (max-width: 768px) {
    .country-analytics-widget {
        padding: 15px;
    }

    .article-analytics-table th,
    .article-analytics-table td {
        padding: 8px;
        font-size: 13px;
    }

    .country-flag-small {
        width: 18px;
        height: 13px;
    }
}

/* Chart Section Styles - Support dynamic article IDs */
[id^="chart-section-"] {
    background: white;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

[id^="chart-section-"] h3 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

[id^="chart-section-"] select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

[id^="chart-section-"] select:hover {
    border-color: #667eea;
}

[id^="chart-section-"] select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Legacy support for #chart-section */
#chart-section {
    background: white;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#chart-section h3 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

#chart-section select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

#chart-section select:hover {
    border-color: #667eea;
}

#chart-section select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Mobile responsive chart styles */
@media (max-width: 768px) {
    [id^="chart-section-"],
    #chart-section {
        padding: 15px;
    }

    [id^="chart-section-"] > div:first-child,
    #chart-section > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px !important;
    }

    [id^="chart-section-"] h3,
    #chart-section h3 {
        font-size: 1rem !important;
        width: 100% !important;
    }

    [id^="chart-section-"] select,
    #chart-section select {
        width: 100%;
        font-size: 0.9rem;
    }

    [id^="chart-section-"] > div:nth-child(2),
    #chart-section > div:nth-child(2) {
        height: 300px !important;
    }

    [id^="chart-section-"] label,
    #chart-section label {
        font-size: 0.8rem !important;
    }
}

/* Touch-friendly interactions on mobile */
@media (hover: none) and (pointer: coarse) {
    [id^="chart-section-"] select,
    #chart-section select {
        min-height: 44px;
        font-size: 16px;
    }
}

/* Ensure chart canvas is visible and properly sized */
[id^="chart-section-"] canvas,
#chart-section canvas {
    display: block !important;
    max-width: 100% !important;
    height: auto !important;
}

[id^="chart-section-"] > div[style*="position: relative"],
#chart-section > div[style*="position: relative"] {
    position: relative !important;
    height: 350px !important;
    width: 100% !important;
    min-height: 350px !important;
}