/* ============================================================
   Mapsted Maps JavaScript API Sandbox — styles
   Dark theme default, Mapsted brand accent #2d9e6b (M-logo streak C, Electric Emerald)
   ============================================================ */

/* --- Custom properties ------------------------------------ */
:root {
  /* Brand — Mapsted M-logo streak C (Electric Emerald), dark-mode defaults */
  --accent:          #3ab87e;
  --accent-hover:    #2d9e6b;
  --accent-active:   #248a5c;

  /* Dark theme (default) */
  --bg-app:          #1e1e1e;
  --bg-toolbar:      #252526;
  --bg-panel:        #252526;
  --bg-editor:       #1e1e1e;
  --bg-log:          #1a1a1a;
  --bg-log-entry:    #252526;
  --bg-btn:          #3a3a3a;
  --bg-btn-hover:    #4a4a4a;
  --bg-resizer:      #3c3c3c;
  --bg-resizer-hover:#555555;

  --border:          #3c3c3c;
  --border-focus:    #3ab87e;

  --text-primary:    #d4d4d4;
  --text-secondary:  #9d9d9d;
  --text-toolbar:    #cccccc;
  --text-btn:        #cccccc;
  --text-title:      #ffffff;

  --log-select:      #4fc3f7;
  --log-floorchange: #81c995;
  --log-error:       #f28b82;
  --log-default:     #d4d4d4;
  --log-timestamp:   #888888;
  --log-payload:     #ce9178;

  --shadow-toolbar:  0 1px 4px rgba(0,0,0,0.5);
  --shadow-panel:    0 0 0 1px var(--border);
}

/* Light theme override */
[data-theme="light"] {
  /* Brand accent — light mode Electric Emerald (deeper for AA on white) */
  --accent:          #2d9e6b;
  --accent-hover:    #248a5c;
  --accent-active:   #1c7550;
  --border-focus:    #2d9e6b;

  --bg-app:          #f5f5f5;
  --bg-toolbar:      #ffffff;
  --bg-panel:        #ffffff;
  --bg-editor:       #fffffe;
  --bg-log:          #fafafa;
  --bg-log-entry:    #f0f0f0;
  --bg-btn:          #e8e8e8;
  --bg-btn-hover:    #d8d8d8;
  --bg-resizer:      #e0e0e0;
  --bg-resizer-hover:#c8c8c8;

  --border:          #dcdcdc;
  --text-primary:    #1e1e1e;
  --text-secondary:  #555555;
  --text-toolbar:    #333333;
  --text-btn:        #333333;
  --text-title:      #111111;

  --log-select:      #0277bd;
  --log-floorchange: #2e7d32;
  --log-error:       #c62828;
  --log-default:     #1e1e1e;
  --log-timestamp:   #777777;
  --log-payload:     #a0522d;

  --shadow-toolbar:  0 1px 4px rgba(0,0,0,0.12);
}

/* --- Reset ------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg-app);
  color: var(--text-primary);
}

/* --- App shell -------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* --- Toolbar ---------------------------------------------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 48px;
  flex-shrink: 0;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-toolbar);
  z-index: 10;
}

#toolbar-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-title);
  letter-spacing: 0.01em;
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toolbar-title .title-logo {
  height: 24px;
  width: 24px;
  padding: 3px;
  box-sizing: border-box;
  flex-shrink: 0;
  margin-left: 6px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-btn);
  color: var(--text-btn);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1;
}

.toolbar-btn:hover {
  background: var(--bg-btn-hover);
  border-color: #666;
}

.toolbar-btn:active {
  transform: translateY(1px);
}

.toolbar-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.toolbar-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.toolbar-btn.primary:active {
  background: var(--accent-active);
}

/* W-28c — disabled while Run is in flight: muted colour + wait cursor.
   Inline SVG retains aria affordance; pointer-events preserved so cursor
   style applies. */
.toolbar-btn.primary:disabled,
.toolbar-btn.primary[disabled] {
  opacity: 0.55;
  cursor: wait;
  background: var(--accent);
  border-color: var(--accent);
}

/* W-28c — dirty indicator: editor has changes not yet applied via Run.
   Pulsing dot after the label draws the eye without moving layout. */
.toolbar-btn.primary.is-dirty::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
  margin-left: 6px;
  vertical-align: middle;
  animation: mm-run-dirty-pulse 1.4s ease-in-out infinite;
}
@keyframes mm-run-dirty-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

.toolbar-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  fill: currentColor;
}

#btn-theme {
  padding: 5px 8px;
  font-size: 15px;
}

/* Property picker (demo selector) — inherits toolbar-btn visual baseline */
.toolbar-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-btn);
  color: var(--text-btn);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1;
  height: 28px;
  max-width: 260px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.toolbar-select:hover {
  background: var(--bg-btn-hover);
  border-color: #666;
}

.toolbar-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ──────────────────────────────────────────────────────────────
   Compact mode (W-15.6)
   ──────────────────────────────────────────────────────────────
   When the sandbox is embedded inside a docs iframe via
   docs/.vitepress/components/SandboxEmbed.vue with ?compact=true,
   hide the toolbar, event log, and vertical resizer. The editor +
   map take over the available space. Property picker (normally in
   toolbar) goes with the toolbar — embed URLs specify the property
   directly via ?property=<id>, so no picker needed inside.

   Per WAVE-2-SPEC.md Task 2 embed cert criterion "editor + map
   only, no toolbar, no event log".
*/
body.compact #toolbar {
  display: none;
}
body.compact #panel-log {
  display: none;
}
body.compact #v-resizer {
  display: none;
}
body.compact #status-bar {
  display: none;
}
body.compact #main {
  /* toolbar + status-bar are hidden, main should fill the viewport */
  height: 100vh;
}
body.compact #right-column {
  /* event log row is hidden — map should fill the right column */
  flex-direction: column;
}
body.compact #panel-map {
  flex: 1 1 auto;
  height: auto;
}

/* S049 W2.0.8 — compact-mode layout overrides for nested-iframe embed.
   When SandboxEmbed nests the sandbox in a tutorial page, the resulting
   iframe is typically ~600-700px wide — narrower than the 768px mobile
   breakpoint, which would otherwise stack panels vertically (editor on
   top, map cramped below ~220px). The cramped 220px panel makes the V3
   SDK iframe boot at sub-MAP_MOUNTED dimensions in some properties
   (PREX-S049-02). Force row layout in compact regardless of viewport
   width — embed authors size with `:height="N"` so editor + map split
   the available height 50/50. */
body.compact #main {
  flex-direction: row !important;
}
body.compact #panel-editor {
  flex: 1 1 50% !important;
  width: auto !important;
  height: auto !important;
  border-right: 1px solid var(--border) !important;
  border-bottom: none !important;
}
body.compact #h-resizer {
  display: block !important;
}
body.compact #right-column {
  flex: 1 1 50% !important;
}

/* Visually hidden label (retains screen-reader access) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Toast notification */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 9px 16px;
  background: #323232;
  color: #fff;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 9999;
}

#toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Main content area ------------------------------------ */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* --- Panels ----------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 32px;
  flex-shrink: 0;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}

.panel-header-actions {
  display: flex;
  gap: 4px;
}

.panel-btn {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.panel-btn:hover {
  background: var(--bg-btn);
  color: var(--text-primary);
}

/* --- Code editor panel ------------------------------------ */
#panel-editor {
  width: 50%;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

#editor-container {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* --- Right column: map + log ------------------------------ */
#right-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* --- Map panel -------------------------------------------- */
#panel-map {
  flex: 1;
  border-bottom: 1px solid var(--border);
  min-height: 0;
  position: relative;
}

#mapsted-map {
  width: 100%;
  height: 100%;
}

/* Map placeholder shown before first Run */
#map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
  text-align: center;
  padding: 24px;
}

#map-placeholder svg {
  width: 48px;
  height: 48px;
  fill: var(--border);
}

#map-placeholder.hidden {
  display: none;
}

/* S049 W2.0.6 — compact-mode loading indicator. Hidden by default;
   app.js makes it visible during compact auto-run SDK boot, hides
   on SDK READY. Mirrors #map-placeholder positioning. */
#compact-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
  text-align: center;
  padding: 24px;
  background: var(--bg-panel);
  z-index: 1;
}

#compact-loading.hidden {
  display: none;
}

.compact-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: mm-compact-spin 0.9s linear infinite;
}

@keyframes mm-compact-spin {
  to { transform: rotate(360deg); }
}

/* --- Vertical resizer between map and log ----------------- */
#v-resizer {
  height: 5px;
  flex-shrink: 0;
  background: var(--bg-resizer);
  cursor: row-resize;
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}

#v-resizer:hover,
#v-resizer.dragging {
  background: var(--accent);
}

/* While a resizer is being dragged, neutralise iframe mouse-event capture
   so the document-level mousemove/mouseup handlers keep firing even when
   the cursor crosses into the cross-origin SDK iframe. Without this, the
   drag silently freezes mid-motion (user S057 2026-04-26: "scroll to
   resize... in the middle... can't fix it"). */
body.resizing iframe {
  pointer-events: none;
}

/* --- Event log panel -------------------------------------- */
#panel-log {
  height: 200px;
  flex-shrink: 0;
  min-height: 80px;
  max-height: 60vh;
}

#log-entries {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  font-family: "Consolas", "Menlo", "Monaco", monospace;
  font-size: 12px;
  background: var(--bg-log);
}

#log-entries::-webkit-scrollbar {
  width: 6px;
}

#log-entries::-webkit-scrollbar-track {
  background: transparent;
}

#log-entries::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.log-entry {
  display: flex;
  gap: 8px;
  padding: 3px 12px;
  line-height: 1.6;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
}

.log-entry:hover {
  background: var(--bg-log-entry);
}

.log-ts {
  color: var(--log-timestamp);
  flex-shrink: 0;
  user-select: none;
}

.log-name {
  font-weight: 600;
  flex-shrink: 0;
}

.log-name.ev-select      { color: var(--log-select); }
.log-name.ev-floorChange { color: var(--log-floorchange); }
.log-name.ev-error       { color: var(--log-error); }
.log-name.ev-default     { color: var(--log-default); }

.log-payload {
  color: var(--log-payload);
  word-break: break-all;
  white-space: pre-wrap;
}

.log-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
}

/* --- Horizontal resizer between editor and right col ------ */
#h-resizer {
  width: 5px;
  flex-shrink: 0;
  background: var(--bg-resizer);
  cursor: col-resize;
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}

#h-resizer:hover,
#h-resizer.dragging {
  background: var(--accent);
}

/* --- Status bar ------------------------------------------- */
#status-bar {
  height: 22px;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
}

/* W-27/W-28b — solid white on --accent (Electric Emerald #2d9e6b light /
   #3ab87e dark) yields 4.6:1 / 7.1:1 per WCAG 2.1 — passes AA on both modes. */
#status-bar span {
  opacity: 1;
}

/* --- Responsive: mobile (<768px) -------------------------- */
@media (max-width: 767px) {
  #main {
    flex-direction: column;
  }

  #panel-editor {
    width: 100%;
    height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  #h-resizer {
    display: none;
  }

  #right-column {
    flex: 1;
    min-height: 0;
  }

  #panel-map {
    flex: 1;
  }

  #panel-log {
    height: 160px;
  }

  #toolbar-title {
    font-size: 13px;
  }

  .toolbar-btn {
    padding: 5px 9px;
    font-size: 12px;
  }

  .toolbar-btn .btn-label {
    display: none;
  }
}

/* --- Scrollbar (Firefox) ---------------------------------- */
#log-entries {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* --- Run error overlay in map ----------------------------- */
#run-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,0.75);
  color: var(--log-error);
  font-family: "Consolas", monospace;
  font-size: 13px;
  padding: 24px;
  text-align: center;
  z-index: 20;
}

#run-error.hidden {
  display: none;
}

#run-error .err-title {
  font-size: 15px;
  font-weight: 700;
}

#run-error .err-dismiss {
  margin-top: 8px;
  padding: 5px 14px;
  border: 1px solid var(--log-error);
  border-radius: 4px;
  background: transparent;
  color: var(--log-error);
  cursor: pointer;
  font-size: 12px;
}

#run-error .err-dismiss:hover {
  background: rgba(242, 139, 130, 0.15);
}

/* ============================================================
   S049 W2.0.4 — Reduced-motion support (WCAG 2.3.3 + 2.2 AA)
   Honour OS-level `prefers-reduced-motion: reduce` setting:
   suppress every animation + transition site-wide so users with
   vestibular disorders, motion sickness, or focus-impacting
   sensitivities are not subjected to the dirty-pulse animation,
   toast slides, panel-resize transitions, or button hover fades.
   Universal selector with !important is the conventional pattern
   (https://www.w3.org/WAI/WCAG22/Techniques/css/C39).
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
