/* styles.css */
:root {
  --toolbar-bg: rgba(255, 255, 255, 0.75);
  --toolbar-border: rgba(255, 255, 255, 0.5);
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --accent-color: #0071e3;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  overflow: hidden;
  transition: background-color 0.3s ease;
  user-select: none; 
}

#root { width: 100%; height: 100%; }

.react-flow__background { transition: opacity 0.3s ease; }
.react-flow__pane { cursor: grab; }
.react-flow__pane:active { cursor: grabbing; }

/* 畫筆模式的指標 */
.drawing-mode .react-flow__pane { cursor: crosshair !important; }

/* Main Toolbar */
.toolbar-container {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 12px 24px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--toolbar-border);
  border-radius: 100px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
}
.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}
.toolbar-btn:hover { background: rgba(0, 0, 0, 0.06); transform: scale(1.05); }
.toolbar-btn:active { transform: scale(0.95); }

/* --- 繪圖專屬工具列 (Apple Pencil Palette Style) --- */
.drawing-toolbar {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--toolbar-border);
  border-radius: 30px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  align-items: center;
}
.drawing-tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.drawing-tool-btn.active {
  background: var(--accent-color);
  color: white;
  transform: scale(1.1);
}

/* --- Inline Toolbars (Node & Edge) --- */
.text-format-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--shadow-md);
}
.text-format-toolbar .divider {
  width: 1px;
  height: 20px;
  background: rgba(0,0,0,0.1);
  margin: 0 4px;
}
.format-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.1s, color 0.1s;
}
.format-btn:hover { background: rgba(0,0,0,0.08); }
.format-btn.active { background: var(--accent-color); color: white; }

.font-size-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
}
.font-size-control button {
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.1s;
}
.font-size-control button:hover { background: rgba(0,0,0,0.08); }
.font-size-label {
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* 原生調色盤 */
.native-color-picker {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
}
.native-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.native-color-picker::-webkit-color-swatch { border: 1px solid rgba(0,0,0,0.15); border-radius: 50%; }
.native-color-picker::-moz-color-swatch { border: 1px solid rgba(0,0,0,0.15); border-radius: 50%; }

/* 自訂字體下拉選單 (Popover) */
.custom-font-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  width: 180px;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.font-menu-item {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  transition: background 0.1s;
}
.font-menu-item:hover { background: rgba(0,0,0,0.08); }

/* 附件選單 */
.attach-menu {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 12px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 4px;
  width: 150px;
  z-index: 50;
}
.attach-menu button {
  background: transparent;
  border: none;
  padding: 10px;
  text-align: left;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.attach-menu button:hover { background: rgba(0,0,0,0.05); }

/* 形狀選擇選單 */
.shape-picker-menu {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 16px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--toolbar-border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
  z-index: 50;
}
.shape-picker-menu::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: var(--toolbar-bg);
  border-right: 1px solid var(--toolbar-border);
  border-bottom: 1px solid var(--toolbar-border);
}
.shape-btn {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.05);
  background: rgba(255,255,255,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  color: var(--accent-color);
}
.shape-btn:hover { 
  background: white; 
  transform: scale(1.05);
  box-shadow: var(--shadow-sm);
}
.shape-btn:active { transform: scale(0.95); }
.shape-btn svg { width: 32px; height: 32px; }

/* Edge Toolbar */
.edge-toolbar {
  background: var(--toolbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
}
.edge-toolbar button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.1s;
}
.edge-toolbar button:hover { background: rgba(0,0,0,0.08); }
.edge-toolbar .divider { width: 1px; height: 18px; background: rgba(0,0,0,0.1); }

/* --- 畫布設定面板 --- */
.bg-settings-popover {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--toolbar-border);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 260px;
}
.bg-settings-popover h4 {
  margin: 0;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(0,0,0,0.1);
  padding-bottom: 8px;
}
.bg-settings-popover label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-primary);
}
.bg-settings-popover input[type="range"] {
  width: 100px;
}
.bg-settings-popover select {
  background: rgba(0,0,0,0.05);
  border: none;
  border-radius: 6px;
  padding: 4px;
  outline: none;
}

/* --- Nodes --- */
.custom-node {
  padding: 16px;
  font-size: 14px;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}
.custom-node.selected { box-shadow: 0 0 0 2px var(--accent-color), var(--shadow-lg) !important; }

/* 擬真便條紙 (Realistic Sticky Note) */
.sticky-node {
  background-color: #ffecb3;
  border-radius: 2px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.1);
}
.sticky-node::after {
  content: "";
  position: absolute;
  z-index: -1;
  bottom: 8px;
  left: 10px;
  right: 10px;
  height: 20%;
  border-radius: 50%;
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s;
}
.sticky-node.selected::after { opacity: 0; }
.sticky-node textarea {
  flex-grow: 1;
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  line-height: 1.5;
  outline: none;
}

/* 純文字節點 (Plain Text Node) */
.plain-text-node {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0;
}
.plain-text-node.selected { box-shadow: 0 0 0 2px var(--accent-color) !important; border-radius: 8px; }
.plain-text-node textarea {
  flex-grow: 1;
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  line-height: 1.2;
  outline: none;
  padding: 8px;
  box-sizing: border-box;
}

/* 圖片節點 */
.image-node {
  padding: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.image-node img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* PDF節點 */
.pdf-node {
  padding: 0;
  border-radius: 12px;
  background: white;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.1);
}
.pdf-node iframe {
  width: 100%;
  height: 100%;
  border: none;
  pointer-events: all;
}

/* 連結節點 */
.link-node {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(0,0,0,0.05);
}
.link-node a {
  color: var(--accent-color);
  text-decoration: none;
  word-break: break-all;
  font-size: 14px;
}
.link-node a:hover { text-decoration: underline; }

/* 基本圖形節點 (Shape Node) */
.shape-node {
  padding: 0;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0;
  position: relative;
  width: 100%;
  height: 100%;
}
.shape-node svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none; /* SVG doesn't block interactions */
  filter: drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.08));
  transition: filter 0.2s ease;
}
.shape-node svg path, .shape-node svg rect, .shape-node svg circle, .shape-node svg polygon, .shape-node svg ellipse {
  pointer-events: all; /* but the drawn shapes do */
  transition: fill 0.2s, stroke 0.2s, stroke-width 0.2s;
}
.shape-node .text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-sizing: border-box;
  pointer-events: none; /* Text wrapper doesn't block interactions */
}
.shape-node .text-overlay textarea,
.shape-node .text-overlay .rich-text-editor {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  text-align: center;
  display: flex;
  pointer-events: all; /* Textarea allows typing */
}
.shape-node .text-overlay [data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: rgba(0,0,0,0.3);
  pointer-events: none;
}
.shape-node.selected svg {
  filter: drop-shadow(0px 6px 16px rgba(0, 0, 0, 0.12)) drop-shadow(0px 0px 4px rgba(0, 113, 227, 0.6));
}

.collapsible-node {
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,0.05);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}
.collapsible-node .collapsible-header {
  padding: 8px 12px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.collapsible-node.is-collapsed .collapsible-header {
  border-bottom: none;
}
.collapsible-node.is-collapsed {
  height: max-content !important;
}
.collapsible-header input,
.collapsible-header .rich-text-editor {
  font-weight: 600;
  font-size: 15px;
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
}
.collapsible-body {
  overflow: hidden;
  transition: opacity 0.2s ease;
  max-height: 500px;
  opacity: 1;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}
.collapsible-body.collapsed {
  max-height: 0;
  opacity: 0;
  flex-grow: 0;
}
.collapsible-body textarea {
  flex-grow: 1;
  width: 100%;
  border: none;
  background: rgba(0,0,0,0.03);
  border-radius: 8px;
  padding: 10px;
  resize: none;
  line-height: 1.5;
  outline: none;
  box-sizing: border-box;
}

/* Drawing Node */
.drawing-node { pointer-events: none; }
.drawing-node svg { overflow: visible; }
.drawing-node path { pointer-events: all; cursor: pointer; }
.drawing-node.selected path { filter: drop-shadow(0px 0px 4px var(--accent-color)); }

/* 縮放控制點 Apple 原生樣式 */
.react-flow__resize-control.handle {
  width: 12px !important;
  height: 12px !important;
  border-radius: 50% !important;
  border: 2px solid white !important;
  background-color: #0071e3 !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3) !important;
}

/* Connection Handles */
.react-flow__handle {
  width: 14px;
  height: 14px;
  background-color: var(--accent-color);
  border: 3px solid white;
  opacity: 0;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.react-flow__node:hover .react-flow__handle, .react-flow__handle:hover { opacity: 1; }
.react-flow__handle:hover { transform: scale(1.3); }

/* --- 多選與排版工具列 --- */
.multi-select-toolbar {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--toolbar-border);
  border-radius: 100px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
}
.multi-select-toolbar button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  transition: all 0.1s;
}
.multi-select-toolbar button:hover {
  background: rgba(0,0,0,0.08);
  transform: scale(1.05);
}
.multi-select-toolbar button:active {
  transform: scale(0.95);
}
.multi-select-toolbar span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.multi-select-toolbar .divider {
  width: 1px;
  height: 20px;
  background: rgba(0,0,0,0.1);
}

/* --- 右鍵選單 (Context Menu) --- */
.context-menu {
  position: absolute;
  background: var(--toolbar-bg);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  padding: 6px 0;
  min-width: 160px;
}
.context-menu button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.1s;
  width: 100%;
}
.context-menu button:hover {
  background: rgba(0, 0, 0, 0.05);
}
.context-menu .divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
  margin: 4px 0;
}

/* Force inactive child nodes to be completely unclickable */
.inactive-child, .inactive-child * {
  pointer-events: none !important;
}

/* 樹狀結構折疊按鈕 */
.tree-collapse-btn {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--toolbar-border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  color: var(--text-secondary);
  transition: all 0.2s;
  pointer-events: auto;
}
.tree-collapse-btn:hover {
  background: var(--bg-secondary);
  color: var(--accent-color);
  transform: translateY(-50%) scale(1.1);
}

/* --- Dashboard Styles --- */
.dashboard-container {
  min-height: 100vh;
  background-color: #f5f5f7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 40px;
}
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
}
.dashboard-header h1 {
  font-size: 32px;
  font-weight: 700;
  color: #007aff;
  margin: 0;
}
.dashboard-actions button {
  background-color: #007aff;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
}
.dashboard-actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}
.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}
.board-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.board-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
.board-card-thumbnail {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 48px;
  font-weight: 800;
  opacity: 0.8;
}
.board-card-info {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.board-card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 4px;
  margin-left: -4px;
}
.board-card-title:hover {
  border-color: #e5e5ea;
}
.board-card-title:focus {
  outline: none;
  border-color: #007aff;
  background: white;
}
.board-card-date {
  font-size: 12px;
  color: #86868b;
}
