/* ============================================================
   MapLab — Frontend Map CSS
   Scoped to .maplabpro-wrap to avoid conflicts with page styles
   ============================================================ */

/* ── Wrapper — isolate Leaflet z-indexes from page stacking context ── */

.maplabpro-wrap {
    isolation: isolate;
    position: relative;
}

/* ── Filter buttons ──────────────────────────────────────────── */

.maplabpro-filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.maplabpro-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    font-size: 0.875rem;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.maplabpro-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.maplabpro-btn.is-active {
    background: #e8820c;
    border-color: #e8820c;
    color: #fff;
    font-weight: 600;
}

/* ── Map container ───────────────────────────────────────────── */

.maplabpro-map {
    width: 100%;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    margin-bottom: 1.5rem;
    position: relative;
}

/* Marker icon — reset browser defaults from Leaflet */
.maplabpro-marker {
    background: none !important;
    border: none !important;
}

/* ── Popup overrides ─────────────────────────────────────────── */

.maplabpro-popup-wrap .leaflet-popup-content-wrapper {
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.16);
    padding: 0;
}

.maplabpro-popup-wrap .leaflet-popup-content {
    margin: 0;
    font-family: var(--font-base, system-ui, sans-serif);
    font-size: 0.875rem;
}

.maplabpro-popup-wrap .leaflet-popup-tip-container {
    margin-top: -1px;
}

.maplabpro-popup {
    padding: 1rem 1.125rem;
    min-width: 200px;
}

.maplabpro-popup__logo {
    background: #f8f9fa;
    border-bottom: 1px solid #e5e7eb;
    margin: -1rem -1.125rem 0.75rem -1.125rem;
    padding: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
}

.maplabpro-popup__logo img {
    max-height: min(48px, var(--maplabpro-logo-max-height, 120px));
    max-width: 180px;
    object-fit: contain;
}

.maplabpro-popup__title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #e8820c;
    margin-bottom: 0.1875rem;
}

.maplabpro-popup__company {
    font-weight: 700;
    color: #1a2332;
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.maplabpro-popup__address {
    color: #6b7280;
    line-height: 1.5;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
}

.maplabpro-popup__contact {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
}

.maplabpro-popup__contact a,
.maplabpro-popup__link a {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: #1a2332;
    text-decoration: none;
}

.maplabpro-popup__contact a:hover,
.maplabpro-popup__link a:hover {
    color: #e8820c;
    text-decoration: underline;
}

.maplabpro-popup__link {
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

.maplabpro-popup__fields + .maplabpro-popup__link,
.maplabpro-popup__logo + .maplabpro-popup__link,
.maplabpro-popup > .maplabpro-popup__link:first-child {
    border-top: 1px solid #e5e7eb;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
}

/* ── Location cards grid ─────────────────────────────────────── */

.maplabpro-cards-grid {
    display: grid;
    gap: 1rem;
    margin-top: 0.5rem;
}

.maplabpro-cards-grid[hidden] {
    display: none;
}

.maplabpro-cards-6 { grid-template-columns: repeat(6, 1fr); }
.maplabpro-cards-5 { grid-template-columns: repeat(5, 1fr); }
.maplabpro-cards-4 { grid-template-columns: repeat(4, 1fr); }
.maplabpro-cards-3 { grid-template-columns: repeat(3, 1fr); }
.maplabpro-cards-2 { grid-template-columns: repeat(2, 1fr); }
.maplabpro-cards-1 { grid-template-columns: 1fr; }

@media (max-width: 1024px) {
    .maplabpro-cards-6,
    .maplabpro-cards-5,
    .maplabpro-cards-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .maplabpro-cards-6,
    .maplabpro-cards-5,
    .maplabpro-cards-4,
    .maplabpro-cards-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .maplabpro-cards-6,
    .maplabpro-cards-5,
    .maplabpro-cards-4,
    .maplabpro-cards-3,
    .maplabpro-cards-2 { grid-template-columns: 1fr; }
}

.maplabpro-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 0.8125rem;
    transition: box-shadow 0.15s;
}

.maplabpro-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
}

.maplabpro-card__logo {
    background: #f8f9fa;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.5rem;
}

/* Recommended logo size: 300×100px (3:1 ratio), transparent PNG or SVG */
.maplabpro-card__logo img {
    display: block;
    width: 100%;
    max-height: var(--maplabpro-logo-max-height, 120px);
    height: auto;
    object-fit: contain;
}

.maplabpro-card__body {
    padding: 0.75rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.maplabpro-card__title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #e8820c;
}

.maplabpro-card__company {
    font-weight: 700;
    color: #1a2332;
    line-height: 1.3;
}

.maplabpro-card__address {
    color: #6b7280;
    line-height: 1.5;
    margin-top: 0.125rem;
}

.maplabpro-card__contact {
    color: #374151;
    margin-top: 0.25rem;
}

.maplabpro-card__links {
    margin-top: auto;
    padding-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.maplabpro-card__links a {
    color: #1a2332;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.maplabpro-card__links a:hover {
    color: #e8820c;
}

.maplabpro-icon {
    width: 13px;
    height: 13px;
    fill: currentColor;
    flex-shrink: 0;
}

.maplabpro-cards-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #9ca3af;
    padding: 2rem;
}

/* ── Search bar (Pro) ────────────────────────────────────────── */

.maplabpro-controls {
    align-items: center;
    display: grid;
    gap: 0.75rem;
    grid-template-columns: minmax(180px, 280px) minmax(260px, 1fr) max-content;
    margin-bottom: 0.75rem;
}

.maplabpro-controls .maplabpro-search-bar,
.maplabpro-controls .maplabpro-filter-wrap,
.maplabpro-controls .maplabpro-field-filters {
    margin: 0;
}

.maplabpro-sr-only {
    height: 1px;
    margin: -1px;
    overflow: hidden;
    position: absolute;
    width: 1px;
    clip: rect(0 0 0 0);
}

.maplabpro-search-bar {
    margin-bottom: 0.625rem;
    min-width: 0;
}

.maplabpro-search-control {
    position: relative;
}

.maplabpro-search-input {
    display: block;
    width: 100%;
    padding: 0.4375rem 2.375rem 0.4375rem 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    font-size: 0.875rem;
    line-height: 1.5;
    box-sizing: border-box;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.maplabpro-search-input:focus {
    outline: none;
    border-color: #e8820c;
    box-shadow: 0 0 0 3px rgba(232, 130, 12, 0.15);
}

.maplabpro-search-input::placeholder {
    color: #9ca3af;
}

.maplabpro-search-clear {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: #6b7280;
    cursor: pointer;
    display: inline-flex;
    font-size: 1.25rem;
    height: 2rem;
    justify-content: center;
    line-height: 1;
    padding: 0;
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2rem;
}

.maplabpro-search-clear:hover,
.maplabpro-search-clear:focus {
    background: #f3f4f6;
    color: #1f2937;
    outline: none;
}

.maplabpro-search-clear[hidden] {
    display: none;
}

.maplabpro-reset {
    align-items: center;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #374151;
    cursor: pointer;
    display: inline-flex;
    font-size: 0.875rem;
    font-weight: 600;
    justify-content: center;
    min-height: 2.375rem;
    padding: 0.4375rem 0.875rem;
    white-space: nowrap;
    width: auto;
    justify-self: start;
}

.maplabpro-reset:hover,
.maplabpro-reset:focus {
    background: #f3f4f6;
    border-color: #9ca3af;
    outline: none;
}

.maplabpro-reset[hidden] {
    display: none;
}

.maplabpro-results-meta {
    color: #6b7280;
    font-size: 0.8125rem;
    margin: 0 0 0.625rem;
}

.maplabpro-legend {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: -0.125rem 0 0.875rem;
}

.maplabpro-legend__item {
    align-items: center;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #374151;
    cursor: pointer;
    display: inline-flex;
    font-size: 0.8125rem;
    gap: 0.375rem;
    line-height: 1.35;
    min-height: 2rem;
    padding: 0.25rem 0.625rem;
}

.maplabpro-legend__item:hover,
.maplabpro-legend__item:focus {
    background: #f3f4f6;
    border-color: #9ca3af;
    outline: none;
}

.maplabpro-legend__item.is-active {
    background: #1f3f73;
    border-color: #1f3f73;
    color: #fff;
}

.maplabpro-legend__icon {
    display: inline-flex;
    height: 1.25rem;
    width: 1.25rem;
}

.maplabpro-legend__icon svg {
    display: block;
    height: 100%;
    width: 100%;
}

.maplabpro-filter-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    min-width: 0;
}

.maplabpro-filter-wrap--buttons {
    gap: 0.5rem;
    grid-column: 1 / -1;
}

.maplabpro-filter-wrap--buttons + .maplabpro-search-bar {
    grid-column: 1 / 3;
}

.maplabpro-filter-select-wrap {
    color: #4b5563;
    display: flex;
    flex: 1 1 220px;
    flex-direction: column;
    font-size: 0.75rem;
    font-weight: 700;
    gap: 0.25rem;
    line-height: 1.2;
    min-width: 0;
}

.maplabpro-filter-select {
    appearance: none;
    background:
        linear-gradient(45deg, transparent 50%, #6b7280 50%) calc(100% - 18px) 50% / 6px 6px no-repeat,
        linear-gradient(135deg, #6b7280 50%, transparent 50%) calc(100% - 13px) 50% / 6px 6px no-repeat,
        #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #374151;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.5;
    min-height: 2.375rem;
    padding: 0.4375rem 2.375rem 0.4375rem 0.75rem;
    width: 100%;
}

.maplabpro-filter-select:focus {
    border-color: #e8820c;
    box-shadow: 0 0 0 3px rgba(232, 130, 12, 0.15);
    outline: none;
}

.maplabpro-cluster {
    align-items: center;
    background: rgba(26, 35, 50, 0.18);
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.2);
    display: flex;
    justify-content: center;
}

.maplabpro-cluster span {
    align-items: center;
    background: #1f3f73;
    border: 3px solid #fff;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(17, 24, 39, 0.28);
    color: #fff;
    display: flex;
    font-size: 0.875rem;
    font-weight: 700;
    height: calc(100% - 10px);
    justify-content: center;
    min-height: 30px;
    min-width: 30px;
    width: calc(100% - 10px);
}

/* ── Secondary filter row (nested regions, Pro) ──────────────── */

.maplabpro-filter-secondary {
    flex: 0 0 220px;
}

.maplabpro-filter-secondary:empty {
    display: none;
}

.maplabpro-field-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    grid-column: 1 / -1;
}

.maplabpro-field-filters[hidden] {
    display: none;
}

.maplabpro-map-empty {
    align-items: center;
    background: #f8fafc;
    color: #6b7280;
    display: flex;
    font-size: 0.9375rem;
    inset: 0;
    justify-content: center;
    padding: 1rem;
    position: absolute;
    text-align: center;
    z-index: 401;
}

.maplabpro-map-empty[hidden] {
    display: none;
}

@media (max-width: 700px) {
    .maplabpro-controls {
        align-items: stretch;
        grid-template-columns: 1fr;
    }

    .maplabpro-search-bar,
    .maplabpro-filter-wrap {
        flex-direction: column;
        width: 100%;
    }

    .maplabpro-filter-select-wrap {
        flex-basis: auto;
        width: 100%;
    }

    .maplabpro-reset {
        width: 100%;
    }
}

.maplabpro-btn-sub {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #f9fafb;
    color: #374151;
    font-size: 0.8125rem;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.maplabpro-btn-sub:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.maplabpro-btn-sub.is-active {
    background: #e8820c;
    border-color: #e8820c;
    color: #fff;
    font-weight: 600;
}

/* ── Custom fields in popups and cards (Pro) ─────────────────── */

.maplabpro-popup__fields {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.maplabpro-card__fields {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.maplabpro-card__fields .maplabpro-card__logo {
    margin: -0.75rem -1rem 0.5rem;
}

.maplabpro-field-divider {
    border-top: 1px solid #f0f0f0;
    margin: 0.45rem 0;
    min-height: 1px;
}

.maplabpro-field-row {
    font-size: 0.8125rem;
    color: #374151;
    line-height: 1.4;
}

.maplabpro-field-label {
    display: inline;
    font-weight: 600;
    color: #6b7280;
    margin-right: 0.25rem;
}

.maplabpro-field-row a {
    color: #1a2332;
    text-decoration: none;
}

.maplabpro-field-row a:hover {
    color: #e8820c;
    text-decoration: underline;
}

.maplabpro-card__actions {
    border-top: 1px solid #f0f0f0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin: 0.75rem 1rem 0;
    padding: 0.75rem 0 1rem;
}

.maplabpro-card__actions a,
.maplabpro-location-back,
.maplabpro-location-map-link {
    color: #1f3f73;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.maplabpro-card__actions a:hover,
.maplabpro-location-back:hover,
.maplabpro-location-map-link:hover {
    color: #e8820c;
    text-decoration: underline;
}

/* ── Location detail page ───────────────────────────────────── */

.maplabpro-location {
    box-sizing: border-box;
    color: #1f2937;
    margin: 0 auto;
    max-width: 1180px;
    padding: 1rem;
}

.maplabpro-location-back {
    display: inline-flex;
    margin-bottom: 1rem;
}

.maplabpro-location-layout {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
    align-items: start;
}

.maplabpro-location-main,
.maplabpro-location-side {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
    overflow: hidden;
}

.maplabpro-location-fields {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.25rem;
}

.maplabpro-location-logo {
    align-items: center;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.maplabpro-location-logo img {
    display: block;
    height: auto;
    max-height: 180px;
    max-width: 100%;
    object-fit: contain;
}

.maplabpro-location-title {
    color: #0f172a;
    font-size: 2rem;
    line-height: 1.15;
    margin: 0 0 0.25rem;
}

.maplabpro-location-company {
    color: #1f2937;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.3;
}

.maplabpro-location .maplabpro-field-row {
    font-size: 1rem;
}

.maplabpro-location .maplabpro-field-divider {
    margin: 0.9rem 0;
}

.maplabpro-location-map {
    height: 320px;
    width: 100%;
}

.maplabpro-location-map-link {
    display: inline-flex;
    padding: 1rem 1rem 0;
}

.maplabpro-location-map-link:last-child {
    padding-bottom: 1rem;
}

@media (max-width: 820px) {
    .maplabpro-location-layout {
        grid-template-columns: 1fr;
    }

    .maplabpro-location-title {
        font-size: 1.6rem;
    }
}

/* ── Error state ─────────────────────────────────────────────── */

.maplabpro-error {
    padding: 1rem;
    color: #6b7280;
    font-size: 0.875rem;
    text-align: center;
}

/* ── Attribution ─────────────────────────────────────────────── */

.leaflet-control-attribution {
    font-size: 11px;
}
