/* =============================================================================
   Healthcare Practitioners Map – Frontend Styles
   
   Design philosophy:
   - All colours reference BSR theme CSS variables (--bsr-green, --bsr-light-green,
     --bsr-dark, --bsr-white, --bsr-light) with hardcoded fallbacks.
   - Typography (font-family, font-weight, color on headings/links) is inherited
     from the BSR theme. The plugin does NOT override these.
   - `!important` is used only where WordPress core or Leaflet would otherwise
     break layout (e.g. the .card max-width fix, Leaflet link decoration).
   ============================================================================= */


/* -----------------------------------------------------------------------------
   Container
   ----------------------------------------------------------------------------- */

.hpm-container {
    /* Allow the map to expand beyond the theme's .entry-content 1000 px limit */
    max-width: 1200px;
    margin: 0 auto;
}


/* -----------------------------------------------------------------------------
   Map layer-switcher buttons
   ----------------------------------------------------------------------------- */

.hpm-layer-switcher {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.hpm-layer-btn {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 80px;
    border: 1px solid var(--bsr-green, #446463);
    background: transparent;
    color: var(--bsr-green, #446463);
    border-radius: 4px;
}

.hpm-layer-btn:hover {
    background: var(--bsr-light-green, #82a198);
    border-color: var(--bsr-light-green, #82a198);
    color: var(--bsr-white, #fff);
}

.hpm-layer-btn.active {
    background: var(--bsr-green, #446463);
    border-color: var(--bsr-green, #446463);
    color: var(--bsr-white, #fff);
}


/* -----------------------------------------------------------------------------
   Search section
   ----------------------------------------------------------------------------- */

.hpm-search-section {
    margin-bottom: 24px;
}

.hpm-search-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.hpm-search-input-group {
    position: relative;
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.hpm-search-input-group input[type="text"] {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--bsr-light-green, #82a198);
    font-size: 16px;
    font-family: inherit;
    color: inherit;
    background: var(--bsr-white, #fff);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    border-radius: 4px;
}

.hpm-search-input-group input[type="text"]:focus {
    outline: none;
    border-color: var(--bsr-green, #446463);
    box-shadow: 0 0 0 3px rgba(68, 100, 99, 0.1);
}

.hpm-search-input-group select {
    min-width: 120px;
    padding: 12px 16px;
    border: 1px solid var(--bsr-light-green, #82a198);
    font-size: 16px;
    font-family: inherit;
    color: inherit;
    background: var(--bsr-white, #fff);
    cursor: pointer;
    height: auto;
    border-radius: 4px;
}

.hpm-search-input-group select:focus {
    outline: none;
    border-color: var(--bsr-green, #446463);
    box-shadow: 0 0 0 3px rgba(68, 100, 99, 0.1);
}

.hpm-search-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Search status */
.hpm-search-status {
    padding: 12px;
    margin-top: 16px;
    display: none;
    animation: slideIn 0.3s ease;
}

.hpm-status-success {
    background: var(--bsr-light-green, #82a198);
    color: var(--bsr-white, #fff);
}

.hpm-status-error {
    background: #fde7e7;
    color: #d63638;
    border: 1px solid #d63638;
}

.hpm-status-loading {
    background: rgba(68, 100, 99, 0.07);
    color: var(--bsr-green, #446463);
    border: 1px solid var(--bsr-green, #446463);
}


/* -----------------------------------------------------------------------------
   Buttons
   Buttons intentionally keep explicit background/color so they remain readable
   regardless of any theme that sets a { color: ... } or button { ... }.
   ----------------------------------------------------------------------------- */

.hpm-button {
    padding: 12px 24px;
    border: none;
    font-size: 16px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    background: var(--bsr-green, #446463);
    color: var(--bsr-white, #fff);
    border-radius: 4px;
}

.hpm-button:hover,
.hpm-button:focus {
    background: var(--bsr-light-green, #82a198);
    color: var(--bsr-white, #fff);
    transform: translateY(-2px);
    text-decoration: none;
}

/* Primary variant – same as base, kept for semantic clarity */
.hpm-button.hpm-primary {
    background: var(--bsr-green, #446463);
    color: var(--bsr-white, #fff);
}

.hpm-button.hpm-primary:hover {
    background: var(--bsr-light-green, #82a198);
}

/* Secondary variant */
.hpm-button.hpm-secondary {
    background: rgba(130, 161, 152, 0.12);
    color: var(--bsr-dark, #333);
    border: 1px solid rgba(130, 161, 152, 0.3);
}

.hpm-button.hpm-secondary:hover {
    background: rgba(130, 161, 152, 0.25);
    color: var(--bsr-dark, #333);
    transform: translateY(-1px);
}

/* Small variant */
.hpm-button.hpm-small {
    padding: 8px 16px;
    font-size: 14px;
    min-height: 36px;
}

/* Buttons inside practitioner action bar */
.hpm-practitioner-actions .hpm-button {
    flex: 1;
    min-width: 90px;
}


/* -----------------------------------------------------------------------------
   Layout: map + list side by side
   ----------------------------------------------------------------------------- */

.hpm-content-wrapper {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}


/* -----------------------------------------------------------------------------
   Map section
   ----------------------------------------------------------------------------- */

.hpm-map-section {
    background: var(--bsr-white, #fff);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(68, 100, 99, 0.15);
}

.hpm-map-controls {
    background: rgba(130, 161, 152, 0.1);
    padding: 16px;
    border-bottom: 1px solid rgba(68, 100, 99, 0.15);
}

#hpm-map {
    width: 100%;
    height: 500px;
    position: relative;
}

/* Leaflet overrides – these need !important because Leaflet injects its own
   inline styles and stylesheet with high specificity. */
.leaflet-container a {
    color: inherit;
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out,
.leaflet-fullscreen-button {
    text-decoration: none !important;
}


/* -----------------------------------------------------------------------------
   Practitioner list (sidebar)
   ----------------------------------------------------------------------------- */

.hpm-list-section {
    background: var(--bsr-white, #fff);
    border: 1px solid rgba(68, 100, 99, 0.15);
    max-height: 600px;
    display: flex;
    flex-direction: column;
}

.hpm-list-header {
    padding: 20px;
    border-bottom: 1px solid rgba(68, 100, 99, 0.15);
    background: rgba(130, 161, 152, 0.1);
}

/* h3 inside the list header inherits font-family, weight and color from theme */
.hpm-list-header h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
}

.hpm-list-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 14px;
    border: 1px solid rgba(68, 100, 99, 0.25);
    font-size: 14px;
    font-family: inherit;
    color: inherit;
    background: var(--bsr-white, #fff);
    border-radius: 4px;
}

.hpm-list-search input:focus {
    outline: none;
    border-color: var(--bsr-green, #446463);
    box-shadow: 0 0 0 3px rgba(68, 100, 99, 0.1);
}

.hpm-practitioners-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.hpm-loading,
.hpm-no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--bsr-dark, #646970);
    font-size: 16px;
}


/* -----------------------------------------------------------------------------
   Practitioner cards
   ----------------------------------------------------------------------------- */

/*
 * WordPress core sometimes limits .card width to 520 px.
 * This block uses high specificity (no !important) to override that.
 */
.hpm-container .hpm-practitioner-card,
.hpm-practitioners-list .hpm-practitioner-card {
    max-width: 100%;
}

.hpm-practitioner-card {
    border: 1px solid rgba(68, 100, 99, 0.15);
    margin-bottom: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    background: rgba(130, 161, 152, 0.07);
    animation: fadeIn 0.5s ease;
}

.hpm-practitioner-card:hover {
    background: var(--bsr-white, #fff);
    border-color: var(--bsr-light-green, #82a198);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(68, 100, 99, 0.12);
}

/* Card header (collapsible toggle) */
.hpm-practitioner-header {
    padding: 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.3s ease;
    border-bottom: 1px solid transparent;
}

.hpm-practitioner-card.expanded .hpm-practitioner-header {
    border-bottom-color: rgba(68, 100, 99, 0.15);
}

/*
 * Headings inside cards inherit font-family, font-weight and color from the
 * BSR theme (h1–h6 rule). We only set font-size and margin here.
 */
.hpm-header-content h4 {
    margin: 0;
    font-size: 18px;
    line-height: 1.4;
}

.hpm-header-content h5 {
    margin: 4px 0 0;
    font-size: 14px;
    line-height: 1.4;
}

/* Collapse chevron */
.hpm-collapse-icon {
    font-size: 14px;
    color: var(--bsr-light-green, #82a198);
    transition: transform 0.3s ease, color 0.3s ease;
    flex-shrink: 0;
}

.hpm-practitioner-card.expanded .hpm-collapse-icon {
    transform: rotate(180deg);
    color: var(--bsr-green, #446463);
}

/* Collapsible details panel */
.hpm-practitioner-details {
    padding: 0 16px 16px;
}

/* Practice image */
.hpm-practitioner-image {
    height: 120px;
    overflow: hidden;
    background: rgba(130, 161, 152, 0.1);
}

.hpm-practitioner-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Info block */
.hpm-practitioner-info {
    padding: 16px;
}

/* Practice name – inherits heading styles from theme */
.hpm-practice-name {
    font-size: 18px;
    line-height: 1.3;
    margin-bottom: 4px;
}

/* Practitioner personal name */
.hpm-practitioner-name {
    margin: 4px 0 12px;
    font-size: 14px;
}

/* Distance badge */
.hpm-distance {
    display: inline-block;
    background: rgba(130, 161, 152, 0.15);
    color: var(--bsr-green, #446463);
    padding: 3px 8px;
    font-size: 12px;
    margin-bottom: 8px;
}

/* Address */
.hpm-address {
    font-size: 14px;
    line-height: 1.5;
    color: inherit;
}

.hpm-icon {
    margin-right: 4px;
}

/* Contact block */
.hpm-contact-info {
    margin: 12px 0;
}

.hpm-contact-item {
    margin-bottom: 6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Links inside cards inherit the theme's a { color: var(--bsr-green) } */
.hpm-contact-item a {
    color: inherit;
}

/* Excerpt */
.hpm-practitioner-excerpt {
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.6;
}

/* Action buttons row */
.hpm-practitioner-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}


/* -----------------------------------------------------------------------------
   Custom map markers
   ----------------------------------------------------------------------------- */

.hpm-marker {
    border: 2px solid var(--bsr-green, #446463);
    background: var(--bsr-white, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    cursor: pointer;
    border-radius: 50%;
    width: 30px;
    height: 30px;
}

.hpm-marker:hover,
.hpm-marker-highlighted {
    background: var(--bsr-green, #446463);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(68, 100, 99, 0.4);
}

.hpm-marker-inner {
    font-size: 16px;
    line-height: 1;
    color: var(--bsr-green, #446463);
}

.hpm-marker-highlighted .hpm-marker-inner {
    color: var(--bsr-white, #fff);
    filter: grayscale(1) brightness(2);
}

/* Cluster icons (Leaflet MarkerCluster) */
.hpm-cluster-icon {
    background: transparent;
    border: none;
}


/* -----------------------------------------------------------------------------
   Map popup
   ----------------------------------------------------------------------------- */

.leaflet-popup-content-wrapper {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.hpm-popup-content {
    padding: 4px;
    font-family: inherit;
}

/* Popup title & subtitle inherit heading styles from theme */
.hpm-popup-title {
    margin: 0 0 4px;
    font-size: 16px;
    line-height: 1.3;
}

.hpm-popup-subtitle {
    margin: 0 0 8px;
    font-size: 13px;
}

.hpm-popup-address,
.hpm-popup-distance {
    margin-bottom: 6px;
    font-size: 13px;
}

.hpm-popup-contact {
    margin-bottom: 10px;
}

.hpm-popup-contact div {
    margin-bottom: 3px;
    font-size: 13px;
}

/* Popup links inherit theme link color */
.hpm-popup-contact a {
    color: inherit;
}

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

.hpm-popup-btn {
    padding: 8px 18px;
    border: none;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    background: var(--bsr-green, #446463);
    color: var(--bsr-white, #fff);
    text-decoration: none;
    border-radius: 4px;
}

.hpm-popup-btn:hover {
    background: var(--bsr-light-green, #82a198);
    color: var(--bsr-white, #fff);
    transform: translateY(-2px);
}


/* -----------------------------------------------------------------------------
   Marker cluster colours (Leaflet MarkerCluster default override)
   ----------------------------------------------------------------------------- */

.marker-cluster-small     { background-color: rgba(0, 124, 186, 0.6); }
.marker-cluster-small div { background-color: rgba(0, 124, 186, 0.4); }

.marker-cluster-medium     { background-color: rgba(255, 145, 73, 0.6); }
.marker-cluster-medium div { background-color: rgba(255, 145, 73, 0.4); }

.marker-cluster-large     { background-color: rgba(214, 54, 56, 0.6); }
.marker-cluster-large div { background-color: rgba(214, 54, 56, 0.4); }


/* -----------------------------------------------------------------------------
   Address autocomplete dropdown
   ----------------------------------------------------------------------------- */

#hpm-search-address {
    position: relative;
}

.hpm-autocomplete-dropdown {
    position: absolute;
    top: 52px;
    left: 0;
    z-index: 1000;
    background: var(--bsr-white, #fff);
    border: 1px solid rgba(68, 100, 99, 0.25);
    border-top: none;
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

.hpm-autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    border-bottom: 1px solid rgba(68, 100, 99, 0.08);
}

.hpm-autocomplete-item:hover {
    background: rgba(130, 161, 152, 0.15);
}


/* -----------------------------------------------------------------------------
   Animations
   ----------------------------------------------------------------------------- */

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

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}


/* -----------------------------------------------------------------------------
   Responsive – tablet
   ----------------------------------------------------------------------------- */

@media screen and (max-width: 1024px) {
    .hpm-content-wrapper {
        grid-template-columns: 1fr;
    }

    .hpm-list-section {
        max-height: 800px;
    }
}


/* -----------------------------------------------------------------------------
   Responsive – mobile
   ----------------------------------------------------------------------------- */

@media screen and (max-width: 768px) {
    .hpm-search-input-group {
        flex-direction: column;
        align-items: stretch;
    }

    .hpm-search-input-group select {
        width: 100%;
    }

    .hpm-search-buttons {
        flex-direction: column;
    }

    .hpm-layer-switcher {
        justify-content: center;
    }

    .hpm-layer-btn {
        flex: 1;
        text-align: center;
    }

    #hpm-map {
        height: 400px;
    }

    .hpm-practitioner-actions {
        flex-direction: column;
    }

    .hpm-practitioner-actions .hpm-button {
        flex: none;
    }

    .hpm-popup-actions {
        flex-direction: column;
    }
}

@media screen and (max-width: 480px) {
    #hpm-map {
        height: 300px;
    }

    .hpm-list-section {
        max-height: 600px;
    }
}


/* -----------------------------------------------------------------------------
   Print
   ----------------------------------------------------------------------------- */

@media print {
    .hpm-search-section,
    .hpm-map-controls,
    .hpm-practitioner-actions {
        display: none;
    }

    .hpm-content-wrapper {
        grid-template-columns: 1fr;
    }

    .hpm-practitioner-card {
        break-inside: avoid;
        margin-bottom: 20px;
        box-shadow: none;
        border: 1px solid #000;
    }
}


/* -----------------------------------------------------------------------------
   Accessibility
   ----------------------------------------------------------------------------- */

.hpm-button:focus-visible,
.hpm-layer-btn:focus-visible {
    outline: 2px solid var(--bsr-green, #446463);
    outline-offset: 2px;
}

.hpm-practitioner-card:focus-visible {
    outline: 2px solid var(--bsr-green, #446463);
    outline-offset: 4px;
}


/* -----------------------------------------------------------------------------
   High-contrast mode
   ----------------------------------------------------------------------------- */

@media (prefers-contrast: high) {
    .hpm-practitioner-card {
        border-width: 2px;
    }

    .hpm-marker {
        border-width: 3px;
        border-color: #000;
    }
}


/* -----------------------------------------------------------------------------
   Reduced motion
   ----------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .hpm-practitioner-card,
    .hpm-button,
    .hpm-popup-btn,
    .hpm-marker {
        transition: none;
        animation: none;
    }

    .hpm-practitioner-card:hover,
    .hpm-button:hover,
    .hpm-popup-btn:hover {
        transform: none;
    }
}