/* ── Canvas viewport ──────────────────────────────────────────────────────── */
.canvas-viewport-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;
}

.canvas-viewport-wrap.panning { cursor: grabbing; }
.canvas-viewport-wrap.connecting { cursor: crosshair; }

.canvas-vp {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ── SVG connections layer (inside .canvas-vp) ───────────────────────────── */
.canvas-svg {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
}

.canvas-svg .edge-hit {
  stroke: transparent;
  stroke-width: 14;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

.canvas-svg .edge-line {
  fill: none;
  stroke: rgba(99, 102, 241, 0.25);
  stroke-width: 1.5;
  pointer-events: none;
  transition: stroke .15s;
}

.canvas-svg .edge-line.selected {
  stroke: var(--accent);
  stroke-width: 2;
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

.canvas-svg .edge-line.temp {
  stroke: var(--accent-h);
  stroke-width: 1.8;
  stroke-dasharray: 6 4;
  opacity: .9;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  position: absolute;
  border-radius: var(--radius-lg);
  background: rgba(12, 14, 28, 0.82);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow), 0 1px 0 rgba(255,255,255,0.05) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  user-select: none;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-lg), 0 1px 0 rgba(255,255,255,0.08) inset;
}

.card.selected {
  border-color: rgba(99, 102, 241, 0.55);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.18), var(--shadow-lg), var(--glow-sm);
}

.card.dragging {
  opacity: .92;
  box-shadow: var(--shadow-xl), 0 0 30px rgba(99,102,241,0.2);
  transform: scale(1.01);
  z-index: 9999 !important;
}

/* Card header */
.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 9px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: grab;
  flex-shrink: 0;
  background: rgba(255,255,255,0.02);
}
.card-header:active { cursor: grabbing; }

.card-header-icon {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.card-header-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-header-type {
  font-size: 10px;
  color: var(--text3);
  font-weight: 500;
  flex-shrink: 0;
  letter-spacing: .02em;
}

.card-header-menu {
  opacity: 0;
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: opacity .12s, background .12s;
  flex-shrink: 0;
}
.card:hover .card-header-menu { opacity: 1; }
.card-header-menu:hover { background: rgba(255,255,255,0.07); }

/* Card body */
.card-body {
  padding: 10px 12px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.card-body::-webkit-scrollbar { width: 3px; }
.card-body::-webkit-scrollbar-track { background: transparent; }
.card-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.card-row:last-child { margin-bottom: 0; }

/* Divider between sections inside card body */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* Reorder / purchase alert panel */
.card-reorder {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 6px;
}

.card-reorder.urgent {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
}

.card-reorder-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--yellow);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.card-reorder.urgent .card-reorder-title { color: var(--red); }

/* Delivery countdown */
.card-countdown {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--surface2);
  color: var(--text2);
}
.card-countdown.soon   { background: rgba(245,158,11,.15); color: var(--yellow); }
.card-countdown.late   { background: rgba(239,68,68,.15);  color: var(--red); }
.card-countdown.ok     { background: rgba(34,197,94,.12);  color: var(--green); }

/* Purchase order items list */
.card-items {
  margin-top: 6px;
}
.card-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  gap: 6px;
}
.card-item-row:last-child { border-bottom: none; }
.card-item-name {
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.card-item-qty {
  color: var(--text3);
  flex-shrink: 0;
}

.card-label {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

/* ── Logistics card (purchase_order) ─────────────────────────────────────── */
.logi-card {
  padding: 10px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Route strip */
.logi-route {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border-radius: 6px;
  padding: 8px 10px;
}
.logi-route-end {
  flex: 0 0 auto;
  max-width: 72px;
}
.logi-route-end.right { text-align: right; }
.logi-route-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-bottom: 2px;
}
.logi-route-dot.origin { background: var(--accent); box-shadow: 0 0 0 2px rgba(99,102,241,.25); }
.logi-route-dot.dest   { background: var(--green);  box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
.logi-route-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logi-route-date {
  font-size: 10px;
  color: var(--text3);
  margin-top: 1px;
}
.logi-route-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.logi-route-mode {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: .02em;
  white-space: nowrap;
}
.logi-route-arrow {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 2px;
}
.logi-route-track {
  flex: 1;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  overflow: hidden;
}
.logi-route-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 2px;
  transition: width .4s ease;
}
.logi-arrow-tip { color: var(--text3); flex-shrink: 0; }

/* Step tracker */
.logi-steps {
  display: flex;
  align-items: center;
}
.logi-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 0 0 auto;
}
.logi-step-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text3);
  transition: border-color .2s, background .2s;
}
.logi-step.done .logi-step-dot {
  border-color: var(--accent);
  background: rgba(99,102,241,.12);
  color: var(--accent);
}
.logi-step.current .logi-step-dot {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
.logi-step-label {
  font-size: 9px;
  color: var(--text3);
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
}
.logi-step.done .logi-step-label    { color: var(--accent); }
.logi-step.current .logi-step-label { color: var(--text); font-weight: 700; }
.logi-step-line {
  flex: 1;
  height: 2px;
  background: var(--border2);
  margin-bottom: 14px;
  min-width: 6px;
}
.logi-steps.cancelled .logi-step-dot { border-color: var(--red); }

/* Footer */
.logi-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.logi-total {
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  margin-left: auto;
}

/* Items list */
.logi-items { display: flex; flex-direction: column; gap: 1px; }
.logi-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.logi-item-row:last-child { border-bottom: none; }
.logi-item-name {
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.logi-item-qty { color: var(--text3); flex-shrink: 0; font-size: 10px; }

.card-value {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Card footer */
.card-footer {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Port handles (shown on hover) */
.card-ports {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.card-port {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  pointer-events: all;
  cursor: crosshair;
  opacity: 0;
  transition: opacity .12s, transform .12s;
}

.card:hover .card-port { opacity: 1; }
.card-port:hover { transform: translate(-50%, -50%) scale(1.4); }

/* Ports 5px inside each edge so overflow:hidden never clips the click target */
.card-port[data-port="top"]    { top: 5px;              left: 50%; }
.card-port[data-port="right"]  { top: 50%;              left: calc(100% - 5px); }
.card-port[data-port="bottom"] { top: calc(100% - 5px); left: 50%; }
.card-port[data-port="left"]   { top: 50%;              left: 5px; }

/* Resize handle */
.card-resize {
  position: absolute;
  bottom: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize;
  pointer-events: all;
  opacity: 0;
  transition: opacity .12s;
}
.card:hover .card-resize { opacity: 1; }
.card-resize:hover { opacity: 1 !important; }
.card-resize::after {
  content: '';
  position: absolute;
  bottom: 4px; right: 4px;
  width: 7px; height: 7px;
  border-right: 2px solid var(--text2);
  border-bottom: 2px solid var(--text2);
  border-radius: 0 0 2px 0;
}

/* Badges defined in components.css — keeping alias only */
.badge-gray { background: rgba(255,255,255,0.06); color: var(--text2); }

/* ── Flow card ────────────────────────────────────────────────────────────── */
.flow-body {
  padding: 0 !important;
  overflow: visible !important;
}
.flow-product-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  background: linear-gradient(135deg, rgba(14,165,233,.1) 0%, rgba(99,102,241,.08) 100%);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.flow-product-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.flow-supplier-tag {
  font-size: 10px;
  color: var(--text3);
  margin-top: 2px;
}
.flow-stock-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-lo);
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.flow-pipeline {
  display: flex;
  align-items: center;
  padding: 10px 8px 6px;
  gap: 0;
  overflow-x: auto;
}
.flow-pipeline::-webkit-scrollbar { display: none; }
.flow-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 44px;
}
.flow-node-bubble {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border2);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all .2s;
}
.flow-node.active .flow-node-bubble {
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.flow-node-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  line-height: 1;
}
.flow-node-label {
  font-size: 9px;
  color: var(--text3);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}
.flow-node-sep {
  flex: 0 0 10px;
  height: 1.5px;
  background: var(--border2);
  margin-top: -14px;
  align-self: center;
}
.flow-node-sep.active {
  background: linear-gradient(90deg, var(--accent), var(--green));
}
.flow-summary-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.flow-summary-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}
.flow-summary-label {
  color: var(--text3);
}
.flow-summary-sep {
  color: var(--border2);
}

/* ── Note card ────────────────────────────────────────────────────────────── */
.card.note {
  background: #2a2010;
  border-color: #4a3820;
}

.card.note .card-header {
  background: #f59e0b;
  border-bottom-color: #d97706;
}

.card.note .card-header-title { color: #1a0f00; }
.card.note .card-body { padding: 10px 12px; }
.card.note .note-content {
  font-size: 12px;
  color: #d4a654;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex: 1;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--green);
  transition: width .3s;
}

/* ── Selection box (rubber band) ─────────────────────────────────────────── */
.selection-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: var(--accent-lo);
  border-radius: 3px;
  pointer-events: none;
}

/* ── Context menu ────────────────────────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 4px;
  z-index: 1000;
  min-width: 160px;
  box-shadow: var(--shadow-lg);
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  transition: background .1s, color .1s;
}
.ctx-item:hover { background: var(--surface2); color: var(--text); }
.ctx-item.danger:hover { background: var(--red-lo); color: var(--red); }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 0; }

/* ── Sticky card ─────────────────────────────────────────────────────────── */
.card-sticky {
  background: var(--sticky-bg, #f59e0b) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-color: rgba(0,0,0,0.12) !important;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25), 0 2px 6px rgba(0,0,0,0.15) !important;
  min-width: 120px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
}
.card-sticky .card-ports { opacity: 0; }
.card-sticky:hover .card-ports { opacity: 1; }
.card-sticky .card-port { border-color: rgba(0,0,0,0.25); }
.card-sticky .card-resize::after { border-color: rgba(0,0,0,0.35); }

.sticky-body {
  flex: 1;
  padding: 14px;
  display: flex;
  align-items: flex-start;
  overflow: hidden;
}
.sticky-text {
  font-size: 14px;
  font-weight: 500;
  color: rgba(0,0,0,0.72);
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.55;
  width: 100%;
}
.sticky-textarea {
  width: 100%;
  height: 100%;
  min-height: 80px;
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-weight: 500;
  color: rgba(0,0,0,0.72);
  line-height: 1.55;
  font-family: inherit;
}

/* ── Embed card ──────────────────────────────────────────────────────────── */
.card-embed {
  overflow: hidden;
}
.card-embed .embed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: grab;
  flex-shrink: 0;
  background: rgba(255,255,255,0.02);
}
.embed-open-btn {
  font-size: 13px;
  color: var(--text3);
  text-decoration: none;
  transition: color .12s;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
}
.embed-open-btn:hover { color: var(--accent); background: var(--accent-lo); }
.embed-frame {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 120px;
}
.embed-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  pointer-events: none;
}
.card-embed:hover .embed-frame iframe { pointer-events: auto; }
.embed-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  min-height: 120px;
  color: var(--text3);
  font-size: 12px;
}
.embed-placeholder span:first-child { font-size: 32px; }

/* ── Folder card ─────────────────────────────────────────────────────────── */
.folder-stats {
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.folder-files {
  margin-bottom: 10px;
}
.folder-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 11px;
  color: var(--text2);
  overflow: hidden;
}
.folder-file-row span:first-child { font-size: 14px; flex-shrink: 0; }
.folder-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-file-size { color: var(--text3); flex-shrink: 0; }
.folder-empty {
  font-size: 11px;
  color: var(--text3);
  text-align: center;
  padding: 12px 0;
  margin-bottom: 8px;
}
.folder-open-btn {
  width: 100%;
  margin-top: 4px;
}

/* ── Card creation picker (Miro-style) ───────────────────────────────────── */
.card-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: transparent;
}

.card-picker {
  position: fixed;
  top: calc(var(--topbar-h) + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 13, 26, 0.97);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 16px;
  width: 520px;
  max-width: calc(100vw - 32px);
  z-index: 8001;
  animation: pickerIn .15s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pickerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.96); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.card-picker-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 10px;
}

.card-picker-section {
  margin-bottom: 14px;
}
.card-picker-section:last-child { margin-bottom: 0; }

.card-picker-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}

.card-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}

.card-picker-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s, transform .1s;
  text-align: center;
}
.card-picker-item:hover {
  background: var(--surface2);
  border-color: var(--border);
  transform: translateY(-1px);
}
.card-picker-item:active { transform: scale(.97); }

.card-picker-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.card-picker-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text2);
  line-height: 1.2;
}

/* ── Shape card ──────────────────────────────────────────────────────────── */
.card-shape {
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  overflow: visible;
}
.card-shape .card-ports { pointer-events: none; }
.card-shape .card-port  { pointer-events: all; }
.card-shape .card-resize { pointer-events: all; }

.shape-body {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: move;
}
.shape-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.shape-emoji {
  font-size: clamp(28px, 40%, 64px);
  line-height: 1;
  user-select: none;
}
.shape-label-overlay {
  position: absolute;
  bottom: 50%;
  transform: translateY(50%);
  left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shape-label {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  text-align: center;
  pointer-events: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shape-label-input {
  position: absolute;
  bottom: 4px;
  left: 8px; right: 8px;
  background: rgba(0,0,0,.6);
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  padding: 3px 6px;
  text-align: center;
  outline: none;
}
.card-shape.selected .shape-svg g {
  filter: drop-shadow(0 0 6px rgba(99,102,241,.6));
}

/* ── Shape library panel ─────────────────────────────────────────────────── */
.lib-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: transparent;
}
.lib-panel {
  position: fixed;
  top: calc(var(--topbar-h) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 640px;
  max-width: calc(100vw - 32px);
  background: rgba(11, 13, 26, 0.97);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: 8001;
  overflow: hidden;
  animation: pickerIn .15s cubic-bezier(.34,1.56,.64,1);
}
.lib-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.lib-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text3);
  flex-shrink: 0;
}
.lib-cats {
  display: flex;
  gap: 4px;
}
.lib-cat-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.lib-cat-btn:hover { background: var(--surface2); color: var(--text2); }
.lib-cat-btn.active { background: var(--accent-lo); color: var(--accent); border-color: rgba(99,102,241,.3); }

.lib-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.lib-palette {
  display: flex;
  gap: 5px;
  flex: 1;
  flex-wrap: wrap;
}
.lib-color {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .1s, border-color .1s;
  flex-shrink: 0;
}
.lib-color:hover  { transform: scale(1.2); }
.lib-color.active { border-color: var(--text); transform: scale(1.1); }

.lib-fill-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text3);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.lib-fill-toggle input { cursor: pointer; accent-color: var(--accent); }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  padding: 12px 16px 16px;
  max-height: 340px;
  overflow-y: auto;
}
.lib-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .1s, border-color .1s, transform .1s;
}
.lib-item:hover {
  background: var(--surface2);
  border-color: var(--border);
  transform: translateY(-1px);
}
.lib-item:active { transform: scale(.96); }
.lib-item-preview {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: visible;
  position: relative;
}
.lib-item-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text3);
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Purchase items form rows ────────────────────────────────────────────── */
.purchase-item-row {
  display: grid;
  grid-template-columns: 1fr 80px 70px 100px 36px;
  gap: 6px;
  align-items: center;
}
.purchase-items-btn {
  width: 100%;
  margin-top: 4px;
}

/* ── Upstream reference strip ────────────────────────────────────────────── */
.card-upstream-ref {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  margin: -2px -2px 6px -2px;
  background: rgba(255,255,255,0.04);
  border-left: 2px solid var(--uc, #f59e0b);
  border-radius: 0 4px 4px 0;
  font-size: 10px;
  color: var(--text3);
  overflow: hidden;
}
.card-upstream-ref span:first-child { font-size: 11px; flex-shrink: 0; }
.card-upstream-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text2);
  font-weight: 500;
}
.card-upstream-arrow { flex-shrink: 0; opacity: .5; }

/* ── Mini stage indicators (Compra) ──────────────────────────────────────── */
.card-stages {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 2px 0 4px;
}
.card-stage-dot {
  font-size: 10px;
  color: var(--text3);
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.card-stage-dot.done    { color: var(--text2); }
.card-stage-dot.current { background: var(--accent-lo); color: var(--accent); font-weight: 600; }
.card-stage-line {
  flex: 1;
  height: 1px;
  min-width: 8px;
  background: var(--border);
}
