/*
  노드 기반 화이트보드 캔버스 스타일
  구조:
    .canvas-stage  : 뷰포트(고정). pan/zoom 이벤트 수신, 점 그리드 배경
    .canvas-world  : transform(translate+scale) 적용되는 무한 평면
    .wb-edges      : SVG 연결선 레이어
    .wb-node       : 절대 위치 노드
*/

.canvas-stage {
  position: fixed;
  inset: 0 0 0 var(--sidebar-w);
  overflow: hidden;
  background-color: var(--canvas-bg);
  background-image: radial-gradient(circle, #c8c8c8 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.canvas-stage.is-panning {
  cursor: grabbing;
}

.canvas-stage.mode-select {
  cursor: default;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  width: 0;
  height: 0;
}

/* ===== 돋보기(루페) ===== */
/* 활성 중에는 OS 커서를 숨겨 원형 돋보기가 커서를 대신하도록 함 */
.canvas-stage.is-magnifying {
  cursor: none;
}

/* 좌우만 둥근 직사각형(필) 형태, 보더 없음 */
.canvas-loupe {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  border-radius: 999px;
  overflow: hidden;
  pointer-events: none;
  background-color: var(--canvas-bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* 리퀴드 글래스 림: 상단 하이라이트 + 안쪽 밝은 림 + 하단 볼록 그림자 */
.canvas-loupe::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(130% 90% at 28% 18%, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0) 42%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.55),
    inset 0 0 16px 6px rgba(255, 255, 255, 0.3),
    inset 0 10px 24px rgba(255, 255, 255, 0.22),
    inset 0 -12px 26px rgba(0, 0, 0, 0.2);
}

.canvas-loupe-world {
  will-change: transform;
}

/* 루페 밖(아래) 안내 문구 — JS가 left/top으로 위치 지정 */
.canvas-loupe-label {
  position: fixed;
  top: 0;
  left: 0;
  transform: translateX(-50%);
  z-index: 200;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  pointer-events: none;
}

/* ===== 연결선(SVG) ===== */
.wb-edges {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.wb-edge-path {
  fill: none;
  stroke: #1a1a1a;
  stroke-width: 2;
  pointer-events: stroke;
  cursor: pointer;
}

.wb-edge-path:hover {
  stroke: var(--accent);
  stroke-width: 3;
}

.wb-edge-path.selected {
  stroke: var(--link);
  stroke-width: 3;
}

.wb-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}

/* 연결 중 미리보기 선 */
.wb-edge-preview {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

/* ===== 노드 ===== */
.wb-node {
  position: absolute;
  background-color: #fff;
  border: 2px solid #000;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: grab;
}

.wb-node.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.wb-node.selected {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.wb-node.type-planning {
  border-color: var(--accent);
}

.wb-node.type-sticker {
  background-color: #c8ff00;
  border: none;
  border-radius: 16px;
}

.wb-node-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.wb-node-titlewrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.wb-node-emoji {
  font-size: 1.35rem;
  line-height: 1.2;
}

.wb-node-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #000;
  word-break: break-word;
}

.wb-node-type {
  font-size: 0.6875rem;
  color: var(--muted);
}

.wb-node-actions {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.wb-node:hover .wb-node-actions {
  opacity: 1;
}

.wb-node-action {
  border: none;
  background: transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.wb-node-action:hover {
  background-color: #f1f1f1;
}

.wb-node-action.danger:hover {
  background-color: #fde8e8;
  color: var(--danger);
}

.wb-node-content {
  font-size: 0.75rem;
  color: #000;
  font-weight: 500;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.wb-node-content p {
  margin: 0;
}

.wb-node-content p + p {
  margin-top: 0.3em;
}

.wb-node-photo {
  padding: 0;
  border: none;
  overflow: hidden;
}

.wb-node-photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.wb-node-photo .wb-node-actions {
  position: absolute;
  top: 6px;
  bottom: auto;
  right: 6px;
}

/* 이미지 좌측 상단 제목 오버레이 (가독성 위해 어두운 레이어) */
.wb-photo-title {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.wb-node-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 160px;
  background-color: #f3f4f6;
  color: #9ca3af;
  font-size: 0.8125rem;
}

/* ===== 인덱스 탭 ===== */
/* 노드 우측 상단에 가로로 길게 붙는 인덱스 탭 (색상은 인라인 style로 주입) */
.wb-node-index {
  position: absolute;
  top: 14px;
  left: calc(100% - 18px);
  z-index: 4;
  height: 28px;
  min-width: 116px;
  max-width: 220px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  border: none;
  border-radius: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.wb-node-index-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #000;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 사진 노드는 overflow:hidden이라 탭이 잘리므로, 인덱스가 있을 때만 노출 허용 */
.wb-node-photo.has-index {
  overflow: visible;
}

/* 인덱스 클릭 시 노드 위로 떠오르는 인라인 에디터 */
.wb-node-index-editor {
  position: absolute;
  top: -8px;
  right: 0;
  transform: translateY(-100%);
  z-index: 110;
  width: max-content;
  max-width: 260px;
  padding: 8px;
  background: #fff;
  border: none;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  cursor: default;
}

.wb-node-index-editor[hidden] {
  display: none;
}

.wb-index-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.wb-index-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.wb-index-swatch.is-active {
  border-color: #000;
}

.wb-index-edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wb-index-input {
  flex: 1;
  min-width: 0;
  width: 150px;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: #f1f1f1;
  font-size: 13px;
  font-family: inherit;
}

.wb-index-input:focus {
  outline: none;
}

.wb-index-save {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.wb-index-save:hover {
  background: var(--primary-hover);
}

/* ===== 파일(폴더) 노드 ===== */
/* 폴더에 담겨 캔버스에서 숨겨진 멤버 */
.wb-node-hidden {
  display: none !important;
}

/* 파일 노드는 카드가 아니라 폴더 그래픽 컨테이너 */
.wb-node.type-file {
  width: auto !important;
  height: auto !important;
  min-height: 0;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* 노드를 폴더 위로 끌어 편입 대상이 된 상태 */
.wb-node.type-file.drop-target {
  outline: 2px dashed var(--link);
  outline-offset: 6px;
  border-radius: 10px;
}

.wb-folder {
  position: relative;
  width: 104px;
  height: 80px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

/* 뒷면 + 탭 (진한 파랑) */
.wb-folder-back {
  position: absolute;
  inset: 16px 0 0 0;
  background: #2f6fed;
  border-radius: 9px;
}

.wb-folder-back::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 0;
  width: 48px;
  height: 16px;
  background: #2f6fed;
  border-radius: 9px 9px 0 0;
}

/* 앞면 (밝은 파랑) */
.wb-folder-front {
  position: absolute;
  inset: 28px 0 0 0;
  background: #5b8def;
  border-radius: 9px;
  box-shadow: 0 3px 7px rgba(20, 50, 120, 0.22);
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.wb-folder:hover .wb-folder-front {
  background: #6f9cf6;
}

.wb-folder:active .wb-folder-front {
  transform: translateY(1px);
}

.wb-folder-count {
  position: absolute;
  top: 12px;
  right: -6px;
  z-index: 2;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.wb-folder-label {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 130px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--foreground);
}

.wb-folder-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ===== 포트(연결점) ===== */
.wb-port {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background-color: #fff;
  border: 2px solid #000;
  border-radius: 50%;
  transform: translateY(-50%);
  z-index: 5;
  cursor: crosshair;
}

.wb-port:hover {
  background-color: var(--accent);
  border-color: var(--accent);
}

.wb-port.in {
  left: -8px;
}

.wb-port.out {
  right: -8px;
}

.type-planning .wb-port {
  border-color: var(--accent);
}

/* ===== 리사이즈 핸들 ===== */
.wb-resize {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background-color: #000;
  border: 2px solid #fff;
  border-radius: 2px;
  cursor: nwse-resize;
  z-index: 6;
  opacity: 0;
}

.wb-node.selected .wb-resize {
  opacity: 1;
}

/* ===== 툴바 ===== */
/* 최상단 중앙: 커서를 따라가는 눈 위젯 */
.wb-eyes {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  z-index: 60;
  pointer-events: none;
}

/* 보드 캔버스: 사이드바 폭만큼 보정해 캔버스 영역 중앙에 정렬 */
.wb-eyes-canvas {
  left: calc(50% + var(--sidebar-w) / 2);
}

/* 인라인 배치(랜딩 nav 브랜드 자리 등): 고정 해제 + 흐름 안에 표시 */
.wb-eyes-inline {
  position: static;
  top: auto;
  left: auto;
  transform: none;
  width: 56px;
  z-index: auto;
}

.wb-eyes svg {
  display: block;
  width: 100%;
  height: auto;
}

/* 깜빡임: 눈 크기는 그대로 두고 눈꺼풀이 상단 → 하단으로 내려와 덮음 */
.wb-eyes .wb-lid {
  transform: translateY(-104px);
  transition: transform 130ms ease;
}

/* 입력 필드 포커스 중: 눈을 약 1/3 감아 집중하는 표정 */
.wb-eyes.is-focusing .wb-lid {
  transform: translateY(-69px);
}

/* 비밀번호 입력 중(is-hiding) · 클릭/홀드(is-blinking)는 완전히 감김 */
.wb-eyes.is-hiding .wb-lid,
.wb-eyes.is-blinking .wb-lid {
  transform: translateY(0);
}

/* 놀람: 로그아웃 버튼 호버 시 동공이 작아짐 */
.wb-eyes .wb-pupil {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 120ms ease;
}

.wb-eyes.is-startled .wb-pupil {
  transform: scale(0.45);
}

/* 돋보기 사용 중: 눈 위젯 위에 커서 루페와 동일한 글래스를 씌움 */
.wb-eyes-loupe {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92px;
  height: 46px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
  background: radial-gradient(130% 90% at 28% 18%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 45%);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.25),
    inset 0 0 0 2px rgba(255, 255, 255, 0.6),
    inset 0 0 10px 4px rgba(255, 255, 255, 0.35),
    inset 0 6px 14px rgba(255, 255, 255, 0.25),
    inset 0 -8px 16px rgba(0, 0, 0, 0.18);
}

.wb-eyes.is-loupe .wb-eyes-loupe {
  opacity: 1;
}

.wb-toolbar {
  position: fixed;
  bottom: 16px;
  left: calc(50% + var(--sidebar-w) / 2);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: #fff;
  border-radius: 12px;
  padding: 6px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 50;
}

.wb-toolbar .wb-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wb-toolbar .wb-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border);
  margin: 0 4px;
}

.wb-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background-color: transparent;
  border-radius: 8px;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--foreground);
  cursor: pointer;
  white-space: nowrap;
}

.wb-tool-btn:hover {
  background-color: #f1f1f1;
}

.wb-tool-btn.active {
  background-color: #1a1a1a;
  color: #fff;
}

/* 상단 좌측: 보드 정보 */
.wb-topbar {
  position: fixed;
  top: 16px;
  left: calc(var(--sidebar-w) + 16px);
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 50;
}

.wb-topbar .wb-board-name {
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: text;
  padding: 2px 6px;
  border-radius: 6px;
}

.wb-topbar .wb-board-name:hover {
  background-color: var(--background);
}

.wb-topbar .wb-board-name-input {
  font-size: 0.9375rem;
  font-weight: 700;
  font-family: inherit;
  color: var(--foreground);
  border: 2px solid #000;
  border-radius: 6px;
  padding: 1px 5px;
  outline: none;
  min-width: 120px;
}

/* 우측 하단: 줌 표시 */
.wb-zoom-indicator {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8125rem;
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 50;
}
