html:has(.mv-draw-body) {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

html:has(.mv-draw-body.mv-draw-embedded) {
  height: 100%;
  max-height: 100%;
}

body.mv-draw-body {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #0f172a;
  color: #e2e8f0;
}

body.mv-draw-body.mv-draw-embedded {
  min-height: 0;
  max-height: 100%;
}

.mv-draw-embedded .mv-draw-topbar .topbar-brand,
.mv-draw-embedded .mv-draw-topbar .standalone-title,
.mv-draw-embedded .mv-draw-topbar .standalone-meta .page-close,
.mv-draw-embedded .mv-draw-topbar .standalone-meta .topbar-version,
.mv-draw-embedded .mv-draw-topbar #mv-btn-help {
  display: none;
}

.mv-draw-embedded .mv-draw-topbar {
  padding-block: 0.35rem;
}

.mv-composer-modes {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.mv-composer-modes-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.15rem;
}

.mv-composer-mode-btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  min-width: 0;
}

.mv-composer-mode-btn.active {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
  font-weight: 600;
}

.mv-draw-embedded .mv-composer-modes-label {
  display: none;
}

.mv-file-menu-mooreview {
  margin-top: 0.2rem;
  color: #cbd5e1;
}

.mv-draw-topbar {
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-start;
}

.mv-draw-topbar .standalone-title {
  flex: 0 0 auto;
  font-size: 1rem;
  white-space: nowrap;
}

.mv-draw-topbar .standalone-meta {
  margin-left: auto;
  flex-shrink: 0;
}

.mv-file-menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.mv-file-menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 60;
  min-width: 15rem;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #1e293b;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.mv-file-menu-panel.view-hidden {
  display: none;
}

/* File dropdown must not sit above modal dialogs (e.g. File → New with unsaved changes). */
body.mv-draw-body:has(dialog[open]) .mv-file-menu-panel,
body.mv-draw-body:has(#mv-unsaved-overlay:not(.view-hidden)) .mv-file-menu-panel,
body.mv-draw-body:has(#mv-open-overlay:not(.view-hidden)) .mv-file-menu-panel {
  display: none !important;
}

.mv-file-menu-path {
  padding: 0.45rem 0.85rem 0.55rem;
  font-size: 0.72rem;
  color: #94a3b8;
}

.mv-file-menu-path-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}

.mv-file-menu-path-value {
  color: #e2e8f0;
  word-break: break-all;
  line-height: 1.35;
}

.mv-file-menu-session {
  margin-top: 0.25rem;
  font-size: 0.68rem;
  color: #64748b;
}

.mv-project-status-block {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  max-width: 16rem;
}

.mv-project-path {
  font-size: 0.68rem;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mv-project-name {
  max-width: 16rem;
}

.mv-open-loading {
  margin: 0.5rem 0;
}

.mv-project-item-path {
  font-size: 0.7rem;
  color: #64748b;
  word-break: break-all;
}

.mv-file-menu {
  flex: 0 0 auto;
}

.mv-file-menu-wrap .topbar-project-trigger[aria-expanded="true"] {
  background: var(--ps-purple-dark);
}

.mv-dialog {
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: #1e293b;
  color: #e2e8f0;
  max-width: min(420px, 92vw);
  width: min(420px, 92vw);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  overscroll-behavior: contain;
}

.mv-open-dialog {
  min-width: min(460px, 92vw);
  max-width: min(520px, 92vw);
}

.mv-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
  margin: 0.75rem 0;
}

.mv-project-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 0.85rem;
}

.mv-project-item:hover,
.mv-project-item:focus-visible {
  border-color: var(--ps-purple-light, #efd9f2);
  background: #334155;
  outline: none;
}

.mv-project-item-name {
  font-weight: 600;
}

.mv-project-item-meta {
  font-size: 0.75rem;
  color: #94a3b8;
}

.mv-help-dialog {
  width: min(720px, 94vw);
  max-height: min(85vh, 720px);
  padding: 0;
  overflow: hidden;
}

.mv-help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #475569;
}

.mv-help-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.mv-help-layout {
  display: grid;
  grid-template-columns: 160px 1fr;
  min-height: 360px;
  max-height: calc(85vh - 56px);
}

.mv-help-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.65rem;
  border-right: 1px solid #334155;
  background: #0f172a;
  overflow-y: auto;
}

.mv-help-nav-link {
  display: block;
  padding: 0.4rem 0.55rem;
  border-radius: 4px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.82rem;
}

.mv-help-nav-link:hover {
  background: #334155;
  color: #f8fafc;
}

.mv-help-body {
  padding: 0.85rem 1rem 1.1rem;
  overflow-y: auto;
  font-size: 0.88rem;
  line-height: 1.45;
}

.mv-help-body h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: #e2e8f0;
}

.mv-help-section {
  margin-bottom: 1.25rem;
  scroll-margin-top: 0.5rem;
}

.mv-help-section p,
.mv-help-section ul,
.mv-help-section ol {
  margin: 0 0 0.65rem;
}

.mv-help-section ul,
.mv-help-section ol {
  padding-left: 1.25rem;
}

.mv-help-body kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border: 1px solid #475569;
  border-radius: 4px;
  background: #0f172a;
  font-size: 0.78rem;
  font-family: ui-monospace, monospace;
}

.mv-help-body code {
  font-size: 0.82em;
}

@media (max-width: 640px) {
  .mv-help-layout {
    grid-template-columns: 1fr;
  }
  .mv-help-nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid #334155;
  }
}

.mv-draw-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
}

.mv-snap-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}

.mv-snap-toggle input {
  accent-color: var(--ps-purple, #49104F);
}

.mv-snap-grid {
  font-size: 0.82rem;
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
}

.mv-export-orientation {
  font-size: 0.82rem;
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
  max-width: 7.5rem;
}

.mv-align-hint {
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

/* MV Draw buttons — matches top toolbar (slate default, purple + outline when .active) */
body.mv-draw-body button.mv-draw-btn {
  appearance: none;
  box-sizing: border-box;
  border: 1px solid #475569;
  background-color: #334155;
  color: #f8fafc;
  font-size: 0.82rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.25;
  transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, outline-color 0.12s ease;
}

body.mv-draw-body button.mv-draw-btn:hover:not(:disabled) {
  background-color: #475569;
  border-color: #64748b;
}

body.mv-draw-body button.mv-draw-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background-color: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

body.mv-draw-body .topbar button.mv-draw-btn.mv-tool.active,
body.mv-draw-body .topbar button.mv-draw-btn.mv-tool.active:hover,
body.mv-draw-body .topbar button.mv-draw-btn.mv-tool.active:focus-visible,
body.mv-draw-body .mv-draw-inspector button.mv-draw-btn.mv-sheet-btn.active,
body.mv-draw-body .mv-draw-inspector button.mv-draw-btn.mv-sheet-btn.active:hover,
body.mv-draw-body .mv-draw-inspector button.mv-draw-btn.mv-sheet-btn.active:focus-visible {
  background-color: #8b5cf6;
  color: #fff;
  border-color: #ddd6fe;
  outline: 2px solid #c4b5fd;
  outline-offset: 2px;
  box-shadow: 0 0 0 1px #0f172a, inset 0 1px 0 rgba(255, 255, 255, 0.15);
  position: relative;
  z-index: 1;
}

body.mv-draw-body button.mv-draw-btn--danger {
  background-color: var(--danger, #dc2626);
  border-color: var(--danger, #dc2626);
  color: #fff;
}

body.mv-draw-body button.mv-draw-btn--danger:hover:not(:disabled) {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

.mv-align-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.mv-align-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.mv-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.mv-group-hint {
  margin-bottom: 0.45rem;
}

.mv-align-grid .mv-draw-btn,
.mv-align-actions .mv-draw-btn,
.mv-extents-actions .mv-draw-btn,
.mv-sheet-grid .mv-draw-btn {
  width: 100%;
}

.mv-group-actions .mv-draw-btn {
  flex: 1 1 calc(50% - 0.2rem);
}

.mv-toolbar-sep {
  width: 1px;
  height: 1.5rem;
  background: #475569;
  margin: 0 0.25rem;
}

.mv-line-palette {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.mv-line-kind {
  min-width: 3.6rem;
  padding: 0.2rem 0.45rem;
  border: 2px solid #475569;
  border-radius: 4px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.mv-line-kind[data-line-kind="src"] {
  border-bottom-color: #38bdf8;
}

.mv-line-kind[data-line-kind="return"] {
  border-bottom-color: #ef4444;
}

.mv-line-kind[data-line-kind="electric"] {
  border-bottom-color: #eab308;
}

.mv-line-kind.active {
  background: #334155;
  box-shadow: inset 0 0 0 1px #94a3b8;
}

.mv-line-kind:focus-visible {
  outline: 2px solid #a78bfa;
  outline-offset: 1px;
}

#mv-snap-label {
  color: #a78bfa;
}

.mv-draw-layout {
  display: grid;
  grid-template-columns: 240px 1fr 260px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.mv-draw-sidebar,
.mv-draw-inspector {
  background: #1e293b;
  border-right: 1px solid #334155;
  padding: 0.75rem 1rem;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mv-draw-inspector {
  border-right: none;
  border-left: 1px solid #334155;
}

.mv-sidebar-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.mv-sidebar-subtitle {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #94a3b8;
}

.mv-sidebar-hint {
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.mv-library-search-label {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 0.45rem;
}

.mv-library-search {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.82rem;
}

.mv-symbol-thumb-hmi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #1e293b;
}

.mv-symbol-thumb-hmi img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mv-symbol-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.mv-symbol-group {
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0f172a;
  overflow: hidden;
}

.mv-symbol-group-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.55rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: #cbd5e1;
}

.mv-symbol-group-summary::-webkit-details-marker {
  display: none;
}

.mv-symbol-group-summary:hover {
  background: #1e293b;
}

.mv-symbol-group[open] > .mv-symbol-group-summary {
  border-bottom: 1px solid #334155;
  background: #1e293b;
}

.mv-symbol-group-label {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.mv-symbol-group-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.mv-symbol-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: #334155;
  color: #94a3b8;
  font-size: 0.68rem;
  font-weight: 600;
}

.mv-symbol-group-caret {
  display: inline-block;
  font-size: 0.7rem;
  color: #94a3b8;
  transition: transform 0.15s ease;
}

.mv-symbol-group[open] .mv-symbol-group-caret {
  transform: rotate(180deg);
}

.mv-symbol-group-panel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem;
}

.mv-symbol-group-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  margin: 0.65rem 0 0.25rem;
}

.mv-symbol-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 0.82rem;
}

.mv-symbol-btn:hover,
.mv-symbol-btn.selected {
  border-color: var(--ps-purple-light, #efd9f2);
  background: #334155;
}

.mv-symbol-thumb {
  width: 36px;
  height: 24px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid #475569;
}

.mv-draw-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.mv-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #020617;
}

#mv-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.mv-draw-hud {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.75rem;
  background: #1e293b;
  border-top: 1px solid #334155;
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.mv-extents-info {
  margin-bottom: 0.5rem;
}

.mv-extents-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.mv-workspace-scale-label {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}

.mv-workspace-scale-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.mv-workspace-scale-row input {
  width: 4.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
}

.mv-sheet-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.mv-sheet-hint {
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

.mv-inspector-form label,
.mv-draw-inspector > label {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}

.mv-inspector-form input,
.mv-draw-inspector input,
.mv-draw-inspector textarea {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
}

.mv-inspector-sep {
  border: none;
  border-top: 1px solid #334155;
  margin: 1rem 0;
}

.mv-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.mv-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}

.mv-modal-overlay.view-hidden {
  display: none !important;
}

.mv-modal-overlay .mv-modal-panel {
  position: relative;
  z-index: 1;
  pointer-events: auto;
  max-height: calc(100dvh - 2rem);
}

.mv-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.mv-unsaved-dialog {
  min-width: min(400px, 92vw);
}

.mv-unsaved-actions {
  flex-wrap: wrap;
}

.mv-unsaved-actions .btn-primary {
  margin-left: auto;
}

@media (max-width: 960px) {
  .mv-draw-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .mv-draw-sidebar,
  .mv-draw-inspector {
    max-height: 180px;
    border: none;
    border-bottom: 1px solid #334155;
  }
}
