/* ============================================================
   Map Builder Pro — Builder & Demo App UI
   ============================================================ */

/* ── Theme neutralisation ─────────────────────────────────── */
/* Collapse the WP theme wrapper so the builder fills the viewport */
body:has(.mb-builder-app) {
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}
body:has(.mb-builder-app) #page,
body:has(.mb-builder-app) #content,
body:has(.mb-builder-app) .site,
body:has(.mb-builder-app) .hfeed {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
}
body:has(.mb-builder-app) #masthead,
body:has(.mb-builder-app) #colophon,
body:has(.mb-builder-app) .site-header,
body:has(.mb-builder-app) .site-footer,
body:has(.mb-builder-app) #secondary,
body:has(.mb-builder-app) .widget-area,
body:has(.mb-builder-app) .entry-header,
body:has(.mb-builder-app) .entry-footer,
body:has(.mb-builder-app) .entry-title {
    display: none !important;
}
body:has(.mb-builder-app) #primary,
body:has(.mb-builder-app) #main,
body:has(.mb-builder-app) .site-main,
body:has(.mb-builder-app) .entry-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    display: block !important;
}

/* ── Force full-viewport layout ───────────────────────────── */
.mb-builder-app *,
.mb-builder-app *::before,
.mb-builder-app *::after {
    box-sizing: border-box;
}

/* Override WordPress theme interference in the builder */
.mb-builder-app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 32px); /* subtract WP admin bar */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-size: 13px;
    color: #1a1a1a;
    background: #f0f2f0;
    overflow: hidden;
    position: relative;
    /* Reset any theme margin/padding that breaks the app layout */
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
}

/* When admin bar is not visible (front-end non-admin view) */
body:not(.admin-bar) .mb-builder-app {
    height: 100vh;
}

/* ── Top bar ──────────────────────────────────────────────── */
.mb-topbar {
    display: flex;
    align-items: center;
    background: #1c2b2a;
    color: #fff;
    padding: 0 20px;
    height: 54px;
    flex-shrink: 0;
    gap: 12px;
    box-shadow: 0 1px 0 rgba(255,255,255,.05);
    z-index: 100;
}

.mb-logo {
    font-size: 15px;
    font-weight: 800;
    color: #74c69d;
    letter-spacing: -.3px;
    white-space: nowrap;
}
.mb-topbar-sep   { color: rgba(255,255,255,.2); font-size: 18px; }
.mb-topbar-label { font-size: 13px; color: rgba(255,255,255,.5); white-space: nowrap; }
.mb-topbar-center { flex: 1; text-align: center; overflow: hidden; padding: 0 10px; }

.mb-hint-text {
    font-size: 12px;
    color: rgba(255,255,255,.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mb-hint-text a { color: #74c69d; font-weight: 600; text-decoration: none; }

.mb-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.mb-save-status {
    font-size: 12px;
    color: #74c69d;
    min-width: 110px;
    text-align: right;
    white-space: nowrap;
}

.mb-topbar-btn {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.18);
    color: rgba(255,255,255,.85);
    border-radius: 6px;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
    font-family: inherit;
}
.mb-topbar-btn:hover { background: rgba(255,255,255,.16); }
.mb-topbar-btn-primary {
    background: #2d6a4f;
    border-color: #2d6a4f;
    color: #fff;
}
.mb-topbar-btn-primary:hover { background: #1b4332; }

/* ── Left sidebar ─────────────────────────────────────────── */
.mb-sidebar {
    width: 228px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e8e8e8;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
}
.mb-sidebar::-webkit-scrollbar { width: 4px; }
.mb-sidebar::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.mb-sidebar-section {
    padding: 16px 16px 10px;
    border-bottom: 1px solid #f2f2f2;
}
.mb-sidebar-section:last-child { border-bottom: none; }

.mb-sidebar-section h3 {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #aaa;
    margin: 0 0 14px;
    padding: 0;
}

/* ── Fields ───────────────────────────────────────────────── */
.mb-field { margin-bottom: 14px; }
.mb-field:last-child { margin-bottom: 4px; }

.mb-field > label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #666;
    margin-bottom: 6px;
    line-height: 1;
}

.mb-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mb-colorpick {
    width: 34px;
    height: 34px;
    border: 2px solid #e8e8e8;
    border-radius: 7px;
    cursor: pointer;
    padding: 2px;
    background: none;
    flex-shrink: 0;
    transition: border-color .15s;
}
.mb-colorpick:hover { border-color: #2d6a4f; }
.mb-colorpick::-webkit-color-swatch-wrapper { padding: 0; }
.mb-colorpick::-webkit-color-swatch { border: none; border-radius: 4px; }

.mb-hex {
    font-size: 11px;
    font-family: 'Courier New', Courier, monospace;
    color: #555;
    letter-spacing: .03em;
}

.mb-select {
    width: 100%;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12px;
    background: #fafafa;
    color: #333;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    transition: border-color .15s;
}
.mb-select:focus { border-color: #2d6a4f; background: #fff; }

/* Toggle buttons */
.mb-toggle-row { display: flex; }

.mb-toggle {
    flex: 1;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    padding: 7px 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    color: #666;
    transition: all .12s;
    font-family: inherit;
    line-height: 1;
}
.mb-toggle:first-child { border-radius: 6px 0 0 6px; }
.mb-toggle:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.mb-toggle.active { background: #2d6a4f; color: #fff; border-color: #2d6a4f; }
.mb-toggle:hover:not(.active) { background: #ebebeb; }

/* Small button (reset etc) */
.mb-sm-btn {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    color: #555;
    font-family: inherit;
    transition: all .12s;
}
.mb-sm-btn:hover { background: #f5f5f5; border-color: #ccc; }

/* ── Map canvas ───────────────────────────────────────────── */
.mb-canvas {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: #e8ece8;
    min-width: 0;
    min-height: 300px;
}

/* Ensure SVG fills canvas and is always on top for clicks */
#mapbuilder-svg {
    cursor: default;
    filter: drop-shadow(0 2px 12px rgba(0,0,0,.12));
    display: block;
    width: 100%;
    z-index: 1;
}

/* Fallback: if mb-layout has no height, give it one */
.mb-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    height: calc(100vh - 86px); /* topbar ~54px + admin bar 32px */
}

/* ── Right: per-region panel ──────────────────────────────── */
.mb-state-panel {
    position: fixed;
    top: 32px; /* below WP admin bar */
    right: -310px; /* start off-screen */
    width: 290px;
    height: calc(100vh - 32px);
    background: #fff;
    border-left: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    z-index: 500;
    box-shadow: -4px 0 24px rgba(0,0,0,.12);
    transition: right .22s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}
.mb-state-panel.open {
    right: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Backdrop when panel is open on mobile */
.mb-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 499;
}
.mb-panel-backdrop.open { display: block; }

/* Non-admin bar: panel starts at top */
body:not(.admin-bar) .mb-state-panel { top: 0; height: 100vh; right: -310px; }
body:not(.admin-bar) .mb-state-panel.open { right: 0; }

.mb-state-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 14px;
    border-bottom: 1px solid #f2f2f2;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    flex-shrink: 0;
}
.mb-state-panel-head h2 {
    font-size: 18px;
    font-weight: 800;
    color: #1a1a1a;
    margin: 0;
    padding: 0;
    border: none;
}

.mb-panel-close {
    background: #f5f5f5;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all .12s;
}
.mb-panel-close:hover { background: #ebebeb; color: #333; }

.mb-state-panel-body {
    padding: 18px;
    flex: 1;
}
.mb-state-panel-body .mb-field { margin-bottom: 18px; }
.mb-state-panel-body .mb-field > label {
    font-size: 11px;
    font-weight: 700;
    color: #888;
    margin-bottom: 7px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.mb-input, .mb-textarea {
    width: 100%;
    border: 1px solid #e0e0e0;
    border-radius: 7px;
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    color: #333;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    background: #fafafa;
}
.mb-input:focus, .mb-textarea:focus {
    border-color: #2d6a4f;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(45,106,79,.08);
}
.mb-textarea { height: 90px; resize: vertical; line-height: 1.5; }

.mb-check-field > label {
    display: flex !important;
    align-items: center;
    gap: 9px;
    font-size: 13px !important;
    font-weight: 500 !important;
    color: #444 !important;
    cursor: pointer;
    text-transform: none !important;
    letter-spacing: 0 !important;
}
.mb-check-field input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #2d6a4f;
    flex-shrink: 0;
}

.mb-state-panel-footer {
    display: flex;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid #f2f2f2;
    position: sticky;
    bottom: 0;
    background: #fff;
    flex-shrink: 0;
}

/* ── Primary / ghost buttons ──────────────────────────────── */
.mb-btn-primary {
    background: #2d6a4f;
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
    flex: 1;
}
.mb-btn-primary:hover { background: #1b4332; }

.mb-btn-ghost {
    background: #fff;
    color: #555;
    border: 1px solid #e0e0e0;
    border-radius: 7px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    flex: 1;
}
.mb-btn-ghost:hover { background: #f5f5f5; border-color: #ccc; }

/* ── Embed overlay ────────────────────────────────────────── */
.mb-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(3px);
}

.mb-modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    width: min(660px, 100%);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: mb-modal-in .2s ease;
}
@keyframes mb-modal-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mb-embed-modal {
    max-height: 92vh;
    overflow-y: auto;
}

.mb-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.mb-modal-head h3 {
    font-size: 20px;
    font-weight: 800;
    color: #111;
    margin: 0;
    padding: 0;
    border: none;
}
.mb-modal-head button {
    background: #f5f5f5;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    padding: 4px 10px;
    border-radius: 6px;
    line-height: 1;
    transition: all .12s;
}
.mb-modal-head button:hover { background: #ebebeb; color: #333; }

.mb-modal-box > p {
    font-size: 13px;
    color: #777;
    margin: 0 0 18px;
    line-height: 1.6;
}

.mb-embed-opts {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
    font-size: 13px;
    color: #555;
}
.mb-embed-opts label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.mb-embed-opts input[type="number"] {
    width: 72px;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 6px 8px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}
.mb-embed-opts input[type="number"]:focus { border-color: #2d6a4f; }
.mb-embed-opts input[type="checkbox"] { accent-color: #2d6a4f; }

.mb-embed-textarea {
    width: 100%;
    height: 110px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    background: #f8f8f8;
    resize: none;
    outline: none;
    color: #333;
    line-height: 1.6;
    transition: border-color .15s;
}
.mb-embed-textarea:focus { border-color: #2d6a4f; background: #fff; }

.mb-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
    align-items: center;
}
.mb-modal-foot .mb-btn-primary { flex: none; }
.mb-modal-foot .mb-btn-ghost   { flex: none; }

/* ── Platform tabs ────────────────────────────────────────── */
.mb-platform-tabs {
    margin-top: 22px;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    overflow: hidden;
}

.mb-ptab-head {
    display: flex;
    background: #f5f5f5;
    border-bottom: 1px solid #e8e8e8;
    overflow-x: auto;
    scrollbar-width: none;
}
.mb-ptab-head::-webkit-scrollbar { display: none; }

.mb-ptab {
    flex: 1;
    min-width: 80px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 8px;
    font-size: 11px;
    font-weight: 700;
    color: #888;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    white-space: nowrap;
    text-align: center;
    margin-bottom: -1px;
}
.mb-ptab:hover { color: #333; }
.mb-ptab.active {
    color: #2d6a4f;
    border-bottom-color: #2d6a4f;
    background: #fff;
}

.mb-ptab-body { padding: 16px 18px; background: #fff; }

.mb-ptab-content {
    display: none;
    font-size: 13px;
    color: #444;
    line-height: 1.7;
}
.mb-ptab-content.active { display: block; }

.mb-ptab-content ol {
    padding-left: 20px;
    margin: 0 0 4px;
}
.mb-ptab-content li { margin-bottom: 5px; }
.mb-ptab-content strong { color: #111; }

.mb-ptip {
    background: #f0f7f4;
    border-left: 3px solid #2d6a4f;
    padding: 9px 12px;
    border-radius: 0 6px 6px 0;
    margin-top: 12px;
    font-size: 12px;
    color: #1b4332;
    line-height: 1.5;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .mb-topbar-label { display: none; }
    .mb-save-status  { display: none; }
    .mb-sidebar { width: 180px; }
    .mb-state-panel.open { width: 240px; }
}

@media (max-width: 560px) {
    .mb-sidebar { display: none; } /* slides into a drawer — future enhancement */
    .mb-topbar { padding: 0 12px; gap: 8px; }
    .mb-topbar-btn { padding: 6px 10px; font-size: 11px; }
}

/* ── Label joystick ──────────────────────────────── */
.mb-joystick-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 4px;
}

.mb-joystick {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.mb-joy-row {
    display: flex;
    align-items: center;
    gap: 3px;
}

.mb-joy-btn {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    border: 1px solid #d8d8d8;
    background: #f5f5f5;
    color: #444;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .1s, transform .08s, border-color .1s;
    user-select: none;
    -webkit-user-select: none;
    padding: 0;
    line-height: 1;
}

.mb-joy-btn:hover {
    background: #e8e8e8;
    border-color: #bbb;
}

.mb-joy-btn:active,
.mb-joy-btn.mb-joy-active {
    background: #2d6a4f;
    border-color: #2d6a4f;
    color: #fff;
    transform: scale(.92);
}

.mb-joy-center {
    background: #fff;
    border-color: #ccc;
    font-size: 16px;
    color: #888;
}
.mb-joy-center:hover {
    background: #fff5f5;
    border-color: #e88;
    color: #c44;
}

.mb-joy-readout {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: #888;
    min-width: 44px;
}
.mb-joy-readout span {
    display: flex;
    align-items: center;
    gap: 4px;
}
.mb-joy-readout strong {
    font-size: 12px;
    color: #333;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    min-width: 28px;
}
