:root {
  --bg-dark: #181818;
  --bg-work: #202020;
  --bg-panel: #101010;

  --top-bar-line: #707070;
  --side-bar-line: #707070;

  --line: #707070;
  --text: #e0e0e0;
  --block: #252525;
  --block-border: #b0b0b0;

  --accent: #ffffff;
  --disabled: #555555;

  --arrow-color: #909090;
  --selected-glow: rgba(0,255,255,0.9);

  --radius: 10px;
  --radius-annotation: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  z-index: 10000;
}

#login-box {
  width: min(360px, calc(100vw - 32px));
  padding: 28px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

#login-box h1 {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 22px;
}

#login-box p {
  margin-bottom: 16px;
  font-size: 13px;
  opacity: 0.75;
}

#access-code {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-work);
  color: var(--accent);
  text-align: center;
  font-size: 20px;
  letter-spacing: 4px;
}

#login-box button,
#logout-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-work);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

#login-box button {
  width: 100%;
  margin-top: 12px;
  padding: 9px;
}

#login-error {
  min-height: 18px;
  margin-top: 10px;
  color: #ff6b6b;
  font-size: 12px;
}

#session-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  position: absolute;
  right: 12px;
  font-size: 11px;
}

#fit-plan-button {
  position: absolute;
  left: 82px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-work);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

#brand-name {
  position: absolute;
  right: 130px;
  transform: none;
  color: var(--accent);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

body.viewer-mode #left-panel {
  display: none;
}

#session-role {
  opacity: 0.7;
}

#logout-button {
  padding: 6px 8px;
  font-size: 11px;
}

body.viewer-mode .tool,
body.viewer-mode #context-menu .context-item {
  cursor: default;
}

body.viewer-mode #context-menu .color-dot,
body.viewer-mode #context-menu [data-action="lock"],
body.viewer-mode #context-menu [data-action="add-change-image"],
body.viewer-mode #context-menu [data-action="delete-image"],
body.viewer-mode #context-menu [data-action="add-main"],
body.viewer-mode #context-menu [data-action="add-annotation"],
body.viewer-mode #context-menu [data-action="add-arrow"],
body.viewer-mode #context-menu [data-action="add-image-block"],
body.viewer-mode #context-menu [data-action="delete"] {
  pointer-events: none;
  opacity: 0.45;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#top-bar {
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--top-bar-line);
  display: flex;
  align-items: center;
  padding: 0 12px;
  position: relative;
  z-index: 9999;
}

#menu {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9999;
}

#menu-button {
  width: 60px;
  height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-work);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#menu-button span {
  display: block;
  width: 24px;
  height: 3px;
  background: var(--text);
  position: relative;
}

#menu-button span::before,
#menu-button span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 24px;
  height: 3px;
  background: var(--text);
}

#menu-button span::before {
  top: -7px;
}

#menu-button span::after {
  top: 7px;
}

#menu-dropdown {
  position: absolute;
  top: 110%;
  left: 12px;
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-width: 240px;
  padding: 6px 0;
  display: none;
  z-index: 99999;
}

#menu-dropdown.open {
  display: block;
}

.menu-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.menu-item small {
  font-size: 11px;
  opacity: 0.6;
}

.menu-item:hover {
  background: #2a2a2a;
}

.menu-separator {
  border-top: 1px solid var(--line);
  margin: 4px 0;
}

#doc-title {
  margin: 0 auto;
  width: 60%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-work);
  color: var(--accent);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

#layout {
  flex: 1;
  display: flex;
  height: calc(100vh - 56px);
}

#left-panel {
  width: 220px;
  background: var(--bg-panel);
  border-right: 1px solid var(--side-bar-line);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}

.panel-title {
  font-size: 13px;
  opacity: 0.8;
  font-weight: 600;
}

.tool {
  background: var(--block);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 8px;
  font-size: 13px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
}

.tool-name {
  font-weight: 700;
  color: var(--accent);
}

.tool-desc {
  font-size: 11px;
  opacity: 0.7;
}

#workspace {
  flex: 1;
  position: relative;
  background: var(--bg-work);
  overflow: hidden;
}

#grid-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(112,112,112,0.25) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(112,112,112,0.25) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: 0 0;
  z-index: 0;
}

#canvas {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  z-index: 1;
}

.block {
  position: absolute;
  background: var(--block);
  border-radius: var(--radius);
  border: 4px solid var(--block-border);
  color: var(--text);
  padding: 8px;
  min-width: 420px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  transition: box-shadow 0.12s ease-out, background 0.12s ease-out;
}

.block-main {
  min-width: 460px;
  min-height: 280px;
}

.block-annotation {
  border-radius: var(--radius-annotation);
  min-width: 200px;
  min-height: 110px;
  border-width: 3px;
}

.block-image {
  min-width: 260px;
  min-height: 180px;
  width: 260px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-title {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 16px;
  outline: none;
  font-weight: 800;
  text-align: center;
  transition: font-size 0.1s ease-out;
}

.block-title::placeholder {
  color: #888;
}

.block-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.block-text {
  flex: 1;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 60px;
  font-weight: 600;
  line-height: 18px;
}

.block-image-wrapper {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.block-image-wrapper img {
  width: 100%;
  height: 140px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #1a1a1a;
  display: none;
  pointer-events: none;
}

.block-image-inner {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  border: 2px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  position: relative;
  overflow: hidden;
}

.block-image-plus {
  font-size: 32px;
  color: var(--accent);
  opacity: 0.9;
  pointer-events: none;
}

.block-image-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  pointer-events: none;
}

.block-image-inner.has-image {
  border-style: solid;
  border-color: var(--block-border);
}

.block.disabled {
  opacity: 0.85;
}

.block.selected {
  box-shadow:
    0 0 0 3px var(--selected-glow),
    0 0 25px var(--selected-glow);
  background: #2b2b2b;
}

.arrow {
  position: absolute;
  pointer-events: auto;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.6));
}

.arrow svg {
  overflow: visible;
}

.arrow-path {
  stroke: var(--arrow-instance-color, var(--arrow-color));
  stroke-width: 3;
  fill: none;
  marker-end: url(#arrowhead);
}

.arrow-handle {
  fill: var(--arrow-instance-color, var(--arrow-color));
  stroke: none;
  cursor: pointer;
}

.arrow.selected .arrow-path {
  stroke-width: 6;
  filter: drop-shadow(0 0 12px var(--arrow-instance-color, var(--selected-glow)));
}

.arrow.selected .arrow-handle {
  r: 9;
}

.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #303030;
  cursor: nwse-resize;
  z-index: 10;
}

.resize-handle.br {
  right: -6px;
  bottom: -6px;
}

.resize-handle.bl {
  left: -6px;
  bottom: -6px;
  cursor: nesw-resize;
}

.resize-handle.tr {
  right: -6px;
  top: -6px;
  cursor: nesw-resize;
}

.resize-handle.tl {
  left: -6px;
  top: -6px;
}

#selection-rect {
  position: absolute;
  border: 1px dashed var(--selected-glow);
  background: rgba(0, 255, 255, 0.08);
  pointer-events: none;
  display: none;
  z-index: 999;
}

#context-menu {
  position: absolute;
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-width: 220px;
  padding: 4px 0;
  font-size: 12px;
  display: none;
  z-index: 2000;
}

.context-item {
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.context-item:hover {
  background: #2a2a2a;
}

.context-item.disabled {
  color: var(--disabled);
  cursor: default;
}

.context-item.disabled:hover {
  background: transparent;
}

.context-separator {
  height: 1px;
  background: var(--line);
  margin: 6px 0;
}

.color-row {
  display: flex;
  gap: 4px;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--line);
  cursor: pointer;
}

#help-overlay,
#personalize-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

#help-box,
#personalize-box {
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px 20px;
  max-width: 420px;
  color: var(--text);
  font-size: 13px;
}

#help-box h2,
#personalize-box h2 {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--accent);
}

#help-box ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#help-box li {
  margin-bottom: 6px;
}

#help-close {
  margin-top: 12px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-work);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
  text-align: center;
}

#help-close:hover {
  background: #262626;
}

#personalize-box label {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}

.personalize-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

#personalize-save,
#personalize-cancel {
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-work);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}

#personalize-save:hover,
#personalize-cancel:hover {
  background: #262626;
}
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #444;
  cursor: pointer;
  transition: 0.15s;
}

.color-dot.active {
  border-color: #fff;
  box-shadow: 0 0 6px #fff;
  transform: scale(1.1);
}

@media (max-width: 700px) {
  body {
    overflow: hidden;
  }

  #top-bar {
    height: 52px;
    padding: 0 8px;
  }

  #menu {
    left: 8px;
  }

  #menu-button {
    width: 42px;
    height: 36px;
  }

  #doc-title {
    width: 42%;
    margin-left: 108px;
    margin-right: 0;
    font-size: 12px;
  }

  #brand-name {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-left: 0;
    font-size: 15px;
  }

  #fit-plan-button {
    position: absolute;
    left: 58px;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0;
    font-size: 10px;
  }

  #session-controls {
    position: static;
    margin-left: 6px;
  }

  #session-role {
    display: none;
  }

  #logout-button {
    font-size: 10px;
    padding: 5px 6px;
  }

  #left-panel {
    display: none;
  }

  #layout {
    height: calc(100vh - 52px);
  }

  #workspace {
    width: 100vw;
    touch-action: none;
  }

  #context-menu,
  #help-overlay,
  #personalize-overlay {
    max-width: calc(100vw - 16px);
  }

  #personalize-box,
  #help-box {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
}
