/* --- FLOATING EDIT PANEL --- */

#edit-panel {

  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);

  background: white; padding: 8px 12px; border-radius: 8px;

  box-shadow: 0 4px 12px rgba(0,0,0,0.2); display: none;

  flex-direction: column; gap: 8px; z-index: 1300; border: 2px solid #ffcc00; 

  box-sizing: border-box; width: 340px; min-width: 280px; max-width: calc(100vw - 24px);

}

#edit-panel.visible { display: flex; }



.panel-close-btn {

  position: absolute; top: -10px; right: -10px; width: 24px; height: 24px;

  background: #fff; border: 2px solid #ffcc00; border-radius: 50%; color: #333; cursor: pointer;

  display: flex; align-items: center; justify-content: center; font-size: 0; line-height: 1; padding: 0;

  z-index: 1301; box-shadow: 0 2px 4px rgba(0,0,0,0.2); font-weight: bold;

}

.panel-close-btn::before {
  content: "\00d7";
  display: block;
  font-size: 16px;
  line-height: 1;
  transform: translateY(-1px);
}

.panel-close-btn:hover { color: #ff4d4f; border-color: #ff4d4f; background: #fff0f0; }



.edit-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: space-between; }

.edit-label { font-size: 13px; font-weight: 600; color: #444; }



.input-group { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; flex: 1 1 220px; min-width: 0; position: relative; }

#buffer-input { width: 40px; padding: 4px; border: 1px solid #ccc; border-radius: 4px; font-family: inherit; font-size: 13px; text-align: center; -moz-appearance: textfield; }

#buffer-input::-webkit-outer-spin-button, #buffer-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

#buffer-input:focus { outline: none; border-color: #ffcc00; }



.stepper-btn { width: 24px; height: 24px; background: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #555; user-select: none; }

.stepper-btn:hover { background: #e0e0e0; color: #000; border-color: #999; }

.stepper-btn:active { background: #d0d0d0; }



.preset-btn, .clear-buffer-btn, .copy-btn { width: 24px; height: 24px; border: 1px solid #ccc; background: #f9f9f9; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 10px; margin-left: 4px; }

.preset-btn:hover, .copy-btn:hover { background: #eee; }

.clear-buffer-btn { color: #ff4d4f; font-weight: bold; border-color: #ffccc7; }

.clear-buffer-btn:hover { background: #fff0f0; }



/* COLOR PICKER STYLES */

.color-picker-container {

    position: relative; margin-left: 4px;

}

.color-circle {

    width: 18px; height: 18px; border-radius: 50%; border: 1px solid #ccc; cursor: pointer;

    box-shadow: inset 0 0 2px rgba(0,0,0,0.2); transition: border-color 0.2s;

}

.color-circle:hover { border-color: #000; }

.color-circle.main { border: 2px solid #666; }

.color-menu {

    position: absolute; top: 100%; right: 0; background: white; padding: 6px; border-radius: 6px;

    box-shadow: 0 2px 8px rgba(0,0,0,0.2); border: 1px solid #eee; display: none; 

    grid-template-columns: repeat(3, 1fr); gap: 6px; z-index: 1400; margin-top: 5px;

}

.color-menu.visible { display: grid; }

.color-menu-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 28px;
    border: 1px solid #ffccc7;
    border-radius: 4px;
    background: #fff0f0;
    color: #ff4d4f;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}



.action-btn { padding: 6px 12px; border: 1px solid #ddd; background: #fff; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600; color: #333; transition: all 0.2s; flex: 1 1 140px; min-width: 0; }

.action-btn:hover { background: #f0f0f0; border-color: #bbb; }

.action-btn.delete-node:hover { background: #fff0f0; border-color: #ff4d4f; color: #ff4d4f; }

.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }



#preset-menu {

  position: absolute; top: 100%; right: 0; background: white; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); 

  display: none; flex-direction: column; z-index: 1301; min-width: 140px; margin-top: 4px; max-height: 200px; overflow-y: auto;

}

#preset-menu.visible { display: flex; }

.preset-item { padding: 6px 10px; font-size: 12px; cursor: pointer; color: #333; flex-shrink: 0; }

.preset-item:hover { background: #fffbe6; color: #000; }



#coords-display { font-size: 12px; color: #555; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#buffer-color-indicator { background: #ff5722; }
#measure-color-indicator { background: #ffcc00; }
#panel-section-style { display: none; }
#panel-section-coords { display: none; flex-wrap: nowrap; justify-content: flex-start; }
#panel-section-coords .edit-label { flex: 0 0 auto; }
#panel-section-coords .input-group { flex: 1 1 auto; flex-wrap: nowrap; justify-content: flex-end; }
#panel-section-coords #coords-display { min-width: 0; }
#panel-section-coords .copy-btn { flex: 0 0 auto; }
#panel-section-drawing { display: none; justify-content: center; gap: 12px; width: 100%; }
.drawing-hint { flex: 1 1 100%; color: #555; font-size: 12px; font-weight: 600; line-height: 1.35; text-align: center; }
.draw-finish-btn { background: #ffcc00; border-color: #ffcc00; color: #000; font-weight: 700; }
.draw-cancel-btn { background: #fff0f0; border-color: #ff4d4f; color: #ff4d4f; font-weight: 700; }

@media (max-width: 700px), (hover: none) and (pointer: coarse) {

  #edit-panel {
    width: min(420px, calc(100vw - 24px));
    padding: 10px 12px;
    gap: 10px;
  }

  #panel-section-buffer {
    align-items: flex-start;
  }

  #panel-section-buffer .input-group {
    flex: 1 1 100%;
    gap: 6px;
  }

  #buffer-input {
    width: 58px;
    min-height: 34px;
    padding: 4px 6px;
    font-size: 14px;
  }

  .stepper-btn,
  .preset-btn,
  .clear-buffer-btn,
  .copy-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    font-size: 15px;
    touch-action: none;
  }

  .preset-btn,
  .clear-buffer-btn,
  .copy-btn {
    margin-left: 0;
  }

  .color-picker-container {
    margin-left: 0;
  }

  .color-circle.main {
    width: 32px;
    height: 32px;
  }

  .color-menu {
    top: auto;
    bottom: 100%;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0;
    margin-bottom: 6px;
    padding: 8px;
    grid-template-columns: repeat(4, 32px);
    gap: 7px;
    max-height: min(224px, calc(100vh - 24px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .color-menu .color-circle {
    width: 30px;
    height: 30px;
  }

  .color-menu-close {
    display: flex;
    grid-column: 1 / -1;
    height: 32px;
  }

}
