.tree-node-row {
  display: flex;
  align-items: flex-start;
  gap: calc(16px * var(--scale-tree-items, 1));
  margin-bottom: calc(4px * var(--scale-tree-items, 1));
}

/* Ensure rows with children have consistent top edge alignment */
.tree-node-row.has-children {
  /* Force row to start at wrapper's top edge */
  align-items: flex-start;
  /* Ensure row's bounding box matches wrapper's when children are collapsed */
  min-height: 0;
}

.tree-node-row.dragging {
  opacity: 0.3;
}

/* Drop indicator line - shows where item will be dropped */
/* Positioned absolutely to float over items without affecting layout */
.drop-indicator {
  height: 2px;
  background: var(--accent-primary);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
  pointer-events: none; /* Don't interfere with drag events */
  z-index: 1000; /* Ensure it's on top */
  animation: dropIndicatorPulse 0.5s ease-in-out infinite alternate;
  /* Position is set via inline styles from JavaScript */
}

@keyframes dropIndicatorPulse {
  from {
    opacity: 0.6;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
  }
  to {
    opacity: 1;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.9);
  }
}

.tree-node-wrapper.dragging-overlay {
  cursor: grabbing;
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.4);
  transform: rotate(3deg);
  width: 320px;
  min-width: unset;
  max-width: unset;
}

.tree-node-wrapper.dragging-overlay .tree-node {
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.tree-node-wrapper {
  flex-shrink: 0;
  min-width: 280px;
  max-width: 400px;
  /* Ensure wrapper defines the row's top edge for consistent transform calculations */
  align-self: flex-start;
  margin-top: 0;
  padding-top: 0;
  /* Ensure wrapper height is consistent regardless of children */
  height: fit-content;
  /* Ensure wrapper position is used for transform calculations, not row */
  position: relative;
  /* Ensure wrapper's top edge is at row's top edge */
  top: 0;
}

.tree-node {
  position: relative;
  overflow: visible;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: calc(8px * var(--scale-tree-items, 1));
  padding: calc(6px * var(--scale-tree-items, 1)) calc(10px * var(--scale-tree-items, 1));
  cursor: default;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
  width: 100%;
  font-family: var(--font-tree-items);
  font-weight: var(--weight-tree-items, 400);
  font-size: calc(0.95rem * var(--scale-tree-items, 1));
}

.tree-node::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0) 45%);
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}

.sticker-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.sticker-item {
  position: absolute;
  width: calc(24px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
  pointer-events: none;
}

@keyframes glowPulse {
  0%, 100% {
    box-shadow: 
      0 0 4px rgba(255, 255, 0, 1),
      0 0 8px rgba(255, 255, 0, 0.8),
      0 0 12px rgba(255, 255, 0, 0.6),
      0 2px 4px rgba(0, 0, 0, 0.3) !important;
  }
  50% {
    box-shadow: 
      0 0 6px rgba(255, 255, 0, 1),
      0 0 12px rgba(255, 255, 0, 0.9),
      0 0 18px rgba(255, 255, 0, 0.7),
      0 2px 4px rgba(0, 0, 0, 0.3) !important;
  }
}

@keyframes glowPulseBackground {
  0%, 100% {
    opacity: 0.2;
  }
  50% {
    opacity: 0.4;
  }
}

.tree-node-row:hover:not(.dragging):not(.inbox-mode) > .tree-node-wrapper:hover > .tree-node {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.15);
  transform: scale(1.02);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.tree-node-row.dragging > .tree-node-wrapper > .tree-node {
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
  cursor: grabbing;
}

.node-content {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--scale-tree-items, 1));
  width: 100%;
}

/* Deadline mode: fixed-width cell for the days-remaining counter */
.deadline-counter-cell {
  min-width: calc(58px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: calc(3px * var(--scale-tree-items, 1));
}

.deadline-spinner {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.deadline-spinner-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(11px * var(--scale-tree-items, 1));
  height: calc(8px * var(--scale-tree-items, 1));
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 2px;
  background: #ccc;
  color: #000;
  font-size: 5px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.deadline-spinner-btn:hover {
  background: #b0b0b0;
}

.deadline-spinner-btn:active {
  background: #999;
}

.deadline-spinner-spacer {
  width: calc(11px * var(--scale-tree-items, 1));
  height: calc(8px * var(--scale-tree-items, 1));
}

.deadline-counter {
  font-size: calc(0.75rem * var(--scale-tree-items, 1));
  font-weight: 600;
  color: #000;
  background: #fff;
  padding: calc(1px * var(--scale-tree-items, 1)) calc(6px * var(--scale-tree-items, 1));
  border-radius: calc(4px * var(--scale-tree-items, 1));
  white-space: nowrap;
  user-select: none;
}

.deadline-counter.deadline-today {
  color: #7c3600;
}

.deadline-counter.deadline-overdue {
  color: #b91c1c;
  font-weight: 700;
}

.status-icon-placeholder {
  width: calc(24px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-icon {
  font-size: calc(1.2rem * var(--scale-tree-items, 1));
  line-height: 1;
  display: inline-block;
}

.status-icon-small {
  font-size: calc(0.7rem * var(--scale-tree-items, 1));
  line-height: 1;
  display: inline-block;
}

.status-icon-star {
  filter: drop-shadow(0 0 2px rgba(255, 215, 0, 0.6));
  animation: starPulse 2s ease-in-out infinite;
}

.status-icon-flame {
  filter: drop-shadow(0 0 3px rgba(255, 69, 0, 0.8));
  animation: flameFlicker 1.5s ease-in-out infinite;
}

.status-icon-hourglass {
  filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.8)) 
          drop-shadow(0 0 4px rgba(59, 130, 246, 0.6));
  animation: hourglassShake 1s ease-in-out infinite;
  /* Blue tint effect for hourglass emoji */
  opacity: 0.9;
}

.status-icon-hibernation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(24px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
  position: relative;
}

.status-icon-hibernation svg {
  width: 100%;
  height: 100%;
  display: block;
}

.status-icon-completed {
  color: #22c55e;
  font-weight: bold;
  font-size: calc(1.1rem * var(--scale-tree-items, 1));
  filter: drop-shadow(0 0 2px rgba(34, 197, 94, 0.6));
}

/* Small icons in grid also get animations */
.status-icon-grid .status-icon-small.status-icon-star {
  filter: drop-shadow(0 0 1px rgba(255, 215, 0, 0.6));
  animation: starPulse 2s ease-in-out infinite;
}

.status-icon-grid .status-icon-small.status-icon-flame {
  filter: drop-shadow(0 0 1.5px rgba(255, 69, 0, 0.8));
  animation: flameFlicker 1.5s ease-in-out infinite;
}

.status-icon-grid .status-icon-small.status-icon-hourglass {
  filter: drop-shadow(0 0 1px rgba(59, 130, 246, 0.8));
  animation: hourglassShake 1s ease-in-out infinite;
  opacity: 0.9;
}

.status-icon-grid .status-icon-small.status-icon-hibernation {
  position: relative;
}

.status-icon-grid .status-icon-small.status-icon-hibernation svg {
  width: 100%;
  height: 100%;
  display: block;
}

.status-icon-grid .status-icon-small.status-icon-completed {
  color: #22c55e;
  font-weight: bold;
  font-size: calc(0.9rem * var(--scale-tree-items, 1));
  filter: drop-shadow(0 0 1px rgba(34, 197, 94, 0.6));
}

@keyframes hourglassShake {
  0%, 100% {
    transform: rotate(0deg);
    opacity: 1;
  }
  25% {
    transform: rotate(-2deg);
    opacity: 0.9;
  }
  50% {
    transform: rotate(0deg);
    opacity: 0.85;
  }
  75% {
    transform: rotate(2deg);
    opacity: 0.9;
  }
}

/* 2x2 grid for multiple status icons */
.status-icon-grid {
  width: calc(24px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  padding: 1px;
}

.status-icon-grid .status-icon-small {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-size: calc(0.65rem * var(--scale-tree-items, 1));
}

/* Ellipsis for 5+ icons */
.status-icon-ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(2px * var(--scale-tree-items, 1));
  width: calc(24px * var(--scale-tree-items, 1));
  height: calc(24px * var(--scale-tree-items, 1));
}

.ellipsis-dot {
  width: calc(4px * var(--scale-tree-items, 1));
  height: calc(4px * var(--scale-tree-items, 1));
  border-radius: 50%;
  background-color: #ef4444; /* Red color */
  display: inline-block;
}

@keyframes starPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.9;
  }
}

@keyframes flameFlicker {
  0%, 100% {
    transform: scale(1) rotate(-2deg);
    opacity: 1;
  }
  25% {
    transform: scale(1.05) rotate(1deg);
    opacity: 0.95;
  }
  50% {
    transform: scale(0.98) rotate(-1deg);
    opacity: 0.9;
  }
  75% {
    transform: scale(1.03) rotate(2deg);
    opacity: 0.95;
  }
}

.expand-button {
  width: calc(20px * var(--scale-tree-items, 1));
  height: calc(20px * var(--scale-tree-items, 1));
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: calc(4px * var(--scale-tree-items, 1));
  color: var(--text-secondary);
  font-size: calc(0.65rem * var(--scale-tree-items, 1));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.expand-button:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: scale(1.1);
}

.expand-spacer {
  width: calc(20px * var(--scale-tree-items, 1));
  height: calc(20px * var(--scale-tree-items, 1));
  flex-shrink: 0;
}

.drag-handle {
  width: calc(26px * var(--scale-tree-items, 1));
  height: calc(26px * var(--scale-tree-items, 1));
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: calc(5px * var(--scale-tree-items, 1));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.drag-handle:hover {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-icon {
  color: var(--text-muted);
  font-size: calc(1rem * var(--scale-tree-items, 1));
  letter-spacing: -2px;
}

.drag-handle:hover .drag-icon {
  color: white;
}

.node-title {
  flex: 1;
  font-size: calc(0.9rem * var(--scale-tree-items, 1));
  font-weight: 500;
  color: inherit;
  user-select: none;
  display: flex;
  align-items: center;
  gap: calc(4px * var(--scale-tree-items, 1));
}

.inherited-priority-badge {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
  opacity: 0.8;
}

.tree-node-rename-input {
  flex: 1;
  padding: calc(2px * var(--scale-tree-items, 1)) calc(6px * var(--scale-tree-items, 1));
  border: 1px solid var(--accent-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: calc(0.9rem * var(--scale-tree-items, 1));
  font-weight: 500;
  outline: none;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.children-count {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: white;
  padding: calc(2px * var(--scale-tree-items, 1)) calc(8px * var(--scale-tree-items, 1));
  border-radius: calc(10px * var(--scale-tree-items, 1));
  font-size: calc(0.7rem * var(--scale-tree-items, 1));
  font-weight: 600;
  min-width: calc(20px * var(--scale-tree-items, 1));
  text-align: center;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.tree-node-children {
  display: flex;
  flex-direction: column;
  gap: calc(4px * var(--scale-tree-items, 1));
  padding-left: calc(14px * var(--scale-tree-items, 1));
  border-left: 2px solid var(--border-color);
  position: relative;
  flex: 1;
  min-width: 0;
  /* Ensure children container doesn't affect row height when empty/collapsed */
  min-height: 0;
  /* Ensure children container doesn't affect parent row's bounding box calculation */
  flex-shrink: 1;
}

.tree-node-children::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent-primary) 0%, transparent 100%);
  opacity: 0.3;
}

/* Selection mode: pointer cursor on all items (except the source) */
.tree-node-row.selection-mode {
  cursor: pointer;
}

.tree-node-row.selection-mode.selection-source {
  cursor: default;
  opacity: 0.5;
}

/* In selection mode, suppress the normal hover scale effect */
.tree-node-row.selection-mode:hover:not(.dragging) > .tree-node-wrapper:hover > .tree-node {
  transform: none;
  box-shadow: var(--shadow-sm);
  border-color: var(--border-color);
  background: var(--bg-tertiary);
}

/* Pure-CSS hover glow for picker and selection modes */
.tree-node-row.selection-mode:not(.selection-source):hover > .tree-node-wrapper:hover > .tree-node,
.tree-node-row.context-picker-mode:not(.context-already-assigned):hover > .tree-node-wrapper:hover > .tree-node {
  transition: none;
  box-shadow:
    0 0 4px rgba(255, 255, 0, 1),
    0 0 8px rgba(255, 255, 0, 0.8),
    0 0 12px rgba(255, 255, 0, 0.6),
    0 2px 4px rgba(0, 0, 0, 0.3) !important;
  animation: glowPulse 2s ease-in-out infinite;
  border-color: rgba(255, 255, 0, 0.8) !important;
  position: relative;
}

.tree-node-row.selection-mode:not(.selection-source):hover > .tree-node-wrapper:hover > .tree-node::before,
.tree-node-row.context-picker-mode:not(.context-already-assigned):hover > .tree-node-wrapper:hover > .tree-node::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(255, 255, 0, 0.2), rgba(255, 235, 59, 0.2));
  z-index: -1;
  animation: glowPulseBackground 2s ease-in-out infinite;
}

/* Drag feedback - no animation needed with DragOverlay */

/* ── Deadline mode ─────────────────────────────────────────────────────── */

.tree-node-row.deadline-mode {
  max-width: 100%;
}

.tree-node-row.deadline-mode > .tree-node-wrapper {
  min-width: 0;
  max-width: 100%;
  width: fit-content;
  flex-shrink: 1;
}

.tree-node-row.deadline-mode > .tree-node-wrapper .node-content {
  min-width: 0;
}

.tree-node-row.deadline-mode > .tree-node-wrapper .node-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ── Inbox mode ────────────────────────────────────────────────────────── */

.tree-node-row.inbox-mode {
  width: 100%;
}

.inbox-mode-row > .tree-node-row.inbox-mode {
  width: auto;
}

.tree-node-row.inbox-mode > .tree-node-wrapper {
  min-width: 0;
  max-width: none;
  width: 100%;
  overflow: hidden;
}

.inbox-controls-wrapper {
  display: flex;
  flex-direction: column;
  gap: calc(2px * var(--scale-tree-items, 1));
  flex: 1;
  min-width: 0;
  padding-left: 8px;
}

.inbox-title-row {
  display: flex;
  align-items: center;
  min-width: 0;
}

.inbox-controls {
  display: flex;
  align-items: center;
  gap: calc(4px * var(--scale-tree-items, 1));
  min-width: 0;
}

.inbox-expand-area {
  display: flex;
  align-items: center;
  gap: calc(4px * var(--scale-tree-items, 1));
  flex-shrink: 0;
  min-width: calc(55px * var(--scale-tree-items, 1));
  justify-content: flex-end;
}

.inbox-priority-squares {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.inbox-priority-square {
  width: calc(20px * var(--scale-tree-items, 1));
  height: calc(20px * var(--scale-tree-items, 1));
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}

.inbox-priority-square:hover {
  opacity: 0.85;
}

.inbox-priority-square.inbox-priority-selected {
  border: 2px solid #ff0000;
}

.inbox-btn {
  height: calc(22px * var(--scale-tree-items, 1));
  min-width: calc(24px * var(--scale-tree-items, 1));
  padding: 0 calc(5px * var(--scale-tree-items, 1));
  border: 2px solid transparent;
  border-radius: calc(3px * var(--scale-tree-items, 1));
  background: #555;
  color: #fff;
  font-size: calc(0.65rem * var(--scale-tree-items, 1));
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  box-sizing: border-box;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.inbox-btn:hover {
  background: #666;
}

.inbox-btn.inbox-btn-active {
  border-color: #ff0000;
}

.inbox-btn.inbox-btn-on {
  background: #fff;
  color: #555;
}

.inbox-btn.inbox-btn-on:hover {
  background: #eee;
}

.inbox-btn-wide {
  padding: 0 6px;
}

.inbox-note-icon {
  width: calc(22px * var(--scale-tree-items, 1));
  height: calc(22px * var(--scale-tree-items, 1));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
  border-radius: 3px;
  position: relative;
}

.inbox-note-icon svg {
  width: calc(18px * var(--scale-tree-items, 1));
  height: calc(18px * var(--scale-tree-items, 1));
}

.inbox-note-icon::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  border: 2px solid transparent;
  border-radius: 5px;
  pointer-events: none;
  transition: border-color 0.15s ease;
}

.inbox-note-icon.inbox-note-icon-active::after {
  border-color: #ff0000;
}

.inbox-note-icon:hover {
  opacity: 0.85;
}

.inbox-apply-btn {
  height: calc(22px * var(--scale-tree-items, 1));
  padding: 0 calc(8px * var(--scale-tree-items, 1));
  border: none;
  border-radius: calc(3px * var(--scale-tree-items, 1));
  background: #2563eb;
  color: #fff;
  font-size: calc(0.7rem * var(--scale-tree-items, 1));
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.15s ease;
}

.inbox-apply-btn:hover {
  background: #1d4ed8;
}

.inbox-apply-btn:active {
  background: #1e40af;
}

.inbox-apply-btn.inbox-apply-btn-disabled {
  background: #444;
  color: #888;
  cursor: default;
  pointer-events: none;
}

.inbox-title-clickable {
  cursor: text;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
}

.inbox-title-clickable:hover {
  border-bottom-color: rgba(255, 255, 255, 0.6);
}

.inbox-title-changed {
  font-style: italic;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .tree-node-row {
    gap: calc(12px * var(--scale-tree-items, 1));
  }

  .tree-node-wrapper {
    min-width: 200px;
    max-width: 300px;
  }

  .tree-node {
    padding: calc(12px * var(--scale-tree-items, 1));
  }

  .node-title {
    font-size: calc(0.9rem * var(--scale-tree-items, 1));
  }

  .drag-handle {
    width: calc(28px * var(--scale-tree-items, 1));
    height: calc(28px * var(--scale-tree-items, 1));
  }

  .tree-node-children {
    padding-left: calc(12px * var(--scale-tree-items, 1));
  }
}

