/* ── Canvas viewport ──────────────────────────────────────────────────────── */
.canvas-viewport-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 28px 28px;
  background-color: var(--bg);
}

.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: #4b5680;
  stroke-width: 1.8;
  pointer-events: none;
}

.canvas-svg .edge-line.selected {
  stroke: var(--accent);
  stroke-width: 2;
}

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

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  position: absolute;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
  user-select: none;
}

.card:hover {
  border-color: var(--border2);
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-lo), var(--shadow);
}

.card.dragging {
  opacity: .9;
  box-shadow: var(--shadow-lg);
  z-index: 9999 !important;
}

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

.card-header-icon {
  width: 22px; height: 22px;
  border-radius: 5px;
  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;
}

.card-header-menu {
  opacity: 0;
  width: 22px; height: 22px;
  border-radius: 4px;
  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: var(--surface2); }

/* 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: var(--border2); 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;
}

/* ── Purchase Order — layout de transporte ────────────────────────────────── */
.po-card { padding: 0 !important; overflow: visible !important; }
.po-card .card-divider { margin: 6px 12px; }
.po-card > div:not(.po-route-header):not(.po-stages):not(.po-info-row):not(.card-divider) {
  padding-left: 12px;
  padding-right: 12px;
}

/* Cabeçalho de rota: origem → caminhão → destino */
.po-route-header {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 12px 6px;
  background: linear-gradient(180deg, rgba(14,165,233,.07) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
}
.po-route-origin, .po-route-dest {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 78px;
}
.po-route-dest { flex-direction: row-reverse; text-align: right; }
.po-route-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}
.po-route-dot.origin { background: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.2); }
.po-route-dot.dest   { background: var(--green);  box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.po-route-tag {
  font-size: 9px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1.2;
}
.po-route-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 64px;
}
.po-route-date {
  font-size: 10px;
  color: var(--text3);
  margin-top: 1px;
}
.po-route-middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
}
.po-route-mode {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: .02em;
}
.po-route-line-wrap {
  width: 100%;
  position: relative;
  height: 22px;
}
.po-route-line {
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  transform: translateY(-50%);
}
.po-route-progress {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--accent), #22c55e);
  border-radius: 2px;
  transition: width .4s ease;
}
.po-route-truck {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  line-height: 0;
  filter: drop-shadow(0 1px 3px rgba(99,102,241,.5));
  transition: left .4s ease;
}

/* Trilho de etapas */
.po-stages {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 6px 12px 8px;
  position: relative;
}
.po-stages-track {
  position: absolute;
  top: 15px;
  left: 24px; right: 24px;
  height: 2px;
  background: var(--border2);
  border-radius: 1px;
  z-index: 0;
}
.po-stages-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #22c55e);
  border-radius: 1px;
  transition: width .4s ease;
}
.po-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  z-index: 1;
  flex: 1;
}
.po-stage-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border2);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border2);
  transition: background .2s, box-shadow .2s;
}
.po-stage.done .po-stage-dot {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.po-stage.current .po-stage-dot {
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent), 0 0 6px rgba(99,102,241,.4);
  width: 10px; height: 10px;
}
.po-stage-label {
  font-size: 9px;
  color: var(--text3);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}
.po-stage.done .po-stage-label  { color: var(--accent); font-weight: 600; }
.po-stage.current .po-stage-label { color: var(--text); font-weight: 700; }
.po-stages.cancelado .po-stages-fill { background: var(--red); }
.po-stages.cancelado .po-stage-dot   { background: var(--border2); }

/* Linha de badges de info */
.po-info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 2px 12px 8px;
}
.po-total {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  margin-left: auto;
}
.po-items {
  padding: 0 12px 8px;
}

/* Itens reutilizados */
.po-bridge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  gap: 4px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.po-bridge-item:last-child { border-bottom: none; }
.po-bridge-item-name {
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.po-bridge-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); }

.card-port[data-port="top"]    { top: 0;   left: 50%; }
.card-port[data-port="right"]  { top: 50%; left: 100%; }
.card-port[data-port="bottom"] { top: 100%; left: 50%; }
.card-port[data-port="left"]   { top: 50%; left: 0; }

/* Resize handle */
.card-resize {
  position: absolute;
  bottom: 0; right: 0;
  width: 12px; height: 12px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity .12s;
}
.card:hover .card-resize { opacity: 1; }
.card-resize::after {
  content: '';
  position: absolute;
  bottom: 3px; right: 3px;
  width: 5px; height: 5px;
  border-right: 1.5px solid var(--text3);
  border-bottom: 1.5px solid var(--text3);
}

/* ── Badges / Status pills ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-green   { background: var(--green-lo);  color: var(--green);  }
.badge-yellow  { background: var(--yellow-lo); color: var(--yellow); }
.badge-red     { background: var(--red-lo);    color: var(--red);    }
.badge-blue    { background: var(--blue-lo);   color: var(--blue);   }
.badge-gray    { background: var(--surface2);  color: var(--text2);  }
.badge-accent  { background: var(--accent-lo); color: var(--accent); }

/* ── 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; }
