/* Java Electrindo v45 - Responsive MQTT Dashboard Builder + Canvas Navigation
   Scope: UI/UX layer only. No MQTT/auth/backend/canvas data logic changes. */

/* App containment */
html, body {
  max-width: 100%;
  overflow-x: clip;
}

body.je-v45-ready,
body.je-v45-ready * {
  box-sizing: border-box;
}

/* Remove old injected back buttons */
.je-dash-back-v41,
.je-dash-back-v42,
.je-dash-back-v43,
.je-dash-back-v44,
.je-dash-back-v45-hidden {
  display: none !important;
}

/* Responsive dashboard shell */
body.je-v45-ready header,
body.je-v45-ready .app-header,
body.je-v45-ready .topbar,
body.je-v45-ready .toolbar,
body.je-v45-ready .top-row {
  max-width: 100vw;
  overflow: visible;
}

body.je-v45-ready .workspace,
body.je-v45-ready .app,
body.je-v45-ready .main,
body.je-v45-ready .layout,
body.je-v45-ready .dashboard,
body.je-v45-ready .stage,
body.je-v45-ready .canvas-wrap,
body.je-v45-ready .canvas-shell {
  max-width: 100vw !important;
  box-sizing: border-box !important;
}

/* Right rail stays usable on mobile */
body.je-v45-ready .right-rail,
body.je-v45-ready .tool-rail,
body.je-v45-ready .tools-rail,
body.je-v45-ready .side-tools {
  max-height: calc(100vh - 86px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

/* Make side/popup panels fit screen */
body.je-v45-ready .panel,
body.je-v45-ready .side-panel,
body.je-v45-ready .drawer,
body.je-v45-ready .sheet,
body.je-v45-ready .modal,
body.je-v45-ready .dialog,
body.je-v45-ready .popover,
body.je-v45-ready .config-panel,
body.je-v45-ready .properties-panel {
  max-width: min(720px, calc(100vw - 84px)) !important;
  max-height: calc(100vh - 112px) !important;
  overflow: auto !important;
}

/* Canvas camera behavior */
body.je-v45-hand-active {
  cursor: grab;
}

body.je-v45-hand-active .je-v45-camera-surface,
body.je-v45-hand-active .je-v45-camera-surface * {
  cursor: grab !important;
}

body.je-v45-panning,
body.je-v45-panning .je-v45-camera-surface,
body.je-v45-panning .je-v45-camera-surface * {
  cursor: grabbing !important;
  user-select: none !important;
}

.je-v45-camera-surface {
  touch-action: none;
  transform-origin: 0 0;
  will-change: transform;
}

.je-v45-camera-hud {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 2147482400;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .80);
  color: #e5edf8;
  font: 700 12px/1 system-ui, -apple-system, Segoe UI, sans-serif;
  backdrop-filter: blur(10px);
}

body.je-v45-light-active .je-v45-camera-hud {
  background: rgba(255,255,255,.88);
  color: #0f172a;
}

/* Left MQTT builder */
.je-v45-builder {
  position: fixed;
  left: 14px;
  top: 92px;
  bottom: 56px;
  width: min(320px, calc(100vw - 28px));
  z-index: 2147482300;
  border: 1px solid rgba(148, 163, 184, .26);
  border-radius: 20px;
  background: rgba(15, 23, 42, .92);
  color: #e5edf8;
  box-shadow: 0 24px 70px rgba(2, 8, 23, .25);
  backdrop-filter: blur(14px);
  transform: translateX(calc(-100% - 24px));
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.je-v45-builder.open {
  transform: translateX(0);
}

body.je-v45-light-active .je-v45-builder {
  background: rgba(255,255,255,.94);
  color: #0f172a;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .14);
}

.je-v45-builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, .22);
}

.je-v45-builder-head strong {
  font-size: 15px;
  letter-spacing: -.01em;
}

.je-v45-builder-head button,
.je-v45-builder-toggle,
.je-v45-builder button {
  border: 1px solid rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .74);
  color: #e5edf8;
  border-radius: 12px;
  min-height: 36px;
  padding: 0 11px;
  font-weight: 800;
  cursor: pointer;
}

body.je-v45-light-active .je-v45-builder-head button,
body.je-v45-light-active .je-v45-builder-toggle,
body.je-v45-light-active .je-v45-builder button {
  background: #ffffff;
  color: #0f172a;
}

.je-v45-builder-body {
  padding: 12px;
  overflow: auto;
  display: grid;
  gap: 10px;
}

.je-v45-section {
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 16px;
  overflow: hidden;
}

.je-v45-section summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 12px;
  font-weight: 900;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.je-v45-section summary::-webkit-details-marker {
  display: none;
}

.je-v45-section summary::after {
  content: "+";
  opacity: .75;
}

.je-v45-section[open] summary::after {
  content: "−";
}

.je-v45-tools {
  padding: 0 10px 10px;
  display: grid;
  gap: 8px;
}

.je-v45-tool {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 9px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 9px;
  min-height: 46px !important;
}

.je-v45-tool span:first-child {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #c8102e);
  color: #fff;
  font-size: 13px;
}

.je-v45-tool b {
  display: block;
  font-size: 13px;
}

.je-v45-tool small {
  display: block;
  opacity: .72;
  font-size: 11px;
}

.je-v45-builder-toggle {
  position: fixed;
  left: 14px;
  top: 102px;
  z-index: 2147482350;
  min-height: 42px;
  padding: 0 13px;
}

.je-v45-hand-toggle {
  position: fixed;
  left: 14px;
  top: 152px;
  z-index: 2147482350;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .84);
  color: #e5edf8;
  border-radius: 12px;
  font-weight: 900;
  cursor: pointer;
}

body.je-v45-light-active .je-v45-hand-toggle {
  background: #fff;
  color: #0f172a;
}

.je-v45-hand-toggle.active {
  background: linear-gradient(135deg, #1d4ed8, #c8102e);
  color: #fff;
}

/* Dark/light field stabilization inherited from v44, tightened */
body.je-v45-dark-active input,
body.je-v45-dark-active textarea,
body.je-v45-dark-active select {
  background-color: #0b1220 !important;
  color: #e5edf8 !important;
  -webkit-text-fill-color: #e5edf8 !important;
  border-color: rgba(148, 163, 184, .42) !important;
  box-shadow: none !important;
}

body.je-v45-light-active input,
body.je-v45-light-active textarea,
body.je-v45-light-active select {
  background-color: #ffffff !important;
  color: #0f172a !important;
  -webkit-text-fill-color: #0f172a !important;
  border-color: rgba(15, 23, 42, .16) !important;
  box-shadow: none !important;
}

body.je-v45-dark-active label,
body.je-v45-dark-active .label,
body.je-v45-dark-active .field-label,
body.je-v45-dark-active .field-title,
body.je-v45-dark-active .form-label {
  color: #cbd5e1 !important;
  -webkit-text-fill-color: #cbd5e1 !important;
}

body.je-v45-light-active label,
body.je-v45-light-active .label,
body.je-v45-light-active .field-label,
body.je-v45-light-active .field-title,
body.je-v45-light-active .form-label {
  color: #0f172a !important;
  -webkit-text-fill-color: #0f172a !important;
}

/* Mobile */
@media (max-width: 780px) {
  body.je-v45-ready header,
  body.je-v45-ready .app-header,
  body.je-v45-ready .topbar,
  body.je-v45-ready .toolbar,
  body.je-v45-ready .top-row {
    flex-wrap: wrap !important;
    gap: 8px !important;
    min-height: auto !important;
  }

  body.je-v45-ready header button,
  body.je-v45-ready .app-header button,
  body.je-v45-ready .toolbar button,
  body.je-v45-ready header a,
  body.je-v45-ready .app-header a {
    min-height: 38px !important;
    padding-inline: 10px !important;
    font-size: 12px !important;
  }

  body.je-v45-ready .panel,
  body.je-v45-ready .side-panel,
  body.je-v45-ready .drawer,
  body.je-v45-ready .sheet,
  body.je-v45-ready .modal,
  body.je-v45-ready .dialog,
  body.je-v45-ready .popover {
    left: 10px !important;
    right: 10px !important;
    top: 86px !important;
    width: auto !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 118px) !important;
  }

  .je-v45-builder {
    top: 84px;
    bottom: 46px;
  }

  .je-v45-builder-toggle {
    top: auto;
    bottom: 64px;
    left: 12px;
  }

  .je-v45-hand-toggle {
    top: auto;
    bottom: 112px;
    left: 12px;
  }

  .je-v45-camera-hud {
    right: 10px;
    left: auto;
    bottom: 12px;
  }
}
