/* Site Analytics Pro - Complete Stylesheet + Country Analytics */

.sap-wrapper {
    background: #ffffff !important;
    color: #1a1a1a;
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Header */
.sap-header {
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid #1a1a1a;
}

.sap-header h1 {
    font-size: 42px;
    font-weight: 700;
    letter-spacing: -1px;
    margin: 0 0 10px 0;
    color: #1a1a1a;
}

/* Create Box */
.sap-create-box {
    display: flex;
    gap: 12px;
    margin-bottom: 40px;
    padding: 30px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px solid #eee;
    flex-wrap: wrap;
}

.sap-create-box input,
.sap-create-box select {
    padding: 12px 15px;
    font-size: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    outline: none;
    font-family: inherit;
}

.sap-create-box input:focus {
    border-color: #1a1a1a;
}

.sap-btn-primary {
    background: #1a1a1a;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.sap-btn-primary:hover {
    background: #333;
    transform: translateY(-1px);
}

/* Stats Row */
.sap-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.sap-stat-box {
    background: #fff;
    border: 1px solid #e0e0e0;
    padding: 25px;
    border-radius: 8px;
    text-align: center;
    transition: all 0.2s;
}

.sap-stat-box:hover {
    border-color: #1a1a1a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.sap-stat-box.highlight {
    background: #1a1a1a;
    color: white;
    border-color: #1a1a1a;
}

.sap-stat-box h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: #999;
    letter-spacing: 2px;
    margin: 0 0 10px 0;
    font-weight: 600;
}

.sap-stat-box.highlight h4 {
    color: #ccc;
}

.sap-stat-box .number {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1;
}

.sap-stat-box.highlight .number {
    color: white;
}

/* Filter Bar */
.sap-filter-bar {
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 15px;
    background: #fafafa;
    border-radius: 6px;
}

.filter-btn {
    background: white;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: #999;
    color: #333;
}

.filter-btn.active {
    background: #1a1a1a;
    color: white;
    border-color: #1a1a1a;
}

.sap-btn-small {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    margin-left: 5px;
}

.sap-btn-small.secondary {
    background: #f5f5f5;
    color: #666;
}

/* Chart Box */
.sap-chart-box {
    height: 350px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #eee;
    margin-bottom: 40px;
    position: relative;
}

/* Country Analytics Styles */
.sap-country-analytics {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 30px;
    margin-top: 40px;
}

.country-table-header {
    display: grid;
    grid-template-columns: 60px 1fr 120px 80px;
    gap: 20px;
    align-items: center;
    padding: 0 0 15px 0;
    border-bottom: 2px solid #1a1a1a;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 14px;
    letter-spacing: 0.8px;
    color: #1a1a1a;
}

.country-rows-container {
    display: flex;
    flex-direction: column;
}

.country-table-row {
    display: grid;
    grid-template-columns: 60px 1fr 120px 80px;
    gap: 20px;
    align-items: center;
    padding: 18px 0;
    border-bottom: 1px solid #f0f0f0;
    transition: all 0.2s ease;
}

.country-table-row:hover {
    background: #fafafa;
    margin: 0 -15px;
    padding-left: 15px;
    padding-right: 15px;
}

.country-rank {
    font-weight: 700;
    font-size: 18px;
    color: #1a1a1a;
}

.country-table-row:nth-child(1) .country-rank { font-size: 20px; }
.country-table-row:nth-child(2) .country-rank { color: #333; }
.country-table-row:nth-child(3) .country-rank { color: #555; }
.country-table-row:nth-child(n+4) .country-rank { color: #666; font-size: 16px; }

.country-name {
    font-weight: 600;
    font-size: 16px;
    color: #1a1a1a;
}

.country-clicks {
    text-align: right;
    font-weight: 600;
    font-size: 16px;
    color: #1a1a1a;
    font-variant-numeric: tabular-nums;
}

.country-percent {
    text-align: right;
    font-weight: 700;
    font-size: 16px;
    color: #1a1a1a;
}

/* Pagination */
.country-pagination-wrap {
    display: flex;
    justify-content: flex-end;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
}

.country-pagination {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e0e0e0;
    background: #fff;
    color: #666;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    padding: 0 10px;
    font-family: inherit;
}

.page-btn:hover {
    border-color: #1a1a1a;
    color: #1a1a1a;
}

.page-btn.active {
    background: #1a1a1a;
    color: #fff;
    border-color: #1a1a1a;
}

.page-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.page-dots {
    color: #999;
    padding: 0 5px;
    font-weight: 600;
}

/* Links Container */
.sap-links-container {
    margin-top: 30px;
}

/* Link Card */
.sap-link-card {
    display: flex;
    align-items: center;
    padding: 25px;
    margin-bottom: 15px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    transition: all 0.2s;
}

.sap-link-card:hover {
    border-color: #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.link-details {
    flex: 1;
    min-width: 0;
    padding-right: 20px;
}

.link-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #1a1a1a;
    outline: none;
    border-bottom: 1px solid transparent;
    cursor: text;
    display: inline-block;
}

.link-title:hover {
    border-bottom-color: #ccc;
}

.link-shorturl {
    color: #0066cc;
    font-size: 15px;
    margin-bottom: 6px;
    font-family: monospace;
    font-weight: 500;
}

.link-destination {
    color: #999;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 500px;
    cursor: text;
    outline: none;
}

.link-meta {
    margin-top: 10px;
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 12px;
    color: #999;
}

.rule-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
    background: #e3f2fd;
    color: #1976d2;
}

.rule-badge.simple {
    background: #f5f5f5;
    color: #666;
}

.link-count {
    text-align: center;
    margin-right: 25px;
    min-width: 100px;
}

.count-number {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1;
}

.count-label {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

.link-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.link-actions button {
    padding: 8px 14px;
    border: 1px solid #e0e0e0;
    background: white;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    color: #666;
    transition: all 0.2s;
    font-family: inherit;
}

.link-actions button:hover {
    background: #1a1a1a;
    color: white;
    border-color: #1a1a1a;
}

.btn-stats {
    background: #1a1a1a !important;
    color: white !important;
    border-color: #1a1a1a !important;
    font-weight: 600;
}

.btn-stats:hover {
    background: #333 !important;
}

.btn-reset {
    color: #ff9800 !important;
    border-color: #ffe0b2 !important;
}

.btn-reset:hover {
    background: #ff9800 !important;
    color: white !important;
}

.btn-delete {
    color: #f44336 !important;
    border-color: #ffcdd2 !important;
}

.btn-delete:hover {
    background: #f44336 !important;
    color: white !important;
}

/* No Links Message */
.no-links {
    text-align: center;
    padding: 60px;
    color: #999;
    font-size: 16px;
    background: #fafafa;
    border-radius: 8px;
    border: 2px dashed #e0e0e0;
}

/* Modal Styles */
.sap-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 100000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.3);
    position: relative;
    animation: modalSlide 0.3s ease;
}

.modal-content.large {
    max-width: 1000px;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 25px;
    background: none;
    border: none;
    font-size: 32px;
    color: #999;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

.modal-content h2 {
    margin-bottom: 30px;
    font-size: 28px;
    color: #1a1a1a;
    padding-bottom: 15px;
    border-bottom: 2px solid #eee;
}

.modal-content h3 {
    margin: 0 0 25px 0;
    font-size: 24px;
    color: #1a1a1a;
}

.modal-content label {
    display: block;
    margin: 20px 0 8px 0;
    font-size: 13px;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sap-input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.sap-input:focus {
    outline: none;
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(26,26,26,0.1);
}

.modal-footer {
    margin-top: 30px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-secondary {
    padding: 10px 20px;
    border: 1px solid #ddd;
    background: white;
    color: #666;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f5f5f5;
    border-color: #999;
}

/* Responsive Design */
@media screen and (max-width: 782px) {
    .sap-wrapper {
        padding: 15px;
    }
    
    .sap-header h1 {
        font-size: 32px;
    }
    
    .sap-create-box {
        flex-direction: column;
        padding: 20px;
    }
    
    .sap-create-box input,
    .sap-create-box select {
        width: 100%;
        box-sizing: border-box;
    }
    
    .sap-stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .sap-stat-box {
        padding: 20px;
    }
    
    .sap-stat-box .number {
        font-size: 24px;
    }
    
    .sap-filter-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    #main-custom-dates,
    #link-custom-dates {
        width: 100%;
        margin-left: 0 !important;
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .sap-link-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 20px;
    }
    
    .link-details {
        width: 100%;
        padding-right: 0;
    }
    
    .link-destination {
        max-width: 100%;
        font-size: 12px;
    }
    
    .link-count {
        width: 100%;
        text-align: left;
        margin-right: 0;
        display: flex;
        align-items: baseline;
        gap: 10px;
    }
    
    .count-label {
        font-size: 14px;
    }
    
    .link-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    
    .modal-content {
        padding: 25px;
        margin: 20px;
        width: calc(100% - 40px);
    }
    
    .modal-content.large {
        max-width: calc(100% - 40px);
    }
    
    .sap-stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Country Table Mobile */
    .country-table-header,
    .country-table-row {
        grid-template-columns: 40px 1fr 100px 60px;
        gap: 10px;
        font-size: 14px;
    }
    
    .country-clicks, .country-percent, .country-name, .country-rank {
        font-size: 14px;
    }
}

@media screen and (max-width: 480px) {
    .sap-stats-row {
        grid-template-columns: 1fr;
    }
    
    .link-actions button {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f0f0f0;
    border-top-color: #1a1a1a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Success/Error Messages */
.sap-notice {
    padding: 12px 20px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 4px solid;
}

.sap-notice.success {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #2e7d32;
}

.sap-notice.error {
    background: #ffebee;
    border-color: #f44336;
    color: #c62828;
}

/* Chart Tooltip Customization */
canvas {
    max-height: 100%;
}

/* Edit Modal Specific Fixes */
#editModal .sap-input {
    margin-bottom: 5px;
}

#editModal label {
    margin-top: 15px;
}

/* Date Input Styling */
input[type="date"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    color: #666;
}

/* Scrollbar Styling for Modals */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Focus Visible for Accessibility */
button:focus-visible,
input:focus-visible {
    outline: 2px solid #1a1a1a;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .sap-modal,
    .sap-create-box,
    .link-actions {
        display: none !important;
    }
    
    .sap-link-card {
        break-inside: avoid;
        border: 1px solid #ccc;
    }
}