/**
 * CPT-MapyCZ Plugin Styles
 *
 * Contains styles for map display, table display, and admin components
 */

/* Map container styles */
.cpt-mapycz-map-container {
    width: 100% !important;
    height: 400px !important;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: relative !important;
    z-index: 1 !important; /* Ensure map has proper z-index */
    overflow: hidden;
    min-height: 200px !important;
    display: block !important;
}

/* Critical fix for map display */
#direct-map, [id^="cpt-mapycz-map-"] {
    position: relative !important; 
    z-index: 1 !important;
    display: block !important;
    height: 400px !important;
    width: 100% !important;
}

/* Ensure leaflet containers are visible */
.leaflet-container {
    z-index: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* Error message styles */
.map-error {
    padding: 15px;
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    text-align: center;
    margin: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 80%;
    z-index: 1000;
}

/* Popup styles */
.map-marker-popup {
    min-width: 200px;
    max-width: 300px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.map-marker-popup .popup-title {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #eaeaea;
    padding-bottom: 5px;
}

.map-marker-popup .popup-section {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.map-marker-popup .popup-icon {
    flex: 0 0 24px;
    font-size: 16px;
    text-align: center;
    color: #555;
}

.map-marker-popup .popup-content {
    flex: 1;
}

.map-marker-popup .popup-content p {
    margin: 0 0 5px 0;
    font-size: 14px;
    line-height: 1.4;
}

.map-marker-popup .popup-content a {
    color: #0073aa;
    text-decoration: none;
}

.map-marker-popup .popup-content a:hover {
    text-decoration: underline;
}

.map-marker-popup .popup-info {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f5f5f5;
    font-size: 13px;
    line-height: 1.5;
    color: #444;
}

.map-marker-popup .popup-actions {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #eaeaea;
    text-align: right;
}

.map-marker-popup .popup-button {
    display: inline-block;
    padding: 6px 12px;
    background: #0073aa;
    color: #fff !important;
    text-decoration: none;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s ease;
}

.map-marker-popup .popup-button:hover {
    background: #005a87;
    text-decoration: none;
}

/* Add dashicons for popups */
.map-marker-popup .dashicons {
    width: 18px;
    height: 18px;
    font-size: 18px;
    line-height: 1;
    vertical-align: middle;
}

/* Enhanced cluster styles */
.marker-cluster {
    background-color: rgba(255, 153, 51, 0.6);
    border-radius: 50%;
    text-align: center;
    transition: transform 0.2s ease;
}

.marker-cluster:hover {
    transform: scale(1.1);
}

.cluster-inner {
    width: 36px;
    height: 36px;
    margin-left: 2px;
    margin-top: 2px;
    background-color: rgba(255, 102, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    /* Fix vertical alignment issues */
    line-height: 0;
    padding: 0;
}

/* Table styles */
.cpt-mapycz-locations-table table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.cpt-mapycz-locations-table th,
.cpt-mapycz-locations-table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.cpt-mapycz-locations-table th {
    background-color: #0073aa; /* Darker blue for header */
    color: #ffffff; /* White text for better contrast */
    font-weight: bold;
}

.cpt-mapycz-locations-table tbody tr:nth-child(odd) {
    background-color: #e3f2fd; /* Light Blue */
    color: #1e1e1e; /* Dark text for readability */
}

.cpt-mapycz-locations-table tbody tr:nth-child(even) {
    background-color: #0073aa; /* Dark Blue (same as header) */
    color: #ffffff; /* White text for readability */
}

.cpt-mapycz-locations-table tr:hover {
    background-color: #f0f0f0;
}

/* Table-Map synchronization styles */
.cpt-mapycz-locations-table tr.active-location {
    background-color: #e6f3ff !important;
    box-shadow: inset 3px 0 0 #0073aa;
}

.cpt-mapycz-locations-table tr {
    cursor: pointer;
}

/* Location action buttons */
.cpt-mapycz-locations-table .button {
    display: inline-block;
    padding: 6px 12px;
    background: #0073aa;
    color: #fff;
    text-decoration: none;
    border-radius: 3px;
    font-size: 13px;
    margin-right: 5px;
}

.cpt-mapycz-locations-table .button:hover {
    background: #005177;
}

.map-focus-button {
    background: #f0f0f1;
    border: 1px solid #ddd;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

.map-focus-button:hover {
    background: #0073aa;
    color: white;
    border-color: #005177;
}

.leaflet-marker-icon.highlighted {
    filter: drop-shadow(0 0 8px rgba(255,204,0,0.8)) !important;
    transform: scale(1.2) !important;
    z-index: 1000 !important;
}

/* Table sorting styles */
.cpt-mapycz-locations-table th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 25px;
}

.cpt-mapycz-locations-table th.sortable::after {
    content: "↕";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
}

.cpt-mapycz-locations-table th.sort-asc::after {
    content: "↑";
    opacity: 1;
}

.cpt-mapycz-locations-table th.sort-desc::after {
    content: "↓";
    opacity: 1;
}

/* Sorting feedback styles */
.cpt-mapycz-locations-table.sorting {
    opacity: 0.8;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.cpt-mapycz-locations-table.sorting tbody {
    position: relative;
}

.cpt-mapycz-locations-table.sorting tbody::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.5);
    z-index: 1;
}

/* Export button and search styles */
.table-actions {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

/* AJAX Loading Styles */
.load-more-button {
    display: block;
    margin: 20px auto;
    padding: 10px 25px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.load-more-button:hover {
    background: #005177;
}

.load-more-button:disabled {
    background: #7eb9d2;
    cursor: not-allowed;
}

.load-more-button .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Log Viewer Styles */
.log-viewer-container {
    background: #1d2327;
    border-radius: 4px;
    padding: 20px;
    margin-top: 20px;
    max-width: 1200px;
}

.log-viewer-container pre {
    color: #c3c4c7;
    font-family: monospace;
    white-space: pre-wrap;
    margin: 0;
    line-height: 1.5;
    max-height: 600px;
    overflow-y: auto;
}

.log-viewer-container .log-entry {
    margin-bottom: 5px;
}

.log-viewer-container .log-error {
    color: #ff6b6b;
}

.log-viewer-container .log-warning {
    color: #ffb900;
}

.log-viewer-container .log-info {
    color: #72aee6;
}

.log-viewer-container .log-debug {
    color: #949494;
}

.search-filter-container {
    display: flex;
    gap: 8px;
    flex: 1;
    max-width: 600px;
}

.location-search-input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    flex: 2;
    min-width: 200px;
}

.location-filter-dropdown {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    flex: 1;
    min-width: 150px;
}

.csv-export-button {
    background: #28a745;
    color: white;
    border: 1px solid #218838;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.csv-export-button:hover {
    background: #218838;
}

.no-results-message {
    padding: 15px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    text-align: center;
    color: #6c757d;
    margin: 15px 0;
}

/* Responsive adjustments for search and filter */
@media (max-width: 768px) {
    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-filter-container {
        max-width: 100%;
    }
}

/* Fancy table styles */
table.cpt-mapycz-table-fancy {
    border-collapse: collapse;
    width: 100%;
    border: 1px solid #0064a4;
    margin-bottom: 20px;
}

table.cpt-mapycz-table-fancy th {
    background-color: #16254C; /* Dark Blue for header */
    color: white !important;
    font-weight: bold;
    text-align: left;
    padding: 12px 10px;
    border: 1px solid #0064a4;
}

table.cpt-mapycz-table-fancy td {
    padding: 10px;
    border: 1px solid #0064a4;
}

table.cpt-mapycz-table-fancy tbody tr:nth-child(odd) {
    background-color: #0083C1 !important; /* Light Blue for odd rows */
    color: white !important;
}

table.cpt-mapycz-table-fancy tbody tr:nth-child(even) {
    background-color: #16254C !important; /* Dark Blue for even rows */
    color: white !important;
}

table.cpt-mapycz-table-fancy a {
    color: #ffffff !important;
    font-weight: bold;
    text-decoration: underline;
}

table.cpt-mapycz-table-fancy a:hover {
    text-decoration: none;
}

/* Ensure fancy table styles override WordPress defaults */
.entry-content table.cpt-mapycz-table-fancy,
.wp-block-table table.cpt-mapycz-table-fancy,
.wp-block-post-content table.cpt-mapycz-table-fancy {
    border-collapse: collapse;
    width: 100%;
    border: 1px solid #0064a4;
}

.entry-content table.cpt-mapycz-table-fancy th,
.wp-block-table table.cpt-mapycz-table-fancy th,
.wp-block-post-content table.cpt-mapycz-table-fancy th {
    background-color: #16254C; /* Dark Blue for header */
    color: white !important;
}

.entry-content table.cpt-mapycz-table-fancy td,
.wp-block-table table.cpt-mapycz-table-fancy td,
.wp-block-post-content table.cpt-mapycz-table-fancy td {
    border: 1px solid #0064a4;
}

.entry-content table.cpt-mapycz-table-fancy tr:nth-child(odd),
.wp-block-table table.cpt-mapycz-table-fancy tr:nth-child(odd),
.wp-block-post-content table.cpt-mapycz-table-fancy tr:nth-child(odd) {
    background-color: #0083C1; /* Light Blue for odd rows */
    color: white !important;
}

.entry-content table.cpt-mapycz-table-fancy tr:nth-child(even),
.wp-block-table table.cpt-mapycz-table-fancy tr:nth-child(even),
.wp-block-post-content table.cpt-mapycz-table-fancy tr:nth-child(even) {
    background-color: #16254C; /* Dark Blue for even rows */
    color: white !important;
}

.entry-content table.cpt-mapycz-table-fancy a,
.wp-block-table table.cpt-mapycz-table-fancy a,
.wp-block-post-content table.cpt-mapycz-table-fancy a {
    color: #ffffff !important;
}

/* Enhanced table styles to ensure priority */
body table.cpt-mapycz-table-fancy {
    border-collapse: collapse !important;
    width: 100% !important;
    border: 1px solid #0064a4 !important;
    margin-bottom: 20px !important;
}

body table.cpt-mapycz-table-fancy th {
    background-color: #16254C !important; /* Dark Blue for header */
    color: white !important;
    font-weight: bold !important;
    text-align: left !important;
    padding: 12px 10px !important;
    border: 1px solid #0064a4 !important;
}

body table.cpt-mapycz-table-fancy td {
    padding: 10px !important;
    border: 1px solid #0064a4 !important;
}

body table.cpt-mapycz-table-fancy tr:nth-child(even) {
    background-color: #16254C !important; /* Dark Blue for even rows */
    color: white !important;
}

body table.cpt-mapycz-table-fancy tbody tr:nth-child(odd) {
    background-color: #0083C1 !important; /* Light Blue for odd rows */
    color: white !important;
}

body table.cpt-mapycz-table-fancy a {
    color: #ffffff !important;
    font-weight: bold !important;
    text-decoration: underline !important;
}

/* Fancy popup styles */
.map-marker-popup-fancy {
    background: linear-gradient(135deg, #16254C, #0083C1);
    color: white;
    border-radius: 8px;
    padding: 15px; /* Increased padding for content spacing */
}

.map-marker-popup-fancy .popup-title {
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    padding-bottom: 8px;
    margin-bottom: 10px;
    font-weight: bold;
}

.map-marker-popup-fancy .popup-icon {
    color: white;
}

.map-marker-popup-fancy a {
    color: #ffffff !important; /* Ensure links are white */
    font-weight: bold;
    text-decoration: underline;
}

.map-marker-popup-fancy .popup-info {
    border-top: 1px solid rgba(255,255,255,0.3);
    color: white !important; /* Ensure text in info section is white */
}
