* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: #172033;
  background: #eef3f8;
}
button,
input,
select {
  font: inherit;
}
button {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
}
button:hover {
  background: #f1f5f9;
}
button.active {
  background: #0f4c81;
  color: #fff;
  border-color: #0f4c81;
}
.danger {
  color: #a21919;
}
.topbar {
  height: 72px;
  background: #fff;
  border-bottom: 1px solid #dbe3ec;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 245px;
}
.brand img {
  width: 46px;
  height: 46px;
  object-fit: contain;
}
.brand div {
  display: flex;
  flex-direction: column;
}
.brand strong {
  font-size: 17px;
}
.brand span {
  font-size: 12px;
  color: #64748b;
}
.toolbar {
  display: flex;
  gap: 7px;
  overflow: auto;
  padding: 5px 0;
}
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  height: calc(100vh - 72px);
  min-height: 0;
}
.sidebar {
  background: #fff;
  overflow: auto;
  padding: 14px;
  border-right: 1px solid #dbe3ec;
}
.right-panel {
  border-right: 0;
  border-left: 1px solid #dbe3ec;
}
.sidebar section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid #edf1f5;
}
.sidebar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
  color: #526071;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.segmented button {
  padding: 8px 4px;
  font-size: 12px;
}
.sidebar select,
.sidebar input:not([type="checkbox"]) {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccd6e2;
  border-radius: 7px;
  margin: 4px 0 9px;
}
.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  max-height: 48vh;
  overflow: auto;
  padding: 2px;
}
.icon-item {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  padding: 5px;
}
.icon-item:hover,
.icon-item.selected {
  border-color: #2b6da6;
  background: #e8f2fb;
}
.icon-item img {
  max-width: 100%;
  max-height: 100%;
  pointer-events: none;
}
.workspace-shell {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.workspace-controls {
  height: 42px;
  background: #f8fafc;
  border-bottom: 1px solid #dbe3ec;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  color: #526071;
  font-size: 13px;
}
.workspace-controls div {
  display: flex;
  align-items: center;
  gap: 6px;
}
.workspace-controls button {
  padding: 4px 8px;
}
.viewport {
  position: relative;
  overflow: auto;
  flex: 1;
  background: #cfd8e3;
}
.stage {
  position: relative;
  width: 3000px;
  height: 2000px;
  transform-origin: 0 0;
  background-color: #fff;
  background-image:
    linear-gradient(#e9eef5 1px, transparent 1px),
    linear-gradient(90deg, #e9eef5 1px, transparent 1px);
  background-size: 20px 20px;
  box-shadow: 0 0 0 1px #bcc7d3;
}
.connections {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.connection-hit {
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}
.connection-visible {
  fill: none;
  pointer-events: none;
}
.connection-label {
  font-size: 14px;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}
.diagram-object {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  user-select: none;
  cursor: grab;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 8px;
}
.diagram-object.selected {
  border-color: #1d78b7;
  background: rgba(29, 120, 183, 0.08);
}
.diagram-object.connect-source {
  border-color: #e58b00;
  background: rgba(229, 139, 0, 0.09);
}
.diagram-object img {
  width: 100%;
  height: calc(100% - 22px);
  object-fit: contain;
  pointer-events: none;
}
.diagram-object .label {
  height: 22px;
  line-height: 22px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 #fff;
  pointer-events: none;
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.sidebar label {
  display: block;
  font-size: 12px;
  color: #526071;
}
.check {
  display: flex !important;
  align-items: center;
  gap: 7px;
  margin: 7px 0;
}
.check input {
  width: auto !important;
  margin: 0 !important;
}
.muted {
  color: #718096;
  font-size: 13px;
  line-height: 1.45;
}
.small {
  font-size: 12px;
}
.right-panel button {
  width: 100%;
  margin-top: 4px;
}
@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 220px 1fr;
  }
  .right-panel {
    display: none;
  }
}
@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .left-panel {
    display: none;
  }
  .brand span {
    display: none;
  }
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    padding: 8px;
  }
  .layout {
    height: calc(100vh - 120px);
  }
}

.connection-preview {
  stroke: #2e78b7;
  stroke-width: 3;
  stroke-dasharray: 9 6;
  opacity: 0.75;
  vector-effect: non-scaling-stroke;
}

/* Painel de propriedades recolhível */
.layout.right-panel-hidden {
  grid-template-columns: 260px minmax(0, 1fr);
}

.workspace-shell {
  position: relative;
}

.right-panel.hidden-panel {
  display: none;
}

.toggle-right-panel {
  position: absolute;
  right: 0;
  top: 70px;
  transform: translateY(-50%);
  width: 20px;
  height: 54px;
  padding: 0;
  border-radius: 7px 0 0 7px;
  border: 1px solid #cbd5e1;
  border-right: 0;
  background: #fff;
  color: #526071;
  font-size: 18px;
  line-height: 1;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.toggle-right-panel:hover {
  background: #f1f5f9;
}

@media (max-width: 1050px) {
  .toggle-right-panel {
    display: none;
  }
}
.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.image-modal[hidden] {
  display: none;
}
.image-modal-card {
  width: min(560px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #dbe3ec;
}
.image-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.image-modal-header h2 {
  margin: 0;
  font-size: 17px;
}
.image-modal-header button {
  font-size: 24px;
  line-height: 1;
  padding: 4px 9px;
}
.image-modal-card select,
.image-modal-card input:not([type="file"]) {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccd6e2;
  border-radius: 7px;
  margin: 4px 0 9px;
}
.change-image-grid {
  grid-template-columns: repeat(6, 1fr);
  max-height: 260px;
}
.image-modal-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 13px 0;
  color: #718096;
  font-size: 12px;
}
.image-modal-divider:before,
.image-modal-divider:after {
  content: "";
  height: 1px;
  background: #e2e8f0;
  flex: 1;
}
.image-modal-card #uploadImageBtn {
  width: 100%;
}
@media (max-width: 600px) {
  .change-image-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* =========================================================
   RESPONSIVIDADE — DESKTOP, TABLET E TELEFONE
   ========================================================= */
.mobile-panel-bar {
  display: none;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .right-panel {
    display: none;
  }
  .layout.right-panel-hidden {
    grid-template-columns: 220px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
  }
  body {
    display: flex;
    flex-direction: column;
  }

  .user-bar {
    flex: 0 0 auto;
    padding: 7px 8px;
    gap: 7px;
  }
  .user-bar > div:first-child {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .user-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .user-actions select {
    grid-column: 1/-1;
    min-width: 0;
    width: 100%;
    font-size: 14px;
  }
  .user-actions button {
    min-height: 42px;
    padding: 7px 8px;
    font-size: 13px;
  }

  .topbar {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    display: block;
    padding: 7px 8px;
  }
  .brand {
    min-width: 0;
    margin-bottom: 6px;
  }
  .brand img {
    width: 36px;
    height: 36px;
  }
  .brand strong {
    font-size: 15px;
  }
  .brand span {
    display: none;
  }
  .toolbar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding: 1px 0 3px;
    scrollbar-width: thin;
  }
  .toolbar button {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 8px 10px;
    white-space: nowrap;
    font-size: 13px;
  }

  .layout,
  .layout.right-panel-hidden {
    position: relative;
    display: block;
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }
  .workspace-shell {
    height: 100%;
    min-height: 0;
    width: 100%;
  }

  .mobile-panel-bar {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
    padding: 6px 8px;
    background: #fff;
    border-bottom: 1px solid #dbe3ec;
  }
  .mobile-panel-bar button {
    flex: 1;
    min-height: 42px;
    font-weight: 600;
  }
  .mobile-panel-bar button.active {
    background: #0f4c81;
    color: #fff;
    border-color: #0f4c81;
  }

  .workspace-controls {
    height: auto;
    min-height: 44px;
    gap: 8px;
    padding: 5px 8px;
    flex-wrap: wrap;
  }
  .workspace-controls > #status {
    flex: 1 1 160px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .workspace-controls > div {
    margin-left: auto;
  }
  .workspace-controls button {
    min-width: 38px;
    min-height: 36px;
    padding: 5px 7px;
  }

  .viewport {
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    background: #cfd8e3;
  }
  .stage {
    transform-origin: 0 0;
  }

  .left-panel,
  .right-panel,
  .right-panel.hidden-panel {
    display: none;
    position: absolute;
    z-index: 80;
    top: 0;
    bottom: 0;
    width: min(88vw, 340px);
    max-width: none;
    padding: 12px;
    overflow: auto;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
    border: 0;
    background: #fff;
  }
  .left-panel.mobile-open {
    display: block;
    left: 0;
    border-right: 1px solid #dbe3ec;
  }
  .right-panel.mobile-open {
    display: block;
    right: 0;
    border-left: 1px solid #dbe3ec;
  }
  .sidebar section {
    padding-bottom: 14px;
    margin-bottom: 14px;
  }
  .sidebar select,
  .sidebar input:not([type="checkbox"]) {
    min-height: 44px;
    font-size: 16px;
  }
  .segmented button {
    min-height: 44px;
    font-size: 13px;
  }
  .right-panel button {
    min-height: 44px;
  }
  .icon-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: none;
  }
  .icon-item {
    min-height: 58px;
  }

  .toggle-right-panel {
    display: none !important;
  }
  .image-modal {
    padding: 8px;
    align-items: flex-end;
  }
  .image-modal-card {
    width: 100%;
    max-height: 82%;
    border-radius: 14px 14px 0 0;
    padding: 14px;
  }
  .change-image-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .brand img {
    width: 32px;
    height: 32px;
  }
  .toolbar button {
    font-size: 12px;
    padding: 7px 9px;
  }
  .workspace-controls > #status {
    flex-basis: 100%;
    font-size: 12px;
  }
  .workspace-controls > div {
    width: 100%;
    justify-content: flex-end;
  }
  .left-panel,
  .right-panel,
  .right-panel.hidden-panel {
    width: 92vw;
  }
  .icon-grid,
  .change-image-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
