/* Note Card Container */
.note-card {
  position: absolute;
  min-width: 240px;
  min-height: 180px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
  z-index: 10;
  backdrop-filter: blur(10px);
  cursor: grab;
  touch-action: none !important;
  -webkit-touch-callout: none;
}

.note-card:hover {
  border-color: var(--border-hover);
}

/* Selected State: Fine solid mustard yellow border */
.note-card.is-selected {
  border: 1.5px solid var(--mustard-500) !important;
  box-shadow: 0 0 0 2px var(--mustard-dim), var(--card-shadow);
  z-index: 40;
}

/* Focused / Editing State */
.note-card.is-editing {
  border: 1.5px solid var(--mustard-400) !important;
  box-shadow: 0 0 0 3px var(--mustard-dim), var(--card-shadow-active);
  z-index: 50;
  cursor: default;
  user-select: text;
  -webkit-user-select: text;
}

.note-card.is-dragging {
  cursor: grabbing !important;
  opacity: 0.95;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  z-index: 60;
}

/* Drag & Drop Connection Target Highlight */
.note-card.is-drop-target {
  border-color: var(--mustard-400) !important;
  box-shadow: 0 0 0 3px var(--mustard-500), 0 0 22px var(--mustard-glow), var(--card-shadow-active) !important;
  transform: scale(1.025);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 45;
}

/* Note Header */
.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--card-header-bg);
  border-bottom: 1px solid var(--border-color);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
  cursor: grab;
  gap: 8px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.note-header:active {
  cursor: grabbing;
}

.note-title-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.note-card:not(.is-editing) .note-title-input {
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.note-card.is-editing .note-title-input {
  user-select: auto;
  -webkit-user-select: auto;
  cursor: text;
}

.note-title-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.note-card.has-open-dropdown {
  z-index: 1000 !important;
}

.note-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 50;
  pointer-events: auto;
}

/* Three Dots Menu Button */
.note-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 10px;
  margin: -6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  line-height: 1;
  font-weight: bold;
  transition: all var(--transition-fast);
  position: relative;
  z-index: 100;
  pointer-events: auto !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.note-menu-btn:hover,
.note-menu-btn:active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

@media (max-width: 768px) {
  .note-menu-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 12px;
    margin: -10px;
    font-size: 20px;
  }
}

/* Dropdown Menu */
.note-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  min-width: 170px;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 10000 !important;
  animation: slideDown 0.15s ease;
  pointer-events: auto;
}

.note-dropdown.is-open {
  display: flex;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: all var(--transition-fast);
}

.dropdown-item svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
  stroke: var(--accent);
}

.dropdown-item:hover {
  background: var(--mustard-dim);
  color: var(--mustard-600);
}

[data-theme="dark"] .dropdown-item:hover {
  color: var(--mustard-400);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

.dropdown-item.danger {
  color: var(--danger);
}

.dropdown-item.danger svg {
  stroke: var(--danger);
}

.dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger-hover);
}

/* Note Body / Contenteditable */
.note-body {
  flex: 1;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  outline: none;
  overflow-y: auto;
  max-height: 480px;
  word-break: break-word;
}

.note-card:not(.is-editing) .note-body {
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.note-card.is-editing .note-body {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

.note-body[placeholder]:empty:before {
  content: attr(placeholder);
  color: var(--text-muted);
  cursor: inherit;
}

.note-body b, .note-body strong {
  font-weight: 700;
  color: var(--text-primary);
}

.note-body i, .note-body em {
  font-style: italic;
}

.note-body a {
  color: var(--mustard-600);
  text-decoration: underline;
}

[data-theme="dark"] .note-body a {
  color: var(--mustard-400);
}

/* Images inside Note */
.note-image-container {
  margin: 8px 0;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.note-image-container img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-fast);
}

.note-image-container:hover img {
  transform: scale(1.02);
}

.note-image-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.note-image-container:hover .note-image-delete-btn {
  opacity: 1;
}

/* Connection Handles / Ports on Card */
.connection-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--bg-secondary);
  border: 2px solid var(--mustard-500);
  border-radius: 50%;
  cursor: crosshair;
  z-index: 15;
  transition: transform var(--transition-fast), background var(--transition-fast);
  opacity: 0;
}

.note-card:hover .connection-handle {
  opacity: 1;
}

.connection-handle:hover {
  transform: scale(1.4);
  background: var(--mustard-500);
}

.connection-handle.top {
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
}
.connection-handle.top:hover {
  transform: translateX(-50%) scale(1.4);
}

.connection-handle.bottom {
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
}
.connection-handle.bottom:hover {
  transform: translateX(-50%) scale(1.4);
}

.connection-handle.left {
  top: 50%;
  left: -7px;
  transform: translateY(-50%);
}
.connection-handle.left:hover {
  transform: translateY(-50%) scale(1.4);
}

.connection-handle.right {
  top: 50%;
  right: -7px;
  transform: translateY(-50%);
}
.connection-handle.right:hover {
  transform: translateY(-50%) scale(1.4);
}

/* Resize Handle */
.note-resize-handle {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  cursor: se-resize;
  opacity: 0.4;
  transition: opacity var(--transition-fast);
}

.note-card:hover .note-resize-handle {
  opacity: 1;
}

.note-resize-handle::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
}

/* ===== Per-note style: font, background, text color ===== */
.note-card[data-font="sans"] .note-body,
.note-card[data-font="sans"] .note-title-input {
  font-family: var(--font-sans);
}

.note-card[data-font="mono"] .note-body,
.note-card[data-font="mono"] .note-title-input {
  font-family: var(--font-mono);
}

.note-card[data-font="hand"] .note-body,
.note-card[data-font="hand"] .note-title-input {
  font-family: 'Caveat', 'Comic Sans MS', cursive;
}

.note-card[data-font="hand"] .note-body {
  font-size: 17px;
  line-height: 1.4;
}

.note-card[data-font="hand"] .note-title-input {
  font-size: 17px;
}

/* Background tint (works over both light and dark themes) */
.note-card[data-bg="amber"]  { --note-tint: rgba(245, 158, 11, 0.16); }
.note-card[data-bg="blue"]   { --note-tint: rgba(59, 130, 246, 0.16); }
.note-card[data-bg="green"]  { --note-tint: rgba(34, 197, 94, 0.16); }
.note-card[data-bg="rose"]   { --note-tint: rgba(244, 63, 94, 0.16); }
.note-card[data-bg="violet"] { --note-tint: rgba(139, 92, 246, 0.16); }

.note-card[data-bg]:not([data-bg="default"]) {
  background: linear-gradient(var(--note-tint), var(--note-tint)), var(--bg-secondary);
}

/* Text colors (theme-aware for contrast) */
.note-card[data-fg="amber"]  { --note-fg: #b45309; }
.note-card[data-fg="blue"]   { --note-fg: #1d4ed8; }
.note-card[data-fg="green"]  { --note-fg: #15803d; }
.note-card[data-fg="rose"]   { --note-fg: #be123c; }
.note-card[data-fg="violet"] { --note-fg: #6d28d9; }

[data-theme="dark"] .note-card[data-fg="amber"]  { --note-fg: #fbbf24; }
[data-theme="dark"] .note-card[data-fg="blue"]   { --note-fg: #60a5fa; }
[data-theme="dark"] .note-card[data-fg="green"]  { --note-fg: #4ade80; }
[data-theme="dark"] .note-card[data-fg="rose"]   { --note-fg: #fb7185; }
[data-theme="dark"] .note-card[data-fg="violet"] { --note-fg: #a78bfa; }

.note-card[data-fg]:not([data-fg="default"]) .note-body,
.note-card[data-fg]:not([data-fg="default"]) .note-body b,
.note-card[data-fg]:not([data-fg="default"]) .note-body strong,
.note-card[data-fg]:not([data-fg="default"]) .note-title-input {
  color: var(--note-fg);
}

/* Style section inside the note dropdown */
.note-style-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 6px;
}

.note-style-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.note-style-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.style-chip {
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.style-chip:hover {
  border-color: var(--mustard-500);
}

.style-chip.is-active {
  border-color: var(--mustard-500);
  background: var(--mustard-dim);
  box-shadow: 0 0 0 1px var(--mustard-500);
}

.style-chip.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: var(--swatch-color, transparent);
}

.style-chip.swatch[data-swatch="default"] {
  background: linear-gradient(135deg, transparent 45%, var(--text-muted) 45%, var(--text-muted) 55%, transparent 55%), var(--bg-tertiary);
}

.style-chip.swatch[data-swatch="amber"]  { --swatch-color: #f59e0b; }
.style-chip.swatch[data-swatch="blue"]   { --swatch-color: #3b82f6; }
.style-chip.swatch[data-swatch="green"]  { --swatch-color: #22c55e; }
.style-chip.swatch[data-swatch="rose"]   { --swatch-color: #f43f5e; }
.style-chip.swatch[data-swatch="violet"] { --swatch-color: #8b5cf6; }

/* Smooth movement while arranging notes */
#notes-layer.is-arranging .note-card {
  transition: left 0.5s cubic-bezier(0.16, 1, 0.3, 1), top 0.5s cubic-bezier(0.16, 1, 0.3, 1), box-shadow var(--transition-fast), border-color var(--transition-fast);
}
