/* Utility */
.hidden {
  display: none !important;
}

/* Modern Design Tokens */
:root {
  --font-primary: 'Outfit', sans-serif;
  --font-secondary: 'Plus Jakarta Sans', sans-serif;

  /* HSL Tailored Colors */
  --bg-app: hsl(220, 24%, 7%);
  --bg-card: hsla(220, 20%, 12%, 0.6);
  --bg-card-hover: hsla(220, 20%, 16%, 0.8);
  --bg-modal: hsla(220, 24%, 10%, 0.95);
  
  --border-color: hsla(220, 16%, 22%, 0.5);
  --border-color-glow: hsla(220, 16%, 35%, 0.8);

  --color-primary: hsl(262, 83%, 68%); /* Purple */
  --color-primary-glow: hsla(262, 83%, 68%, 0.25);
  
  --color-secondary: hsl(190, 90%, 50%); /* Cyan */
  --color-secondary-glow: hsla(190, 90%, 50%, 0.25);
  
  --color-success: hsl(145, 80%, 50%); /* Green */
  --color-warning: hsl(35, 90%, 55%); /* Orange */
  --color-danger: hsl(355, 85%, 60%); /* Red */
  
  --color-text: hsl(0, 0%, 94%);
  --color-text-muted: hsl(220, 12%, 60%);
  --color-text-dark: hsl(220, 16%, 30%);

  /* Level Colors */
  --color-level-1: hsl(262, 83%, 68%);   /* Project - Indigo/Purple */
  --color-level-2: hsl(210, 100%, 60%);  /* Initiative - Blue */
  --color-level-3: hsl(160, 85%, 45%);   /* Epic - Emerald */
  --color-level-4: hsl(35, 90%, 55%);    /* Task - Orange/Gold */

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);

  --backdrop-blur: blur(12px);
  --transition-fast: 0.15s ease;
  --transition-medium: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base resets & layouts */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  max-height: 100dvh;
}

body {
  background-color: var(--bg-app);
  color: var(--color-text);
  font-family: var(--font-primary);
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

/* Header styling */
#app-header {
  background: hsla(220, 24%, 6%, 0.85);
  backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  z-index: 10;
  flex-shrink: 0;
}

#brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--color-text) 50%, var(--color-text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text .subtext {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

#search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 99px;
  padding: 0.5rem 1rem;
  width: 320px;
  transition: var(--transition-fast);
  position: relative;
}

#search-bar:focus-within {
  border-color: var(--color-primary);
  background: var(--bg-card-hover);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.search-icon {
  color: var(--color-text-muted);
  margin-right: 0.5rem;
  flex-shrink: 0;
}

#global-search {
  width: 100%;
  font-size: 0.85rem;
}

#global-search::placeholder {
  color: var(--color-text-dark);
}

#search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
}

.search-candidate-box {
  position: relative;
}

.search-candidate-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 99;
  box-shadow: var(--shadow-lg);
  backdrop-filter: var(--backdrop-blur);
}

.search-candidate-dropdown.hidden {
  display: none;
}

#existing-search-bar .search-candidate-dropdown {
  z-index: 110;
}

.search-candidate-empty {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.search-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: var(--transition-fast);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: var(--bg-card-hover);
}

.search-item.selected {
  background: hsla(262, 83%, 68%, 0.15);
  border-left: 3px solid var(--color-primary);
  padding-left: calc(1rem - 3px);
}

.search-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.search-item-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-item-meta {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.search-item-type {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
}

#header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.view-toggle-group {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
  color: var(--color-text-muted);
}

.toggle-btn svg {
  opacity: 0.7;
}

.toggle-btn.active {
  background: hsla(262, 83%, 68%, 0.15);
  color: var(--color-text);
  border: 1px solid hsla(262, 83%, 68%, 0.3);
}

.toggle-btn.active svg {
  color: var(--color-primary);
  opacity: 1;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 12px var(--color-primary-glow);
}

.btn-secondary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--color-text-muted);
}

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#btn-refresh.refreshing .refresh-icon {
  animation: spin 1s linear infinite;
}

.sync-hud {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--color-text-muted);
  max-width: 11rem;
  line-height: 1.2;
  white-space: nowrap;
}

/* Viewports styling */
#app-viewport {
  flex-grow: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  overflow: auto;
}

.view-panel.active {
  display: flex;
  flex-direction: column;
}

/* --- Hierarchy View (Tree) --- */
#view-hierarchy {
  padding: 2rem;
  background: radial-gradient(circle at 10% 20%, hsla(262, 83%, 68%, 0.03) 0%, transparent 50%);
}

#hierarchy-toolbar {
  max-width: 800px;
  margin: 0 auto 1rem auto;
  width: 100%;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.tree-container {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.orphan-section {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
}

.orphan-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-level-4);
}

.orphan-section-count {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  background: hsla(35, 90%, 55%, 0.15);
  border: 1px solid hsla(35, 90%, 55%, 0.25);
}

.tree-node-wrapper.orphan-node > .tree-node-row {
  border-style: dashed;
  opacity: 0.92;
}

.graph-card.orphan-card {
  border-style: dashed;
  opacity: 0.92;
}

.graph-orphan-section {
  width: 100%;
}

.tree-node-wrapper {
  margin-bottom: 0.5rem;
}

.tree-node-row {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  transition: var(--transition-fast);
  backdrop-filter: var(--backdrop-blur);
  position: relative;
}

.tree-node-row:hover {
  border-color: var(--border-color-glow);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

/* Status group colors (Notion: to-do, in progress, complete) */
.tree-node-row.status-group-to-do {
  border-left: 3px solid hsl(220, 12%, 52%);
  background: hsla(220, 14%, 18%, 0.72);
}

.tree-node-row.status-group-in-progress {
  border-left: 3px solid var(--color-level-2);
  background: hsla(210, 100%, 60%, 0.1);
}

.tree-node-row.status-group-complete {
  border-left: 3px solid var(--color-success);
  background: hsla(145, 80%, 50%, 0.1);
}

.tree-node-row.status-group-to-do:hover {
  background: hsla(220, 14%, 22%, 0.85);
}

.tree-node-row.status-group-in-progress:hover {
  background: hsla(210, 100%, 60%, 0.16);
}

.tree-node-row.status-group-complete:hover {
  background: hsla(145, 80%, 50%, 0.16);
}

.status-group-to-do .node-status-select {
  border-color: hsla(220, 12%, 52%, 0.45);
  color: hsl(220, 12%, 78%);
}

.status-group-in-progress .node-status-select {
  border-color: hsla(210, 100%, 60%, 0.45);
  color: hsl(210, 100%, 78%);
}

.status-group-complete .node-status-select {
  border-color: hsla(145, 80%, 50%, 0.45);
  color: hsl(145, 80%, 72%);
}

.tree-toggle-arrow {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: 4px;
  margin-right: 0.5rem;
  transition: var(--transition-fast);
}

.tree-toggle-arrow:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
}

.tree-toggle-arrow svg {
  transition: transform var(--transition-fast);
}

.tree-node-wrapper.expanded > .tree-node-row .tree-toggle-arrow svg {
  transform: rotate(90deg);
}

.tree-toggle-arrow.hidden-arrow {
  visibility: hidden;
  pointer-events: none;
}

.tree-node-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-grow: 1;
  min-width: 0;
}

.node-type-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-secondary);
  flex-shrink: 0;
}

.type-project {
  background: hsla(262, 83%, 68%, 0.15);
  color: var(--color-level-1);
  border: 1px solid hsla(262, 83%, 68%, 0.25);
}
.type-initiative {
  background: hsla(210, 100%, 60%, 0.15);
  color: var(--color-level-2);
  border: 1px solid hsla(210, 100%, 60%, 0.25);
}
.type-epic {
  background: hsla(160, 85%, 45%, 0.15);
  color: var(--color-level-3);
  border: 1px solid hsla(160, 85%, 45%, 0.25);
}
.type-task {
  background: hsla(35, 90%, 55%, 0.15);
  color: var(--color-level-4);
  border: 1px solid hsla(35, 90%, 55%, 0.25);
}

.node-title {
  font-size: 0.95rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-status-badge,
.node-status-select {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.15rem 0.4rem;
  border-radius: 99px;
  color: var(--color-text-muted);
  border: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.node-status-select {
  cursor: pointer;
  max-width: 9rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
  padding-right: 1.2rem;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.node-status-select:hover:not(:disabled) {
  border-color: var(--color-primary);
  background-color: hsla(262, 83%, 68%, 0.08);
}

.node-status-select:disabled {
  opacity: 0.6;
  cursor: wait;
}

.node-status-select option {
  background: var(--bg-modal);
  color: var(--color-text);
}

.tree-node-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.tree-node-row:hover .tree-node-actions {
  opacity: 1;
}

.action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
  color: var(--color-text-muted);
  border: 1px solid transparent;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
  border-color: var(--border-color);
}

.action-btn.btn-add-child:hover {
  color: var(--color-secondary);
  background: hsla(190, 90%, 50%, 0.1);
  border-color: hsla(190, 90%, 50%, 0.2);
}

.action-btn.btn-add-sibling:hover {
  color: var(--color-success);
  background: hsla(145, 80%, 50%, 0.1);
  border-color: hsla(145, 80%, 50%, 0.2);
}

.action-btn.btn-add-parent:hover {
  color: var(--color-primary);
  background: hsla(262, 83%, 68%, 0.1);
  border-color: hsla(262, 83%, 68%, 0.2);
}

/* Tree Children List with guidelines */
.tree-node-children {
  margin-left: 28px;
  padding-left: 12px;
  border-left: 1px dashed var(--border-color);
  display: none;
}

.tree-node-wrapper.expanded > .tree-node-children {
  display: block;
}

/* Search Highlights */
.search-highlight {
  background: hsla(50, 100%, 50%, 0.2);
  color: hsl(50, 100%, 70%);
  border-radius: 2px;
  padding: 0 2px;
}

.node-row-hidden {
  display: none !important;
}

/* --- Dependency Graph View (DAG) --- */
#view-dependency {
  background: radial-gradient(circle at 90% 80%, hsla(190, 90%, 50%, 0.02) 0%, transparent 50%),
              radial-gradient(circle at 10% 20%, hsla(262, 83%, 68%, 0.02) 0%, transparent 50%);
  /* Keep .view-panel absolute fill so the DAG scrolls inside the canvas, not grow the page */
  overflow: hidden;
  min-height: 0;
}

#dependency-hud {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
  pointer-events: none;
}

#dependency-hud > * {
  pointer-events: auto;
}

.dependency-hud-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: var(--backdrop-blur);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.hud-btn:hover {
  border-color: var(--color-primary);
  background: var(--bg-card-hover);
}

.hud-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
  animation: pulse-border 2s infinite;
}

#btn-toggle-orphans.active {
  background: hsla(35, 90%, 55%, 0.15);
  color: var(--color-level-4);
  border-color: hsla(35, 90%, 55%, 0.35);
  box-shadow: none;
  animation: none;
}

#btn-toggle-orphans:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.orphan-toggle-count {
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 99px;
  background: hsla(35, 90%, 55%, 0.2);
  color: var(--color-level-4);
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#hud-status {
  background: hsla(262, 83%, 68%, 0.15);
  border: 1px solid hsla(262, 83%, 68%, 0.3);
  padding: 0.4rem 1rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-primary);
  backdrop-filter: var(--backdrop-blur);
}

.hud-zoom-controls {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: var(--backdrop-blur);
  border-radius: 8px;
  padding: 2px;
}

.hud-zoom-controls button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition-fast);
}

.hud-zoom-controls button:hover {
  background: rgba(255, 255, 255, 0.05);
}

#zoom-indicator {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 0.5rem;
  min-width: 50px;
  text-align: center;
  color: var(--color-text-muted);
}

#btn-zoom-reset {
  font-size: 0.75rem !important;
  font-weight: 500 !important;
  width: auto !important;
  padding: 0 0.5rem;
}

/* Canvas & Graph Layout */
#graph-canvas-container {
  width: 100%;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  padding: 5rem 2rem 2rem 2rem;
  cursor: grab;
}

#graph-canvas-container.grabbing {
  cursor: grabbing;
  user-select: none;
}

#graph-world-sizer {
  position: relative;
}

#graph-world {
  position: relative;
  display: inline-block;
}

#graph-edges-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

#graph-edges-svg path.graph-edge-path {
  fill: none;
  stroke: hsl(220, 24%, 58%);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

#graph-columns-container {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  align-items: flex-start;
  position: relative;
  z-index: 2;
  width: max-content;
  min-width: 100%;
}

.graph-dag-layer {
  position: relative;
  min-width: 100%;
}

.graph-dag-layer #graph-edges-svg {
  position: absolute;
  top: 0;
  left: 0;
}

.graph-card.graph-card-positioned {
  position: absolute;
  margin: 0;
  z-index: 2;
}

.graph-card.graph-card-positioned:hover {
  transform: none;
}

.graph-card.graph-card-positioned .connector-pin {
  display: none;
}

.graph-cards-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  width: 100%;
}

/* Graph Node Cards */
.graph-card {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  position: relative;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  backdrop-filter: var(--backdrop-blur);
  cursor: pointer;
  user-select: none;
}

.graph-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.graph-card:not([class*="status-group-"]):hover {
  border-color: var(--border-color-glow);
}

/* Dependency graph status group colors */
.graph-card.status-group-to-do {
  border-color: hsla(220, 12%, 52%, 0.55);
  border-left-width: 4px;
  border-left-color: hsl(220, 12%, 64%);
  background: hsla(220, 16%, 17%, 0.95);
  box-shadow: inset 0 1px 0 hsla(220, 12%, 70%, 0.08);
}

.graph-card.status-group-in-progress {
  border-color: hsla(210, 100%, 60%, 0.5);
  border-left-width: 4px;
  border-left-color: var(--color-level-2);
  background: hsla(210, 65%, 18%, 0.95);
  box-shadow: inset 0 1px 0 hsla(210, 100%, 70%, 0.12);
}

.graph-card.status-group-complete {
  border-color: hsla(145, 80%, 50%, 0.5);
  border-left-width: 4px;
  border-left-color: var(--color-success);
  background: hsla(145, 45%, 16%, 0.95);
  box-shadow: inset 0 1px 0 hsla(145, 80%, 60%, 0.12);
}

.graph-card.status-group-to-do:hover {
  border-color: hsla(220, 12%, 58%, 0.7);
  border-left-color: hsl(220, 12%, 72%);
  background: hsla(220, 16%, 20%, 0.98);
}

.graph-card.status-group-in-progress:hover {
  border-color: hsla(210, 100%, 60%, 0.65);
  border-left-color: hsl(210, 100%, 68%);
  background: hsla(210, 65%, 21%, 0.98);
}

.graph-card.status-group-complete:hover {
  border-color: hsla(145, 80%, 50%, 0.65);
  border-left-color: hsl(145, 80%, 60%);
  background: hsla(145, 45%, 19%, 0.98);
}

/* Highlight matching search in Graph */
.graph-card.search-match {
  border-color: var(--color-secondary);
  box-shadow: 0 0 12px var(--color-secondary-glow);
}

.graph-card.search-mismatch {
  opacity: 0.25;
}

/* Dynamic Graph Card States */
.graph-card.linking-source {
  border-color: var(--color-primary);
  box-shadow: 0 0 14px var(--color-primary-glow);
  animation: pulse-border 2s infinite;
}

.graph-card.linking-target-candidate:hover {
  border-color: var(--color-success);
  box-shadow: 0 0 14px hsla(145, 80%, 50%, 0.3);
}

.graph-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.graph-card-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  min-width: 0;
}

.graph-card-options {
  position: relative;
  flex-shrink: 0;
}

.graph-options-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 700;
  border: 1px solid transparent;
  transition: var(--transition-fast);
}

.graph-options-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-color);
  color: var(--color-text);
}

.graph-card-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: var(--backdrop-blur);
  z-index: 30;
  overflow: hidden;
}

.graph-menu-item {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  color: var(--color-text);
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: var(--transition-fast);
}

.graph-menu-item:last-child {
  border-bottom: none;
}

.graph-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.graph-menu-item.btn-remove-parent-link {
  color: var(--color-danger);
}

.graph-menu-item.btn-remove-parent-link:hover {
  background: hsla(355, 85%, 60%, 0.12);
}

.graph-menu-empty {
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.graph-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
  word-break: break-word;
}

.graph-card-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.graph-card-actions {
  display: flex;
  gap: 0.3rem;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.graph-card:hover .graph-card-actions {
  opacity: 1;
}

.graph-action-btn {
  width: auto;
  min-width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border-radius: 5px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
  border: 1px solid transparent;
  padding: 0 0.35rem;
}

.graph-action-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.graph-action-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
  border-color: var(--border-color);
}

.graph-action-btn.btn-add-child:hover {
  color: var(--color-secondary);
  background: hsla(190, 90%, 50%, 0.1);
}

/* Connector Pins for drawing arrows */
.connector-pin {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-color);
  border: 2px solid var(--bg-app);
  transform: translateY(-50%);
  z-index: 3;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.connector-pin-left {
  left: -6px;
}

.connector-pin-right {
  right: -6px;
}

.graph-card:hover .connector-pin {
  background: var(--color-text-muted);
  transform: translateY(-50%) scale(1.2);
}

.graph-card.linking-source .connector-pin-right {
  background: var(--color-primary);
  transform: translateY(-50%) scale(1.3);
}

/* Modals & Popups (Slide-up drawer for mobile, center modal for desktop) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-medium);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

#issue-modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  width: 460px;
  max-width: 90%;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(30px);
  transition: transform var(--transition-medium);
}

.modal-overlay.active #issue-modal {
  transform: translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

#btn-close-modal {
  cursor: pointer;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  transition: var(--transition-fast);
}

#btn-close-modal:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
}

#issue-form {
  padding: 1.5rem;
}

.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

.form-group input, .form-group select {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--color-primary);
  background: rgba(0, 0, 0, 0.3);
}

.form-group select option {
  background: var(--bg-modal);
  color: var(--color-text);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

#context-info-group {
  flex-direction: row;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-color);
  padding: 0.75rem;
  border-radius: 8px;
}

.context-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.context-badge {
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--color-primary-glow);
  color: var(--color-primary);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 2rem;
}

/* Loading Spinner Overlay */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 1;
  transition: opacity var(--transition-medium);
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.05);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner-container p {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1000;
}

.toast {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  max-width: 400px;
  transform: translateY(20px);
  opacity: 0;
  transition: transform var(--transition-medium), opacity var(--transition-medium);
}

.toast.active {
  transform: translateY(0);
  opacity: 1;
}

.toast-success { border-left: 4px solid var(--color-success); }
.toast-error { border-left: 4px solid var(--color-danger); }
.toast-info { border-left: 4px solid var(--color-primary); }

.toast-icon {
  flex-shrink: 0;
}

.toast-icon-success { color: var(--color-success); }
.toast-icon-error { color: var(--color-danger); }
.toast-icon-info { color: var(--color-primary); }

.toast-message {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.4;
}

/* Animations */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-border {
  0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(167, 139, 250, 0); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

/* ==========================================================
   Mobile Responsive Adjustments
   ========================================================== */
@media (max-width: 768px) {
  /* Phone-first chrome (D042): two compact bands, not a stacked desktop header */
  #app-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "brand search"
      "actions actions";
    padding: 0.4rem 0.6rem;
    align-items: center;
    gap: 0.4rem 0.5rem;
  }

  #brand {
    grid-area: brand;
    justify-content: flex-start;
  }

  .logo-icon svg {
    width: 20px;
    height: 20px;
  }

  .logo-text {
    display: none;
  }

  #search-bar {
    grid-area: search;
    width: auto;
    min-width: 0;
    padding: 0.35rem 0.7rem;
  }

  #header-actions {
    grid-area: actions;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.35rem;
  }

  #scope-toggle-group,
  .view-toggle-group {
    flex: 0 0 auto;
    justify-content: center;
  }

  .toggle-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.78rem;
    gap: 0.2rem;
  }

  /* Icon-only view toggles; keep Personal/Work labels (D042) */
  .view-toggle-group:not(#scope-toggle-group) .toggle-btn span {
    display: none;
  }

  #btn-refresh span,
  #btn-quick-create span,
  #sync-hud {
    display: none;
  }

  #dependency-hud .hud-btn > span:not(.orphan-toggle-count) {
    display: none;
  }

  #btn-refresh,
  #btn-quick-create {
    padding: 0.4rem 0.55rem;
  }

  /* Viewports */
  #view-hierarchy {
    padding: 1rem;
  }
  
  .tree-node-row {
    padding: 0.6rem 0.75rem;
  }
  
  .tree-node-actions {
    opacity: 1; /* Always visible on mobile since there is no hover */
  }
  
  .tree-node-children {
    margin-left: 14px;
    padding-left: 8px;
  }

  /* Overlay HUD: one row over the canvas, not a second stacked header (D042) */
  #dependency-hud {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    align-items: center;
    gap: 0.35rem;
    background: hsla(220, 24%, 7%, 0.8);
    backdrop-filter: blur(8px);
    padding: 0.35rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
  }

  #hierarchy-toolbar {
    margin-bottom: 0.5rem;
  }

  .hud-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.78rem;
  }

  .hud-zoom-controls {
    justify-content: center;
    margin-left: auto;
  }

  #graph-canvas-container {
    padding-top: 3.25rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Mobile Drawer Modal */
  #issue-modal {
    position: absolute;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    border-bottom: none;
  }

  .modal-overlay.active #issue-modal {
    transform: translateY(0);
  }

  /* Actions inside Cards: always visible on mobile */
  .graph-card-actions {
    opacity: 1;
  }
}

/* Modal Tabs Layout */
.modal-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1.5rem 0 1.5rem;
  gap: 1rem;
}

.modal-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  padding: 0.5rem 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.modal-tab:hover {
  color: var(--color-text);
}

.modal-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* Link Existing Search List */
.search-results-list,
#existing-search-bar .search-candidate-dropdown {
  max-height: 220px;
}

.existing-result-item {
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: var(--transition-fast);
  color: var(--color-text);
}

.existing-result-item:last-child {
  border-bottom: none;
}

.existing-result-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.existing-result-item.selected {
  background: hsla(262, 83%, 68%, 0.15);
  border-left: 3px solid var(--color-primary);
  padding-left: calc(0.8rem - 3px);
}

.existing-result-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.existing-result-empty {
  padding: 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* Drag and Drop Card Hover state */
.graph-card.drag-hover {
  border-color: var(--color-success) !important;
  box-shadow: 0 0 14px hsla(145, 80%, 50%, 0.3) !important;
  transform: scale(1.02) !important;
}

.graph-card.dragging-card {
  opacity: 0.4;
}
