/* ==================== DASHBOARD DRAG-AND-DROP ==================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}
.dashboard-card-wrap {
  position: relative;
  isolation: isolate;
}
.dashboard-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  overflow: hidden;
  min-width: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, z-index 0.15s ease, opacity 0.15s ease;
}
.dashboard-card:active {
  cursor: grabbing;
}
.dashboard-card.is-dragging {
  opacity: 0.35;
  pointer-events: none;
  z-index: 50;
  box-shadow: var(--shadow-xl);
}
/* The dragged wrap stays in the grid as a live placeholder: other cards
   reflow around it while dragging, so the drop position is visible
   before release instead of guessed from a horizontal line. */
.dashboard-card-wrap.is-drag-source .dashboard-card {
  opacity: 0.35;
  border-style: dashed;
}
.dashboard-card.is-drag-over {
  border-color: var(--accent);
  background: var(--accent-weak);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}
.dashboard-ghost {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  min-height: 150px;
  padding: 16px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-xl);
  z-index: 100;
  pointer-events: none;
  opacity: 0.95;
  transform: translate(var(--gx, 0), var(--gy, 0));
  /* iOS lift: the dragged card floats slightly larger, separate from
     the translate that follows the pointer, so it does not lag. */
  scale: 1.06;
  transition: scale 180ms ease-out;
  will-change: transform;
}
.dashboard-grid.is-dragging .dashboard-card-wrap {
  will-change: transform;
}
.dashboard-drop-line {
  position: fixed;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  z-index: 95;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.dashboard-drop-line.is-show {
  opacity: 1;
}
.dashboard-drop-line.horizontal {
  width: 100%;
  left: 0;
}
.dashboard-drop-line.vertical {
  width: 100%;
  left: 0;
}
.dashboard-placeholder {
  visibility: hidden;
  pointer-events: none;
}

/* ===== Chú thích biểu đồ dòng lỗi (3 nút bật/tắt đường dữ liệu) ===== */
.chart-legend-wrap {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 6px;
}
.chart-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  min-height: 34px;
}
.chart-legend-item:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
}
.chart-legend-item.is-active {
  border-color: transparent;
  color: #fff;
}
.chart-legend-item.is-empty {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}
.chart-legend-item.is-empty:hover {
  border-color: var(--border);
  background: var(--card);
}
.chart-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.12);
}
.chart-legend-item.is-active .chart-legend-dot {
  box-shadow: 0 0 0 1.5px #fff;
}
.chart-legend-label {
  white-space: nowrap;
}
.chart-legend-state {
  font-size: 10.5px;
  font-weight: 700;
  opacity: 0.85;
  white-space: nowrap;
}
.chart-legend-item.is-active .chart-legend-state { opacity: 1; }

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .dashboard-ghost {
    width: 100%;
    max-width: none;
  }
}

/* Resize handles for dashboard cards */
.dashboard-card.is-resizable {
  position: relative;
}
.dashboard-card.is-resizable::after {
  content: '';
  position: absolute;
  inset: 0;
  cursor: default;
  z-index: 1;
  pointer-events: none;
}
.dashboard-resize-handle {
  position: absolute;
  z-index: 2;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease, background-color 0.15s ease;
  box-sizing: border-box;
}
.dashboard-card:hover .dashboard-resize-handle { opacity: 0.55; }
.dashboard-card.is-resizing .dashboard-resize-handle { opacity: 0.9; }
.dashboard-resize-handle.e { right: 0; top: 0; bottom: 0; width: 12px; cursor: ew-resize; }
.dashboard-resize-handle.s { bottom: 0; left: 0; right: 0; height: 12px; cursor: ns-resize; }
.dashboard-resize-handle.se { right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; border-radius: 0 0 6px 0; }
.dashboard-resize-handle.e:hover, .dashboard-resize-handle.s:hover, .dashboard-resize-handle.se:hover {
  opacity: 1;
  background-color: var(--accent);
}
.dashboard-card.is-resizing {
  cursor: default !important;
  z-index: 60;
}
.dashboard-card.is-resizing .dashboard-resize-handle { cursor: default; }
