/* Map Embed Block — Frontend */

.map-embed {
    position: relative;
    margin: 2rem 0;
    box-sizing: border-box;
    overflow: hidden;
}

/* ---- Tab bar ---- */
.map-embed__tabs {
    display: flex;
    gap: 0;
    max-width: 48rem;
    margin: 0 auto;
    padding: 0 1rem;
    box-sizing: border-box;
}

.map-embed__tab {
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--color-border, #d0d0d0);
    border-bottom: none;
    background: var(--color-surface-muted, #f4f4f4);
    color: var(--color-text, #444);
    font-family: var(--font-body, sans-serif);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    margin-right: -1px;
    position: relative;
    transition: background 0.15s, color 0.15s;
}

.map-embed__tab:hover {
    background: var(--color-surface, #fff);
    color: var(--color-heading-blue, #5396FB);
}

.map-embed__tab.is-active {
    background: var(--color-surface, #fff);
    color: var(--color-heading-blue, #5396FB);
    font-weight: 600;
    z-index: 1;
    border-bottom: 2px solid var(--color-surface, #fff);
    margin-bottom: -1px;
}

/* ---- Body ---- */
.map-embed__body {
    position: relative;
    border-top: 1px solid var(--color-border, #d0d0d0);
}

/* ---- Category bar — floating panel, top-right of map (like legend) ---- */
.map-embed__catbar {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.93);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    max-height: calc(100% - 20px);
    overflow-y: auto;
}

.map-embed__catbar-label {
    font-family: var(--font-body, sans-serif);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted, #888);
    margin-bottom: 2px;
}

.map-embed__catbar-loading {
    font-size: 0.75rem;
    color: var(--color-text-muted, #999);
    font-style: italic;
}

.map-embed__cat-btn {
    padding: 4px 12px;
    border: none;
    border-radius: 3px;
    background: transparent;
    font-family: var(--font-body, sans-serif);
    font-size: 0.8125rem;
    color: var(--color-text, #444);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
    text-align: left;
}

.map-embed__cat-btn:hover {
    background: rgba(0,0,0,0.06);
    color: var(--color-heading-blue, #5396FB);
}

.map-embed__cat-btn.is-active {
    background: var(--color-heading-blue, #5396FB);
    color: #fff;
    font-weight: 600;
}

/* ---- Controls overlay — lets button sit on top of iframe ---- */
.map-embed__controls-overlay {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 5;
    pointer-events: none;
}

/* ---- Fullscreen button — bottom-left of map ---- */
.map-embed__fullscreen-btn {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 29px;
    height: 29px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: #fff;
    color: #333;
    cursor: pointer;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
    transition: background 0.15s;
}

.map-embed__fullscreen-btn:hover {
    background: #f0f0f0;
}

/* ---- Load placeholder ---- */
.map-embed__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    box-sizing: border-box;
    background: linear-gradient(135deg, #e8f0fe 0%, #f0f4f8 100%);
    color: #8899aa;
}

.map-embed__placeholder svg {
    opacity: 0.4;
}

.map-embed__load-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: 6px;
    background: var(--color-heading-blue, #5396FB);
    color: #fff;
    font-family: var(--font-body, sans-serif);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(83,150,251,0.3);
}

.map-embed__load-btn:hover {
    background: #3a7bd5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(83,150,251,0.4);
}

.map-embed__load-btn:active {
    transform: translateY(0);
}

html[data-theme="dark"] .map-embed__placeholder {
    background: linear-gradient(135deg, #1a2030 0%, #1e2838 100%);
    color: #556677;
}

html[data-theme="dim"] .map-embed__placeholder {
    background: linear-gradient(135deg, #e8e0d0 0%, #ece4d4 100%);
    color: #8a8070;
}

/* ---- Iframe ---- */
.map-embed__iframe {
    display: block;
    width: 100%;
    border: none;
}

.map-embed__iframe.is-hidden {
    display: none;
}

/* ---- Download row ---- */
.map-embed__download {
    max-width: 48rem;
    margin: 0 auto 0.5rem;
    padding: 0 1rem;
    box-sizing: border-box;
}

.map-embed__download-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body, sans-serif);
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--color-heading-blue, #5396FB);
    text-decoration: none;
    padding: 0.5rem 0;
    transition: color 0.15s;
}

.map-embed__download-link:hover {
    color: var(--color-link-hover, #3a7bd5);
    text-decoration: underline;
}

.map-embed__download-link svg { flex-shrink: 0; }
.map-embed__download-link strong { font-weight: 600; }

.map-embed__file-size {
    color: var(--color-text-muted, #888);
    font-size: 0.875rem;
    font-weight: 400;
}

/* ---- Fullscreen mode ---- */
.map-embed.is-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh;
    height: 100dvh;            /* dvh excludes mobile browser chrome */
    margin: 0 !important;
    z-index: 99999;
    background: var(--color-surface, #fff);
    display: flex;
    flex-direction: column;
}

.map-embed.is-fullscreen .map-embed__tabs {
    max-width: none;
    padding: 0.5rem 1rem 0;
    flex-shrink: 0;
}

.map-embed.is-fullscreen .map-embed__body {
    flex: 1;
    min-height: 0;
    position: relative;
}

.map-embed.is-fullscreen .map-embed__iframe {
    height: 100% !important;
    max-height: none !important;   /* override the mobile 120vw cap */
}

/* Pin the close button to the actual visible viewport so the iOS bottom
   toolbar can never hide it — it's the only way to exit fullscreen. */
.map-embed.is-fullscreen .map-embed__controls-overlay {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    left:   calc(env(safe-area-inset-left, 0px) + 10px);
    z-index: 100000;
}

.map-embed.is-fullscreen .map-embed__fullscreen-btn svg {
    transform: rotate(180deg);
}


/* ---- Responsive: smaller buttons on mobile ---- */
@media screen and (max-width: 48em) {
    .map-embed__catbar {
        gap: 3px;
        padding: 5px 6px;
    }
    .map-embed__cat-btn {
        padding: 2px 7px;
        font-size: 0.6875rem;
    }
    .map-embed__catbar-label {
        font-size: 0.625rem;
    }
    /* The block stores a fixed mapHeight (default 700px) inline on the iframe
       and placeholder. On mobile that produces a tall portrait box. Override
       it to ~1:1.2 ratio relative to viewport width. Skip in fullscreen. */
    .map-embed:not(.is-fullscreen) .map-embed__iframe,
    .map-embed:not(.is-fullscreen) .map-embed__placeholder {
        height: 120vw !important;
    }
}

/* ---- Dark theme ---- */
html[data-theme="dark"] .map-embed__tab {
    background: #1e2530;
    border-color: #3a3f4a;
    color: #b0b8c4;
}
html[data-theme="dark"] .map-embed__tab:hover {
    background: #252c38;
    color: #7ab8ff;
}
html[data-theme="dark"] .map-embed__tab.is-active {
    background: #252c38;
    color: #7ab8ff;
    border-bottom-color: #252c38;
}
html[data-theme="dark"] .map-embed__body {
    border-color: #3a3f4a;
}
html[data-theme="dark"] .map-embed__catbar {
    background: rgba(30,37,48,0.93);
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
html[data-theme="dark"] .map-embed__catbar-label { color: #666; }
html[data-theme="dark"] .map-embed__cat-btn { color: #b0b8c4; }
html[data-theme="dark"] .map-embed__cat-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #7ab8ff;
}
html[data-theme="dark"] .map-embed__cat-btn.is-active {
    background: #3a7bd5;
    color: #fff;
}
html[data-theme="dark"] .map-embed.is-fullscreen {
    background: #1a1f2a;
}
html[data-theme="dark"] .map-embed__download-link { color: #7ab8ff; }
html[data-theme="dark"] .map-embed__download-link:hover { color: #a8d0ff; }
html[data-theme="dark"] .map-embed__file-size { color: #777; }

/* ---- Dim theme ---- */
html[data-theme="dim"] .map-embed__tab {
    background: #e8e0d0;
    border-color: #c8c0b0;
    color: #5a5040;
}
html[data-theme="dim"] .map-embed__tab:hover {
    background: #f0e8d8;
    color: #4a7fc7;
}
html[data-theme="dim"] .map-embed__tab.is-active {
    background: #f0e8d8;
    color: #4a7fc7;
    border-bottom-color: #f0e8d8;
}
html[data-theme="dim"] .map-embed__body { border-color: #c8c0b0; }
html[data-theme="dim"] .map-embed__catbar {
    background: rgba(240,232,216,0.93);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
html[data-theme="dim"] .map-embed__cat-btn { color: #5a5040; }
html[data-theme="dim"] .map-embed__cat-btn:hover {
    background: rgba(0,0,0,0.06);
    color: #4a7fc7;
}
html[data-theme="dim"] .map-embed__cat-btn.is-active {
    background: #4a7fc7;
    color: #fff;
}
html[data-theme="dim"] .map-embed.is-fullscreen { background: #f0e8d8; }
html[data-theme="dim"] .map-embed__download-link { color: #4a7fc7; }
html[data-theme="dim"] .map-embed__download-link:hover { color: #3a6ab0; }

/* ============================================
   Editor styles
   ============================================ */
.map-embed-block {
    border: 1px dashed #ccc;
    border-radius: 8px;
    padding: 16px;
    background: #fafafa;
}

.map-embed-block__section { margin-bottom: 14px; }

.map-embed-block__label {
    display: block;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
    color: #555;
}

.map-embed-block__slot {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: #fff;
    overflow: hidden;
}

.map-embed-block__slot-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.map-embed-block__slot-arrows {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-shrink: 0;
}

.map-embed-block__slot-arrows .components-button {
    min-width: 0 !important;
    padding: 0 4px !important;
    font-size: 10px;
    line-height: 1;
}

.map-embed-block__label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.map-embed-block__label-row .map-embed-block__label {
    margin-bottom: 0;
}

.map-embed-block__df-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 13px;
}

.map-embed-block__df-num {
    font-weight: 600;
    color: #888;
    width: 24px;
    flex-shrink: 0;
}

.map-embed-block__upload-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.map-embed-block__filename {
    font-size: 13px;
    color: #333;
    background: #e8e8e8;
    padding: 2px 8px;
    border-radius: 4px;
}

.map-embed-block__tabs {
    display: flex;
    gap: 4px;
}

.map-embed-block__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: #f0f0f0;
    border-radius: 8px;
    color: #888;
    margin-top: 8px;
}

.map-embed-block__placeholder .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
    color: #bbb;
}

.map-embed-block__help {
    font-size: 12px;
    color: #777;
    font-style: italic;
    margin: -6px 0 12px;
    padding: 6px 10px;
    background: #f0f7ff;
    border-left: 3px solid #5396FB;
    border-radius: 0 4px 4px 0;
    line-height: 1.5;
}
