/* ==========================================================================
   IAA OS — Crime Board
   Style: tableau de liège, post-its, photos épinglées, fil rouge d'enquête.
   Canvas infini zoomable avec éléments positionnés en absolu.
   ========================================================================== */

.crimeboard {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  background:
    /* Texture liège subtile */
    radial-gradient(circle at 15% 20%, rgba(165, 100, 50, 0.08) 0%, transparent 35%),
    radial-gradient(circle at 85% 60%, rgba(140, 80, 40, 0.07) 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, rgba(180, 120, 70, 0.05) 0%, transparent 45%),
    linear-gradient(135deg, #3d2817 0%, #2d1f14 100%);
}

.crimeboard.panning { cursor: grabbing; }

.crimeboard.linking { cursor: crosshair; }

.crimeboard.linking .cb-node:not(.can-link) { opacity: 0.4; }

/* Cork texture noise overlay */
.crimeboard::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-radial-gradient(circle at 30% 40%, rgba(0, 0, 0, 0.03) 0px, transparent 2px, transparent 8px),
    repeating-radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.015) 0px, transparent 2px, transparent 6px);
  pointer-events: none;
}

/* ==========================================================================
   Infinite canvas (the transform surface)
   ========================================================================== */
.cb-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* SVG layer for red strings — sibling of canvas, transformed identically */
.cb-links-svg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
  transform-origin: 0 0;
  will-change: transform;
}

.cb-links-group { pointer-events: auto; }

.cb-link {
  fill: none;
  stroke: #c42f3d;
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
  pointer-events: stroke;
  cursor: pointer;
  transition: stroke-width 0.15s, stroke 0.15s;
}

.cb-link:hover {
  stroke: #ff5a6a;
  stroke-width: 3.5;
}

.cb-link.selected {
  stroke: #ff8080;
  stroke-width: 4;
  filter: drop-shadow(0 0 6px rgba(255, 90, 100, 0.8));
}

.cb-link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}

/* Link endpoint knots (subtle red knot at each end) */
.cb-link-knot {
  fill: #8a1e28;
  stroke: #c42f3d;
  stroke-width: 0.5;
}

/* ==========================================================================
   Nodes (shared base)
   ========================================================================== */
.cb-node {
  position: absolute;
  transform-origin: center center;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: grab;
  will-change: transform;
  z-index: 2;
}

.cb-node.dragging {
  cursor: grabbing;
  z-index: 100 !important;
  transition: none;
}

.cb-node.dragging .cb-node-inner {
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  transform: rotate(var(--rotation, 0deg)) scale(1.03);
}

.cb-node.selected .cb-node-inner {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 4px;
}

.cb-node.can-link .cb-node-inner {
  animation: cbPulseLink 1.5s ease-in-out infinite;
}

@keyframes cbPulseLink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196, 47, 61, 0.5), 0 8px 16px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 0 0 10px rgba(196, 47, 61, 0), 0 8px 16px rgba(0,0,0,0.5); }
}

.cb-node-inner {
  position: relative;
  transform: rotate(var(--rotation, 0deg));
  transition: transform 0.2s var(--ease-snap);
}

/* Pushpin — the red tack at the top of each item */
.cb-pin {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.6));
}

.cb-pin svg { width: 100%; height: 100%; display: block; }

/* ==========================================================================
   Post-it notes
   ========================================================================== */
.cb-postit .cb-node-inner {
  width: 180px;
  min-height: 180px;
  padding: 22px 16px 16px;
  background: var(--postit-color, #f9e88c);
  color: #2c2416;
  font-family: 'Caveat', 'Comic Sans MS', cursive;
  font-size: 18px;
  line-height: 1.35;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 8px 16px rgba(0, 0, 0, 0.5),
    inset 0 -12px 24px rgba(0, 0, 0, 0.04);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Post-it color variants */
.cb-postit[data-color="yellow"] { --postit-color: #f9e88c; --rotation: -1.5deg; }
.cb-postit[data-color="pink"]   { --postit-color: #f9b4c4; --rotation: 1deg; }
.cb-postit[data-color="green"]  { --postit-color: #b4e8a1; --rotation: -2deg; }
.cb-postit[data-color="blue"]   { --postit-color: #a7d4f0; --rotation: 1.8deg; }
.cb-postit[data-color="orange"] { --postit-color: #f9c88c; --rotation: -0.8deg; }
.cb-postit[data-color="white"]  { --postit-color: #f5f2e8; --rotation: 1.2deg; color: #1a1a1a; }

.cb-postit .cb-text {
  width: 100%;
  outline: none;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  resize: none;
  overflow: hidden;
  min-height: 130px;
}

.cb-postit .cb-text::placeholder { color: rgba(0, 0, 0, 0.3); }

/* Faux paper fold corner */
.cb-postit .cb-node-inner::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 24px;
  height: 24px;
  background:
    linear-gradient(135deg, transparent 50%, rgba(0, 0, 0, 0.12) 50%);
}

/* ==========================================================================
   Photo / Image nodes
   ========================================================================== */
.cb-photo .cb-node-inner {
  width: 160px;
  padding: 8px 8px 26px;
  background: #f5f2e8;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 10px 20px rgba(0, 0, 0, 0.55);
  --rotation: 2deg;
}

.cb-photo[data-rot="1"] .cb-node-inner { --rotation: -1.5deg; }
.cb-photo[data-rot="2"] .cb-node-inner { --rotation: 2.2deg; }
.cb-photo[data-rot="3"] .cb-node-inner { --rotation: -3deg; }
.cb-photo[data-rot="4"] .cb-node-inner { --rotation: 1.5deg; }

.cb-photo img {
  display: block;
  width: 100%;
  height: 180px;
  object-fit: cover;
  filter: grayscale(15%) contrast(1.05) saturate(0.9);
  background: #222;
}

.cb-photo .cb-caption {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  text-align: center;
  color: #2c2416;
  margin-top: 6px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   Case card nodes (mini-dossiers pinned to board)
   ========================================================================== */
.cb-card .cb-node-inner {
  width: 200px;
  padding: 12px 14px;
  background: #e8e4d4;
  color: #1a1a1a;
  font-family: 'Courier New', monospace;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 10px 18px rgba(0, 0, 0, 0.5);
  --rotation: -1deg;
  border-left: 4px solid #c42f3d;
}

.cb-card .cb-card-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #c42f3d;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.cb-card .cb-card-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  color: #1a1a1a;
}

.cb-card .cb-card-body {
  font-size: 11px;
  line-height: 1.45;
  color: #333;
}

/* ==========================================================================
   Text / Headline nodes (red marker on paper)
   ========================================================================== */
.cb-text-node .cb-node-inner {
  padding: 10px 16px;
  background: #f5efe0;
  color: #1a1a1a;
  font-family: 'Special Elite', 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  max-width: 260px;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    0 8px 14px rgba(0, 0, 0, 0.45);
  --rotation: -0.5deg;
  border: 1px dashed rgba(0, 0, 0, 0.2);
}

.cb-text-node .cb-text {
  outline: none;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  width: 100%;
  min-width: 140px;
  resize: none;
  overflow: hidden;
}

/* ==========================================================================
   Node controls (floating on hover)
   ========================================================================== */
.cb-node-controls {
  position: absolute;
  top: -36px;
  right: -4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  z-index: 10;
}

.cb-node:hover .cb-node-controls,
.cb-node.selected .cb-node-controls {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.cb-ctrl-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 18, 32, 0.92);
  border: 1px solid rgba(120, 170, 230, 0.3);
  color: var(--text-primary);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: all 0.15s;
}

.cb-ctrl-btn:hover {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

.cb-ctrl-btn.danger:hover {
  background: var(--status-critical);
  border-color: var(--status-critical);
}

.cb-ctrl-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ==========================================================================
   Toolbar (top-left floating tools)
   ========================================================================== */
.cb-toolbar {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 50;
}

.cb-tool-group {
  background: rgba(10, 18, 32, 0.92);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(10px);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.cb-tool {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.cb-tool:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.cb-tool.active {
  background: var(--accent-blue);
  color: white;
}

.cb-tool svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }

.cb-tool[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(10, 18, 32, 0.95);
  color: var(--text-primary);
  padding: 4px 10px;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  border: 1px solid var(--border-default);
  pointer-events: none;
  z-index: 100;
}

/* ==========================================================================
   Post-it color picker (submenu)
   ========================================================================== */
.cb-color-picker {
  position: absolute;
  left: 52px;
  background: rgba(10, 18, 32, 0.95);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(10px);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  z-index: 60;
}

.cb-color-picker.open { display: flex; }

.cb-color-swatch {
  width: 28px;
  height: 28px;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.15s, border-color 0.15s;
}

.cb-color-swatch:hover { transform: scale(1.1); border-color: var(--accent-cyan); }

/* ==========================================================================
   Top bar (info + zoom controls)
   ========================================================================== */
.cb-topbar {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 50;
}

.cb-info-chip {
  padding: 8px 14px;
  background: rgba(10, 18, 32, 0.92);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cb-info-chip .saved-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-low);
  transition: background 0.2s;
}

/* Presence indicator (other agents on this board) */
.cb-presence {
  padding: 8px 12px;
  background: rgba(74, 143, 224, 0.18);
  border: 1px solid var(--accent-cyan);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-cyan);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
  max-width: 240px;
}

.cb-presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5eff8a;
  box-shadow: 0 0 8px rgba(94, 255, 138, 0.8);
  flex-shrink: 0;
  animation: cbPresencePulse 2s ease-in-out infinite;
}

@keyframes cbPresencePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.cb-presence-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-info-chip .saved-dot.saving { background: var(--accent-gold); animation: cbSavingPulse 0.8s infinite; }
.cb-info-chip .saved-dot.error { background: var(--status-critical); }

@keyframes cbSavingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.cb-zoom-controls {
  display: flex;
  background: rgba(10, 18, 32, 0.92);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(10px);
}

.cb-zoom-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-mono);
  font-size: 14px;
}

.cb-zoom-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.cb-zoom-level {
  padding: 0 12px;
  display: flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  min-width: 56px;
  justify-content: center;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Empty-state hint
   ========================================================================== */
.cb-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(245, 242, 232, 0.3);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
  pointer-events: none;
  line-height: 2;
}

.cb-hint span { display: block; }
.cb-hint-large { font-size: 20px; letter-spacing: 6px; font-family: 'Rajdhani', sans-serif; font-weight: 700; margin-bottom: 8px; color: rgba(245, 242, 232, 0.4); }

/* Temporary preview line while linking */
.cb-link-preview {
  stroke: #ff5a6a;
  stroke-width: 2;
  stroke-dasharray: 6 5;
  fill: none;
  pointer-events: none;
  opacity: 0.8;
}

/* Link source highlight */
.cb-node.link-source .cb-node-inner {
  outline: 2px solid #c42f3d;
  outline-offset: 4px;
  animation: cbPulseLink 1s ease-in-out infinite;
}

/* Context-menu style override within the board (just in case) */
.crimeboard .context-menu { z-index: 3001; }
