/**
 * Service Areas Map - Frontend Styles
 *
 * @package Service_Areas_Map
 * 
 * STYLING PRIORITY SYSTEM:
 * ========================
 * 1. Elementor Widget Styles (highest) - Override everything via {{WRAPPER}} selectors
 * 2. Plugin Settings (CSS Variables) - Applied via inline styles on .sam-container
 * 3. Default CSS Variables (lowest) - Defined in :root below
 *
 * Elementor widget styles use specific selectors like:
 * .elementor-widget-service_areas_map .sam-pill { ... }
 * This specificity automatically overrides the base styles.
 */

/* CSS Variables - Override via inline styles on .sam-container */
:root {
    --sam-primary-color: #2196F3;
    --sam-pill-bg: #F5F5F5;
    --sam-pill-text: #333333;
    --sam-pill-border: #E0E0E0;
    --sam-pill-active-bg: #2196F3;
    --sam-pill-active-text: #FFFFFF;
    --sam-card-bg: #FFFFFF;
}

/* Container */
.sam-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* Header Section */
.sam-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 0 10px;
}

.sam-title {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 10px;
    color: #1e1e1e;
    line-height: 1.2;
}

.sam-subtitle {
    font-size: 18px;
    color: #666;
    margin: 0 0 10px;
    line-height: 1.4;
}

.sam-helper-text {
    font-size: 14px;
    color: #999;
    margin: 0;
    line-height: 1.4;
}

/* Main Content Layout - Two Column Cards */
.sam-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

/* Left Card - Pills Column */
.sam-pills-column {
    background: var(--sam-card-bg);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    padding: 20px;
    max-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for pills column */
.sam-pills-column::-webkit-scrollbar {
    width: 8px;
}

.sam-pills-column::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.sam-pills-column::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.sam-pills-column::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.sam-pills-wrapper {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sam-pill-group {
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 20px;
}

.sam-pill-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.sam-group-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px;
    color: #333;
    letter-spacing: -0.01em;
}

.sam-group-description {
    font-size: 13px;
    color: #666;
    margin: 0 0 12px;
    line-height: 1.4;
}

.sam-pills {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Individual Pill Buttons */
.sam-pill {
    padding: 12px 16px;
    border: 1.5px solid var(--sam-pill-border);
    border-radius: 8px;
    background: var(--sam-pill-bg);
    color: var(--sam-pill-text);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    position: relative;
    overflow: hidden;
}

.sam-pill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--sam-primary-color);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sam-pill:hover {
    border-color: var(--sam-primary-color);
    transform: translateX(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.sam-pill:hover::before {
    opacity: 1;
}

.sam-pill:active {
    transform: translateX(2px) scale(0.98);
}

.sam-pill:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.sam-pill-active {
    background: var(--sam-pill-active-bg);
    border-color: var(--sam-pill-active-bg);
    color: var(--sam-pill-active-text);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
}

.sam-pill-active::before {
    opacity: 0;
}

.sam-pill-active:hover {
    background: var(--sam-pill-active-bg);
    border-color: var(--sam-pill-active-bg);
    transform: translateX(0);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

/* Right Card - Map Column */
.sam-map-column {
    background: var(--sam-card-bg);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    position: relative;
}

.sam-map-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    background: #f5f5f5;
}

.sam-map-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* JS API Map Canvas */
.sam-map-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f5f5f5;
}

/* Loading state for JS API map */
.sam-map-canvas.sam-map-loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sam-map-canvas.sam-map-loading::before {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--sam-primary-color, #2196F3);
    border-radius: 50%;
    animation: sam-map-spin 1s linear infinite;
}

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

/* Error state for JS API map */
.sam-map-canvas.sam-map-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666;
    text-align: center;
    padding: 20px;
}

.sam-map-canvas.sam-map-error::before {
    content: '⚠';
    font-size: 48px;
    margin-bottom: 10px;
    color: #ffc107;
}

/* Caption Card */
.sam-caption {
    background: var(--sam-card-bg);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    text-align: center;
    font-size: 14px;
}

.sam-caption-label {
    color: #666;
    font-weight: 500;
    margin-right: 6px;
}

.sam-caption-location {
    color: var(--sam-primary-color);
    font-weight: 600;
    transition: opacity 0.15s ease;
}

/* No Locations Message */
.sam-no-locations {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.sam-no-locations p {
    margin: 0;
    font-size: 14px;
}

/* Admin Notice (API Key Missing) */
.sam-admin-notice {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    border-radius: 8px;
    padding: 16px 20px;
    margin: 20px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.sam-admin-notice p {
    margin: 0 0 8px;
    color: #856404;
    line-height: 1.5;
}

.sam-admin-notice p:last-child {
    margin-bottom: 0;
}

.sam-admin-notice strong {
    font-weight: 600;
}

.sam-admin-notice a {
    color: #0073aa;
    text-decoration: none;
    font-weight: 500;
}

.sam-admin-notice a:hover {
    text-decoration: underline;
}

.sam-notice-visibility {
    font-size: 12px;
    font-style: italic;
    color: #9a7b3c !important;
    margin-top: 8px !important;
}

/* Tablet Layout (768px - 1024px) */
@media screen and (max-width: 1024px) {
    .sam-content {
        grid-template-columns: 280px 1fr;
        gap: 20px;
    }
    
    .sam-pills-column {
        max-height: 500px;
    }
}

/* Tablet/Mobile Stack (≤768px) */
@media screen and (max-width: 768px) {
    .sam-container {
        padding: 16px;
    }
    
    .sam-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .sam-pills-column {
        max-height: none;
        overflow-y: visible;
    }
    
    .sam-title {
        font-size: 26px;
    }
    
    .sam-subtitle {
        font-size: 16px;
    }
    
    .sam-helper-text {
        font-size: 13px;
    }
}

/* Mobile - Horizontal Scrolling Pills (≤600px) */
@media screen and (max-width: 600px) {
    .sam-pills {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 10px;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    
    .sam-pills::-webkit-scrollbar {
        height: 6px;
    }
    
    .sam-pills::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }
    
    .sam-pills::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 3px;
    }
    
    .sam-pill {
        min-width: 140px;
        flex-shrink: 0;
        scroll-snap-align: start;
    }
    
    .sam-title {
        font-size: 22px;
    }
    
    .sam-subtitle {
        font-size: 15px;
    }
}

/* Small Mobile (≤480px) */
@media screen and (max-width: 480px) {
    .sam-container {
        padding: 12px;
    }
    
    .sam-pills-column {
        padding: 16px;
        border-radius: 10px;
    }
    
    .sam-map-column {
        border-radius: 10px;
    }
    
    .sam-caption {
        padding: 12px 16px;
        border-radius: 10px;
        font-size: 13px;
    }
    
    .sam-pill {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .sam-title {
        font-size: 20px;
    }
}

/* Print Styles */
@media print {
    .sam-pills-column {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .sam-map-column {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
    
    .sam-pill {
        border: 1px solid #ddd;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .sam-pill,
    .sam-caption-location,
    .sam-pill::before {
        transition: none;
    }
}

/* ==========================================================================
   Layout Variations (for Elementor widget overrides)
   ========================================================================== */

/**
 * Stacked Layout - Map on top, pills below
 * Applied via .sam-layout-stacked wrapper class
 */
.sam-layout-stacked .sam-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
}

.sam-layout-stacked .sam-pills-column {
    order: 2;
    max-height: none;
    overflow-y: visible;
}

.sam-layout-stacked .sam-map-column {
    order: 1;
    min-height: 400px;
}

/* Stacked: Pills become horizontal scrolling row */
.sam-layout-stacked .sam-pills {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.sam-layout-stacked .sam-pill {
    flex: 0 0 auto;
}

.sam-layout-stacked .sam-pill-group {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    align-items: center;
    padding: 12px 16px;
}

.sam-layout-stacked .sam-group-title {
    width: 100%;
    text-align: center;
    margin-bottom: 8px;
}

/**
 * Side Layout - Explicit side-by-side (default behavior, but can override stacked on mobile)
 * Applied via .sam-layout-side wrapper class
 */
.sam-layout-side .sam-content {
    grid-template-columns: 320px 1fr;
}

/* Side layout on smaller screens - maintains side-by-side longer */
@media screen and (max-width: 768px) {
    .sam-layout-side .sam-content {
        grid-template-columns: 240px 1fr;
    }
}

@media screen and (max-width: 600px) {
    .sam-layout-side .sam-content {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Elementor Widget Overrides - Higher Specificity
   ========================================================================== */

/**
 * Elementor adds .elementor-widget-service_areas_map class to widget wrapper.
 * Styles applied through Elementor's style tab automatically get higher specificity
 * because they're applied to {{WRAPPER}} which resolves to the widget's unique ID.
 *
 * Example: .elementor-element-abc123 .sam-pill { ... }
 *
 * This section provides additional reset and compatibility rules.
 */

/* Ensure Elementor typography controls work properly */
.elementor-widget-service_areas_map .sam-title,
.elementor-widget-service_areas_map .sam-subtitle,
.elementor-widget-service_areas_map .sam-helper-text,
.elementor-widget-service_areas_map .sam-group-title,
.elementor-widget-service_areas_map .sam-group-description,
.elementor-widget-service_areas_map .sam-pill,
.elementor-widget-service_areas_map .sam-caption-label,
.elementor-widget-service_areas_map .sam-caption-location {
    /* Reset to allow Elementor typography to take over */
    font-family: inherit;
}

/* Allow Elementor color controls to override CSS variables */
.elementor-widget-service_areas_map .sam-pill {
    /* Fallback to CSS variable if Elementor color not set */
    background-color: var(--sam-pill-bg, #F5F5F5);
    color: var(--sam-pill-text, #333333);
    border-color: var(--sam-pill-border, #E0E0E0);
}

.elementor-widget-service_areas_map .sam-pill-active,
.elementor-widget-service_areas_map .sam-pill-active:hover {
    background-color: var(--sam-pill-active-bg, #2196F3);
    color: var(--sam-pill-active-text, #FFFFFF);
    border-color: var(--sam-pill-active-bg, #2196F3);
}

/* Ensure card backgrounds respond to Elementor settings */
.elementor-widget-service_areas_map .sam-pills-column,
.elementor-widget-service_areas_map .sam-map-column,
.elementor-widget-service_areas_map .sam-caption {
    background: var(--sam-card-bg, #FFFFFF);
}

/* Caption location uses primary color - allow override */
.elementor-widget-service_areas_map .sam-caption-location {
    color: var(--sam-primary-color, #2196F3);
}

/* Accent line on pills - allow primary color override */
.elementor-widget-service_areas_map .sam-pill::before {
    background: var(--sam-primary-color, #2196F3);
}

